Re: safe eval of moderately simple math expressions

2009-04-11 Thread Aaron Brady
On Apr 11, 8:09 am, Paul McGuire wrote: > On Apr 11, 2:41 am, Aaron Brady wrote: > > > > > Why do I get the feeling that the authors of 'pyparsing' are out of > > breath? > > What kind of breathlessness do you mean?  I'm still breathing, last > time I checked. > > The-rumors-of-my-demise-have-bee

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Paul McGuire
On Apr 11, 2:41 am, Aaron Brady wrote: > > Why do I get the feeling that the authors of 'pyparsing' are out of > breath? > What kind of breathlessness do you mean? I'm still breathing, last time I checked. The-rumors-of-my-demise-have-been-greatly-exaggerated'ly yours, -- Paul -- http://mail.

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Steven D'Aprano
On Sat, 11 Apr 2009 11:03:16 +0200, Joel Hedlund wrote: > Peter Otten wrote: >> But what you're planning to do seems more like >> > def is_it_safe(source): >> ... return "_" not in source >> ... > source = "getattr(42, '\\x5f\\x5fclass\\x5f\\x5f')" if > is_it_safe(source): >> ...

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Aaron Brady
On Apr 11, 3:18 am, Joel Hedlund wrote: > Aaron Brady wrote: > > Would you be willing to examine a syntax tree to determine if there > > are any class accesses? > > Sure? How do I do that? I've never done that type of thing before so I > can't really say if it would work or not. > > /Joel NO PROM

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Joel Hedlund
Peter Otten wrote: Joel Hedlund wrote: Peter Otten wrote: def is_it_safe(source): return "_" not in source and r'\' not in source "".join(map(chr, [95, 95, 110, 111, 95, 95])) '__no__' But you don't have access to neither map or chr? /Joel '5f5f7374696c6c5f6e6f745f736166655f5f'.dec

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Peter Otten
Joel Hedlund wrote: > Peter Otten wrote: >>> def is_it_safe(source): >>> return "_" not in source and r'\' not in source >> > "".join(map(chr, [95, 95, 110, 111, 95, 95])) >> '__no__' > > But you don't have access to neither map or chr? > > /Joel >>> '5f5f7374696c6c5f6e6f745f736166655

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Joel Hedlund
Peter Otten wrote: def is_it_safe(source): return "_" not in source and r'\' not in source "".join(map(chr, [95, 95, 110, 111, 95, 95])) '__no__' But you don't have access to neither map or chr? /Joel -- http://mail.python.org/mailman/listinfo/python-list

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Peter Otten
Joel Hedlund wrote: > Peter Otten wrote: >> But what you're planning to do seems more like >> > def is_it_safe(source): >> ... return "_" not in source >> ... > source = "getattr(42, '\\x5f\\x5fclass\\x5f\\x5f')" > if is_it_safe(source): >> ... print eval(source) >> ... >> >

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Joel Hedlund
Peter Otten wrote: But what you're planning to do seems more like def is_it_safe(source): ... return "_" not in source ... source = "getattr(42, '\\x5f\\x5fclass\\x5f\\x5f')" if is_it_safe(source): ... print eval(source) ... Bah. You are completely right of course. Just as a thou

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Peter Otten
Joel Hedlund wrote: > Matt Nordhoff wrote: > '\x5f' >> '_' > getattr(42, '\x5f\x5fclass\x5f\x5f') # __class__ >> >> >> Is that enough to show you the error of your ways? > > No, because > > >>> print '_' in '\x5f\x5fclass\x5f\x5f' > True But what you're planning to do seems more like

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Joel Hedlund
Matt Nordhoff wrote: '\x5f' '_' getattr(42, '\x5f\x5fclass\x5f\x5f') # __class__ Is that enough to show you the error of your ways? No, because >>> print '_' in '\x5f\x5fclass\x5f\x5f' True :-D Cuz seriously, it's a bad idea. Yes probably, but that's not why. :-) (BTW: What if a use

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Joel Hedlund
Matt Nordhoff wrote: '\x5f' '_' getattr(42, '\x5f\x5fclass\x5f\x5f') # __class__ Is that enough to show you the error of your ways? No, because >>> print '_' in '\x5f\x5fclass\x5f\x5f' True :-D Cuz seriously, it's a bad idea. Yes probably, but that's not why. :-) (BTW: What if a use

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Joel Hedlund
Aaron Brady wrote: Would you be willing to examine a syntax tree to determine if there are any class accesses? Sure? How do I do that? I've never done that type of thing before so I can't really say if it would work or not. /Joel -- http://mail.python.org/mailman/listinfo/python-list

Re: safe eval of moderately simple math expressions

2009-04-11 Thread Aaron Brady
On Apr 10, 7:54 pm, Steven D'Aprano wrote: > On Thu, 09 Apr 2009 13:13:50 -0400, Terry Reedy wrote: > > Joel Hedlund wrote: > >> Hi all! > > >> I'm writing a program that presents a lot of numbers to the user, and I > >> want to let the user apply moderately simple arithmentics to these > >> numbe

Re: safe eval of moderately simple math expressions

2009-04-10 Thread Steven D'Aprano
On Thu, 09 Apr 2009 13:13:50 -0400, Terry Reedy wrote: > Joel Hedlund wrote: >> Hi all! >> >> I'm writing a program that presents a lot of numbers to the user, and I >> want to let the user apply moderately simple arithmentics to these >> numbers. One possibility that comes to mind is to use the

Re: safe eval of moderately simple math expressions

2009-04-09 Thread CTO
how about sympy? http://code.google.com/p/sympy/ -- http://mail.python.org/mailman/listinfo/python-list

Re: safe eval of moderately simple math expressions

2009-04-09 Thread Paul McGuire
On Apr 9, 10:56 am, Joel Hedlund wrote: > Hi all! > > I'm writing a program that presents a lot of numbers to the user, and I > want to let the user apply moderately simple arithmentics to these > numbers. Joel - Take a look at the examples page on the pyparsing wiki (http:// pyparsing.wikispace

Re: safe eval of moderately simple math expressions

2009-04-09 Thread Terry Reedy
Joel Hedlund wrote: Hi all! I'm writing a program that presents a lot of numbers to the user, and I want to let the user apply moderately simple arithmentics to these numbers. One possibility that comes to mind is to use the eval function, but since that sends up all kinds of warning flags in

Re: safe eval of moderately simple math expressions

2009-04-09 Thread Aaron Brady
On Apr 9, 10:56 am, Joel Hedlund wrote: > Hi all! > > I'm writing a program that presents a lot of numbers to the user, and I > want to let the user apply moderately simple arithmentics to these > numbers. One possibility that comes to mind is to use the eval function, > but since that sends up al

Re: safe eval of moderately simple math expressions

2009-04-09 Thread Matt Nordhoff
Joel Hedlund wrote: > Hi all! > > I'm writing a program that presents a lot of numbers to the user, and I > want to let the user apply moderately simple arithmentics to these > numbers. One possibility that comes to mind is to use the eval function, > but since that sends up all kinds of warning f

safe eval of moderately simple math expressions

2009-04-09 Thread Joel Hedlund
Hi all! I'm writing a program that presents a lot of numbers to the user, and I want to let the user apply moderately simple arithmentics to these numbers. One possibility that comes to mind is to use the eval function, but since that sends up all kinds of warning flags in my head, I thought