2
2
The `compat` module provides support for backwards compatibility with older
3
3
versions of Django/Python, and compatibility wrappers around optional packages.
4
4
"""
5
-
6
- from __future__ import unicode_literals
7
-
8
5
import sys
6
+ from collections .abc import Mapping , MutableMapping # noqa
9
7
10
8
from django .conf import settings
11
9
from django .core import validators
12
- from django .utils import six
13
10
from django .views .generic import View
14
11
15
- try :
16
- # Python 3
17
- from collections .abc import Mapping , MutableMapping # noqa
18
- except ImportError :
19
- # Python 2.7
20
- from collections import Mapping , MutableMapping # noqa
21
-
22
12
try :
23
13
from django .urls import ( # noqa
24
14
URLPattern ,
36
26
except ImportError :
37
27
ProhibitNullCharactersValidator = None
38
28
39
- try :
40
- from unittest import mock
41
- except ImportError :
42
- mock = None
43
-
44
29
45
30
def get_original_route (urlpattern ):
46
31
"""
@@ -89,23 +74,6 @@ def make_url_resolver(regex, urlpatterns):
89
74
return URLResolver (regex , urlpatterns )
90
75
91
76
92
- def unicode_repr (instance ):
93
- # Get the repr of an instance, but ensure it is a unicode string
94
- # on both python 3 (already the case) and 2 (not the case).
95
- if six .PY2 :
96
- return repr (instance ).decode ('utf-8' )
97
- return repr (instance )
98
-
99
-
100
- def unicode_to_repr (value ):
101
- # Coerce a unicode string to the correct repr return type, depending on
102
- # the Python version. We wrap all our `__repr__` implementations with
103
- # this and then use unicode throughout internally.
104
- if six .PY2 :
105
- return value .encode ('utf-8' )
106
- return value
107
-
108
-
109
77
def unicode_http_header (value ):
110
78
# Coerce HTTP header value to unicode.
111
79
if isinstance (value , bytes ):
@@ -168,15 +136,6 @@ def is_guardian_installed():
168
136
"""
169
137
django-guardian is optional and only imported if in INSTALLED_APPS.
170
138
"""
171
- try :
172
- import guardian
173
- except ImportError :
174
- guardian = None
175
-
176
- if six .PY2 and (not guardian or guardian .VERSION >= (1 , 5 )):
177
- # Guardian 1.5.0, for Django 2.2 is NOT compatible with Python 2.7.
178
- # Remove when dropping PY2.
179
- return False
180
139
return 'guardian' in settings .INSTALLED_APPS
181
140
182
141
@@ -289,17 +248,12 @@ def md_filter_add_syntax_highlight(md):
289
248
290
249
# `separators` argument to `json.dumps()` differs between 2.x and 3.x
291
250
# See: https://bugs.python.org/issue22767
292
- if six .PY3 :
293
- SHORT_SEPARATORS = (',' , ':' )
294
- LONG_SEPARATORS = (', ' , ': ' )
295
- INDENT_SEPARATORS = (',' , ': ' )
296
- else :
297
- SHORT_SEPARATORS = (b',' , b':' )
298
- LONG_SEPARATORS = (b', ' , b': ' )
299
- INDENT_SEPARATORS = (b',' , b': ' )
251
+ SHORT_SEPARATORS = (',' , ':' )
252
+ LONG_SEPARATORS = (', ' , ': ' )
253
+ INDENT_SEPARATORS = (',' , ': ' )
300
254
301
255
302
- class CustomValidatorMessage ( object ) :
256
+ class CustomValidatorMessage :
303
257
"""
304
258
We need to avoid evaluation of `lazy` translated `message` in `django.core.validators.BaseValidator.__init__`.
305
259
https://github.com/django/django/blob/75ed5900321d170debef4ac452b8b3cf8a1c2384/django/core/validators.py#L297
@@ -309,7 +263,7 @@ class CustomValidatorMessage(object):
309
263
310
264
def __init__ (self , * args , ** kwargs ):
311
265
self .message = kwargs .pop ('message' , self .message )
312
- super (CustomValidatorMessage , self ).__init__ (* args , ** kwargs )
266
+ super ().__init__ (* args , ** kwargs )
313
267
314
268
315
269
class MinValueValidator (CustomValidatorMessage , validators .MinValueValidator ):
0 commit comments