Small fixes based on feedback in pull request.

This commit is contained in:
Casey Davidson
2016-06-13 21:02:19 -07:00
committed by Nate Prewitt
parent 033dfc165d
commit 1003fdf0f2
3 changed files with 4 additions and 2 deletions
+2
View File
@@ -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
View File
@@ -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
View File
@@ -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