Changeset 1189 for trunk/genshi/input.py
- Timestamp:
- Dec 29, 2012, 2:02:20 PM (11 years ago)
- File:
-
- 1 edited
-
trunk/genshi/input.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/genshi/input.py
r1157 r1189 17 17 18 18 from itertools import chain 19 import codecs 19 20 import htmlentitydefs as entities 20 21 import HTMLParser as html … … 318 319 """ 319 320 def _generate(): 321 if self.encoding: 322 reader = codecs.getreader(self.encoding) 323 source = reader(self.source) 324 else: 325 source = self.source 320 326 try: 321 327 bufsize = 4 * 1024 # 4K … … 323 329 while 1: 324 330 while not done and len(self._queue) == 0: 325 data = s elf.source.read(bufsize)331 data = source.read(bufsize) 326 332 if not data: # end of data 327 333 self.close() … … 329 335 else: 330 336 if not isinstance(data, unicode): 331 # bytes 332 if self.encoding: 333 data = data.decode(self.encoding) 334 else: 335 raise UnicodeError("source returned bytes, but no encoding specified") 337 raise UnicodeError("source returned bytes, but no encoding specified") 336 338 self.feed(data) 337 339 for kind, data, pos in self._queue: … … 433 435 """ 434 436 if isinstance(text, unicode): 435 return Stream(list(HTMLParser(StringIO(text), encoding=encoding))) 437 # If it's unicode text the encoding should be set to None. 438 # The option to pass in an incorrect encoding is for ease 439 # of writing doctests that work in both Python 2.x and 3.x. 440 return Stream(list(HTMLParser(StringIO(text), encoding=None))) 436 441 return Stream(list(HTMLParser(BytesIO(text), encoding=encoding))) 437 442
Note: See TracChangeset
for help on using the changeset viewer.
