Changeset 1079 for trunk/genshi/input.py
- Timestamp:
- Nov 12, 2009, 12:36:14 PM (14 years ago)
- File:
-
- 1 edited
-
trunk/genshi/input.py (modified) (7 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/genshi/input.py
r1077 r1079 17 17 18 18 from itertools import chain 19 try: 20 import htmlentitydefs as entities 21 import HTMLParser as html 22 except ImportError: 23 from html import entities 24 from html import parser as html 25 try: 26 from StringIO import StringIO 27 BytesIO = StringIO 28 except ImportError: 29 from io import BytesIO, StringIO 19 30 from xml.parsers import expat 20 import HTMLParser as html21 import htmlentitydefs22 from StringIO import StringIO23 31 24 32 from genshi.core import Attrs, QName, Stream, stripentities … … 89 97 90 98 _entitydefs = ['<!ENTITY %s "&#%d;">' % (name, value) for name, value in 91 htmlentitydefs.name2codepoint.items()]99 entities.name2codepoint.items()] 92 100 _external_dtd = '\n'.join(_entitydefs) 93 101 … … 170 178 def _build_foreign(self, context, base, sysid, pubid): 171 179 parser = self.expat.ExternalEntityParserCreate(context) 172 parser.ParseFile( StringIO(self._external_dtd))180 parser.ParseFile(BytesIO(self._external_dtd)) 173 181 return 1 174 182 … … 238 246 # deal with undefined entities 239 247 try: 240 text = unichr( htmlentitydefs.name2codepoint[text[1:-1]])248 text = unichr(entities.name2codepoint[text[1:-1]]) 241 249 self._enqueue(TEXT, text) 242 250 except KeyError: … … 268 276 :raises ParseError: if the XML text is not well-formed 269 277 """ 270 return Stream(list(XMLParser( StringIO(text))))278 return Stream(list(XMLParser(BytesIO(text)))) 271 279 272 280 … … 388 396 def handle_entityref(self, name): 389 397 try: 390 text = unichr( htmlentitydefs.name2codepoint[name])398 text = unichr(entities.name2codepoint[name]) 391 399 except KeyError: 392 400 text = '&%s;' % name … … 422 430 fails 423 431 """ 424 return Stream(list(HTMLParser( StringIO(text), encoding=encoding)))432 return Stream(list(HTMLParser(BytesIO(text), encoding=encoding))) 425 433 426 434 def _coalesce(stream):
Note: See TracChangeset
for help on using the changeset viewer.
