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

Commit9d5e39c

Browse files
committed
Add a more general fix for#127 (CPy #20007) based on#136.
1 parent082c042 commit9d5e39c

File tree

2 files changed

+25
-8
lines changed

2 files changed

+25
-8
lines changed

‎html5lib/inputstream.py‎

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__importabsolute_import,division,unicode_literals
2-
fromsiximporttext_type
2+
3+
fromsiximporttext_type,get_method_self
34
fromsix.movesimporthttp_client
45

56
importcodecs
@@ -130,12 +131,13 @@ def _readFromBuffer(self, bytes):
130131

131132

132133
defHTMLInputStream(source,encoding=None,parseMeta=True,chardet=True):
133-
ifisinstance(source,http_client.HTTPResponse):
134-
# Work around Python bug #20007: read(0) closes the connection.
135-
# http://bugs.python.org/issue20007
136-
isUnicode=False
137-
elifhasattr(source,"read"):
138-
isUnicode=isinstance(source.read(0),text_type)
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)
139141
else:
140142
isUnicode=isinstance(source,text_type)
141143

‎html5lib/tests/test_stream.py‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
importcodecs
66
fromioimportBytesIO
77

8-
fromsix.movesimporthttp_client
8+
fromsix.movesimporthttp_client,urllib
99

1010
fromhtml5lib.inputstreamimport (BufferedStream,HTMLInputStream,
1111
HTMLUnicodeInputStream,HTMLBinaryInputStream)
@@ -170,6 +170,21 @@ def makefile(self, _mode, _bufsize=None):
170170
stream=HTMLInputStream(source)
171171
self.assertEqual(stream.charsUntil(" "),"Text")
172172

173+
deftest_python_issue_20007_b(self):
174+
"""
175+
Make sure we have a work-around for Python bug #20007
176+
http://bugs.python.org/issue20007
177+
"""
178+
classFakeSocket(object):
179+
defmakefile(self,_mode,_bufsize=None):
180+
returnBytesIO(b"HTTP/1.1 200 Ok\r\n\r\nText")
181+
182+
source=http_client.HTTPResponse(FakeSocket())
183+
source.begin()
184+
wrapped=urllib.response.addinfourl(source,source.msg,"http://example.com")
185+
stream=HTMLInputStream(source)
186+
self.assertEqual(stream.charsUntil(" "),"Text")
187+
173188

174189
defbuildTestSuite():
175190
returnunittest.defaultTestLoader.loadTestsFromName(__name__)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp