mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-10 19:56:59 +03:00
Remove unnecessary use of compat shim six.binary_type (#6189)
The type bytes is available on all supported Pythons. On Python 2.7, it is an alias for str, same as six.binary_type. Makes the code more forward compatible with Python 3.
This commit is contained in:
parent
fc6cbb5b26
commit
ed6340ee76
|
@ -96,7 +96,7 @@ def unicode_to_repr(value):
|
|||
|
||||
def unicode_http_header(value):
|
||||
# Coerce HTTP header value to unicode.
|
||||
if isinstance(value, six.binary_type):
|
||||
if isinstance(value, bytes):
|
||||
return value.decode('iso-8859-1')
|
||||
return value
|
||||
|
||||
|
|
|
@ -1780,7 +1780,7 @@ class JSONField(Field):
|
|||
def to_internal_value(self, data):
|
||||
try:
|
||||
if self.binary or getattr(data, 'is_json_string', False):
|
||||
if isinstance(data, six.binary_type):
|
||||
if isinstance(data, bytes):
|
||||
data = data.decode('utf-8')
|
||||
return json.loads(data)
|
||||
else:
|
||||
|
|
|
@ -47,7 +47,7 @@ class JSONEncoder(json.JSONEncoder):
|
|||
return six.text_type(obj)
|
||||
elif isinstance(obj, QuerySet):
|
||||
return tuple(obj)
|
||||
elif isinstance(obj, six.binary_type):
|
||||
elif isinstance(obj, bytes):
|
||||
# Best-effort for binary blobs. See #4187.
|
||||
return obj.decode('utf-8')
|
||||
elif hasattr(obj, 'tolist'):
|
||||
|
|
Loading…
Reference in New Issue
Block a user