mirror of
https://github.com/kennethreitz/requests.git
synced 2026-06-05 22:50:18 +00:00
Small fixes based on feedback in pull request.
This commit is contained in:
committed by
Nate Prewitt
parent
033dfc165d
commit
1003fdf0f2
@@ -110,6 +110,8 @@ class UnrewindableBodyError(RequestException):
|
||||
class ConflictingHeaderError(RequestException):
|
||||
"""Mutually exclusive request headers set"""
|
||||
|
||||
class UnreachableCodeError(RequestException, RuntimeError):
|
||||
"""Unreachable code block reached"""
|
||||
|
||||
# Warnings
|
||||
|
||||
|
||||
+1
-1
@@ -527,7 +527,7 @@ class PreparedRequest(RequestEncodingMixin, RequestHooksMixin):
|
||||
elif is_stream and not length:
|
||||
self.headers['Transfer-Encoding'] = 'chunked'
|
||||
else:
|
||||
assert False, "If body is not null, it must either have a length or be streamable"
|
||||
raise UnreachableCodeError("Non-null body must have length or be streamable")
|
||||
elif (self.method not in ('GET', 'HEAD')) and (self.headers.get('Content-Length') is None):
|
||||
self.headers['Content-Length'] = '0'
|
||||
|
||||
|
||||
+1
-1
@@ -884,6 +884,6 @@ def rewind_body(prepared_request):
|
||||
def determine_if_stream(data):
|
||||
"""Given data, determines if it should be sent as a stream.
|
||||
"""
|
||||
is_iterable = hasattr(data, '__iter__')
|
||||
is_iterable = getattr(data, '__iter__', False)
|
||||
is_io_type = not isinstance(data, (basestring, list, tuple, dict))
|
||||
return is_iterable and is_io_type
|
||||
|
||||
Reference in New Issue
Block a user