1
0
Fork 0
mirror of https://github.com/evilhero/mylar synced 2024-12-24 16:51:42 +00:00
mylar/lib/requests/packages/urllib3/util/response.py
2015-04-15 01:42:03 -04:00

22 lines
566 B
Python

def is_fp_closed(obj):
"""
Checks whether a given file-like object is closed.
:param obj:
The file-like object to check.
"""
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.")