def createConfig(self): config = SandboxConfig.fromOptparseOptions(self.options) config.enable('traceback') config.enable('stdin') config.enable('stdout') config.enable('stderr') config.enable('exit') config.enable('site') config.enable('encodings') config._builtins_whitelist.add('compile') config.allowModuleSourceCode('code') config.allowModule('sys', 'api_version', 'version', 'hexversion') config.allowSafeModule('sys', 'version_info') if HAVE_PYPY: config.enable('unicodedata') config.allowModule('os', 'write', 'waitpid') config.allowSafeModule('pyrepl', 'input') config.allowModule('pyrepl.keymap', 'compile_keymap', 'parse_keys') if self.options.debug: config.allowModule('sys', '_getframe') config.allowSafeModule('_sandbox', '_test_crash') config.allowModuleSourceCode('sandbox') if not config.cpython_restricted: config.allowPath(__file__) return config
def parseOptions(): parser = OptionParser(usage="%prog [options] -- script.py [script options] [arg1 arg2 ...]") SandboxConfig.createOptparseOptions(parser) options, argv = parser.parse_args() if not argv: parser.print_help() exit(1) config = SandboxConfig.fromOptparseOptions(options) return config, argv
def parseOptions(self): parser = OptionParser(usage="%prog [options]") SandboxConfig.createOptparseOptions(parser, default_timeout=None) parser.add_option("--verbose", "-v", help="Verbose mode", action="store_true", default=False) parser.add_option("--quiet", "-q", help="Quiet mode", action="store_true", default=False) options, argv = parser.parse_args() if argv: parser.print_help() exit(1) if options.quiet: options.verbose = False config = SandboxConfig.fromOptparseOptions(options) return config, options