Changeset 385
- Timestamp:
- Oct 22, 2006, 4:57:40 PM (17 years ago)
- Location:
- trunk/genshi
- Files:
-
- 4 edited
-
input.py (modified) (4 diffs)
-
template.py (modified) (2 diffs)
-
tests/input.py (modified) (1 diff)
-
tests/template.py (modified) (2 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): -
trunk/genshi/template.py
r384 r385 1288 1288 1289 1289 @param search_path: a list of absolute path names that should be 1290 searched for template files 1290 searched for template files, or a string containing a single 1291 absolute path 1291 1292 @param auto_reload: whether to check the last modification time of 1292 1293 template files, and reload them if they have changed … … 1297 1298 if self.search_path is None: 1298 1299 self.search_path = [] 1300 elif isinstance(self.search_path, basestring): 1301 self.search_path = [self.search_path] 1299 1302 self.auto_reload = auto_reload 1300 1303 self._cache = LRUCache(max_cache_size) -
trunk/genshi/tests/input.py
r361 r385 121 121 self.assertEqual((None, 1, 6), pos) 122 122 123 def test_input_encoding(self): 124 text = u'<div>\xf6</div>'.encode('iso-8859-1') 125 events = list(HTMLParser(StringIO(text), encoding='iso-8859-1')) 126 kind, data, pos = events[1] 127 self.assertEqual(Stream.TEXT, kind) 128 self.assertEqual(u'\xf6', data) 129 123 130 def test_unicode_input(self): 124 131 text = u'<div>\u2013</div>' -
trunk/genshi/tests/template.py
r370 r385 1141 1141 1142 1142 1143 # FIXME 1144 #def test_empty_lines(self): 1145 # tmpl = TextTemplate("""Your items: 1146 # 1147 # #for item in items 1148 # * ${item} 1149 # 1150 # #end""") 1151 # self.assertEqual("""Your items: 1152 # * 0 1153 # * 1 1154 # * 2 1155 # """, tmpl.generate(items=range(3)).render('text')) 1156 1157 1143 1158 class TemplateLoaderTestCase(unittest.TestCase): 1144 1159 """Tests for the template loader.""" … … 1149 1164 def tearDown(self): 1150 1165 shutil.rmtree(self.dirname) 1166 1167 def test_search_path_empty(self): 1168 loader = TemplateLoader() 1169 self.assertEqual([], loader.search_path) 1170 1171 def test_search_path_as_string(self): 1172 loader = TemplateLoader(self.dirname) 1173 self.assertEqual([self.dirname], loader.search_path) 1151 1174 1152 1175 def test_relative_include_samedir(self):
Note: See TracChangeset
for help on using the changeset viewer.
