Changeset 385 for trunk/genshi/input.py
- Timestamp:
- Oct 22, 2006, 4:57:40 PM (17 years ago)
- File:
-
- 1 edited
-
trunk/genshi/input.py (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/genshi/input.py
r361 r385 77 77 78 78 def __init__(self, source, filename=None): 79 """Initialize the parser for the given XML text.79 """Initialize the parser for the given XML input. 80 80 81 81 @param source: the XML text as a file-like object … … 251 251 'param']) 252 252 253 def __init__(self, source, filename=None): 253 def __init__(self, source, filename=None, encoding='utf-8'): 254 """Initialize the parser for the given HTML input. 255 256 @param source: the HTML text as a file-like object 257 @param filename: the name of the file, if known 258 @param filename: encoding of the file; ignored if the input is unicode 259 """ 254 260 html.HTMLParser.__init__(self) 255 261 self.source = source 256 262 self.filename = filename 263 self.encoding = encoding 257 264 self._queue = [] 258 265 self._open_tags = [] … … 322 329 323 330 def handle_data(self, text): 331 if not isinstance(text, unicode): 332 text = text.decode(self.encoding, 'replace') 324 333 self._enqueue(TEXT, text) 325 334 … … 344 353 345 354 346 def HTML(text ):347 return Stream(list(HTMLParser(StringIO(text) )))355 def HTML(text, encoding='utf-8'): 356 return Stream(list(HTMLParser(StringIO(text), encoding=encoding))) 348 357 349 358 def _coalesce(stream):
Note: See TracChangeset
for help on using the changeset viewer.
