Merge pull request #2858 from kazmiruk/version-2.4.x

change SortedDict to OrderedDict + fix list and tuple concatination
This commit is contained in:
Tom Christie 2015-04-27 16:21:10 +01:00
commit 91ba27174c
8 changed files with 44 additions and 12 deletions

View File

@ -265,3 +265,30 @@ except ImportError:
klass.__unicode__ = klass.__str__
klass.__str__ = lambda self: self.__unicode__().encode('utf-8')
return klass
"""
SortedDict deprecated since django 1.8. There is collections.OrderedDict
which available since python 2.7 and python 3.1. There are no need of other
checks because of django 1.7+ requires python 2.7+
"""
try:
from collections import OrderedDict as SortedDict
except ImportError:
from django.utils.datastructures import SortedDict
"""
GenericForeignKey moves from generic to fields in django 1.9 and in 1.8 shows
deprecation warnings
"""
if django.VERSION >= (1, 8):
from django.contrib.contenttypes.fields import GenericForeignKey
else:
from django.contrib.contenttypes.generic import GenericForeignKey
"""
django.utils.importlib is deprecated since django 1.8
"""
try:
import importlib
except ImportError:
from django.utils import importlib

View File

@ -22,11 +22,10 @@ from django.forms import widgets
from django.utils import six, timezone
from django.utils.encoding import is_protected_type
from django.utils.translation import ugettext_lazy as _
from django.utils.datastructures import SortedDict
from django.utils.dateparse import parse_date, parse_datetime, parse_time
from rest_framework import ISO_8601
from rest_framework.compat import (
BytesIO, smart_text,
BytesIO, smart_text, SortedDict,
force_text, is_non_str_iterable
)
from rest_framework.settings import api_settings

View File

@ -20,8 +20,8 @@ from collections import namedtuple
from django.conf.urls import patterns, url
from django.core.exceptions import ImproperlyConfigured
from django.core.urlresolvers import NoReverseMatch
from django.utils.datastructures import SortedDict
from rest_framework import views
from rest_framework.compat import SortedDict
from rest_framework.response import Response
from rest_framework.reverse import reverse
from rest_framework.urlpatterns import format_suffix_patterns

View File

@ -16,14 +16,13 @@ import datetime
import inspect
import types
from decimal import Decimal
from django.contrib.contenttypes.generic import GenericForeignKey
from django.core.paginator import Page
from django.db import models
from django.forms import widgets
from django.utils import six
from django.utils.datastructures import SortedDict
from django.utils.functional import cached_property
from django.core.exceptions import ObjectDoesNotExist
from rest_framework.compat import SortedDict, GenericForeignKey
from rest_framework.settings import api_settings
@ -110,9 +109,17 @@ class SortedDictWithMetadata(SortedDict):
"""
A sorted dict-like object, that can have additional properties attached.
"""
def __reduce__(self):
"""
Used by pickle (e.g., caching) if OrderedDict is used instead of SortedDict
Overriden to remove the metadata from the dict, since it shouldn't be
pickle and may in some instances be unpickleable.
"""
return self.__class__, (SortedDict(self), )
def __getstate__(self):
"""
Used by pickle (e.g., caching).
Used by pickle (e.g., caching) in SortedDict
Overriden to remove the metadata from the dict, since it shouldn't be
pickle and may in some instances be unpickleable.
"""

View File

@ -19,8 +19,9 @@ back to the defaults.
"""
from __future__ import unicode_literals
from django.conf import settings
from django.utils import importlib, six
from django.utils import six
from rest_framework import ISO_8601
from rest_framework.compat import importlib
USER_SETTINGS = getattr(settings, 'REST_FRAMEWORK', None)

View File

@ -4,9 +4,8 @@ Helper classes for parsers.
from __future__ import unicode_literals
from django.utils import timezone
from django.db.models.query import QuerySet
from django.utils.datastructures import SortedDict
from django.utils.functional import Promise
from rest_framework.compat import force_text
from rest_framework.compat import force_text, SortedDict
from rest_framework.serializers import DictWithMetadata, SortedDictWithMetadata
import datetime
import decimal

View File

@ -5,10 +5,9 @@ from __future__ import unicode_literals
from django.core.exceptions import PermissionDenied
from django.http import Http404
from django.utils.datastructures import SortedDict
from django.views.decorators.csrf import csrf_exempt
from rest_framework import status, exceptions
from rest_framework.compat import smart_text, HttpResponseBase, View
from rest_framework.compat import smart_text, HttpResponseBase, SortedDict, View
from rest_framework.request import Request
from rest_framework.response import Response
from rest_framework.settings import api_settings

View File

@ -10,8 +10,8 @@ from uuid import uuid4
from django.core import validators
from django.db import models
from django.test import TestCase
from django.utils.datastructures import SortedDict
from rest_framework import serializers
from rest_framework.compat import SortedDict
from tests.models import RESTFrameworkModel