Re: '_[1]' in .co_names using builtin compile() in Python 2.6

2013-11-28 Thread magnus.ly...@gmail.com
On Wednesday, November 27, 2013 9:09:32 PM UTC+1, Ned Batchelder wrote: > I hope you aren't trying to prevent malice this way: you cannot examine > a piece of Python code to prove that it's safe to execute. No worry. Whoever has access to modifying those configuration files can cause a mess in a

Re: '_[1]' in .co_names using builtin compile() in Python 2.6

2013-11-27 Thread Steven D'Aprano
On Wed, 27 Nov 2013 11:40:52 -0800, magnus.ly...@gmail.com wrote: > What I'm really after, is to check that python expressions embedded in > text files are: - well behaved (no syntax errors etc) - don't > accidentally access anything it shouldn't - I serve them with the values > they need on execu

Re: '_[1]' in .co_names using builtin compile() in Python 2.6

2013-11-27 Thread Ned Batchelder
On 11/27/13 3:44 PM, Chris Kaynor wrote: On Wed, Nov 27, 2013 at 12:09 PM, Ned Batchelder mailto:n...@nedbatchelder.com>> wrote: * Is there perhaps a better way to achieve what I'm trying to do? What I'm really after, is to check that python expressions embedded in text

Re: '_[1]' in .co_names using builtin compile() in Python 2.6

2013-11-27 Thread Chris Kaynor
On Wed, Nov 27, 2013 at 12:09 PM, Ned Batchelder wrote: > * Is there perhaps a better way to achieve what I'm trying to do? >> >> What I'm really after, is to check that python expressions embedded in >> text files are: >> - well behaved (no syntax errors etc) >> - don't accidentally access anythi

Re: '_[1]' in .co_names using builtin compile() in Python 2.6

2013-11-27 Thread Ian Kelly
On Nov 27, 2013 2:11 PM, "Ned Batchelder" wrote: > > On 11/27/13 2:40 PM, magnus.ly...@gmail.com wrote: >> >> So, in the case of "a.b + x" I'm really just interested in a and x, not b. So the (almost) whole story is that I do: >> >> # Find names not starting with ".", i.e a & b in "a.c + b" >

Re: '_[1]' in .co_names using builtin compile() in Python 2.6

2013-11-27 Thread Ned Batchelder
On 11/27/13 2:40 PM, magnus.ly...@gmail.com wrote: When I run e.g. compile('sin(5) * cos(6)', '', 'eval').co_names, I get ('sin', 'cos'), which is just what I expected. But when I have a list comprehension in the expression, I get a little surprise: compile('[x*x for x in y]', '', 'eval').co_

'_[1]' in .co_names using builtin compile() in Python 2.6

2013-11-27 Thread magnus.ly...@gmail.com
When I run e.g. compile('sin(5) * cos(6)', '', 'eval').co_names, I get ('sin', 'cos'), which is just what I expected. But when I have a list comprehension in the expression, I get a little surprise: >>> compile('[x*x for x in y]', '', 'eval').co_names ('_[1]', 'y', 'x') >>> This happens in Pyth