diff --git a/.travis.yml b/.travis.yml index 9807bea..27cdd88 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,5 @@ language: python python: - - "2.6" - "2.7" - "3.3" - "3.4" diff --git a/README.rst b/README.rst index 9237124..ce80c78 100644 --- a/README.rst +++ b/README.rst @@ -6,12 +6,19 @@ Real-time captcha-to-text decodings :target: https://travis-ci.org/gotlium/antigate .. image:: https://coveralls.io/repos/gotlium/antigate/badge.png?branch=master :target: https://coveralls.io/r/gotlium/antigate?branch=master -.. image:: https://pypip.in/v/antigate/badge.png +.. image:: https://img.shields.io/badge/python-2.6,2.7,3.3,3.4-blue.svg + :alt: Python 2.6, 2.7, 3.3, 3.4 + :target: https://pypi.python.org/pypi/antigate/ +.. image:: https://img.shields.io/pypi/v/antigate.svg :alt: Current version on PyPi :target: https://crate.io/packages/antigate/ -.. image:: https://pypip.in/d/antigate/badge.png +.. image:: https://img.shields.io/pypi/dm/antigate.svg :alt: Downloads from PyPi :target: https://crate.io/packages/antigate/ +.. image:: https://img.shields.io/badge/license-GPLv2-green.svg + :target: https://pypi.python.org/pypi/antigate/ + :alt: License + Documentation available at `Read the Docs `_. @@ -118,7 +125,7 @@ Get results for multiple ids: Compatibility: ------------- -* Python: 2.6, 2.7, 3.3 +* Python: 2.6, 2.7, 3.3, 3.4 .. image:: https://d2weczhvl823v0.cloudfront.net/gotlium/antigate/trend.png diff --git a/antigate/__init__.py b/antigate/__init__.py index 38fbdc3..83dda9e 100644 --- a/antigate/__init__.py +++ b/antigate/__init__.py @@ -29,10 +29,7 @@ class AntiGate(object): def __init__(self, key, captcha_file='', auto_run=True, grab_config=None, send_config=None, domain='antigate.com', binary=False): - self.g = Grab() - self.g.setup(timeout=30) - if grab_config: - self.g.setup(**grab_config) + self.g = Grab(**(grab_config or {})) self.key = key self.captcha_id = None self.captcha_key = None @@ -97,6 +94,8 @@ def _go(self, url, err): def _send(self, captcha_file, binary=False): if binary: body = base64.b64encode(captcha_file) + if six.PY3: + body = body.decode('utf-8') self.g.setup(post=self._update_params( {'method': 'base64', 'key': self.key, 'body': body}, self.send_config @@ -144,6 +143,8 @@ def get(self, captcha_id=None): def _get_multi(self, ids): self._go(self._get_build_url(data={ 'ids': ','.join(map(str, ids))}), 'Can not get result') + if six.PY3: + return self.g.response.body.decode('utf-8').split('|') return self.g.response.body.split('|') def get_multi(self, ids): diff --git a/requirements/package.txt b/requirements/package.txt index 3dacdb2..d5ee891 100644 --- a/requirements/package.txt +++ b/requirements/package.txt @@ -1,5 +1,5 @@ -grab==0.4.13 -lxml==3.2.4 -pycurl==7.19.0.2 -xmltodict==0.8.3 +grab==0.6.21 +lxml==3.4.4 +pycurl==7.19.5.1 +xmltodict==0.9.2 six==1.9.0 diff --git a/requirements/tests.txt b/requirements/tests.txt index 1e7ec84..3aca8f7 100644 --- a/requirements/tests.txt +++ b/requirements/tests.txt @@ -1,3 +1,3 @@ -flake8==2.1.0 +flake8==2.4.1 coverage==3.7 coveralls==0.3 diff --git a/test_cases.py b/test_cases.py index bbdf8e3..aa6ceb7 100644 --- a/test_cases.py +++ b/test_cases.py @@ -1,5 +1,4 @@ import unittest -import os from antigate import AntiGate @@ -22,8 +21,10 @@ def test_base(self): self.assertEqual(str(AntiGate(API_KEY, IMAGE1)), '123') def test_base_binary(self): + fp = open(IMAGE1, 'rb') self.assertEqual(str(AntiGate( - API_KEY, open(IMAGE1, 'rb').read(), binary=True)), '123') + API_KEY, fp.read(), binary=True)), '123') + fp.close() def test_abuse(self): gate = AntiGate(API_KEY, IMAGE1) @@ -41,9 +42,10 @@ def test_manual(self): def test_manual_binary(self): gate = AntiGate(API_KEY, auto_run=False) - - captcha_id = gate.send(open(IMAGE1, 'rb').read(), binary=True) + fp = open(IMAGE1, 'rb') + captcha_id = gate.send(fp.read(), binary=True) self.assertTrue(str(captcha_id).isdigit()) + fp.close() captcha_value = gate.get(captcha_id) self.assertEqual(str(captcha_value), '123') @@ -61,8 +63,12 @@ def test_multiple(self): def test_multiple_binary(self): gate = AntiGate(API_KEY, auto_run=False) - captcha_id1 = gate.send(open(IMAGE1, 'rb').read(), binary=True) - captcha_id2 = gate.send(open(IMAGE2, 'rb').read(), binary=True) + fp1 = open(IMAGE1, 'rb') + fp2 = open(IMAGE2, 'rb') + captcha_id1 = gate.send(fp1.read(), binary=True) + captcha_id2 = gate.send(fp2.read(), binary=True) + fp1.close() + fp2.close() self.assertTrue(str(captcha_id1).isdigit()) self.assertTrue(str(captcha_id2).isdigit()) diff --git a/tox.ini b/tox.ini index 2e288bd..55bb237 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,9 @@ [tox] envlist = - py33, + pep8, + py27, + py34, + coverage, [testenv] usedevelop = True @@ -13,25 +16,22 @@ commands = [testenv:pep8] deps = - flake8==2.1.0 + flake8==2.4.1 commands = flake8 antigate [testenv:coverage] deps = - coverage==3.7 + coverage==3.7.1 commands = coverage run --branch --source=antigate test_cases.py coverage report --omit="antigate/test*" -[testenv:pypy] -basepython = pypy - -[testenv:py26] -basepython = python2.6 - [testenv:py27] basepython = python2.7 [testenv:py33] basepython = python3.3 + +[testenv:py34] +basepython = python3.4