Skip to content

Commit

Permalink
Merge pull request #1175 from benoitc/fix/1174
Browse files Browse the repository at this point in the history
reuse util.is_fileobject
  • Loading branch information
benoitc committed Jan 2, 2016
2 parents f6b172d + 5bc13be commit 305f373
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 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.has_fileno(respiter.filelike):
return False

try:
Expand Down
6 changes: 3 additions & 3 deletions gunicorn/util.py
Expand Up @@ -510,14 +510,14 @@ def to_bytestring(value, encoding="utf8"):

return value.encode(encoding)

def is_fileobject(obj):
if not hasattr(obj, "tell") or not hasattr(obj, "fileno"):
def has_fileno(obj):
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 305f373

Please sign in to comment.