comparison genshi/template/interpolation.py @ 647:5af131b37ab4 experimental-sandboxed

restricted is the new secure
author aronacher
date Wed, 26 Sep 2007 17:56:41 +0000
parents 9ada030ad986
children
comparison
equal deleted inserted replaced
646:b6cdfcb37496 647:5af131b37ab4
29 NAMESTART = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_' 29 NAMESTART = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ_'
30 NAMECHARS = NAMESTART + '.0123456789' 30 NAMECHARS = NAMESTART + '.0123456789'
31 PREFIX = '$' 31 PREFIX = '$'
32 32
33 def interpolate(text, basedir=None, filename=None, lineno=-1, offset=0, 33 def interpolate(text, basedir=None, filename=None, lineno=-1, offset=0,
34 lookup='strict'): 34 lookup='strict', restricted=False):
35 """Parse the given string and extract expressions. 35 """Parse the given string and extract expressions.
36 36
37 This function is a generator that yields `TEXT` events for literal strings, 37 This function is a generator that yields `TEXT` events for literal strings,
38 and `EXPR` events for expressions, depending on the results of parsing the 38 and `EXPR` events for expressions, depending on the results of parsing the
39 string. 39 string.
71 del textbuf[:] 71 del textbuf[:]
72 textpos = None 72 textpos = None
73 if chunk: 73 if chunk:
74 try: 74 try:
75 expr = Expression(chunk.strip(), pos[0], pos[1], 75 expr = Expression(chunk.strip(), pos[0], pos[1],
76 lookup=lookup) 76 lookup=lookup, restricted=restricted)
77 yield EXPR, expr, tuple(pos) 77 yield EXPR, expr, tuple(pos)
78 except SyntaxError, err: 78 except SyntaxError, err:
79 raise TemplateSyntaxError(err, filepath, pos[1], 79 raise TemplateSyntaxError(err, filepath, pos[1],
80 pos[2] + (err.offset or 0)) 80 pos[2] + (err.offset or 0))
81 else: 81 else:
Copyright (C) 2012-2017 Edgewall Software