Skip to content

Commit

Permalink
reuse util.is_fileobject
Browse files Browse the repository at this point in the history
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
  • Loading branch information
benoitc committed Dec 31, 2015
1 parent f6b172d commit d55ef38
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 5 deletions.
4 changes: 1 addition & 3 deletions gunicorn/http/wsgi.py
Expand Up @@ -353,9 +353,7 @@ def sendfile(self, respiter):
if self.cfg.is_ssl or not self.can_sendfile():
return False

try:
fileno = respiter.filelike.fileno()
except AttributeError:
if not util.is_fileobject(respiter.filelike):
return False

try:
Expand Down
4 changes: 2 additions & 2 deletions gunicorn/util.py
Expand Up @@ -511,13 +511,13 @@ def to_bytestring(value, encoding="utf8"):
return value.encode(encoding)

def is_fileobject(obj):
if not hasattr(obj, "tell") or not hasattr(obj, "fileno"):
if not hasattr(obj, "fileno"):
return False

# check BytesIO case and maybe others
try:
obj.fileno()
except (IOError, io.UnsupportedOperation):
except (AttributeError, IOError, io.UnsupportedOperation):
return False

return True
Expand Down

0 comments on commit d55ef38

Please sign in to comment.