aboutsummaryrefslogtreecommitdiff
path: root/urllib3/util/response.py
diff options
context:
space:
mode:
authorSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:39 -0700
committerSVN-Git Migration <python-modules-team@lists.alioth.debian.org>2015-10-08 13:19:39 -0700
commit54bdd56778a37ea9d56d451d4ae49b99cbbfceaa (patch)
tree3b69a7371b29898f08ced7514b42bad8afdc8759 /urllib3/util/response.py
parent0f393d00b51bc54c5075447e4a8b21f0bed6acd8 (diff)
downloadpython-urllib3-54bdd56778a37ea9d56d451d4ae49b99cbbfceaa.tar
python-urllib3-54bdd56778a37ea9d56d451d4ae49b99cbbfceaa.tar.gz
Imported Upstream version 1.9.1
Diffstat (limited to 'urllib3/util/response.py')
-rw-r--r--urllib3/util/response.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/urllib3/util/response.py b/urllib3/util/response.py
index d0325bc..45fff55 100644
--- a/urllib3/util/response.py
+++ b/urllib3/util/response.py
@@ -5,9 +5,18 @@ def is_fp_closed(obj):
:param obj:
The file-like object to check.
"""
- if hasattr(obj, 'fp'):
- # Object is a container for another file-like object that gets released
- # on exhaustion (e.g. HTTPResponse)
+
+ 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
- return obj.closed
+ raise ValueError("Unable to determine whether fp is closed.")