aboutsummaryrefslogtreecommitdiffstats
path: root/rest_framework/compat.py
diff options
context:
space:
mode:
authorXavier Ordoquy2013-01-03 11:41:07 +0100
committerXavier Ordoquy2013-01-03 11:41:07 +0100
commit60250f22c8e144494f372338c16a2167cccb319d (patch)
treea467ab51837175ab29abec7eb22bb936375763da /rest_framework/compat.py
parentcf51dcc9bb409fb985d5aa09c426d1ed33f6e9b4 (diff)
downloaddjango-rest-framework-60250f22c8e144494f372338c16a2167cccb319d.tar.bz2
Move the various compat things to the compat module.
Diffstat (limited to 'rest_framework/compat.py')
-rw-r--r--rest_framework/compat.py24
1 files changed, 21 insertions, 3 deletions
diff --git a/rest_framework/compat.py b/rest_framework/compat.py
index 9b38c208..5924cd6d 100644
--- a/rest_framework/compat.py
+++ b/rest_framework/compat.py
@@ -4,16 +4,34 @@ versions of django/python, and compatibility wrappers around optional packages.
"""
# flake8: noqa
from __future__ import unicode_literals
-import six
import django
+# Try to import six from Django, fallback to six itself (1.3.x)
+try:
+ from django.utils import six
+except:
+ import six
+
# location of patterns, url, include changes in 1.4 onwards
try:
from django.conf.urls import patterns, url, include
except:
from django.conf.urls.defaults import patterns, url, include
+# Handle django.utils.encoding rename:
+# smart_unicode -> smart_text
+# force_unicode -> force_text
+try:
+ from django.utils.encoding import smart_text
+except ImportError:
+ from django.utils.encoding import smart_unicode as smart_text
+try:
+ from django.utils.encoding import force_text
+except ImportError:
+ from django.utils.encoding import force_unicode as force_text
+
+
# django-filter is optional
try:
import django_filters
@@ -25,9 +43,9 @@ except:
try:
import cStringIO.StringIO as StringIO
except ImportError:
- from six import StringIO
+ StringIO = six.StringIO
-from six import BytesIO
+BytesIO = six.BytesIO
# urlparse compat import (Required because it changed in python 3.x)