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

Commit3b3bc21

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

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
@@ -131,13 +131,15 @@ def _readFromBuffer(self, bytes):
131131

132132

133133
defHTMLInputStream(source,encoding=None,parseMeta=True,chardet=True):
134-
ifhasattr(source,"read"):
135-
ifisinstance(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+
elifhasattr(source,"read"):
142+
isUnicode=isinstance(source.read(0),text_type)
141143
else:
142144
isUnicode=isinstance(source,text_type)
143145

‎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