rexec r_eval and s_eval (bug?)

Chris Liechti cliechti at gmx.net
Wed Nov 21 20:43:00 EST 2001


from what i read in the docs, "r_eval" and "s_eval" should behave like the 
same, except for the sys.stdxxx variables.
the r_* version has no access to sys.stdxxx but the s_* versions have 
access to a secure sys.stdxxx object

exaple 1:
>>> r = rexec.RExec()
>>> r.s_exec('import sys')
>>> r.s_exec('print "stdout" in dir(sys)')
1
>>> r = rexec.RExec()
>>> r.r_exec('import sys')
>>> r.r_exec('print "stdout" in dir(sys)')
0
>>> 

stdout (and also stderr, stdin) is only available when the sys module was 
imported with s_exec. this is what the manual implies.
however, strange things happen if i try to modify sys.stdout and even mix 
r_exec and s_exec statements or even try "sys.stdout = None" and then 
"print sys.stdout".... and it gets even worse.

look at this example:

example 2:
>>> r = rexec.RExec()
>>> r.r_eval('dir()')
['__builtins__', '__doc__', '__name__']
>>> r = rexec.RExec()
>>> r.s_eval('dir()')
>>> 

r_eval works as expected and returns a dictionary. however s_eval seems to 
have a problem as it returns None. (other test strings show the same 
behaviour e.g. "25" or "'hello'" etc.)

both function should actually return the same objects, as long as the 
expression has nothing to do with sys.stdxxx, but they don't.

is this a bug or a feature that i don't understand?

chris

(Examples from Python 2.1/Win32)

-- 
Chris <cliechti at gmx.net>




More information about the Python-list mailing list