|
1 | 1 | from __future__ import absolute_import, division, unicode_literals
|
2 | 2 |
|
3 |
| -from six import text_type, get_method_self |
4 |
| -from six.moves import http_client |
| 3 | +from six import text_type |
| 4 | +from six.moves import http_client, urllib |
5 | 5 |
|
6 | 6 | import codecs
|
7 | 7 | import re
|
@@ -131,13 +131,15 @@ def _readFromBuffer(self, bytes):
|
131 | 131 |
|
132 | 132 |
|
133 | 133 | def HTMLInputStream(source, encoding=None, parseMeta=True, chardet=True):
|
134 |
| - if hasattr(source, "read"): |
135 |
| - if isinstance(get_method_self(source.read), http_client.HTTPResponse): |
136 |
| - # Work around Python bug #20007: read(0) closes the connection. |
137 |
| - # http://bugs.python.org/issue20007 |
138 |
| - isUnicode = False |
139 |
| - else: |
140 |
| - isUnicode = isinstance(source.read(0), text_type) |
| 134 | + # Work around Python bug #20007: read(0) closes the connection. |
| 135 | + # http://bugs.python.org/issue20007 |
| 136 | + if (isinstance(source, http_client.HTTPResponse) or |
| 137 | + # Also check for addinfourl wrapping HTTPResponse |
| 138 | + (isinstance(source, urllib.response.addbase) and |
| 139 | + isinstance(source.fp, http_client.HTTPResponse))): |
| 140 | + isUnicode = False |
| 141 | + elif hasattr(source, "read"): |
| 142 | + isUnicode = isinstance(source.read(0), text_type) |
141 | 143 | else:
|
142 | 144 | isUnicode = isinstance(source, text_type)
|
143 | 145 |
|
|
0 commit comments