mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-22 09:36:49 +03:00
Move the various compat things to the compat module.
This commit is contained in:
parent
cf51dcc9bb
commit
60250f22c8
|
@ -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)
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
|
||||
from __future__ import unicode_literals
|
||||
import six
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
|
@ -14,14 +13,12 @@ from django.conf import settings
|
|||
from django import forms
|
||||
from django.forms import widgets
|
||||
from django.utils.encoding import is_protected_type
|
||||
try:
|
||||
from django.utils.encoding import smart_text
|
||||
except ImportError:
|
||||
from django.utils.encoding import smart_unicode as smart_text
|
||||
from django.utils.translation import ugettext_lazy as _
|
||||
from rest_framework.compat import parse_date, parse_datetime
|
||||
from rest_framework.compat import timezone
|
||||
from rest_framework.compat import BytesIO
|
||||
from rest_framework.compat import six
|
||||
from rest_framework.compat import smart_text
|
||||
|
||||
|
||||
def is_simple_callable(obj):
|
||||
|
|
|
@ -5,14 +5,13 @@ They give us a generic way of being able to handle various media types
|
|||
on the request, such as form content or json encoded data.
|
||||
"""
|
||||
|
||||
import six
|
||||
|
||||
from django.http import QueryDict
|
||||
from django.http.multipartparser import MultiPartParser as DjangoMultiPartParser
|
||||
from django.http.multipartparser import MultiPartParserError
|
||||
from django.utils import simplejson as json
|
||||
from rest_framework.compat import yaml, ETParseError
|
||||
from rest_framework.exceptions import ParseError
|
||||
from rest_framework.compat import six
|
||||
from xml.etree import ElementTree as ET
|
||||
from xml.parsers.expat import ExpatError
|
||||
import datetime
|
||||
|
|
|
@ -6,13 +6,10 @@ from django.core.urlresolvers import resolve, get_script_prefix
|
|||
from django import forms
|
||||
from django.forms import widgets
|
||||
from django.forms.models import ModelChoiceIterator
|
||||
try:
|
||||
from django.utils.encoding import smart_text
|
||||
except ImportError:
|
||||
from django.utils.encoding import smart_unicode as smart_text
|
||||
from rest_framework.fields import Field, WritableField
|
||||
from rest_framework.reverse import reverse
|
||||
from rest_framework.compat import urlparse
|
||||
from rest_framework.compat import smart_text
|
||||
|
||||
##### Relational fields #####
|
||||
|
||||
|
|
|
@ -9,7 +9,6 @@ The wrapped request then offers a richer API, in particular :
|
|||
- full support of PUT method, including support for file uploads
|
||||
- form overloading of HTTP method, content type and content
|
||||
"""
|
||||
import six
|
||||
from rest_framework.compat import BytesIO
|
||||
|
||||
from django.http.multipartparser import parse_header
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
import six
|
||||
|
||||
from django.core.handlers.wsgi import STATUS_CODE_TEXT
|
||||
from django.template.response import SimpleTemplateResponse
|
||||
|
||||
from rest_framework.compat import six
|
||||
|
||||
|
||||
class Response(SimpleTemplateResponse):
|
||||
"""
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import six
|
||||
|
||||
import copy
|
||||
import datetime
|
||||
import types
|
||||
|
@ -8,6 +6,7 @@ from django.db import models
|
|||
from django.forms import widgets
|
||||
from django.utils.datastructures import SortedDict
|
||||
from rest_framework.compat import get_concrete_model
|
||||
from rest_framework.compat import six
|
||||
|
||||
# Note: We do the following so that users of the framework can use this style:
|
||||
#
|
||||
|
|
|
@ -19,8 +19,7 @@ back to the defaults.
|
|||
"""
|
||||
from django.conf import settings
|
||||
from django.utils import importlib
|
||||
from six import string_types
|
||||
|
||||
from rest_framework.compat import six
|
||||
|
||||
|
||||
USER_SETTINGS = getattr(settings, 'REST_FRAMEWORK', None)
|
||||
|
@ -100,7 +99,7 @@ def perform_import(val, setting_name):
|
|||
If the given setting is a string import notation,
|
||||
then perform the necessary import or imports.
|
||||
"""
|
||||
if isinstance(val, string_types):
|
||||
if isinstance(val, six.string_types):
|
||||
return import_from_string(val, setting_name)
|
||||
elif isinstance(val, (list, tuple)):
|
||||
return [import_from_string(item, setting_name) for item in val]
|
||||
|
@ -118,6 +117,7 @@ def import_from_string(val, setting_name):
|
|||
module = importlib.import_module(module_path)
|
||||
return getattr(module, class_name)
|
||||
except:
|
||||
raise
|
||||
msg = "Could not import '%s' for API setting '%s'" % (val, setting_name)
|
||||
raise ImportError(msg)
|
||||
|
||||
|
|
|
@ -1,16 +1,14 @@
|
|||
from __future__ import unicode_literals, absolute_import
|
||||
import six
|
||||
|
||||
from django import template
|
||||
from django.core.urlresolvers import reverse
|
||||
from django.http import QueryDict
|
||||
try:
|
||||
from django.utils.encoding import force_text
|
||||
except ImportError:
|
||||
from django.utils.encoding import force_unicode as force_text
|
||||
from django.utils.html import escape
|
||||
from django.utils.safestring import SafeData, mark_safe
|
||||
from rest_framework.compat import urlparse
|
||||
from rest_framework.compat import force_text
|
||||
from rest_framework.compat import six
|
||||
|
||||
import re
|
||||
import string
|
||||
|
||||
|
|
|
@ -1,11 +1,10 @@
|
|||
from rest_framework.compat import BytesIO
|
||||
|
||||
import datetime
|
||||
import six
|
||||
|
||||
from django.test import TestCase
|
||||
|
||||
from rest_framework import serializers
|
||||
from rest_framework.compat import BytesIO
|
||||
from rest_framework.compat import six
|
||||
|
||||
|
||||
class UploadedFile(object):
|
||||
|
|
|
@ -1,14 +1,12 @@
|
|||
from __future__ import unicode_literals
|
||||
|
||||
import six
|
||||
|
||||
from django.db import models
|
||||
from django.test import TestCase
|
||||
from django.test.client import RequestFactory
|
||||
from django.utils import simplejson as json
|
||||
from rest_framework import generics, serializers, status
|
||||
from rest_framework.tests.models import BasicModel, Comment, SlugBasedModel
|
||||
|
||||
from rest_framework.compat import six
|
||||
|
||||
factory = RequestFactory()
|
||||
|
||||
|
|
|
@ -1,5 +1,3 @@
|
|||
import six
|
||||
|
||||
from django.core.exceptions import PermissionDenied
|
||||
from django.http import Http404
|
||||
from django.test import TestCase
|
||||
|
@ -9,6 +7,7 @@ from rest_framework.compat import patterns, url
|
|||
from rest_framework.decorators import api_view, renderer_classes
|
||||
from rest_framework.renderers import TemplateHTMLRenderer
|
||||
from rest_framework.response import Response
|
||||
from rest_framework.compat import six
|
||||
|
||||
|
||||
@api_view(('GET',))
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import pickle
|
||||
import re
|
||||
import six
|
||||
|
||||
from django.core.cache import cache
|
||||
from django.test import TestCase
|
||||
|
@ -16,6 +15,7 @@ from rest_framework.parsers import YAMLParser, XMLParser
|
|||
from rest_framework.settings import api_settings
|
||||
|
||||
from rest_framework.compat import StringIO
|
||||
from rest_framework.compat import six
|
||||
import datetime
|
||||
from decimal import Decimal
|
||||
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
"""
|
||||
Tests for content parsing, and form-overloaded content parsing.
|
||||
"""
|
||||
import six
|
||||
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth import authenticate, login, logout
|
||||
from django.contrib.sessions.middleware import SessionMiddleware
|
||||
|
@ -22,6 +20,7 @@ from rest_framework.request import Request
|
|||
from rest_framework.response import Response
|
||||
from rest_framework.settings import api_settings
|
||||
from rest_framework.views import APIView
|
||||
from rest_framework.compat import six
|
||||
|
||||
|
||||
factory = RequestFactory()
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
import unittest
|
||||
import six
|
||||
|
||||
from django.test import TestCase
|
||||
from rest_framework.compat import patterns, url, include
|
||||
from rest_framework.response import Response
|
||||
|
@ -12,6 +9,7 @@ from rest_framework.renderers import (
|
|||
BrowsableAPIRenderer
|
||||
)
|
||||
from rest_framework.settings import api_settings
|
||||
from rest_framework.compat import six
|
||||
|
||||
|
||||
class MockPickleRenderer(BaseRenderer):
|
||||
|
|
|
@ -1,13 +1,7 @@
|
|||
|
||||
import six
|
||||
|
||||
try:
|
||||
from django.utils.encoding import smart_text
|
||||
except ImportError:
|
||||
from django.utils.encoding import smart_unicode as smart_text
|
||||
|
||||
from django.utils.xmlutils import SimplerXMLGenerator
|
||||
from rest_framework.compat import StringIO
|
||||
from rest_framework.compat import six
|
||||
from rest_framework.compat import smart_text
|
||||
import re
|
||||
import xml.etree.ElementTree as ET
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user