From aed6279aaedabd66a2452e7fec7e25ef62f1278b Mon Sep 17 00:00:00 2001 From: Juan Carlos Garcia Segovia Date: Sat, 6 Oct 2012 18:05:38 +0000 Subject: [PATCH 1/3] 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(). --- html5lib/inputstream.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/html5lib/inputstream.py b/html5lib/inputstream.py index 159901be..9bf4d1e0 100644 --- a/html5lib/inputstream.py +++ b/html5lib/inputstream.py @@ -202,10 +202,9 @@ def openStream(self, source): else: stream = StringIO(source) - if ( # not isinstance(stream, BufferedIOBase) and - not(hasattr(stream, "tell") and - hasattr(stream, "seek")) or - stream is sys.stdin): + try: + stream.seek(stream.tell()) + except: stream = BufferedStream(stream) return stream @@ -437,8 +436,9 @@ def openStream(self, source): else: stream = BytesIO(source) - if (not(hasattr(stream, "tell") and hasattr(stream, "seek")) or - stream is sys.stdin): + try: + stream.seek(stream.tell()) + except: stream = BufferedStream(stream) return stream From 27c3ebebcbf28c0715724bcbdccb3045d97ec8c1 Mon Sep 17 00:00:00 2001 From: Geoffrey Sneddon Date: Thu, 2 May 2013 23:32:38 +0100 Subject: [PATCH 2/3] fixup! Google Code Issue 215: Properly detect seekable streams Fix flake failure about unused import. --- html5lib/inputstream.py | 1 - 1 file changed, 1 deletion(-) diff --git a/html5lib/inputstream.py b/html5lib/inputstream.py index 9bf4d1e0..db169356 100644 --- a/html5lib/inputstream.py +++ b/html5lib/inputstream.py @@ -3,7 +3,6 @@ import codecs import re -import sys from .constants import EOF, spaceCharacters, asciiLetters, asciiUppercase from .constants import encodings, ReparseException From bc3b9bb533f63c6014801e48a650fd5692735380 Mon Sep 17 00:00:00 2001 From: Geoffrey Sneddon Date: Sat, 4 May 2013 14:20:39 +0100 Subject: [PATCH 3/3] We don't need to be able to seek in HTMLUnicodeInputStream. --- html5lib/inputstream.py | 5 ----- 1 file changed, 5 deletions(-) diff --git a/html5lib/inputstream.py b/html5lib/inputstream.py index db169356..7eab174a 100644 --- a/html5lib/inputstream.py +++ b/html5lib/inputstream.py @@ -201,11 +201,6 @@ def openStream(self, source): else: stream = StringIO(source) - try: - stream.seek(stream.tell()) - except: - stream = BufferedStream(stream) - return stream def _position(self, offset):