Skip to content

Commit 0eacde6

Browse files
committed
General StringIO for python 2 and 3
1 parent b21ed70 commit 0eacde6

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

html5lib/inputstream.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,12 @@ def openStream(self, source):
195195
if isinstance(source, unicode):
196196
source = source.encode('utf-8')
197197
self.charEncoding = ("utf-8", "certain")
198-
import cStringIO
199-
stream = cStringIO.StringIO(str(source))
198+
try:
199+
from io import BytesIO
200+
except:
201+
# 2to3 converts this line to: from io import StringIO
202+
from cStringIO import StringIO as BytesIO
203+
stream = BytesIO(source)
200204

201205
if (not(hasattr(stream, "tell") and hasattr(stream, "seek")) or
202206
stream is sys.stdin):

0 commit comments

Comments
 (0)