[Python-bugs-list] [ python-Bugs-446645 ] rexec and function attributes

noreply@sourceforge.net noreply@sourceforge.net
Tue, 31 Jul 2001 19:21:51 -0700


Bugs item #446645, was opened at 2001-07-31 19:21
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=446645&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Matthew Brecknell (brecknell)
Assigned to: Nobody/Anonymous (nobody)
Summary: rexec and function attributes

Initial Comment:
The behaviour of the rexec module seems to be 
inconsistent with respect to function attributes. The 
function attribute dictionary is read-only in the 
restricted environment until you go and write to it 
outside the restricted environment. After that, the 
dictionary becomes writable in the restricted 
environment too. See the following examples:

Python 2.1 (#1, Jun 29 2001, 15:51:00) 
[GCC 2.95.3 19991030 (prerelease)] on openbsd2
Type "copyright", "credits" or "license" for more 
information.
>>> import rexec
>>> r = rexec.RExec()
>>> def f(): pass
... 
>>> r.modules['__main__'].f = f
>>> r.r_exec('f.__dict__["attr"] = "value"')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/opt/python/lib/python2.1/rexec.py", line 264, 
in r_exec
    exec code in m.__dict__
  File "<string>", line 1, in ?
TypeError: object does not support item assignment
>>> f.attr = "value"
>>> r.r_exec('f.__dict__["attr"] = "new value"')
>>> f.attr
'new value'
>>> 

Or, looking at it another way:

Python 2.1 (#1, Jun 29 2001, 15:51:00) 
[GCC 2.95.3 19991030 (prerelease)] on openbsd2
Type "copyright", "credits" or "license" for more 
information.
>>> import rexec
>>> r = rexec.RExec()
>>> r.r_exec("def f(): pass")
>>> r.r_exec('f.__dict__["attr"] = "value"')
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/opt/python/lib/python2.1/rexec.py", line 264, 
in r_exec
    exec code in m.__dict__
  File "<string>", line 1, in ?
TypeError: object does not support item assignment
>>> f = r.modules['__main__'].f
>>> f.attr = "value"
>>> r.r_exec('f.__dict__["attr"] = "new value"')
>>> f.attr
'new value'
>>> 

Please don't abuse me too much for still being on 
Python 2.1, since I haven't had time to try 2.1.1 or 
2.2a1! If I don't put this in now, I'll forget. I'm 
guessing that neither rexec nor function attributes 
are widely used, so not too many people would have 
come across this. If I get more time down the track, 
I'll look into it further.

Regards,
Matt.


----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=105470&aid=446645&group_id=5470