mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-06-13 10:03:20 +03:00
Used early return as before
This commit is contained in:
parent
c05926b851
commit
1b5a84ab8b
|
@ -150,6 +150,8 @@ class APIRequestFactory(DjangoRequestFactory):
|
||||||
"""
|
"""
|
||||||
Encode the data returning a two tuple of (bytes, content_type)
|
Encode the data returning a two tuple of (bytes, content_type)
|
||||||
"""
|
"""
|
||||||
|
if data is None:
|
||||||
|
return (b'', content_type)
|
||||||
|
|
||||||
assert format is None or content_type is None, (
|
assert format is None or content_type is None, (
|
||||||
'You may not set both `format` and `content_type`.'
|
'You may not set both `format` and `content_type`.'
|
||||||
|
@ -161,9 +163,6 @@ class APIRequestFactory(DjangoRequestFactory):
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
if data is None:
|
|
||||||
data = ''
|
|
||||||
|
|
||||||
# Content type specified explicitly, treat data as a raw bytestring
|
# Content type specified explicitly, treat data as a raw bytestring
|
||||||
ret = force_bytes(data, settings.DEFAULT_CHARSET)
|
ret = force_bytes(data, settings.DEFAULT_CHARSET)
|
||||||
|
|
||||||
|
@ -181,6 +180,7 @@ class APIRequestFactory(DjangoRequestFactory):
|
||||||
|
|
||||||
# Use format and render the data into a bytestring
|
# Use format and render the data into a bytestring
|
||||||
renderer = self.renderer_classes[format]()
|
renderer = self.renderer_classes[format]()
|
||||||
|
ret = renderer.render(data)
|
||||||
|
|
||||||
# Determine the content-type header from the renderer
|
# Determine the content-type header from the renderer
|
||||||
content_type = renderer.media_type
|
content_type = renderer.media_type
|
||||||
|
@ -189,14 +189,9 @@ class APIRequestFactory(DjangoRequestFactory):
|
||||||
content_type, renderer.charset
|
content_type, renderer.charset
|
||||||
)
|
)
|
||||||
|
|
||||||
if data is None:
|
# Coerce text to bytes if required.
|
||||||
ret = ''
|
if isinstance(ret, str):
|
||||||
else:
|
ret = ret.encode(renderer.charset)
|
||||||
ret = renderer.render(data)
|
|
||||||
|
|
||||||
# Coerce text to bytes if required.
|
|
||||||
if isinstance(ret, str) and renderer.charset:
|
|
||||||
ret = ret.encode(renderer.charset)
|
|
||||||
|
|
||||||
return ret, content_type
|
return ret, content_type
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user