|
1 | 1 | # flake8: noqa
|
| 2 | +import sys |
2 | 3 |
|
3 | 4 | # Required PIL classes may or may not be available from the root namespace
|
4 | 5 | # depending on the installation method used.
|
@@ -39,15 +40,18 @@ def emit(self, record):
|
39 | 40 | # This function will replace `unicode` used in the code
|
40 | 41 | # If Django version is under 1.5 then use `force_unicde`
|
41 | 42 | # 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) |
51 | 55 |
|
52 | 56 | __all__ = ['Image', 'ImageColor', 'ImageChops', 'ImageEnhance', 'ImageFile',
|
53 | 57 | 'ImageFilter', 'ImageDraw', 'ImageStat', 'StringIO', 'NullHandler',
|
|
0 commit comments