当前位置: 首页>>代码示例>>Python>>正文


Python rexec.RExec方法代码示例

本文整理汇总了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 ) 
开发者ID:PythonClassRoom,项目名称:PythonClassBook,代码行数:24,代码来源:fig21_09.py

示例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) 
开发者ID:glmcdona,项目名称:meddle,代码行数:45,代码来源:Bastion.py

示例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 
开发者ID:ofermend,项目名称:medicare-demo,代码行数:44,代码来源:test_descr.py


注:本文中的rexec.RExec方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。