|
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
|
@@ -120,13 +120,15 @@ def _readFromBuffer(self, bytes):
|
120 | 120 |
|
121 | 121 |
|
122 | 122 | def HTMLInputStream(source, encoding=None, parseMeta=True, chardet=True):
|
123 |
| - if hasattr(source, "read"): |
124 |
| - if isinstance(get_method_self(source.read), http_client.HTTPResponse): |
125 |
| - # Work around Python bug #20007: read(0) closes the connection. |
126 |
| - # http://bugs.python.org/issue20007 |
127 |
| - isUnicode = False |
128 |
| - else: |
129 |
| - isUnicode = isinstance(source.read(0), text_type) |
| 123 | + # Work around Python bug #20007: read(0) closes the connection. |
| 124 | + # http://bugs.python.org/issue20007 |
| 125 | + if (isinstance(source, http_client.HTTPResponse) or |
| 126 | + # Also check for addinfourl wrapping HTTPResponse |
| 127 | + (isinstance(source, urllib.response.addbase) and |
| 128 | + isinstance(source.fp, http_client.HTTPResponse))): |
| 129 | + isUnicode = False |
| 130 | + elif hasattr(source, "read"): |
| 131 | + isUnicode = isinstance(source.read(0), text_type) |
130 | 132 | else:
|
131 | 133 | isUnicode = isinstance(source, text_type)
|
132 | 134 |
|
|
0 commit comments