Ticket #123: disable_python.patch
| File disable_python.patch, 7.3 KB (added by fschwindt@…, 16 years ago) |
|---|
-
genshi/template/base.py
288 288 """ 289 289 290 290 def __init__(self, source, basedir=None, filename=None, loader=None, 291 encoding=None, lookup='lenient' ):291 encoding=None, lookup='lenient', disable_python=False): 292 292 """Initialize a template from either a string, a file-like object, or 293 293 an already parsed markup stream. 294 294 … … 305 305 :param encoding: the encoding of the `source` 306 306 :param lookup: the variable lookup mechanism; either "lenient" (the 307 307 default), "strict", or a custom lookup class 308 :param disable_python: whether to allow python code blocks 308 309 """ 309 310 self.basedir = basedir 310 311 self.filename = filename … … 314 315 self.filepath = filename 315 316 self.loader = loader 316 317 self.lookup = lookup 318 self.disable_python = disable_python 317 319 318 320 if isinstance(source, basestring): 319 321 source = StringIO(source) -
genshi/template/tests/markup.py
438 438 finally: 439 439 shutil.rmtree(dirname) 440 440 441 def test_disable_python_true(self): 442 xml = ("""<?python 443 title = "A Genshi Template" 444 ?> 445 <html xmlns:py="http://genshi.edgewall.org/"> 446 <head> 447 <title py:content="title">This is replaced.</title> 448 </head> 449 </html>""") 450 try: 451 tmpl = MarkupTemplate(xml, filename='test.html', 452 disable_python=True) 453 self.fail('Expected SyntaxError') 454 except TemplateSyntaxError, e: 455 self.assertEqual('test.html', e.filename) 441 456 457 def test_disable_python_false(self): 458 xml = ("""<?python 459 title = "A Genshi Template" 460 ?> 461 <html xmlns:py="http://genshi.edgewall.org/"> 462 <head> 463 <title py:content="title">This is replaced.</title> 464 </head> 465 </html>""") 466 try: 467 tmpl = MarkupTemplate(xml, filename='test.html', 468 disable_python=False) 469 except TemplateSyntaxError, e: 470 self.fail('Unexpected SyntaxError') 471 442 472 def suite(): 443 473 suite = unittest.TestSuite() 444 474 suite.addTest(doctest.DocTestSuite(MarkupTemplate.__module__)) -
genshi/template/plugin.py
63 63 raise ConfigurationError('Unknown lookup errors mode "%s"' % 64 64 lookup_errors) 65 65 66 disable_python = options.get('genshi.disable_python', False) 67 if not isinstance(disable_python, bool): 68 raise ConfigurationError('Invalid value for disable_python "%s"' % 69 disable_python) 70 66 71 self.loader = TemplateLoader(filter(None, search_path), 67 72 auto_reload=auto_reload, 68 73 max_cache_size=max_cache_size, 69 74 default_class=self.template_class, 70 variable_lookup=lookup_errors) 75 variable_lookup=lookup_errors, 76 disable_python=disable_python) 71 77 72 78 def load_template(self, templatename, template_string=None): 73 79 """Find a template specified in python 'dot' notation, or load one from -
genshi/template/markup.py
67 67 ('strip', StripDirective)] 68 68 69 69 def __init__(self, source, basedir=None, filename=None, loader=None, 70 encoding=None, lookup='lenient' ):70 encoding=None, lookup='lenient', disable_python=False): 71 71 Template.__init__(self, source, basedir=basedir, filename=filename, 72 loader=loader, encoding=encoding, lookup=lookup) 72 loader=loader, encoding=encoding, lookup=lookup, 73 disable_python=disable_python) 73 74 # Make sure the include filter comes after the match filter 74 75 if loader: 75 76 self.filters.remove(self._include) … … 185 186 pos)] 186 187 187 188 elif kind is PI and data[0] == 'python': 189 if self.disable_python: 190 raise TemplateSyntaxError('Python code block are ' 191 'disabled', 192 self.filepath, *pos[1:]) 188 193 try: 189 194 # As Expat doesn't report whitespace between the PI target 190 195 # and the data, we have to jump through some hoops here to -
genshi/template/loader.py
73 73 """ 74 74 def __init__(self, search_path=None, auto_reload=False, 75 75 default_encoding=None, max_cache_size=25, default_class=None, 76 variable_lookup='lenient', callback=None): 76 variable_lookup='lenient', disable_python=False, 77 callback=None): 77 78 """Create the template laoder. 78 79 79 80 :param search_path: a list of absolute path names that should be … … 90 91 :param variable_lookup: the variable lookup mechanism; either "lenient" 91 92 (the default), "strict", or a custom lookup 92 93 class 94 :param disable_python: whether to allow python code blocks 93 95 :param callback: (optional) a callback function that is invoked after a 94 96 template was initialized by this loader; the function 95 97 is passed the template object as only argument. This … … 108 110 self.default_encoding = default_encoding 109 111 self.default_class = default_class or MarkupTemplate 110 112 self.variable_lookup = variable_lookup 113 self.disable_python = disable_python 111 114 if callback is not None and not callable(callback): 112 115 raise TypeError('The "callback" parameter needs to be callable') 113 116 self.callback = callback … … 200 203 dirname = '' 201 204 tmpl = cls(fileobj, basedir=dirname, filename=filename, 202 205 loader=self, lookup=self.variable_lookup, 203 encoding=encoding) 206 encoding=encoding, 207 disable_python=self.disable_python) 204 208 if self.callback: 205 209 self.callback(tmpl) 206 210 self._cache[filename] = tmpl
