Skip to content

Commit 8383e40

Browse files
committed
Fix for Python 3
1 parent fb0f915 commit 8383e40

File tree

1 file changed

+6
-7
lines changed

1 file changed

+6
-7
lines changed

rest_framework/utils/encoders.py

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import decimal
88
import json
99
import uuid
10-
from json.encoder import (FLOAT_REPR, INFINITY, _make_iterencode,
10+
from json.encoder import (INFINITY, _make_iterencode,
1111
encode_basestring, encode_basestring_ascii)
1212

1313
from django.db.models.query import QuerySet
@@ -17,6 +17,11 @@
1717

1818
from rest_framework.compat import coreapi, total_seconds
1919

20+
try:
21+
from json.encoder import FLOAT_REPR
22+
except:
23+
FLOAT_REPR = float.__repr__
24+
2025

2126
class JSONEncoder(json.JSONEncoder):
2227
"""
@@ -47,12 +52,6 @@ def _encoder(o, _orig_encoder=_encoder,
4752
o = o.decode(_encoding)
4853
return _orig_encoder(o)
4954

50-
if self.encoding != 'utf-8':
51-
def _encoder(o, _orig_encoder=_encoder, _encoding=self.encoding):
52-
if isinstance(o, str):
53-
o = o.decode(_encoding)
54-
return _orig_encoder(o)
55-
5655
def floatstr(o, allow_nan=self.allow_nan,
5756
_repr=FLOAT_REPR, _inf=INFINITY, _neginf=-INFINITY):
5857
# Check for specials. Note that this type of test is processor

0 commit comments

Comments
 (0)