diff options
Diffstat (limited to 'rest_framework/utils')
| -rw-r--r-- | rest_framework/utils/encoders.py | 34 | ||||
| -rw-r--r-- | rest_framework/utils/formatting.py | 4 | ||||
| -rw-r--r-- | rest_framework/utils/mediatypes.py | 6 | 
3 files changed, 27 insertions, 17 deletions
| diff --git a/rest_framework/utils/encoders.py b/rest_framework/utils/encoders.py index e5fa4194..00ffdfba 100644 --- a/rest_framework/utils/encoders.py +++ b/rest_framework/utils/encoders.py @@ -2,10 +2,11 @@  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 timezone, force_text +from rest_framework.compat import force_text  from rest_framework.serializers import DictWithMetadata, SortedDictWithMetadata  import datetime  import decimal @@ -97,14 +98,23 @@ else:                      node.flow_style = best_style              return node -    SafeDumper.add_representer(decimal.Decimal, -            SafeDumper.represent_decimal) - -    SafeDumper.add_representer(SortedDict, -            yaml.representer.SafeRepresenter.represent_dict) -    SafeDumper.add_representer(DictWithMetadata, -            yaml.representer.SafeRepresenter.represent_dict) -    SafeDumper.add_representer(SortedDictWithMetadata, -            yaml.representer.SafeRepresenter.represent_dict) -    SafeDumper.add_representer(types.GeneratorType, -            yaml.representer.SafeRepresenter.represent_list) +    SafeDumper.add_representer( +        decimal.Decimal, +        SafeDumper.represent_decimal +    ) +    SafeDumper.add_representer( +        SortedDict, +        yaml.representer.SafeRepresenter.represent_dict +    ) +    SafeDumper.add_representer( +        DictWithMetadata, +        yaml.representer.SafeRepresenter.represent_dict +    ) +    SafeDumper.add_representer( +        SortedDictWithMetadata, +        yaml.representer.SafeRepresenter.represent_dict +    ) +    SafeDumper.add_representer( +        types.GeneratorType, +        yaml.representer.SafeRepresenter.represent_list +    ) diff --git a/rest_framework/utils/formatting.py b/rest_framework/utils/formatting.py index 4b59ba84..6d53aed1 100644 --- a/rest_framework/utils/formatting.py +++ b/rest_framework/utils/formatting.py @@ -6,8 +6,6 @@ from __future__ import unicode_literals  from django.utils.html import escape  from django.utils.safestring import mark_safe  from rest_framework.compat import apply_markdown -from rest_framework.settings import api_settings -from textwrap import dedent  import re @@ -40,6 +38,7 @@ def dedent(content):      return content.strip() +  def camelcase_to_spaces(content):      """      Translate 'CamelCaseNames' to 'Camel Case Names'. @@ -49,6 +48,7 @@ def camelcase_to_spaces(content):      content = re.sub(camelcase_boundry, ' \\1', content).strip()      return ' '.join(content.split('_')).title() +  def markup_description(description):      """      Apply HTML markup to the given description. diff --git a/rest_framework/utils/mediatypes.py b/rest_framework/utils/mediatypes.py index c09c2933..87b3cc6a 100644 --- a/rest_framework/utils/mediatypes.py +++ b/rest_framework/utils/mediatypes.py @@ -57,7 +57,7 @@ class _MediaType(object):              if key != 'q' and other.params.get(key, None) != self.params.get(key, None):                  return False -        if self.sub_type != '*' and other.sub_type != '*'  and other.sub_type != self.sub_type: +        if self.sub_type != '*' and other.sub_type != '*' and other.sub_type != self.sub_type:              return False          if self.main_type != '*' and other.main_type != '*' and other.main_type != self.main_type: @@ -74,12 +74,12 @@ class _MediaType(object):              return 0          elif self.sub_type == '*':              return 1 -        elif not self.params or self.params.keys() == ['q']: +        elif not self.params or list(self.params.keys()) == ['q']:              return 2          return 3      def __str__(self): -        return unicode(self).encode('utf-8') +        return self.__unicode__().encode('utf-8')      def __unicode__(self):          ret = "%s/%s" % (self.main_type, self.sub_type) | 
