Skip to content

Commit 8a9b076

Browse files
committed
Merge PR #534 from jaap3:patch-1
force_text and smart_text were deprecated in Django 3.0 and are removed in Django 4.0
2 parents 7cbc71d + 3bb1c3b commit 8a9b076

File tree

8 files changed

+37
-12
lines changed

8 files changed

+37
-12
lines changed

.github/workflows/python.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
strategy:
1414
max-parallel: 4
1515
matrix:
16-
python-version: ['3.6', '3.7', '3.8', '3.9', '3.10']
16+
python-version: ['2.7', '3.6', '3.7', '3.8', '3.9', '3.10']
1717

1818
steps:
1919
- uses: actions/checkout@v2

imagekit/lib.py

Lines changed: 13 additions & 7 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,13 +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_text, force_bytes, smart_text
44-
except ImportError:
45-
# Django < 1.5
46-
from django.utils.encoding import (force_unicode as force_text,
47-
smart_str as force_bytes,
48-
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)
4955

5056
__all__ = ['Image', 'ImageColor', 'ImageChops', 'ImageEnhance', 'ImageFile',
5157
'ImageFilter', 'ImageDraw', 'ImageStat', 'StringIO', 'NullHandler',

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,8 @@ def exec_file(filepath, globalz=None, localz=None):
4545
zip_safe=False,
4646
include_package_data=True,
4747
install_requires=[
48-
'django-appconf>=0.5',
48+
"django-appconf>=0.5,<1.0.4; python_version<'3'",
49+
"django-appconf; python_version>'3'",
4950
'pilkit>=0.2.0',
5051
'six',
5152
],

test-requirements.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Test requirements
2+
mock; python_version<'3'
23
beautifulsoup4
34
Pillow
45
pytest

tests/test_cachefiles.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,10 @@
11
import pytest
22

3-
from unittest import mock
3+
try:
4+
from unittest import mock
5+
except ImportError:
6+
import mock
7+
48
from django.conf import settings
59
from hashlib import md5
610
from imagekit.cachefiles import ImageCacheFile, LazyImageCacheFile

tests/test_no_extra_queries.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,8 @@
1-
from unittest.mock import Mock, PropertyMock, patch
1+
try:
2+
from unittest.mock import Mock, PropertyMock, patch
3+
except:
4+
from mock import Mock, PropertyMock, patch
5+
26
from .models import Photo
37

48

tests/test_optimistic_strategy.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
from imagekit.cachefiles import ImageCacheFile
2-
from unittest.mock import Mock
2+
3+
try:
4+
from unittest.mock import Mock
5+
except:
6+
from mock import Mock
7+
38
from .utils import create_image
49
from django.core.files.storage import FileSystemStorage
510
from imagekit.cachefiles.backends import Simple as SimpleCFBackend

tox.ini

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
[tox]
22
envlist =
3+
py27-django{111,18}
34
py{36,37,38,39,310}-django{22,31,32},
45
py310-djangomain,
56
coverage-report
67

78
[gh-actions]
89
python =
10+
2.7: py27
911
3.6: py36
1012
3.7: py37
1113
3.8: py38
@@ -15,6 +17,8 @@ python =
1517
[testenv]
1618
deps =
1719
-r test-requirements.txt
20+
django18: django~=1.8.0
21+
django111: django~=1.11.0
1822
django22: django~=2.2.0
1923
django31: django~=3.1.0
2024
django32: django~=3.2.0

0 commit comments

Comments
 (0)