Edit File by line
/home/barbar84/public_h.../wp-conte.../plugins/sujqvwi/ExeBy/smexe_ro.../usr/lib64/python2....
File: rexec.py
"""Restricted execution facilities.
[0] Fix | Delete
[1] Fix | Delete
The class RExec exports methods r_exec(), r_eval(), r_execfile(), and
[2] Fix | Delete
r_import(), which correspond roughly to the built-in operations
[3] Fix | Delete
exec, eval(), execfile() and import, but executing the code in an
[4] Fix | Delete
environment that only exposes those built-in operations that are
[5] Fix | Delete
deemed safe. To this end, a modest collection of 'fake' modules is
[6] Fix | Delete
created which mimics the standard modules by the same names. It is a
[7] Fix | Delete
policy decision which built-in modules and operations are made
[8] Fix | Delete
available; this module provides a reasonable default, but derived
[9] Fix | Delete
classes can change the policies e.g. by overriding or extending class
[10] Fix | Delete
variables like ok_builtin_modules or methods like make_sys().
[11] Fix | Delete
[12] Fix | Delete
XXX To do:
[13] Fix | Delete
- r_open should allow writing tmp dir
[14] Fix | Delete
- r_exec etc. with explicit globals/locals? (Use rexec("exec ... in ...")?)
[15] Fix | Delete
[16] Fix | Delete
"""
[17] Fix | Delete
from warnings import warnpy3k
[18] Fix | Delete
warnpy3k("the rexec module has been removed in Python 3.0", stacklevel=2)
[19] Fix | Delete
del warnpy3k
[20] Fix | Delete
[21] Fix | Delete
[22] Fix | Delete
import sys
[23] Fix | Delete
import __builtin__
[24] Fix | Delete
import os
[25] Fix | Delete
import ihooks
[26] Fix | Delete
import imp
[27] Fix | Delete
[28] Fix | Delete
__all__ = ["RExec"]
[29] Fix | Delete
[30] Fix | Delete
class FileBase:
[31] Fix | Delete
[32] Fix | Delete
ok_file_methods = ('fileno', 'flush', 'isatty', 'read', 'readline',
[33] Fix | Delete
'readlines', 'seek', 'tell', 'write', 'writelines', 'xreadlines',
[34] Fix | Delete
'__iter__')
[35] Fix | Delete
[36] Fix | Delete
[37] Fix | Delete
class FileWrapper(FileBase):
[38] Fix | Delete
[39] Fix | Delete
# XXX This is just like a Bastion -- should use that!
[40] Fix | Delete
[41] Fix | Delete
def __init__(self, f):
[42] Fix | Delete
for m in self.ok_file_methods:
[43] Fix | Delete
if not hasattr(self, m) and hasattr(f, m):
[44] Fix | Delete
setattr(self, m, getattr(f, m))
[45] Fix | Delete
[46] Fix | Delete
def close(self):
[47] Fix | Delete
self.flush()
[48] Fix | Delete
[49] Fix | Delete
[50] Fix | Delete
TEMPLATE = """
[51] Fix | Delete
def %s(self, *args):
[52] Fix | Delete
return getattr(self.mod, self.name).%s(*args)
[53] Fix | Delete
"""
[54] Fix | Delete
[55] Fix | Delete
class FileDelegate(FileBase):
[56] Fix | Delete
[57] Fix | Delete
def __init__(self, mod, name):
[58] Fix | Delete
self.mod = mod
[59] Fix | Delete
self.name = name
[60] Fix | Delete
[61] Fix | Delete
for m in FileBase.ok_file_methods + ('close',):
[62] Fix | Delete
exec TEMPLATE % (m, m)
[63] Fix | Delete
[64] Fix | Delete
[65] Fix | Delete
class RHooks(ihooks.Hooks):
[66] Fix | Delete
[67] Fix | Delete
def __init__(self, *args):
[68] Fix | Delete
# Hacks to support both old and new interfaces:
[69] Fix | Delete
# old interface was RHooks(rexec[, verbose])
[70] Fix | Delete
# new interface is RHooks([verbose])
[71] Fix | Delete
verbose = 0
[72] Fix | Delete
rexec = None
[73] Fix | Delete
if args and type(args[-1]) == type(0):
[74] Fix | Delete
verbose = args[-1]
[75] Fix | Delete
args = args[:-1]
[76] Fix | Delete
if args and hasattr(args[0], '__class__'):
[77] Fix | Delete
rexec = args[0]
[78] Fix | Delete
args = args[1:]
[79] Fix | Delete
if args:
[80] Fix | Delete
raise TypeError, "too many arguments"
[81] Fix | Delete
ihooks.Hooks.__init__(self, verbose)
[82] Fix | Delete
self.rexec = rexec
[83] Fix | Delete
[84] Fix | Delete
def set_rexec(self, rexec):
[85] Fix | Delete
# Called by RExec instance to complete initialization
[86] Fix | Delete
self.rexec = rexec
[87] Fix | Delete
[88] Fix | Delete
def get_suffixes(self):
[89] Fix | Delete
return self.rexec.get_suffixes()
[90] Fix | Delete
[91] Fix | Delete
def is_builtin(self, name):
[92] Fix | Delete
return self.rexec.is_builtin(name)
[93] Fix | Delete
[94] Fix | Delete
def init_builtin(self, name):
[95] Fix | Delete
m = __import__(name)
[96] Fix | Delete
return self.rexec.copy_except(m, ())
[97] Fix | Delete
[98] Fix | Delete
def init_frozen(self, name): raise SystemError, "don't use this"
[99] Fix | Delete
def load_source(self, *args): raise SystemError, "don't use this"
[100] Fix | Delete
def load_compiled(self, *args): raise SystemError, "don't use this"
[101] Fix | Delete
def load_package(self, *args): raise SystemError, "don't use this"
[102] Fix | Delete
[103] Fix | Delete
def load_dynamic(self, name, filename, file):
[104] Fix | Delete
return self.rexec.load_dynamic(name, filename, file)
[105] Fix | Delete
[106] Fix | Delete
def add_module(self, name):
[107] Fix | Delete
return self.rexec.add_module(name)
[108] Fix | Delete
[109] Fix | Delete
def modules_dict(self):
[110] Fix | Delete
return self.rexec.modules
[111] Fix | Delete
[112] Fix | Delete
def default_path(self):
[113] Fix | Delete
return self.rexec.modules['sys'].path
[114] Fix | Delete
[115] Fix | Delete
[116] Fix | Delete
# XXX Backwards compatibility
[117] Fix | Delete
RModuleLoader = ihooks.FancyModuleLoader
[118] Fix | Delete
RModuleImporter = ihooks.ModuleImporter
[119] Fix | Delete
[120] Fix | Delete
[121] Fix | Delete
class RExec(ihooks._Verbose):
[122] Fix | Delete
"""Basic restricted execution framework.
[123] Fix | Delete
[124] Fix | Delete
Code executed in this restricted environment will only have access to
[125] Fix | Delete
modules and functions that are deemed safe; you can subclass RExec to
[126] Fix | Delete
add or remove capabilities as desired.
[127] Fix | Delete
[128] Fix | Delete
The RExec class can prevent code from performing unsafe operations like
[129] Fix | Delete
reading or writing disk files, or using TCP/IP sockets. However, it does
[130] Fix | Delete
not protect against code using extremely large amounts of memory or
[131] Fix | Delete
processor time.
[132] Fix | Delete
[133] Fix | Delete
"""
[134] Fix | Delete
[135] Fix | Delete
ok_path = tuple(sys.path) # That's a policy decision
[136] Fix | Delete
[137] Fix | Delete
ok_builtin_modules = ('audioop', 'array', 'binascii',
[138] Fix | Delete
'cmath', 'errno', 'imageop',
[139] Fix | Delete
'marshal', 'math', 'md5', 'operator',
[140] Fix | Delete
'parser', 'select',
[141] Fix | Delete
'sha', '_sre', 'strop', 'struct', 'time',
[142] Fix | Delete
'_weakref')
[143] Fix | Delete
[144] Fix | Delete
ok_posix_names = ('error', 'fstat', 'listdir', 'lstat', 'readlink',
[145] Fix | Delete
'stat', 'times', 'uname', 'getpid', 'getppid',
[146] Fix | Delete
'getcwd', 'getuid', 'getgid', 'geteuid', 'getegid')
[147] Fix | Delete
[148] Fix | Delete
ok_sys_names = ('byteorder', 'copyright', 'exit', 'getdefaultencoding',
[149] Fix | Delete
'getrefcount', 'hexversion', 'maxint', 'maxunicode',
[150] Fix | Delete
'platform', 'ps1', 'ps2', 'version', 'version_info')
[151] Fix | Delete
[152] Fix | Delete
nok_builtin_names = ('open', 'file', 'reload', '__import__')
[153] Fix | Delete
[154] Fix | Delete
ok_file_types = (imp.C_EXTENSION, imp.PY_SOURCE)
[155] Fix | Delete
[156] Fix | Delete
def __init__(self, hooks = None, verbose = 0):
[157] Fix | Delete
"""Returns an instance of the RExec class.
[158] Fix | Delete
[159] Fix | Delete
The hooks parameter is an instance of the RHooks class or a subclass
[160] Fix | Delete
of it. If it is omitted or None, the default RHooks class is
[161] Fix | Delete
instantiated.
[162] Fix | Delete
[163] Fix | Delete
Whenever the RExec module searches for a module (even a built-in one)
[164] Fix | Delete
or reads a module's code, it doesn't actually go out to the file
[165] Fix | Delete
system itself. Rather, it calls methods of an RHooks instance that
[166] Fix | Delete
was passed to or created by its constructor. (Actually, the RExec
[167] Fix | Delete
object doesn't make these calls --- they are made by a module loader
[168] Fix | Delete
object that's part of the RExec object. This allows another level of
[169] Fix | Delete
flexibility, which can be useful when changing the mechanics of
[170] Fix | Delete
import within the restricted environment.)
[171] Fix | Delete
[172] Fix | Delete
By providing an alternate RHooks object, we can control the file
[173] Fix | Delete
system accesses made to import a module, without changing the
[174] Fix | Delete
actual algorithm that controls the order in which those accesses are
[175] Fix | Delete
made. For instance, we could substitute an RHooks object that
[176] Fix | Delete
passes all filesystem requests to a file server elsewhere, via some
[177] Fix | Delete
RPC mechanism such as ILU. Grail's applet loader uses this to support
[178] Fix | Delete
importing applets from a URL for a directory.
[179] Fix | Delete
[180] Fix | Delete
If the verbose parameter is true, additional debugging output may be
[181] Fix | Delete
sent to standard output.
[182] Fix | Delete
[183] Fix | Delete
"""
[184] Fix | Delete
[185] Fix | Delete
raise RuntimeError, "This code is not secure in Python 2.2 and later"
[186] Fix | Delete
[187] Fix | Delete
ihooks._Verbose.__init__(self, verbose)
[188] Fix | Delete
# XXX There's a circular reference here:
[189] Fix | Delete
self.hooks = hooks or RHooks(verbose)
[190] Fix | Delete
self.hooks.set_rexec(self)
[191] Fix | Delete
self.modules = {}
[192] Fix | Delete
self.ok_dynamic_modules = self.ok_builtin_modules
[193] Fix | Delete
list = []
[194] Fix | Delete
for mname in self.ok_builtin_modules:
[195] Fix | Delete
if mname in sys.builtin_module_names:
[196] Fix | Delete
list.append(mname)
[197] Fix | Delete
self.ok_builtin_modules = tuple(list)
[198] Fix | Delete
self.set_trusted_path()
[199] Fix | Delete
self.make_builtin()
[200] Fix | Delete
self.make_initial_modules()
[201] Fix | Delete
# make_sys must be last because it adds the already created
[202] Fix | Delete
# modules to its builtin_module_names
[203] Fix | Delete
self.make_sys()
[204] Fix | Delete
self.loader = RModuleLoader(self.hooks, verbose)
[205] Fix | Delete
self.importer = RModuleImporter(self.loader, verbose)
[206] Fix | Delete
[207] Fix | Delete
def set_trusted_path(self):
[208] Fix | Delete
# Set the path from which dynamic modules may be loaded.
[209] Fix | Delete
# Those dynamic modules must also occur in ok_builtin_modules
[210] Fix | Delete
self.trusted_path = filter(os.path.isabs, sys.path)
[211] Fix | Delete
[212] Fix | Delete
def load_dynamic(self, name, filename, file):
[213] Fix | Delete
if name not in self.ok_dynamic_modules:
[214] Fix | Delete
raise ImportError, "untrusted dynamic module: %s" % name
[215] Fix | Delete
if name in sys.modules:
[216] Fix | Delete
src = sys.modules[name]
[217] Fix | Delete
else:
[218] Fix | Delete
src = imp.load_dynamic(name, filename, file)
[219] Fix | Delete
dst = self.copy_except(src, [])
[220] Fix | Delete
return dst
[221] Fix | Delete
[222] Fix | Delete
def make_initial_modules(self):
[223] Fix | Delete
self.make_main()
[224] Fix | Delete
self.make_osname()
[225] Fix | Delete
[226] Fix | Delete
# Helpers for RHooks
[227] Fix | Delete
[228] Fix | Delete
def get_suffixes(self):
[229] Fix | Delete
return [item # (suff, mode, type)
[230] Fix | Delete
for item in imp.get_suffixes()
[231] Fix | Delete
if item[2] in self.ok_file_types]
[232] Fix | Delete
[233] Fix | Delete
def is_builtin(self, mname):
[234] Fix | Delete
return mname in self.ok_builtin_modules
[235] Fix | Delete
[236] Fix | Delete
# The make_* methods create specific built-in modules
[237] Fix | Delete
[238] Fix | Delete
def make_builtin(self):
[239] Fix | Delete
m = self.copy_except(__builtin__, self.nok_builtin_names)
[240] Fix | Delete
m.__import__ = self.r_import
[241] Fix | Delete
m.reload = self.r_reload
[242] Fix | Delete
m.open = m.file = self.r_open
[243] Fix | Delete
[244] Fix | Delete
def make_main(self):
[245] Fix | Delete
self.add_module('__main__')
[246] Fix | Delete
[247] Fix | Delete
def make_osname(self):
[248] Fix | Delete
osname = os.name
[249] Fix | Delete
src = __import__(osname)
[250] Fix | Delete
dst = self.copy_only(src, self.ok_posix_names)
[251] Fix | Delete
dst.environ = e = {}
[252] Fix | Delete
for key, value in os.environ.items():
[253] Fix | Delete
e[key] = value
[254] Fix | Delete
[255] Fix | Delete
def make_sys(self):
[256] Fix | Delete
m = self.copy_only(sys, self.ok_sys_names)
[257] Fix | Delete
m.modules = self.modules
[258] Fix | Delete
m.argv = ['RESTRICTED']
[259] Fix | Delete
m.path = map(None, self.ok_path)
[260] Fix | Delete
m.exc_info = self.r_exc_info
[261] Fix | Delete
m = self.modules['sys']
[262] Fix | Delete
l = self.modules.keys() + list(self.ok_builtin_modules)
[263] Fix | Delete
l.sort()
[264] Fix | Delete
m.builtin_module_names = tuple(l)
[265] Fix | Delete
[266] Fix | Delete
# The copy_* methods copy existing modules with some changes
[267] Fix | Delete
[268] Fix | Delete
def copy_except(self, src, exceptions):
[269] Fix | Delete
dst = self.copy_none(src)
[270] Fix | Delete
for name in dir(src):
[271] Fix | Delete
setattr(dst, name, getattr(src, name))
[272] Fix | Delete
for name in exceptions:
[273] Fix | Delete
try:
[274] Fix | Delete
delattr(dst, name)
[275] Fix | Delete
except AttributeError:
[276] Fix | Delete
pass
[277] Fix | Delete
return dst
[278] Fix | Delete
[279] Fix | Delete
def copy_only(self, src, names):
[280] Fix | Delete
dst = self.copy_none(src)
[281] Fix | Delete
for name in names:
[282] Fix | Delete
try:
[283] Fix | Delete
value = getattr(src, name)
[284] Fix | Delete
except AttributeError:
[285] Fix | Delete
continue
[286] Fix | Delete
setattr(dst, name, value)
[287] Fix | Delete
return dst
[288] Fix | Delete
[289] Fix | Delete
def copy_none(self, src):
[290] Fix | Delete
m = self.add_module(src.__name__)
[291] Fix | Delete
m.__doc__ = src.__doc__
[292] Fix | Delete
return m
[293] Fix | Delete
[294] Fix | Delete
# Add a module -- return an existing module or create one
[295] Fix | Delete
[296] Fix | Delete
def add_module(self, mname):
[297] Fix | Delete
m = self.modules.get(mname)
[298] Fix | Delete
if m is None:
[299] Fix | Delete
self.modules[mname] = m = self.hooks.new_module(mname)
[300] Fix | Delete
m.__builtins__ = self.modules['__builtin__']
[301] Fix | Delete
return m
[302] Fix | Delete
[303] Fix | Delete
# The r* methods are public interfaces
[304] Fix | Delete
[305] Fix | Delete
def r_exec(self, code):
[306] Fix | Delete
"""Execute code within a restricted environment.
[307] Fix | Delete
[308] Fix | Delete
The code parameter must either be a string containing one or more
[309] Fix | Delete
lines of Python code, or a compiled code object, which will be
[310] Fix | Delete
executed in the restricted environment's __main__ module.
[311] Fix | Delete
[312] Fix | Delete
"""
[313] Fix | Delete
m = self.add_module('__main__')
[314] Fix | Delete
exec code in m.__dict__
[315] Fix | Delete
[316] Fix | Delete
def r_eval(self, code):
[317] Fix | Delete
"""Evaluate code within a restricted environment.
[318] Fix | Delete
[319] Fix | Delete
The code parameter must either be a string containing a Python
[320] Fix | Delete
expression, or a compiled code object, which will be evaluated in
[321] Fix | Delete
the restricted environment's __main__ module. The value of the
[322] Fix | Delete
expression or code object will be returned.
[323] Fix | Delete
[324] Fix | Delete
"""
[325] Fix | Delete
m = self.add_module('__main__')
[326] Fix | Delete
return eval(code, m.__dict__)
[327] Fix | Delete
[328] Fix | Delete
def r_execfile(self, file):
[329] Fix | Delete
"""Execute the Python code in the file in the restricted
[330] Fix | Delete
environment's __main__ module.
[331] Fix | Delete
[332] Fix | Delete
"""
[333] Fix | Delete
m = self.add_module('__main__')
[334] Fix | Delete
execfile(file, m.__dict__)
[335] Fix | Delete
[336] Fix | Delete
def r_import(self, mname, globals={}, locals={}, fromlist=[]):
[337] Fix | Delete
"""Import a module, raising an ImportError exception if the module
[338] Fix | Delete
is considered unsafe.
[339] Fix | Delete
[340] Fix | Delete
This method is implicitly called by code executing in the
[341] Fix | Delete
restricted environment. Overriding this method in a subclass is
[342] Fix | Delete
used to change the policies enforced by a restricted environment.
[343] Fix | Delete
[344] Fix | Delete
"""
[345] Fix | Delete
return self.importer.import_module(mname, globals, locals, fromlist)
[346] Fix | Delete
[347] Fix | Delete
def r_reload(self, m):
[348] Fix | Delete
"""Reload the module object, re-parsing and re-initializing it.
[349] Fix | Delete
[350] Fix | Delete
This method is implicitly called by code executing in the
[351] Fix | Delete
restricted environment. Overriding this method in a subclass is
[352] Fix | Delete
used to change the policies enforced by a restricted environment.
[353] Fix | Delete
[354] Fix | Delete
"""
[355] Fix | Delete
return self.importer.reload(m)
[356] Fix | Delete
[357] Fix | Delete
def r_unload(self, m):
[358] Fix | Delete
"""Unload the module.
[359] Fix | Delete
[360] Fix | Delete
Removes it from the restricted environment's sys.modules dictionary.
[361] Fix | Delete
[362] Fix | Delete
This method is implicitly called by code executing in the
[363] Fix | Delete
restricted environment. Overriding this method in a subclass is
[364] Fix | Delete
used to change the policies enforced by a restricted environment.
[365] Fix | Delete
[366] Fix | Delete
"""
[367] Fix | Delete
return self.importer.unload(m)
[368] Fix | Delete
[369] Fix | Delete
# The s_* methods are similar but also swap std{in,out,err}
[370] Fix | Delete
[371] Fix | Delete
def make_delegate_files(self):
[372] Fix | Delete
s = self.modules['sys']
[373] Fix | Delete
self.delegate_stdin = FileDelegate(s, 'stdin')
[374] Fix | Delete
self.delegate_stdout = FileDelegate(s, 'stdout')
[375] Fix | Delete
self.delegate_stderr = FileDelegate(s, 'stderr')
[376] Fix | Delete
self.restricted_stdin = FileWrapper(sys.stdin)
[377] Fix | Delete
self.restricted_stdout = FileWrapper(sys.stdout)
[378] Fix | Delete
self.restricted_stderr = FileWrapper(sys.stderr)
[379] Fix | Delete
[380] Fix | Delete
def set_files(self):
[381] Fix | Delete
if not hasattr(self, 'save_stdin'):
[382] Fix | Delete
self.save_files()
[383] Fix | Delete
if not hasattr(self, 'delegate_stdin'):
[384] Fix | Delete
self.make_delegate_files()
[385] Fix | Delete
s = self.modules['sys']
[386] Fix | Delete
s.stdin = self.restricted_stdin
[387] Fix | Delete
s.stdout = self.restricted_stdout
[388] Fix | Delete
s.stderr = self.restricted_stderr
[389] Fix | Delete
sys.stdin = self.delegate_stdin
[390] Fix | Delete
sys.stdout = self.delegate_stdout
[391] Fix | Delete
sys.stderr = self.delegate_stderr
[392] Fix | Delete
[393] Fix | Delete
def reset_files(self):
[394] Fix | Delete
self.restore_files()
[395] Fix | Delete
s = self.modules['sys']
[396] Fix | Delete
self.restricted_stdin = s.stdin
[397] Fix | Delete
self.restricted_stdout = s.stdout
[398] Fix | Delete
self.restricted_stderr = s.stderr
[399] Fix | Delete
[400] Fix | Delete
[401] Fix | Delete
def save_files(self):
[402] Fix | Delete
self.save_stdin = sys.stdin
[403] Fix | Delete
self.save_stdout = sys.stdout
[404] Fix | Delete
self.save_stderr = sys.stderr
[405] Fix | Delete
[406] Fix | Delete
def restore_files(self):
[407] Fix | Delete
sys.stdin = self.save_stdin
[408] Fix | Delete
sys.stdout = self.save_stdout
[409] Fix | Delete
sys.stderr = self.save_stderr
[410] Fix | Delete
[411] Fix | Delete
def s_apply(self, func, args=(), kw={}):
[412] Fix | Delete
self.save_files()
[413] Fix | Delete
try:
[414] Fix | Delete
self.set_files()
[415] Fix | Delete
r = func(*args, **kw)
[416] Fix | Delete
finally:
[417] Fix | Delete
self.restore_files()
[418] Fix | Delete
return r
[419] Fix | Delete
[420] Fix | Delete
def s_exec(self, *args):
[421] Fix | Delete
"""Execute code within a restricted environment.
[422] Fix | Delete
[423] Fix | Delete
Similar to the r_exec() method, but the code will be granted access
[424] Fix | Delete
to restricted versions of the standard I/O streams sys.stdin,
[425] Fix | Delete
sys.stderr, and sys.stdout.
[426] Fix | Delete
[427] Fix | Delete
The code parameter must either be a string containing one or more
[428] Fix | Delete
lines of Python code, or a compiled code object, which will be
[429] Fix | Delete
executed in the restricted environment's __main__ module.
[430] Fix | Delete
[431] Fix | Delete
"""
[432] Fix | Delete
return self.s_apply(self.r_exec, args)
[433] Fix | Delete
[434] Fix | Delete
def s_eval(self, *args):
[435] Fix | Delete
"""Evaluate code within a restricted environment.
[436] Fix | Delete
[437] Fix | Delete
Similar to the r_eval() method, but the code will be granted access
[438] Fix | Delete
to restricted versions of the standard I/O streams sys.stdin,
[439] Fix | Delete
sys.stderr, and sys.stdout.
[440] Fix | Delete
[441] Fix | Delete
The code parameter must either be a string containing a Python
[442] Fix | Delete
expression, or a compiled code object, which will be evaluated in
[443] Fix | Delete
the restricted environment's __main__ module. The value of the
[444] Fix | Delete
expression or code object will be returned.
[445] Fix | Delete
[446] Fix | Delete
"""
[447] Fix | Delete
return self.s_apply(self.r_eval, args)
[448] Fix | Delete
[449] Fix | Delete
def s_execfile(self, *args):
[450] Fix | Delete
"""Execute the Python code in the file in the restricted
[451] Fix | Delete
environment's __main__ module.
[452] Fix | Delete
[453] Fix | Delete
Similar to the r_execfile() method, but the code will be granted
[454] Fix | Delete
access to restricted versions of the standard I/O streams sys.stdin,
[455] Fix | Delete
sys.stderr, and sys.stdout.
[456] Fix | Delete
[457] Fix | Delete
"""
[458] Fix | Delete
return self.s_apply(self.r_execfile, args)
[459] Fix | Delete
[460] Fix | Delete
def s_import(self, *args):
[461] Fix | Delete
"""Import a module, raising an ImportError exception if the module
[462] Fix | Delete
is considered unsafe.
[463] Fix | Delete
[464] Fix | Delete
This method is implicitly called by code executing in the
[465] Fix | Delete
restricted environment. Overriding this method in a subclass is
[466] Fix | Delete
used to change the policies enforced by a restricted environment.
[467] Fix | Delete
[468] Fix | Delete
Similar to the r_import() method, but has access to restricted
[469] Fix | Delete
versions of the standard I/O streams sys.stdin, sys.stderr, and
[470] Fix | Delete
sys.stdout.
[471] Fix | Delete
[472] Fix | Delete
"""
[473] Fix | Delete
return self.s_apply(self.r_import, args)
[474] Fix | Delete
[475] Fix | Delete
def s_reload(self, *args):
[476] Fix | Delete
"""Reload the module object, re-parsing and re-initializing it.
[477] Fix | Delete
[478] Fix | Delete
This method is implicitly called by code executing in the
[479] Fix | Delete
restricted environment. Overriding this method in a subclass is
[480] Fix | Delete
used to change the policies enforced by a restricted environment.
[481] Fix | Delete
[482] Fix | Delete
Similar to the r_reload() method, but has access to restricted
[483] Fix | Delete
versions of the standard I/O streams sys.stdin, sys.stderr, and
[484] Fix | Delete
sys.stdout.
[485] Fix | Delete
[486] Fix | Delete
"""
[487] Fix | Delete
return self.s_apply(self.r_reload, args)
[488] Fix | Delete
[489] Fix | Delete
def s_unload(self, *args):
[490] Fix | Delete
"""Unload the module.
[491] Fix | Delete
[492] Fix | Delete
Removes it from the restricted environment's sys.modules dictionary.
[493] Fix | Delete
[494] Fix | Delete
This method is implicitly called by code executing in the
[495] Fix | Delete
restricted environment. Overriding this method in a subclass is
[496] Fix | Delete
used to change the policies enforced by a restricted environment.
[497] Fix | Delete
[498] Fix | Delete
Similar to the r_unload() method, but has access to restricted
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function