mirror of
https://github.com/frappe/gunicorn.git
synced 2026-01-14 11:09:11 +08:00
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:
parent
f6b172dfec
commit
d55ef38c8a
@ -353,9 +353,7 @@ class Response(object):
|
||||
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:
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user