本文整理匯總了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