From 60250f22c8e144494f372338c16a2167cccb319d Mon Sep 17 00:00:00 2001 From: Xavier Ordoquy Date: Thu, 3 Jan 2013 11:41:07 +0100 Subject: Move the various compat things to the compat module. --- rest_framework/compat.py | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'rest_framework/compat.py') 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) -- cgit v1.2.3