Skip to content

Commit aed6279

Browse files
jcarlosgarciasegoviagsnedders
authored andcommitted
Google Code Issue 215: Properly detect seekable streams
This patch 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().
1 parent 073d792 commit aed6279

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

html5lib/inputstream.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -202,10 +202,9 @@ def openStream(self, source):
202202
else:
203203
stream = StringIO(source)
204204

205-
if ( # not isinstance(stream, BufferedIOBase) and
206-
not(hasattr(stream, "tell") and
207-
hasattr(stream, "seek")) or
208-
stream is sys.stdin):
205+
try:
206+
stream.seek(stream.tell())
207+
except:
209208
stream = BufferedStream(stream)
210209

211210
return stream
@@ -437,8 +436,9 @@ def openStream(self, source):
437436
else:
438437
stream = BytesIO(source)
439438

440-
if (not(hasattr(stream, "tell") and hasattr(stream, "seek")) or
441-
stream is sys.stdin):
439+
try:
440+
stream.seek(stream.tell())
441+
except:
442442
stream = BufferedStream(stream)
443443

444444
return stream

0 commit comments

Comments
 (0)