Skip to content

Commit 3bb1c3b

Browse files
committed
Fix python 2 compatibility
1 parent 6dd0a9a commit 3bb1c3b

File tree

2 files changed

+15
-10
lines changed

2 files changed

+15
-10
lines changed

imagekit/lib.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# flake8: noqa
2+
import sys
23

34
# Required PIL classes may or may not be available from the root namespace
45
# depending on the installation method used.
@@ -39,15 +40,18 @@ def emit(self, record):
3940
# This function will replace `unicode` used in the code
4041
# If Django version is under 1.5 then use `force_unicde`
4142
# It is used for compatibility between Python 2 and Python 3
42-
try:
43-
from django.utils.encoding import (force_str as force_text,
44-
force_bytes,
45-
smart_str as smart_text)
46-
except ImportError:
47-
# Django < 1.5
48-
from django.utils.encoding import (force_unicode as force_text,
49-
smart_str as force_bytes,
50-
smart_unicode as smart_text)
43+
if sys.version_info >= (3, 0):
44+
from django.utils.encoding import (force_bytes,
45+
force_str as force_text,
46+
smart_str as smart_text)
47+
else:
48+
try:
49+
from django.utils.encoding import force_text, force_bytes, smart_text
50+
except ImportError:
51+
# Django < 1.5
52+
from django.utils.encoding import (force_unicode as force_text,
53+
smart_str as force_bytes,
54+
smart_unicode as smart_text)
5155

5256
__all__ = ['Image', 'ImageColor', 'ImageChops', 'ImageEnhance', 'ImageFile',
5357
'ImageFilter', 'ImageDraw', 'ImageStat', 'StringIO', 'NullHandler',

tox.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tox]
22
envlist =
3-
py27-django111
3+
py27-django{111,18}
44
py{36,37,38,39,310}-django{22,31,32},
55
py310-djangomain,
66
coverage-report
@@ -17,6 +17,7 @@ python =
1717
[testenv]
1818
deps =
1919
-r test-requirements.txt
20+
django18: django~=1.8.0
2021
django111: django~=1.11.0
2122
django22: django~=2.2.0
2223
django31: django~=3.1.0

0 commit comments

Comments
 (0)