Commits

Andriy Kornatskyy committed 6f5e9e0

Added support for python3 via integration with pillow.

Comments (0)

Files changed (10)

 		python-sphinx gettext libfreetype6-dev libjpeg8-dev
 
 env:
-	# The following packages available for python < 3.0
-	if [ "$$(echo $(VERSION) | sed 's/\.//')" -lt 30 ]; then \
-		PYTHON_EXE=/usr/local/bin/python$(VERSION); \
-		if [ ! -x $$PYTHON_EXE ]; then \
-			PYTHON_EXE=/usr/bin/python$(VERSION); \
-		fi;\
-		VIRTUALENV_USE_SETUPTOOLS=1; \
-		export VIRTUALENV_USE_SETUPTOOLS; \
-		virtualenv --python=$$PYTHON_EXE \
-			--no-site-packages env; \
-		if [ "$$(echo $(VERSION) | sed 's/\.//')" -ge 30 ]; then \
-			echo -n 'Upgrading distribute...'; \
-			$(EASY_INSTALL) -i $(PYPI) -U -O2 distribute \
-				> /dev/null 2>/dev/null; \
-			echo 'done.'; \
-		fi; \
-		$(EASY_INSTALL) -i $(PYPI) -O2 coverage nose pytest \
-			pytest-pep8 pytest-cov wheezy.caching wheezy.http; \
-		$(PYTHON) setup.py develop -i $(PYPI); \
-	fi;
+	PYTHON_EXE=/usr/local/bin/python$(VERSION); \
+	if [ ! -x $$PYTHON_EXE ]; then \
+		PYTHON_EXE=/usr/bin/python$(VERSION); \
+	fi;\
+	VIRTUALENV_USE_SETUPTOOLS=1; \
+	export VIRTUALENV_USE_SETUPTOOLS; \
+	virtualenv --python=$$PYTHON_EXE \
+		--no-site-packages env; \
+	if [ "$$(echo $(VERSION) | sed 's/\.//')" -ge 30 ]; then \
+		echo -n 'Upgrading distribute...'; \
+		$(EASY_INSTALL) -i $(PYPI) -U -O2 distribute \
+			> /dev/null 2>/dev/null; \
+		echo 'done.'; \
+	fi; \
+	$(EASY_INSTALL) -i $(PYPI) -O2 coverage nose pytest \
+		pytest-pep8 pytest-cov wheezy.caching wheezy.http; \
+	$(PYTHON) setup.py develop -i $(PYPI); \
 
 clean:
 	find src/ -type d -name __pycache__ | xargs rm -rf
 `wheezy.captcha`_ is a `python`_ package written in pure Python
-code. It is a lightweight captcha library that provides integration with:
+code. It is a lightweight captcha library that provides integration
+with (one of below must be installed):
 
 * `PIL`_ - Python Imaging Library 1.1.7.
+* `Pillow`_ - Python Imaging Library (fork).
 
 It is optimized for performance, well tested and documented.
 
 Install
 -------
 
-`wheezy.captcha`_ requires `python`_ version 2.4 to 2.7 or 3.2 (as soon as
-`PIL`_ support released).
+`wheezy.captcha`_ requires `python`_ version 2.4 to 2.7 or 3.2+.
 It is independent of operating system. You can install it from `pypi`_
-site using `setuptools`_::
+site using `setuptools`_ (you need specify extra requirements per
+imaging library of your choice)::
 
     $ easy_install wheezy.captcha
+    $ easy_install wheezy.captcha[PIL]
+    $ easy_install wheezy.captcha[Pillow]
 
 If you are using `virtualenv`_::
 
 .. _`examples`: http://bitbucket.org/akorn/wheezy.captcha/src/tip/demos
 .. _`issues`: http://bitbucket.org/akorn/wheezy.captcha/issues
 .. _`pil`: http://www.pythonware.com/products/pil/
+.. _`pillow`: https://pypi.python.org/pypi/Pillow
 .. _`pypi`: http://pypi.python.org
 .. _`python`: http://www.python.org
 .. _`readthedocs`: http://readthedocs.org/builds/wheezycaptcha

doc/gettingstarted.rst

 Install
 -------
 
-:ref:`wheezy.captcha` requires `python`_ version 2.4 to 2.7 or 3.2.
+:ref:`wheezy.captcha` requires `python`_ version 2.4 to 2.7 or 3.2+.
 It is independent of operating system. You can install it from `pypi`_
-site using `setuptools`_::
+site using `setuptools`_ (you need specify extra requirements per
+imaging library of your choice)::
 
     $ easy_install wheezy.captcha
+    $ easy_install wheezy.captcha[PIL]
+    $ easy_install wheezy.captcha[Pillow]
 
 If you are using `virtualenv`_::
 
 ------------
 
 :ref:`wheezy.captcha` is a `python`_ package written in pure Python code.
-It is a lightweight captcha library that provides integration with:
+It is a lightweight captcha library that provides integration
+with (one of below must be installed):
 
 * `PIL`_ - Python Imaging Library 1.1.7.
+* `Pillow`_ - Python Imaging Library (fork).
 
 It is optimized for performance, well tested and documented.
 
 .. _`examples`: http://bitbucket.org/akorn/wheezy.captcha/src/tip/demos
 .. _`issues`: http://bitbucket.org/akorn/wheezy.captcha/issues
 .. _`pil`: http://www.pythonware.com/products/pil/
+.. _`pillow`: https://pypi.python.org/pypi/Pillow
 .. _`pypi`: http://pypi.python.org
 .. _`python`: http://www.python.org
 .. _`readthedocs`: http://readthedocs.org/builds/wheezycaptcha
 wheezy.caching
 --------------
 
-.. automodule:: wheezy.caching
+.. automodule:: wheezy.captcha
    :members:
 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 
-#: src/wheezy/captcha/http.py:86 src/wheezy/captcha/http.py:95
+#: src/wheezy/captcha/http.py:86 src/wheezy/captcha/http.py:87
+#: src/wheezy/captcha/http.py:95
 msgid "The challenge code is not available."
 msgstr "The challenge code is not available."
 
-#: src/wheezy/captcha/http.py:90 src/wheezy/captcha/http.py:99
+#: src/wheezy/captcha/http.py:90 src/wheezy/captcha/http.py:91
+#: src/wheezy/captcha/http.py:99
 msgid "The turing number is not available."
 msgstr "The turing number is not available."
 
-#: src/wheezy/captcha/http.py:96 src/wheezy/captcha/http.py:105
+#: src/wheezy/captcha/http.py:96 src/wheezy/captcha/http.py:97
+#: src/wheezy/captcha/http.py:105
 msgid "The challenge code is invalid."
 msgstr "The challenge code is invalid."
 
-#: src/wheezy/captcha/http.py:101 src/wheezy/captcha/http.py:110
+#: src/wheezy/captcha/http.py:101 src/wheezy/captcha/http.py:102
+#: src/wheezy/captcha/http.py:110
 msgid "The turing number is invalid."
 msgstr "The turing number is invalid."
 
-#: src/wheezy/captcha/http.py:108 src/wheezy/captcha/http.py:120
+#: src/wheezy/captcha/http.py:108 src/wheezy/captcha/http.py:109
+#: src/wheezy/captcha/http.py:120
 #, python-format
 msgid "The code you typed has expired after %d seconds."
 msgstr "The code you typed has expired after %d seconds."
 
-#: src/wheezy/captcha/http.py:115 src/wheezy/captcha/http.py:129
+#: src/wheezy/captcha/http.py:115 src/wheezy/captcha/http.py:116
+#: src/wheezy/captcha/http.py:129
 #, python-format
 msgid "The code was typed too quickly. Wait at least %d seconds."
 msgstr "The code was typed too quickly. Wait at least %d seconds."
 
-#: src/wheezy/captcha/http.py:120 src/wheezy/captcha/http.py:134
+#: src/wheezy/captcha/http.py:120 src/wheezy/captcha/http.py:121
+#: src/wheezy/captcha/http.py:134
 msgid "The code you typed has no match."
 msgstr "The code you typed has no match."
 

i18n/en/LC_MESSAGES/captcha.po

 "Content-Type: text/plain; charset=UTF-8\n"
 "Content-Transfer-Encoding: 8bit\n"
 
-#: src/wheezy/captcha/http.py:86 src/wheezy/captcha/http.py:95
+#: src/wheezy/captcha/http.py:86 src/wheezy/captcha/http.py:87
+#: src/wheezy/captcha/http.py:95
 msgid "The challenge code is not available."
 msgstr "The challenge code is not available."
 
-#: src/wheezy/captcha/http.py:90 src/wheezy/captcha/http.py:99
+#: src/wheezy/captcha/http.py:90 src/wheezy/captcha/http.py:91
+#: src/wheezy/captcha/http.py:99
 msgid "The turing number is not available."
 msgstr "The turing number is not available."
 
-#: src/wheezy/captcha/http.py:96 src/wheezy/captcha/http.py:105
+#: src/wheezy/captcha/http.py:96 src/wheezy/captcha/http.py:97
+#: src/wheezy/captcha/http.py:105
 msgid "The challenge code is invalid."
 msgstr "The challenge code is invalid."
 
-#: src/wheezy/captcha/http.py:101 src/wheezy/captcha/http.py:110
+#: src/wheezy/captcha/http.py:101 src/wheezy/captcha/http.py:102
+#: src/wheezy/captcha/http.py:110
 msgid "The turing number is invalid."
 msgstr "The turing number is invalid."
 
-#: src/wheezy/captcha/http.py:108 src/wheezy/captcha/http.py:120
+#: src/wheezy/captcha/http.py:108 src/wheezy/captcha/http.py:109
+#: src/wheezy/captcha/http.py:120
 #, python-format
 msgid "The code you typed has expired after %d seconds."
 msgstr "The code you typed has expired after %d seconds."
 
-#: src/wheezy/captcha/http.py:115 src/wheezy/captcha/http.py:129
+#: src/wheezy/captcha/http.py:115 src/wheezy/captcha/http.py:116
+#: src/wheezy/captcha/http.py:129
 #, python-format
 msgid "The code was typed too quickly. Wait at least %d seconds."
 msgstr "The code was typed too quickly. Wait at least %d seconds."
 
-#: src/wheezy/captcha/http.py:120 src/wheezy/captcha/http.py:134
+#: src/wheezy/captcha/http.py:120 src/wheezy/captcha/http.py:121
+#: src/wheezy/captcha/http.py:134
 msgid "The code you typed has no match."
 msgstr "The code you typed has no match."
 
 README = open(os.path.join(os.path.dirname(__file__), 'README.rst')).read()
 
 install_requires = [
-    'PIL>=1.1.7'
 ]
 
 try:
         'Programming Language :: Python :: 2.5',
         'Programming Language :: Python :: 2.6',
         'Programming Language :: Python :: 2.7',
-        #'Programming Language :: Python :: 3',
-        #'Programming Language :: Python :: 3.2',
+        'Programming Language :: Python :: 3',
+        'Programming Language :: Python :: 3.2',
+        'Programming Language :: Python :: 3.3',
         'Programming Language :: Python :: Implementation :: CPython',
         'Programming Language :: Python :: Implementation :: PyPy',
         'Topic :: Internet :: WWW/HTTP',
     zip_safe=False,
     install_requires=install_requires,
     extras_require={
+        'PIL': [
+            'PIL'
+        ],
+        'Pillow': [
+            'Pillow'
+        ],
         'dev': [
             'coverage',
             'nose',

src/wheezy/captcha/comp.py

+""" ``comp`` module.
+"""
+
+import sys
+
+
+PY3 = sys.version_info[0] >= 3
+
+
+if PY3:  # pragma: nocover
+    xrange = range
+else:  # pragma: nocover
+    xrange = xrange
+
+try:  # pragma: nocover
+    from PIL import Image
+    from PIL import ImageFilter
+    from PIL.ImageColor import getrgb
+    from PIL.ImageDraw import Draw
+    from PIL.ImageFont import truetype
+except ImportError:  # pragma: nocover
+    import Image  # noqa
+    import ImageFilter  # noqa
+    from ImageColor import getrgb  # noqa
+    from ImageDraw import Draw  # noqa
+    from ImageFont import truetype  # noqa

src/wheezy/captcha/image.py

 """
 
 import random
-import Image
-import ImageFilter
 
-from ImageColor import getrgb
-from ImageDraw import Draw
-from ImageFont import truetype
+from wheezy.captcha.comp import Draw
+from wheezy.captcha.comp import Image
+from wheezy.captcha.comp import ImageFilter
+from wheezy.captcha.comp import getrgb
+from wheezy.captcha.comp import truetype
+from wheezy.captcha.comp import xrange
 
 
 def captcha(drawings, width=200, height=75):
             c_width, c_height = char_image.size
             mask = char_image.convert('L').point(lambda i: i * 1.97)
             image.paste(char_image,
-                        (offset, (height - c_height) / 2),
+                        (offset, int((height - c_height) / 2)),
                         mask)
             offset += int(c_width * squeeze_factor)
         return image