def setUp(self): self.mox = mox.Mox() self.tmpdir = tempfile.mkdtemp() module_configuration = ModuleConfigurationStub( application_root=self.tmpdir, error_handlers=[ appinfo.ErrorHandlers(error_code='over_quota', file='foo.html'), appinfo.ErrorHandlers(error_code='default', file='error.html'), ]) self.runtime_config = runtime_config_pb2.Config() self.runtime_config.app_id = 'app' self.runtime_config.version_id = 'version' self.runtime_config.api_port = 12345 self.runtime_config.application_root = self.tmpdir self.runtime_config.datacenter = 'us1' self.runtime_config.instance_id = 'abc3dzac4' self.runtime_config.auth_domain = 'gmail.com' self.runtime_config_getter = lambda: self.runtime_config self.proxy = http_runtime.HttpRuntimeProxy(['/runtime'], self.runtime_config_getter, module_configuration, env={'foo': 'bar'}) self.process = self.mox.CreateMock(subprocess.Popen) self.process.stdin = self.mox.CreateMockAnything() self.process.stdout = self.mox.CreateMockAnything() self.mox.StubOutWithMock(safe_subprocess, 'start_process') self.mox.StubOutWithMock(httplib.HTTPConnection, 'connect') self.mox.StubOutWithMock(httplib.HTTPConnection, 'request') self.mox.StubOutWithMock(httplib.HTTPConnection, 'getresponse') self.mox.StubOutWithMock(httplib.HTTPConnection, 'close') self.mox.StubOutWithMock(login, 'get_user_info') self.mox.StubOutWithMock(shutdown, 'async_quit') self.url_map = appinfo.URLMap(url=r'/(get|post).*', script=r'\1.py')
def main(): # Required so PDB prompts work properly. Originally tried to disable buffering # (both by adding the -u flag when starting this process and by adding # "stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)" but neither worked). sys.stdout = AutoFlush(sys.stdout) assert len(sys.argv) == 3 child_in_path = sys.argv[1] child_out_path = sys.argv[2] config = runtime_config_pb2.Config() config.ParseFromString(open(child_in_path, 'rb').read()) os.remove(child_in_path) child_out = open(child_out_path, 'wb') # AppScale: The external port is packed in the same field as the API port. external_api_port = None if config.api_port > 65535: port_bytes = struct.pack('I', config.api_port) config.api_port, external_api_port = struct.unpack('HH', port_bytes) debugging_app = None if config.python_config and config.python_config.startup_script: global_vars = {'config': config} try: execfile(config.python_config.startup_script, global_vars) except Exception, e: debugging_app = StartupScriptFailureApplication( config, str(e), traceback.format_exc())
def setUp(self): self.mox = mox.Mox() self.tmpdir = tempfile.mkdtemp() module_configuration = ModuleConfigurationStub( application_root=self.tmpdir) self.runtime_config = runtime_config_pb2.Config() self.runtime_config.app_id = 'app' self.runtime_config.version_id = 'version' self.runtime_config.api_port = 12345 self.runtime_config.application_root = self.tmpdir self.runtime_config.datacenter = 'us1' self.runtime_config.instance_id = 'abc3dzac4' self.runtime_config.auth_domain = 'gmail.com' self.runtime_config_getter = lambda: self.runtime_config self.proxy = http_runtime.HttpRuntimeProxy( ['/runtime'], self.runtime_config_getter, module_configuration, env={'foo': 'bar'}, start_process_flavor=http_runtime.START_PROCESS_REVERSE) self.mox.StubOutWithMock(self.proxy, '_process_lock') self.process = self.mox.CreateMock(subprocess.Popen) self.process.stdin = self.mox.CreateMockAnything() self.mox.StubOutWithMock(safe_subprocess, 'start_process_file') self.mox.StubOutWithMock(os, 'remove') self.mox.StubOutWithMock(time, 'sleep') self.url_map = appinfo.URLMap(url=r'/(get|post).*', script=r'\1.py') self.mox.StubOutWithMock(http_proxy.HttpProxy, 'wait_for_connection') self.mox.StubOutWithMock(portpicker, 'PickUnusedPort') http_proxy.HttpProxy.wait_for_connection(self.process)
def main(): # Required so PDB prompts work properly. Originally tried to disable buffering # (both by adding the -u flag when starting this process and by adding # "stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)" but neither worked). sys.stdout = AutoFlush(sys.stdout) assert len(sys.argv) == 3 child_in_path = sys.argv[1] config = runtime_config_pb2.Config() config.ParseFromString(open(child_in_path, 'rb').read()) os.remove(child_in_path) debugging_app = None if config.python_config and config.python_config.startup_script: global_vars = {'config': config} try: execfile(config.python_config.startup_script, global_vars) except Exception as e: debugging_app = StartupScriptFailureApplication(config, str(e), traceback.format_exc()) # This line needs to be before enabling the sandbox because os.environ is # patched away. port = os.environ['PORT'] if debugging_app: server = wsgi_server.WsgiServer( ('localhost', port), debugging_app) else: setup_stubs(config) sandbox.enable_sandbox(config) os.path.expanduser = expand_user # This import needs to be after enabling the sandbox so the runtime # implementation imports the sandboxed version of the logging module. # pylint: disable=g-import-not-at-top from google.appengine.tools.devappserver2.python.runtime import ( request_handler) # pylint: enable=g-import-not-at-top server = wsgi_server.WsgiServer( ('localhost', port), request_rewriter.runtime_rewriter_middleware( request_handler.RequestHandler(config))) # Delete devappserver2.python.runtime and devappserver2.python.runtime.sandbox # from sys.modules so that future attempts to import # devappserver2.python.runtime.sandbox from user code goes through and gets # blocked by the sandbox's sys.meta_path import hooks. del sys.modules[sandbox.__name__] del sys.modules[runtime.__name__] server.start() try: while True: time.sleep(1) except KeyboardInterrupt: pass finally: server.quit()
def main(): config = runtime_config_pb2.Config() config.ParseFromString(base64.b64decode(sys.stdin.read())) debugging_app = None if config.python_config and config.python_config.startup_script: global_vars = {'config': config} try: execfile(config.python_config.startup_script, global_vars) except Exception, e: debugging_app = StartupScriptFailureApplication( config, str(e), traceback.format_exc())
def setUp(self): super(SandboxTest, self).setUp() self.mox = mox.Mox() self.old_path = sys.path self.old_meta_path = sys.meta_path self.old_library_format_string = sandbox._THIRD_PARTY_LIBRARY_FORMAT_STRING self.config = runtime_config_pb2.Config() self.app_root = 'test/app/root' self.config.application_root = self.app_root self.config.app_id = 'app' self.config.version_id = '1' self.builtins = __builtin__.__dict__.copy() self.modules = sys.modules.copy()
def test_setup_stubs(self): self.mox.StubOutWithMock(remote_api_stub, 'ConfigureRemoteApi') remote_api_stub.ConfigureRemoteApi('app', '/', mox.IgnoreArg(), 'localhost:12345', use_remote_datastore=False) config = runtime_config_pb2.Config() config.app_id = 'app' config.api_port = 12345 self.mox.ReplayAll() runtime.setup_stubs(config) self.mox.VerifyAll()
def main(): # Required so PDB prompts work properly. Originally tried to disable buffering # (both by adding the -u flag when starting this process and by adding # "stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)" but neither worked). sys.stdout = AutoFlush(sys.stdout) assert len(sys.argv) == 3 child_in_path = sys.argv[1] child_out_path = sys.argv[2] config = runtime_config_pb2.Config() config.ParseFromString(open(child_in_path, 'rb').read()) os.remove(child_in_path) child_out = open(child_out_path, 'wb') debugging_app = None if config.python_config and config.python_config.startup_script: global_vars = {'config': config} try: exec( compile( open(config.python_config.startup_script).read(), config.python_config.startup_script, 'exec'), global_vars) except Exception as e: debugging_app = StartupScriptFailureApplication( config, str(e), traceback.format_exc()) if debugging_app: server = wsgi_server.WsgiServer(('localhost', 0), debugging_app) else: setup_stubs(config) sandbox.enable_sandbox(config) # This import needs to be after enabling the sandbox so the runtime # implementation imports the sandboxed version of the logging module. from google.appengine.tools.devappserver2.python import request_handler server = wsgi_server.WsgiServer( ('localhost', 0), request_rewriter.runtime_rewriter_middleware( request_handler.RequestHandler(config))) server.start() child_out.write('{}\n'.format(server.port).encode()) child_out.close() try: while True: time.sleep(1) except KeyboardInterrupt: pass finally: server.quit()
def main(): config = runtime_config_pb2.Config() config.ParseFromString(base64.b64decode(sys.stdin.read())) server = wsgi_server.WsgiServer( ('localhost', 0), request_rewriter.runtime_rewriter_middleware(PHPRuntime(config))) server.start() print server.port sys.stdout.close() sys.stdout = sys.stderr try: while True: time.sleep(1) except KeyboardInterrupt: pass finally: server.quit()
def main(): # Required so PDB prompts work properly. Originally tried to disable buffering # (both by adding the -u flag when starting this process and by adding # "stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)" but neither worked). sys.stdout = AutoFlush(sys.stdout) assert len(sys.argv) == 3 child_in_path = sys.argv[1] config = runtime_config_pb2.Config() config.ParseFromString(open(child_in_path, 'rb').read()) os.remove(child_in_path) debugging_app = None if config.python_config and config.python_config.startup_script: global_vars = {'config': config} try: execfile(config.python_config.startup_script, global_vars) except Exception, e: debugging_app = StartupScriptFailureApplication( config, str(e), traceback.format_exc())
def main(): config = runtime_config_pb2.Config() config.ParseFromString(base64.b64decode(sys.stdin.read())) # AppScale: The external port is packed in the same field as the API port. external_api_port = None if config.api_port > 65535: port_bytes = struct.pack('I', config.api_port) config.api_port, external_api_port = struct.unpack('HH', port_bytes) debugging_app = None if config.python_config and config.python_config.startup_script: global_vars = {'config': config} try: execfile(config.python_config.startup_script, global_vars) except Exception, e: debugging_app = StartupScriptFailureApplication( config, str(e), traceback.format_exc())
def main(): # Read the runtime configuration from file. config = runtime_config_pb2.Config() config.ParseFromString(open(sys.argv[1], 'rb').read()) # Launch the node process. Note, the port is specified in os.environ. node_app_process = safe_subprocess.start_process( args=[config.node_config.node_executable_path, os.path.join(config.application_root, 'server.js')], env=os.environ.copy(), cwd=config.application_root, stdout=sys.stderr, ) # Wait for the devappserver to kill the process. try: while True: time.sleep(1) except KeyboardInterrupt: pass finally: sys.stdout.close() node_app_process.kill()
from sandbox import * from google.appengine.tools.devappserver2 import runtime_config_pb2 config = runtime_config_pb2.Config() config.application_root = './temp' enable_sandbox(config) import os for path, dirs, files in os.walk('./'): print path for f in files: print f fileHandler = open('abc.txt', 'r') print str(fileHandler)