Mercurial > genshi > genshi-test
comparison genshi/template/markup.py @ 545:6e21c89d9255
Support for Python code blocks in templates can now be disabled. Closes #123.
author | cmlenz |
---|---|
date | Thu, 28 Jun 2007 23:00:24 +0000 |
parents | ced12be33858 |
children | 5458a4e8814c |
comparison
equal
deleted
inserted
replaced
544:74b89383da3f | 545:6e21c89d9255 |
---|---|
65 ('content', ContentDirective), | 65 ('content', ContentDirective), |
66 ('attrs', AttrsDirective), | 66 ('attrs', AttrsDirective), |
67 ('strip', StripDirective)] | 67 ('strip', StripDirective)] |
68 | 68 |
69 def __init__(self, source, basedir=None, filename=None, loader=None, | 69 def __init__(self, source, basedir=None, filename=None, loader=None, |
70 encoding=None, lookup='lenient'): | 70 encoding=None, lookup='lenient', allow_exec=True): |
71 Template.__init__(self, source, basedir=basedir, filename=filename, | 71 Template.__init__(self, source, basedir=basedir, filename=filename, |
72 loader=loader, encoding=encoding, lookup=lookup) | 72 loader=loader, encoding=encoding, lookup=lookup, |
73 allow_exec=allow_exec) | |
73 # Make sure the include filter comes after the match filter | 74 # Make sure the include filter comes after the match filter |
74 if loader: | 75 if loader: |
75 self.filters.remove(self._include) | 76 self.filters.remove(self._include) |
76 self.filters += [self._exec, self._match] | 77 self.filters += [self._exec, self._match] |
77 if loader: | 78 if loader: |
183 substream = substream[1:-1] | 184 substream = substream[1:-1] |
184 stream[start_offset:] = [(SUB, (directives, substream), | 185 stream[start_offset:] = [(SUB, (directives, substream), |
185 pos)] | 186 pos)] |
186 | 187 |
187 elif kind is PI and data[0] == 'python': | 188 elif kind is PI and data[0] == 'python': |
189 if not self.allow_exec: | |
190 raise TemplateSyntaxError('Python code blocks not allowed', | |
191 self.filepath, *pos[1:]) | |
188 try: | 192 try: |
189 # As Expat doesn't report whitespace between the PI target | 193 # As Expat doesn't report whitespace between the PI target |
190 # and the data, we have to jump through some hoops here to | 194 # and the data, we have to jump through some hoops here to |
191 # get correctly indented Python code | 195 # get correctly indented Python code |
192 # Unfortunately, we'll still probably not get the line | 196 # Unfortunately, we'll still probably not get the line |