diff options
| author | Xavier Ordoquy | 2014-04-13 00:05:57 +0200 | 
|---|---|---|
| committer | Xavier Ordoquy | 2014-04-13 00:05:57 +0200 | 
| commit | d08536ad9d026fb7126c430f6d9c18f8540aacd6 (patch) | |
| tree | a8a1d36ce76867e57da23379694ea0609801990b /rest_framework/compat.py | |
| parent | 2911cd64ad67ba193e3d37322ee71692cb482623 (diff) | |
| parent | 93b9245b8714287a440023451ff7880a2f6e5b32 (diff) | |
| download | django-rest-framework-d08536ad9d026fb7126c430f6d9c18f8540aacd6.tar.bz2 | |
Merge remote-tracking branch 'origin/master' into 2.4.0
Conflicts:
	.travis.yml
	docs/api-guide/fields.md
	docs/api-guide/routers.md
	docs/topics/release-notes.md
	rest_framework/authentication.py
	rest_framework/serializers.py
	rest_framework/templatetags/rest_framework.py
	rest_framework/tests/test_authentication.py
	rest_framework/tests/test_filters.py
	rest_framework/tests/test_hyperlinkedserializers.py
	rest_framework/tests/test_serializer.py
	rest_framework/tests/test_testing.py
	rest_framework/utils/encoders.py
	tox.ini
Diffstat (limited to 'rest_framework/compat.py')
| -rw-r--r-- | rest_framework/compat.py | 31 | 
1 files changed, 23 insertions, 8 deletions
| diff --git a/rest_framework/compat.py b/rest_framework/compat.py index 45045c0f..a013a155 100644 --- a/rest_framework/compat.py +++ b/rest_framework/compat.py @@ -121,7 +121,7 @@ from django.test.client import RequestFactory as DjangoRequestFactory  from django.test.client import FakePayload  try:      # In 1.5 the test client uses force_bytes -    from django.utils.encoding import force_bytes_or_smart_bytes +    from django.utils.encoding import force_bytes as force_bytes_or_smart_bytes  except ImportError:      # In 1.4 the test client just uses smart_str      from django.utils.encoding import smart_str as force_bytes_or_smart_bytes @@ -216,13 +216,10 @@ except (ImportError, ImproperlyConfigured):  # OAuth 2 support is optional  try: -    import provider.oauth2 as oauth2_provider -    from provider.oauth2 import models as oauth2_provider_models -    from provider.oauth2 import forms as oauth2_provider_forms +    import provider as oauth2_provider      from provider import scope as oauth2_provider_scope      from provider import constants as oauth2_constants -    from provider import __version__ as provider_version -    if provider_version in ('0.2.3', '0.2.4'): +    if oauth2_provider.__version__ in ('0.2.3', '0.2.4'):          # 0.2.3 and 0.2.4 are supported version that do not support          # timezone aware datetimes          import datetime @@ -232,8 +229,6 @@ try:          from django.utils.timezone import now as provider_now  except ImportError:      oauth2_provider = None -    oauth2_provider_models = None -    oauth2_provider_forms = None      oauth2_provider_scope = None      oauth2_constants = None      provider_now = None @@ -251,3 +246,23 @@ if six.PY3:  else:      def is_non_str_iterable(obj):          return hasattr(obj, '__iter__') + + +try: +    from django.utils.encoding import python_2_unicode_compatible +except ImportError: +    def python_2_unicode_compatible(klass): +        """ +        A decorator that defines __unicode__ and __str__ methods under Python 2. +        Under Python 3 it does nothing. + +        To support Python 2 and 3 with a single code base, define a __str__ method +        returning text and apply this decorator to the class. +        """ +        if '__str__' not in klass.__dict__: +            raise ValueError("@python_2_unicode_compatible cannot be applied " +                             "to %s because it doesn't define __str__()." % +                             klass.__name__) +        klass.__unicode__ = klass.__str__ +        klass.__str__ = lambda self: self.__unicode__().encode('utf-8') +        return klass | 
