aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/compat.py
diff options
context:
space:
mode:
authorTom Christie2015-01-19 15:16:57 +0000
committerTom Christie2015-01-19 15:16:57 +0000
commit6065cdbd939542dec79708615bc3e75b38834f41 (patch)
treeb7e582185f1383d630dfe7b1fb8dc1e504599164 /rest_framework/compat.py
parent4f3c3a06cfc0ea2dfbf46da2d98546664343ce93 (diff)
parentfdeef89ba79e617ea22dae68a0b42b3f60d67a4d (diff)
downloaddjango-rest-framework-6065cdbd939542dec79708615bc3e75b38834f41.tar.bz2
Merge master
Diffstat (limited to 'rest_framework/compat.py')
-rw-r--r--rest_framework/compat.py14
1 files changed, 11 insertions, 3 deletions
diff --git a/rest_framework/compat.py b/rest_framework/compat.py
index ea342994..bd3802ad 100644
--- a/rest_framework/compat.py
+++ b/rest_framework/compat.py
@@ -8,7 +8,7 @@ from __future__ import unicode_literals
from django.core.exceptions import ImproperlyConfigured
from django.conf import settings
from django.utils.encoding import force_text
-from django.utils.six.moves.urllib import parse as urlparse
+from django.utils.six.moves.urllib.parse import urlparse as _urlparse
from django.utils import six
import django
import inspect
@@ -38,10 +38,18 @@ def unicode_http_header(value):
return value
+def total_seconds(timedelta):
+ # TimeDelta.total_seconds() is only available in Python 2.7
+ if hasattr(timedelta, 'total_seconds'):
+ return timedelta.total_seconds()
+ else:
+ return (timedelta.days * 86400.0) + float(timedelta.seconds) + (timedelta.microseconds / 1000000.0)
+
+
# OrderedDict only available in Python 2.7.
# This will always be the case in Django 1.7 and above, as these versions
# no longer support Python 2.6.
-# For Django <= 1.6 and Python 2.6 fall back to OrderedDict.
+# For Django <= 1.6 and Python 2.6 fall back to SortedDict.
try:
from collections import OrderedDict
except ImportError:
@@ -187,7 +195,7 @@ except ImportError:
class RequestFactory(DjangoRequestFactory):
def generic(self, method, path,
data='', content_type='application/octet-stream', **extra):
- parsed = urlparse.urlparse(path)
+ parsed = _urlparse(path)
data = force_bytes_or_smart_bytes(data, settings.DEFAULT_CHARSET)
r = {
'PATH_INFO': self._get_path(parsed),