rexec: I don't seem to understand "nok_builtin_names"
Chris Liechti
cliechti at gmx.net
Thu Mar 28 16:02:42 EST 2002
danielm at cronus.res.cmu.edu (Dan Moskowitz) wrote in
news:39503ed5.0203281151.25d2cdda at posting.google.com:
> Can someone tell me why execing "open" works, but not "len"?
>
>>>> from rexec import RExec
>>>>
>>>> class MyRExec(RExec):
> ... nok_builtin_names = RExec.nok_builtin_names + ("len",)
> ...
>>>> r = MyRExec()
>>>> print 'invisible names: '+`r.nok_builtin_names`
> invisible names: ('open', 'reload', '__import__', 'len')
>>>> r.r_exec('open')
>>>> r.r_exec("len('foo')")
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/usr/local/depot/python2/lib/python2.1/rexec.py", line 264,
in
> r_exec
> exec code in m.__dict__
> File "<string>", line 1, in ?
> NameError: name 'len' is not defined
because "open" is bound to a restricted replacement function:
>>> r.r_exec('print open')
<bound method MyRExec.r_open of <__main__.MyRExec instance at
0x010BB288>>
see the rexec documentation for more details about the restricted
"open" the same aplies to the other builtins, they're replaced with
limited versions.
chris
--
Chris <cliechti at gmx.net>
More information about the Python-list
mailing list