4949except ImportError :
5050 django_filters = None
5151
52-
5352if django .VERSION >= (1 , 6 ):
5453 def clean_manytomany_helptext (text ):
5554 return text
@@ -104,14 +103,6 @@ def get_model_name(model_cls):
104103 return model_cls ._meta .module_name
105104
106105
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-
115106# View._allowed_methods only present from 1.5 onwards
116107if django .VERSION >= (1 , 5 ):
117108 from django .views .generic import View
@@ -123,7 +114,6 @@ def _allowed_methods(self):
123114 return [m .upper () for m in self .http_method_names if hasattr (self , m )]
124115
125116
126-
127117# MinValueValidator, MaxValueValidator et al. only accept `message` in 1.8+
128118if django .VERSION >= (1 , 8 ):
129119 from django .core .validators import MinValueValidator , MaxValueValidator
@@ -187,28 +177,30 @@ def __init__(self, *args, **kwargs):
187177# RequestFactory only provides `generic` from 1.5 onwards
188178from django .test .client import RequestFactory as DjangoRequestFactory
189179from django .test .client import FakePayload
180+
190181try :
191182 # In 1.5 the test client uses force_bytes
192183 from django .utils .encoding import force_bytes as force_bytes_or_smart_bytes
193184except ImportError :
194185 # In 1.4 the test client just uses smart_str
195186 from django .utils .encoding import smart_str as force_bytes_or_smart_bytes
196187
188+
197189class RequestFactory (DjangoRequestFactory ):
198190 def generic (self , method , path ,
199191 data = '' , content_type = 'application/octet-stream' , ** extra ):
200192 parsed = urlparse .urlparse (path )
201193 data = force_bytes_or_smart_bytes (data , settings .DEFAULT_CHARSET )
202194 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 ]),
205197 'REQUEST_METHOD' : six .text_type (method ),
206198 }
207199 if data :
208200 r .update ({
209201 '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 ),
212204 })
213205 elif django .VERSION <= (1 , 4 ):
214206 # For 1.3 we need an empty WSGI payload
@@ -287,10 +279,12 @@ def check_nonce(request, oauth_request, oauth_nonce, oauth_timestamp):
287279 import provider as oauth2_provider
288280 from provider import scope as oauth2_provider_scope
289281 from provider import constants as oauth2_constants
282+
290283 if oauth2_provider .__version__ in ('0.2.3' , '0.2.4' ):
291284 # 0.2.3 and 0.2.4 are supported version that do not support
292285 # timezone aware datetimes
293286 import datetime
287+
294288 provider_now = datetime .datetime .now
295289 else :
296290 # Any other supported version does use timezone aware datetimes
@@ -301,7 +295,7 @@ def check_nonce(request, oauth_request, oauth_nonce, oauth_timestamp):
301295 oauth2_constants = None
302296 provider_now = None
303297
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
305299# See: http://bugs.python.org/issue22767
306300if six .PY3 :
307301 SHORT_SEPARATORS = (',' , ':' )
@@ -316,30 +310,9 @@ def check_nonce(request, oauth_request, oauth_nonce, oauth_timestamp):
316310
317311if six .PY3 :
318312 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 ):
321314 return False
322315 return hasattr (obj , '__iter__' )
323316else :
324317 def is_non_str_iterable (obj ):
325318 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