|
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,13 +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_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) |
49 | 55 |
|
50 | 56 | __all__ = ['Image', 'ImageColor', 'ImageChops', 'ImageEnhance', 'ImageFile', |
51 | 57 | 'ImageFilter', 'ImageDraw', 'ImageStat', 'StringIO', 'NullHandler', |
|
0 commit comments