@@ -198,8 +198,11 @@ def openStream(self, source):
198
198
try :
199
199
from io import BytesIO
200
200
except :
201
- # 2to3 converts this line to: from io import StringIO
202
- from cStringIO import StringIO as BytesIO
201
+ try :
202
+ # 2to3 converts this line to: from io import StringIO
203
+ from cStringIO import StringIO as BytesIO
204
+ except :
205
+ from StringIO import StringIO as BytesIO
203
206
stream = BytesIO (source )
204
207
205
208
if (not (hasattr (stream , "tell" ) and hasattr (stream , "seek" )) or
@@ -227,6 +230,7 @@ def detectEncoding(self, parseMeta=True, chardet=True):
227
230
detector = UniversalDetector ()
228
231
while not detector .done :
229
232
buffer = self .rawStream .read (self .numBytesChardet )
233
+ assert isinstance (buffer , str )
230
234
if not buffer :
231
235
break
232
236
buffers .append (buffer )
@@ -275,6 +279,7 @@ def detectBOM(self):
275
279
276
280
# Go to beginning of file and read in 4 bytes
277
281
string = self .rawStream .read (4 )
282
+ assert isinstance (string , str )
278
283
279
284
# Try detecting the BOM using bytes from the string
280
285
encoding = bomDict .get (string [:3 ]) # UTF-8
@@ -297,6 +302,7 @@ def detectEncodingMeta(self):
297
302
"""Report the encoding declared by the meta element
298
303
"""
299
304
buffer = self .rawStream .read (self .numBytesMeta )
305
+ assert isinstance (buffer , str )
300
306
parser = EncodingParser (buffer )
301
307
self .rawStream .seek (0 )
302
308
encoding = parser .getEncoding ()
0 commit comments