aboutsummaryrefslogtreecommitdiff
path: root/requests/packages/urllib3/util/response.py
diff options
context:
space:
mode:
Diffstat (limited to 'requests/packages/urllib3/util/response.py')
-rw-r--r--requests/packages/urllib3/util/response.py22
1 files changed, 22 insertions, 0 deletions
diff --git a/requests/packages/urllib3/util/response.py b/requests/packages/urllib3/util/response.py
new file mode 100644
index 0000000..45fff55
--- /dev/null
+++ b/requests/packages/urllib3/util/response.py
@@ -0,0 +1,22 @@
+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.")