how to pass arguments to rexec?

Ivan idivanov at
Sun Jun 24 09:15:21 EDT 2001

I have it:
Here is a module to use:import	sys
import	rexec
import	__main__

class	sandbox(rexec.RExec):
	def	__init__			(	self,		hooks=None,	\
							verbose=0,	re_arg=None):
		self.re_arg_			=re_arg;
		rexec.RExec.__init__		(self, hooks, verbose);
		print				"new restricted environment created"
	def	add_module(self, mname):
        	if self.modules.has_key(mname):
            		return			self.modules[mname]
        	self.modules[mname]		=m=self.hooks.new_module(mname)
        	m.__builtins__			=self.modules['__builtin__']
        	m.re_arg			=self.re_arg_
	        return				m
class	arg_test:
	def	__init__			(self):
		self.msg_			="Yes, the test works!"

print "module sandbox2 loaded, no problems"

and to test:

Python 1.5.2 (#0, Apr 13 1999, 10:51:12) [MSC 32 bit (Intel)] on win32
Copyright 1991-1995 Stichting Mathematisch Centrum, Amsterdam
>>> import sandbox2
module sandbox2 loaded, no problems
>>> arg = sandbox2.arg_test()
>>> re = sandbox2.sandbox(None, 1)
new restricted environment created
>>> re.r_exec("print re_arg")
>>> re2 = sandbox2.sandbox(None, 1, arg)
new restricted environment created
>>> re2.r_exec("print re_arg")
<sandbox2.arg_test instance at 871540>
>>> re2.r_exec("print re_arg.msg_")
Yes, the test works!
>>> arg
<sandbox2.arg_test instance at 871540>

More information about the Python-list mailing list