reuse util.is_fileobject

is_fileobject usgae was removed due to the use of the `tell` method check.
This change remove this check wich allows us to completely test if
fileno() is usable. Also it handle most of the exceptions around created by
breaking changes across Python versions. Hopefully we are good now.

fix #1174
This commit is contained in:
benoitc 2015-12-31 14:48:19 +01:00
parent f6b172dfec
commit d55ef38c8a
2 changed files with 3 additions and 5 deletions

View File

@ -353,9 +353,7 @@ class Response(object):
if self.cfg.is_ssl or not self.can_sendfile(): if self.cfg.is_ssl or not self.can_sendfile():
return False return False
try: if not util.is_fileobject(respiter.filelike):
fileno = respiter.filelike.fileno()
except AttributeError:
return False return False
try: try:

View File

@ -511,13 +511,13 @@ def to_bytestring(value, encoding="utf8"):
return value.encode(encoding) return value.encode(encoding)
def is_fileobject(obj): def is_fileobject(obj):
if not hasattr(obj, "tell") or not hasattr(obj, "fileno"): if not hasattr(obj, "fileno"):
return False return False
# check BytesIO case and maybe others # check BytesIO case and maybe others
try: try:
obj.fileno() obj.fileno()
except (IOError, io.UnsupportedOperation): except (AttributeError, IOError, io.UnsupportedOperation):
return False return False
return True return True