mirror of
https://github.com/kennethreitz/requests3.git
synced 2026-06-05 23:10:16 +00:00
c9a188add2
Signed-off-by: Kenneth Reitz <me@kennethreitz.org>
31 lines
733 B
Python
31 lines
733 B
Python
from __future__ import absolute_import
|
|
|
|
|
|
def is_fp_closed(obj):
|
|
"""
|
|
Checks whether a given file-like object is closed.
|
|
|
|
:param obj:
|
|
The file-like object to check.
|
|
"""
|
|
try:
|
|
# Check for our own base response class.
|
|
return obj.complete
|
|
|
|
except AttributeError:
|
|
pass
|
|
try:
|
|
# Check via the official file-like-object way.
|
|
return obj.closed
|
|
|
|
except AttributeError:
|
|
pass
|
|
try:
|
|
# Check if the object is a container for another file-like object that
|
|
# gets released on exhaustion (e.g. HTTPResponse).
|
|
return obj.fp is None
|
|
|
|
except AttributeError:
|
|
pass
|
|
raise ValueError("Unable to determine whether fp is closed.")
|