mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-04 20:40:14 +03:00
Fix for Python 3
This commit is contained in:
parent
fb0f9150b3
commit
8383e40216
|
@ -7,7 +7,7 @@ import datetime
|
||||||
import decimal
|
import decimal
|
||||||
import json
|
import json
|
||||||
import uuid
|
import uuid
|
||||||
from json.encoder import (FLOAT_REPR, INFINITY, _make_iterencode,
|
from json.encoder import (INFINITY, _make_iterencode,
|
||||||
encode_basestring, encode_basestring_ascii)
|
encode_basestring, encode_basestring_ascii)
|
||||||
|
|
||||||
from django.db.models.query import QuerySet
|
from django.db.models.query import QuerySet
|
||||||
|
@ -17,6 +17,11 @@ from django.utils.functional import Promise
|
||||||
|
|
||||||
from rest_framework.compat import coreapi, total_seconds
|
from rest_framework.compat import coreapi, total_seconds
|
||||||
|
|
||||||
|
try:
|
||||||
|
from json.encoder import FLOAT_REPR
|
||||||
|
except:
|
||||||
|
FLOAT_REPR = float.__repr__
|
||||||
|
|
||||||
|
|
||||||
class JSONEncoder(json.JSONEncoder):
|
class JSONEncoder(json.JSONEncoder):
|
||||||
"""
|
"""
|
||||||
|
@ -47,12 +52,6 @@ class JSONEncoder(json.JSONEncoder):
|
||||||
o = o.decode(_encoding)
|
o = o.decode(_encoding)
|
||||||
return _orig_encoder(o)
|
return _orig_encoder(o)
|
||||||
|
|
||||||
if self.encoding != 'utf-8':
|
|
||||||
def _encoder(o, _orig_encoder=_encoder, _encoding=self.encoding):
|
|
||||||
if isinstance(o, str):
|
|
||||||
o = o.decode(_encoding)
|
|
||||||
return _orig_encoder(o)
|
|
||||||
|
|
||||||
def floatstr(o, allow_nan=self.allow_nan,
|
def floatstr(o, allow_nan=self.allow_nan,
|
||||||
_repr=FLOAT_REPR, _inf=INFINITY, _neginf=-INFINITY):
|
_repr=FLOAT_REPR, _inf=INFINITY, _neginf=-INFINITY):
|
||||||
# Check for specials. Note that this type of test is processor
|
# Check for specials. Note that this type of test is processor
|
||||||
|
|
Loading…
Reference in New Issue
Block a user