Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
rexec Namespace Reference

Data Structures

class  FileBase
 
class  FileWrapper
 
class  FileDelegate
 
class  RHooks
 
class  RExec
 

Functions

def test
 

Variables

list __all__ = ["RExec"]
 
string TEMPLATE
 
 RModuleLoader = ihooks.FancyModuleLoader
 
 RModuleImporter = ihooks.ModuleImporter
 

Detailed Description

Restricted execution facilities.

The class RExec exports methods r_exec(), r_eval(), r_execfile(), and
r_import(), which correspond roughly to the built-in operations
exec, eval(), execfile() and import, but executing the code in an
environment that only exposes those built-in operations that are
deemed safe.  To this end, a modest collection of 'fake' modules is
created which mimics the standard modules by the same names.  It is a
policy decision which built-in modules and operations are made
available; this module provides a reasonable default, but derived
classes can change the policies e.g. by overriding or extending class
variables like ok_builtin_modules or methods like make_sys().

XXX To do:
- r_open should allow writing tmp dir
- r_exec etc. with explicit globals/locals? (Use rexec("exec ... in ...")?)

Function Documentation

def rexec.test ( )

Definition at line 360 of file rexec.py.

References pre.compile(), getopt.getopt(), aifc.open(), traceback.print_exc(), and log_faction_ships.tuple.

361 def test():
362  import getopt, traceback
363  opts, args = getopt.getopt(sys.argv[1:], 'vt:')
364  verbose = 0
365  trusted = []
366  for o, a in opts:
367  if o == '-v':
368  verbose = verbose+1
369  if o == '-t':
370  trusted.append(a)
371  r = RExec(verbose=verbose)
372  if trusted:
373  r.ok_builtin_modules = r.ok_builtin_modules + tuple(trusted)
374  if args:
375  r.modules['sys'].argv = args
376  r.modules['sys'].path.insert(0, os.path.dirname(args[0]))
377  else:
378  r.modules['sys'].path.insert(0, "")
379  fp = sys.stdin
380  if args and args[0] != '-':
381  try:
382  fp = open(args[0])
383  except IOError, msg:
384  print "%s: can't open file %s" % (sys.argv[0], `args[0]`)
385  return 1
386  if fp.isatty():
387  print "*** RESTRICTED *** Python", sys.version
388  print 'Type "help", "copyright", "credits" or "license" ' \
389  'for more information.'
390 
391  while 1:
392  try:
393  try:
394  s = raw_input('>>> ')
395  except EOFError:
396  print
397  break
398  if s and s[0] != '#':
399  s = s + '\n'
400  c = compile(s, '<stdin>', 'single')
401  r.s_exec(c)
402  except SystemExit, n:
403  return n
404  except:
406  else:
407  text = fp.read()
408  fp.close()
409  c = compile(text, fp.name, 'exec')
410  try:
411  r.s_exec(c)
412  except SystemExit, n:
413  return n
414  except:
416  return 1
417 

Variable Documentation

list __all__ = ["RExec"]

Definition at line 26 of file rexec.py.

RModuleImporter = ihooks.ModuleImporter

Definition at line 113 of file rexec.py.

RModuleLoader = ihooks.FancyModuleLoader

Definition at line 112 of file rexec.py.

string TEMPLATE
Initial value:
1 = """
2 def %s(self, *args):
3  return apply(getattr(self.mod, self.name).%s, args)
4 """

Definition at line 48 of file rexec.py.