Skip to content

Commit 78b6cf5

Browse files
committed
Removed custom StringIO, force_text, smart_text compat
1 parent b86978c commit 78b6cf5

15 files changed

+27
-39
lines changed

rest_framework/compat.py

+1-22
Original file line numberDiff line numberDiff line change
@@ -7,25 +7,13 @@
77
from __future__ import unicode_literals
88

99
from django.core.exceptions import ImproperlyConfigured
10+
from django.utils.encoding import force_text
1011
from django.conf import settings
1112
from django.utils import six
1213
import django
1314
import inspect
1415

1516

16-
# Handle django.utils.encoding rename in 1.5 onwards.
17-
# smart_unicode -> smart_text
18-
# force_unicode -> force_text
19-
try:
20-
from django.utils.encoding import smart_text
21-
except ImportError:
22-
from django.utils.encoding import smart_unicode as smart_text
23-
try:
24-
from django.utils.encoding import force_text
25-
except ImportError:
26-
from django.utils.encoding import force_unicode as force_text
27-
28-
2917
# OrderedDict only available in Python 2.7.
3018
# This will always be the case in Django 1.7 and above, as these versions
3119
# no longer support Python 2.6.
@@ -71,15 +59,6 @@ def clean_manytomany_helptext(text):
7159
pass
7260

7361

74-
# cStringIO only if it's available, otherwise StringIO
75-
try:
76-
import cStringIO.StringIO as StringIO
77-
except ImportError:
78-
StringIO = six.StringIO
79-
80-
BytesIO = six.BytesIO
81-
82-
8362
# urlparse compat import (Required because it changed in python 3.x)
8463
try:
8564
from urllib import parse as urlparse

rest_framework/exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
(`django.http.Http404` and `django.core.exceptions.PermissionDenied`)
66
"""
77
from __future__ import unicode_literals
8+
from django.utils.encoding import force_text
89

910
from django.utils.translation import ugettext_lazy as _
1011
from django.utils.translation import ungettext_lazy
1112
from rest_framework import status
12-
from rest_framework.compat import force_text
1313
import math
1414

1515

rest_framework/fields.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
from django.forms import ImageField as DjangoImageField
66
from django.utils import six, timezone
77
from django.utils.dateparse import parse_date, parse_datetime, parse_time
8-
from django.utils.encoding import is_protected_type
8+
from django.utils.encoding import is_protected_type, smart_text
99
from django.utils.translation import ugettext_lazy as _
1010
from rest_framework import ISO_8601
1111
from rest_framework.compat import (
12-
smart_text, EmailValidator, MinValueValidator, MaxValueValidator,
12+
EmailValidator, MinValueValidator, MaxValueValidator,
1313
MinLengthValidator, MaxLengthValidator, URLValidator, OrderedDict
1414
)
1515
from rest_framework.exceptions import ValidationError

rest_framework/metadata.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,9 @@
1010

1111
from django.core.exceptions import PermissionDenied
1212
from django.http import Http404
13+
from django.utils.encoding import force_text
1314
from rest_framework import exceptions, serializers
14-
from rest_framework.compat import force_text, OrderedDict
15+
from rest_framework.compat import OrderedDict
1516
from rest_framework.request import clone_request
1617
from rest_framework.utils.field_mapping import ClassLookupDict
1718

rest_framework/parsers.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
from django.http.multipartparser import MultiPartParser as DjangoMultiPartParser
1313
from django.http.multipartparser import MultiPartParserError, parse_header, ChunkIter
1414
from django.utils import six
15-
from rest_framework.compat import etree, yaml, force_text, urlparse
15+
from django.utils.encoding import force_text
16+
from rest_framework.compat import etree, yaml, urlparse
1617
from rest_framework.exceptions import ParseError
1718
from rest_framework import renderers
1819
import json

rest_framework/relations.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
from rest_framework.compat import smart_text, urlparse
1+
from django.utils.encoding import smart_text
2+
from rest_framework.compat import urlparse
23
from rest_framework.fields import get_attribute, empty, Field
34
from rest_framework.reverse import reverse
45
from rest_framework.utils import html

rest_framework/renderers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,13 @@
1515
from django.http.multipartparser import parse_header
1616
from django.template import Context, RequestContext, loader, Template
1717
from django.test.client import encode_multipart
18+
from django.utils.six.moves import StringIO
1819
from django.utils import six
20+
from django.utils.encoding import smart_text
1921
from django.utils.xmlutils import SimplerXMLGenerator
2022
from rest_framework import exceptions, serializers, status, VERSION
2123
from rest_framework.compat import (
22-
SHORT_SEPARATORS, LONG_SEPARATORS, StringIO, smart_text, yaml
24+
SHORT_SEPARATORS, LONG_SEPARATORS, yaml
2325
)
2426
from rest_framework.exceptions import ParseError
2527
from rest_framework.settings import api_settings

rest_framework/request.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,9 @@
1414
from django.http.multipartparser import parse_header
1515
from django.utils.datastructures import MultiValueDict
1616
from django.utils.datastructures import MergeDict as DjangoMergeDict
17+
from django.utils.six import BytesIO
1718
from rest_framework import HTTP_HEADER_ENCODING
1819
from rest_framework import exceptions
19-
from rest_framework.compat import BytesIO
2020
from rest_framework.settings import api_settings
2121
import warnings
2222

rest_framework/templatetags/rest_framework.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
from django.core.urlresolvers import reverse, NoReverseMatch
44
from django.http import QueryDict
55
from django.utils import six
6-
from django.utils.encoding import iri_to_uri
6+
from django.utils.encoding import iri_to_uri, force_text
77
from django.utils.html import escape
88
from django.utils.safestring import SafeData, mark_safe
99
from django.utils.html import smart_urlquote
10-
from rest_framework.compat import urlparse, force_text
10+
from rest_framework.compat import urlparse
1111
from rest_framework.renderers import HTMLFormRenderer
1212
import re
1313

rest_framework/utils/encoders.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@
44
from __future__ import unicode_literals
55
from django.db.models.query import QuerySet
66
from django.utils import six, timezone
7+
from django.utils.encoding import force_text
78
from django.utils.functional import Promise
8-
from rest_framework.compat import force_text, OrderedDict
9+
from rest_framework.compat import OrderedDict
910
import datetime
1011
import decimal
1112
import types

rest_framework/utils/representation.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
of serializer classes and serializer fields.
44
"""
55
from django.db import models
6+
from django.utils.encoding import force_text
67
from django.utils.functional import Promise
7-
from rest_framework.compat import force_text
88
import re
99

1010

rest_framework/views.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@
55

66
from django.core.exceptions import PermissionDenied
77
from django.http import Http404
8+
from django.utils.encoding import smart_text
89
from django.views.decorators.csrf import csrf_exempt
910
from rest_framework import status, exceptions
10-
from rest_framework.compat import smart_text, HttpResponseBase, View
11+
from rest_framework.compat import HttpResponseBase, View
1112
from rest_framework.request import Request
1213
from rest_framework.response import Response
1314
from rest_framework.settings import api_settings

tests/test_description.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from __future__ import unicode_literals
44
from django.test import TestCase
5-
from django.utils.encoding import python_2_unicode_compatible
6-
from rest_framework.compat import apply_markdown, smart_text
5+
from django.utils.encoding import python_2_unicode_compatible, smart_text
6+
from rest_framework.compat import apply_markdown
77
from rest_framework.views import APIView
88
from .description import ViewWithNonASCIICharactersInDocstring
99
from .description import UTF8_TEST_DOCSTRING

tests/test_parsers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
from django.test import TestCase
77
from django.utils import unittest
88
from rest_framework.compat import etree
9-
from rest_framework.compat import StringIO
9+
from django.utils.six.moves import StringIO
1010
from rest_framework.exceptions import ParseError
1111
from rest_framework.parsers import FormParser, FileUploadParser
1212
from rest_framework.parsers import XMLParser

tests/test_renderers.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,11 @@
77
from django.db import models
88
from django.test import TestCase
99
from django.utils import six, unittest
10+
from django.utils.six import BytesIO
11+
from django.utils.six.moves import StringIO
1012
from django.utils.translation import ugettext_lazy as _
1113
from rest_framework import status, permissions
12-
from rest_framework.compat import yaml, etree, StringIO, BytesIO
14+
from rest_framework.compat import yaml, etree
1315
from rest_framework.response import Response
1416
from rest_framework.views import APIView
1517
from rest_framework.renderers import BaseRenderer, JSONRenderer, YAMLRenderer, \

0 commit comments

Comments
 (0)