本文整理汇总了Python中rexec.RExec方法的典型用法代码示例。如果您正苦于以下问题:Python rexec.RExec方法的具体用法?Python rexec.RExec怎么用?Python rexec.RExec使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类rexec
的用法示例。
在下文中一共展示了rexec.RExec方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import rexec [as 别名]
# 或者: from rexec import RExec [as 别名]
def __init__( self ):
"""Create the Web browser GUI"""
Frame.__init__( self )
Pmw.initialise()
self.pack( expand = YES, fill = BOTH )
self.master.title( "Simple Web Browser" )
self.master.geometry( "400x300" )
self.address = Entry( self )
self.address.pack( fill = X, padx = 5, pady = 5 )
self.address.bind( "<Return>", self.getPage )
self.contents = Pmw.ScrolledText( self,
text_state = DISABLED )
self.contents.pack( expand = YES, fill = BOTH, padx = 5,
pady = 5 )
self.rexec = rexec.RExec()
self.module = self.rexec.add_module( "__main__" )
self.environment = self.module.__dict__
self.environment[ "browser" ] = Bastion.Bastion( self )
示例2: _test
# 需要导入模块: import rexec [as 别名]
# 或者: from rexec import RExec [as 别名]
def _test():
"""Test the Bastion() function."""
class Original:
def __init__(self):
self.sum = 0
def add(self, n):
self._add(n)
def _add(self, n):
self.sum = self.sum + n
def total(self):
return self.sum
o = Original()
b = Bastion(o)
testcode = """if 1:
b.add(81)
b.add(18)
print "b.total() =", b.total()
try:
print "b.sum =", b.sum,
except:
print "inaccessible"
else:
print "accessible"
try:
print "b._add =", b._add,
except:
print "inaccessible"
else:
print "accessible"
try:
print "b._get_.func_defaults =", map(type, b._get_.func_defaults),
except:
print "inaccessible"
else:
print "accessible"
\n"""
exec testcode
print '='*20, "Using rexec:", '='*20
import rexec
r = rexec.RExec()
m = r.add_module('__main__')
m.b = b
r.r_exec(testcode)
示例3: restricted
# 需要导入模块: import rexec [as 别名]
# 或者: from rexec import RExec [as 别名]
def restricted():
# XXX This test is disabled because rexec is not deemed safe
return
import rexec
if verbose:
print "Testing interaction with restricted execution ..."
sandbox = rexec.RExec()
code1 = """f = open(%r, 'w')""" % TESTFN
code2 = """f = file(%r, 'w')""" % TESTFN
code3 = """\
f = open(%r)
t = type(f) # a sneaky way to get the file() constructor
f.close()
f = t(%r, 'w') # rexec can't catch this by itself
""" % (TESTFN, TESTFN)
f = open(TESTFN, 'w') # Create the file so code3 can find it.
f.close()
try:
for code in code1, code2, code3:
try:
sandbox.r_exec(code)
except IOError, msg:
if str(msg).find("restricted") >= 0:
outcome = "OK"
else:
outcome = "got an exception, but not an expected one"
else:
outcome = "expected a restricted-execution exception"
if outcome != "OK":
raise TestFailed("%s, in %r" % (outcome, code))
finally:
try:
import os
os.unlink(TESTFN)
except:
pass