Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitc4d1655

Browse files
committed
fixup! Add a more general fix for#127 (CPy #20007) based on#136.
1 parent498629d commitc4d1655

File tree

2 files changed

+17
-10
lines changed

2 files changed

+17
-10
lines changed

‎html5lib/inputstream.py‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from __future__importabsolute_import,division,unicode_literals
22

3-
fromsiximporttext_type,get_method_self
4-
fromsix.movesimporthttp_client
3+
fromsiximporttext_type
4+
fromsix.movesimporthttp_client,urllib
55

66
importcodecs
77
importre
@@ -120,13 +120,15 @@ def _readFromBuffer(self, bytes):
120120

121121

122122
defHTMLInputStream(source,encoding=None,parseMeta=True,chardet=True):
123-
ifhasattr(source,"read"):
124-
ifisinstance(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+
elifhasattr(source,"read"):
131+
isUnicode=isinstance(source.read(0),text_type)
130132
else:
131133
isUnicode=isinstance(source,text_type)
132134

‎html5lib/tests/test_stream.py‎

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
importunittest
55
importcodecs
66
fromioimportBytesIO
7+
importsocket
78

9+
importsix
810
fromsix.movesimporthttp_client,urllib
911

1012
fromhtml5lib.inputstreamimport (BufferedStream,HTMLInputStream,
@@ -175,14 +177,17 @@ def test_python_issue_20007_b(self):
175177
Make sure we have a work-around for Python bug #20007
176178
http://bugs.python.org/issue20007
177179
"""
180+
ifsix.PY2:
181+
return
182+
178183
classFakeSocket(object):
179184
defmakefile(self,_mode,_bufsize=None):
180185
returnBytesIO(b"HTTP/1.1 200 Ok\r\n\r\nText")
181186

182187
source=http_client.HTTPResponse(FakeSocket())
183188
source.begin()
184189
wrapped=urllib.response.addinfourl(source,source.msg,"http://example.com")
185-
stream=HTMLInputStream(source)
190+
stream=HTMLInputStream(wrapped)
186191
self.assertEqual(stream.charsUntil(" "),"Text")
187192

188193

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp