Skip to content

Commit e674941

Browse files
jcarlosgarciasegoviagsnedders
authored andcommitted
Google Code Issue 215: Properly detect seekable streams
Removes the hack that tests for sys.stdin to determine if the stream is seekable (it has tell() and seek() but it is not seekable) by actually calling tell() and seek(). This also removes the wrapping in HTMLUnicodeInputStream, where we do not need the ability to seek.
1 parent 52c37b6 commit e674941

File tree

1 file changed

+3
-9
lines changed

1 file changed

+3
-9
lines changed

html5lib/inputstream.py

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
import codecs
55
import re
6-
import sys
76

87
from .constants import EOF, spaceCharacters, asciiLetters, asciiUppercase
98
from .constants import encodings, ReparseException
@@ -202,12 +201,6 @@ def openStream(self, source):
202201
else:
203202
stream = StringIO(source)
204203

205-
if ( # not isinstance(stream, BufferedIOBase) and
206-
not(hasattr(stream, "tell") and
207-
hasattr(stream, "seek")) or
208-
stream is sys.stdin):
209-
stream = BufferedStream(stream)
210-
211204
return stream
212205

213206
def _position(self, offset):
@@ -437,8 +430,9 @@ def openStream(self, source):
437430
else:
438431
stream = BytesIO(source)
439432

440-
if (not(hasattr(stream, "tell") and hasattr(stream, "seek")) or
441-
stream is sys.stdin):
433+
try:
434+
stream.seek(stream.tell())
435+
except:
442436
stream = BufferedStream(stream)
443437

444438
return stream

0 commit comments

Comments
 (0)