49
49
except ImportError :
50
50
django_filters = None
51
51
52
-
53
52
if django .VERSION >= (1 , 6 ):
54
53
def clean_manytomany_helptext (text ):
55
54
return text
@@ -104,14 +103,6 @@ def get_model_name(model_cls):
104
103
return model_cls ._meta .module_name
105
104
106
105
107
- def get_concrete_model (model_cls ):
108
- try :
109
- return model_cls ._meta .concrete_model
110
- except AttributeError :
111
- # 1.3 does not include concrete model
112
- return model_cls
113
-
114
-
115
106
# View._allowed_methods only present from 1.5 onwards
116
107
if django .VERSION >= (1 , 5 ):
117
108
from django .views .generic import View
@@ -123,7 +114,6 @@ def _allowed_methods(self):
123
114
return [m .upper () for m in self .http_method_names if hasattr (self , m )]
124
115
125
116
126
-
127
117
# MinValueValidator, MaxValueValidator et al. only accept `message` in 1.8+
128
118
if django .VERSION >= (1 , 8 ):
129
119
from django .core .validators import MinValueValidator , MaxValueValidator
@@ -187,28 +177,30 @@ def __init__(self, *args, **kwargs):
187
177
# RequestFactory only provides `generic` from 1.5 onwards
188
178
from django .test .client import RequestFactory as DjangoRequestFactory
189
179
from django .test .client import FakePayload
180
+
190
181
try :
191
182
# In 1.5 the test client uses force_bytes
192
183
from django .utils .encoding import force_bytes as force_bytes_or_smart_bytes
193
184
except ImportError :
194
185
# In 1.4 the test client just uses smart_str
195
186
from django .utils .encoding import smart_str as force_bytes_or_smart_bytes
196
187
188
+
197
189
class RequestFactory (DjangoRequestFactory ):
198
190
def generic (self , method , path ,
199
191
data = '' , content_type = 'application/octet-stream' , ** extra ):
200
192
parsed = urlparse .urlparse (path )
201
193
data = force_bytes_or_smart_bytes (data , settings .DEFAULT_CHARSET )
202
194
r = {
203
- 'PATH_INFO' : self ._get_path (parsed ),
204
- 'QUERY_STRING' : force_text (parsed [4 ]),
195
+ 'PATH_INFO' : self ._get_path (parsed ),
196
+ 'QUERY_STRING' : force_text (parsed [4 ]),
205
197
'REQUEST_METHOD' : six .text_type (method ),
206
198
}
207
199
if data :
208
200
r .update ({
209
201
'CONTENT_LENGTH' : len (data ),
210
- 'CONTENT_TYPE' : six .text_type (content_type ),
211
- 'wsgi.input' : FakePayload (data ),
202
+ 'CONTENT_TYPE' : six .text_type (content_type ),
203
+ 'wsgi.input' : FakePayload (data ),
212
204
})
213
205
elif django .VERSION <= (1 , 4 ):
214
206
# For 1.3 we need an empty WSGI payload
@@ -287,10 +279,12 @@ def check_nonce(request, oauth_request, oauth_nonce, oauth_timestamp):
287
279
import provider as oauth2_provider
288
280
from provider import scope as oauth2_provider_scope
289
281
from provider import constants as oauth2_constants
282
+
290
283
if oauth2_provider .__version__ in ('0.2.3' , '0.2.4' ):
291
284
# 0.2.3 and 0.2.4 are supported version that do not support
292
285
# timezone aware datetimes
293
286
import datetime
287
+
294
288
provider_now = datetime .datetime .now
295
289
else :
296
290
# Any other supported version does use timezone aware datetimes
@@ -301,7 +295,7 @@ def check_nonce(request, oauth_request, oauth_nonce, oauth_timestamp):
301
295
oauth2_constants = None
302
296
provider_now = None
303
297
304
- # `seperators ` argument to `json.dumps()` differs between 2.x and 3.x
298
+ # `separators ` argument to `json.dumps()` differs between 2.x and 3.x
305
299
# See: http://bugs.python.org/issue22767
306
300
if six .PY3 :
307
301
SHORT_SEPARATORS = (',' , ':' )
@@ -316,30 +310,9 @@ def check_nonce(request, oauth_request, oauth_nonce, oauth_timestamp):
316
310
317
311
if six .PY3 :
318
312
def is_non_str_iterable (obj ):
319
- if (isinstance (obj , str ) or
320
- (isinstance (obj , Promise ) and obj ._delegate_text )):
313
+ if isinstance (obj , str ) or (isinstance (obj , Promise ) and obj ._delegate_text ):
321
314
return False
322
315
return hasattr (obj , '__iter__' )
323
316
else :
324
317
def is_non_str_iterable (obj ):
325
318
return hasattr (obj , '__iter__' )
326
-
327
-
328
- try :
329
- from django .utils .encoding import python_2_unicode_compatible
330
- except ImportError :
331
- def python_2_unicode_compatible (klass ):
332
- """
333
- A decorator that defines __unicode__ and __str__ methods under Python 2.
334
- Under Python 3 it does nothing.
335
-
336
- To support Python 2 and 3 with a single code base, define a __str__ method
337
- returning text and apply this decorator to the class.
338
- """
339
- if '__str__' not in klass .__dict__ :
340
- raise ValueError ("@python_2_unicode_compatible cannot be applied "
341
- "to %s because it doesn't define __str__()." %
342
- klass .__name__ )
343
- klass .__unicode__ = klass .__str__
344
- klass .__str__ = lambda self : self .__unicode__ ().encode ('utf-8' )
345
- return klass
0 commit comments