Michael Spencer wrote:
Alternatively, you could edit visitName to allow 'True' and any other
identifiers you specify e.g. (untested):
allowed = {True: True, False: False}
def visitName(self,node, **kw):
try:
return self.allowed[node.name]
except
Michael Spencer wrote:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469
Very nice work. It will be very useful. Thanks.
Only a small problem when I try to evaluate this:
safe_eval('True')
I get:
Traceback (most recent call last):
File safe_eval.py, line 63, in ?
Clodoaldo Pinto wrote:
Michael Spencer wrote:
http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/364469
Very nice work. It will be very useful. Thanks.
Only a small problem when I try to evaluate this:
safe_eval('True')
I get:
Traceback (most recent call last):
File
Em Sex, 2006-04-21 às 18:40 -0700, Clodoaldo Pinto escreveu:
Only a small problem when I try to evaluate this:
safe_eval('True')
Change
def visitName(self,node, **kw):
raise Unsafe_Source_Error(Strings must be quoted,
node.name, node)
To
def default(self, node, **kw):
for child in node.getChildNodes():
return self.visit(child, **kw)
visitExpression = default
I'm not sure I grok this part. It leads to unexpected results:
safe_dict(gid = 'FPS', type = 'Label', pos = [0, 20], text = 'FPS', text2
=
Hi everyone. I'm trying to convert a string that looks like this:
gid = 'FPS', type = 'Label', pos = [0, 20], text = 'FPS', text2 = 'more
text without quotes', fmtline = @VALUE @SIGNAL, signals = [('FPS',
None), ('FPS2', 'something')]
to a dict that looks like this:
{'signals': [('FPS', None),
Kamilche wrote:
Hi everyone. I'm trying to convert a string that looks like this:
gid = 'FPS', type = 'Label', pos = [0, 20], text = 'FPS', text2 = 'more
text without quotes', fmtline = @VALUE @SIGNAL, signals = [('FPS',
None), ('FPS2', 'something')]
to a dict that looks like this:
Thanks! It's interesting, and nearly what I want, but not quite there.
When I run my sample code through it, I get a syntax error because it's
not a valid expression. If I were to put a 'dict(' in front and a ')'
at the end, THEN it nearly works - but it gives me an
'Unsafe_Source_Error: Line 1.
Kamilche wrote:
Thanks! It's interesting, and nearly what I want, but not quite there.
When I run my sample code through it, I get a syntax error because it's
not a valid expression. If I were to put a 'dict(' in front and a ')'
at the end, THEN it nearly works - but it gives me an
Ah, finally, that's exactly what I need! Thanks bunches. I was
attempting to modify your first code to fit my needs, but mine was much
longer, and not yet working, a sure clue that yours is a better
solution. :-D
--
http://mail.python.org/mailman/listinfo/python-list
10 matches
Mail list logo