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

Commit18bc278

Browse files
committed
Fix#127, add a work-around for CPython bug 20007.
The bug has been fixed upstream, but this works around iton older Python versions.This does not change any behavior on Python versions with the fix.
1 parente269a2f commit18bc278

File tree

2 files changed

+22
-1
lines changed

2 files changed

+22
-1
lines changed

‎html5lib/inputstream.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from __future__importabsolute_import,division,unicode_literals
22
fromsiximporttext_type
3+
fromsix.movesimporthttp_client
34

45
importcodecs
56
importre
@@ -118,7 +119,11 @@ def _readFromBuffer(self, bytes):
118119

119120

120121
defHTMLInputStream(source,encoding=None,parseMeta=True,chardet=True):
121-
ifhasattr(source,"read"):
122+
ifisinstance(source,http_client.HTTPResponse):
123+
# Work around Python bug #20007: read(0) closes the connection.
124+
# http://bugs.python.org/issue20007
125+
isUnicode=False
126+
elifhasattr(source,"read"):
122127
isUnicode=isinstance(source.read(0),text_type)
123128
else:
124129
isUnicode=isinstance(source,text_type)

‎html5lib/tests/test_stream.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
importcodecs
66
fromioimportBytesIO
77

8+
fromsix.movesimporthttp_client
9+
810
fromhtml5lib.inputstreamimport (BufferedStream,HTMLInputStream,
911
HTMLUnicodeInputStream,HTMLBinaryInputStream)
1012

@@ -154,6 +156,20 @@ def test_position2(self):
154156
self.assertEqual(stream.char(),"d")
155157
self.assertEqual(stream.position(), (2,1))
156158

159+
deftest_python_issue_20007(self):
160+
"""
161+
Make sure we have a work-around for Python bug #20007
162+
http://bugs.python.org/issue20007
163+
"""
164+
classFakeSocket(object):
165+
defmakefile(self,_mode,_bufsize=None):
166+
returnBytesIO(b"HTTP/1.1 200 Ok\r\n\r\nText")
167+
168+
source=http_client.HTTPResponse(FakeSocket())
169+
source.begin()
170+
stream=HTMLInputStream(source)
171+
self.assertEqual(stream.charsUntil(" "),"Text")
172+
157173

158174
defbuildTestSuite():
159175
returnunittest.defaultTestLoader.loadTestsFromName(__name__)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp