Esempio n. 1
0
def sandbox(testbed):
    """
    Enables parts of the GAE sandbox that are relevant.
    Inserts the stub module import hook which causes the usage of
    appengine-specific httplib, httplib2, socket, etc.
    """
    from google.appengine.tools.devappserver2.python import sandbox

    for name in list(sys.modules):
        if name in sandbox.dist27.MODULE_OVERRIDES:
            del sys.modules[name]
    sys.meta_path.insert(0, sandbox.StubModuleImportHook())
    sys.path_importer_cache = {}

    yield testbed

    sys.meta_path = [
        x for x in sys.meta_path
        if not isinstance(x, sandbox.StubModuleImportHook)
    ]
    sys.path_importer_cache = {}

    # Delete any instances of sandboxed modules.
    for name in list(sys.modules):
        if name in sandbox.dist27.MODULE_OVERRIDES:
            del sys.modules[name]
Esempio n. 2
0
def activate_sandbox():
    """
    Enables parts of the GAE sandbox that are relevant.

    Inserts the stub module import hook which causes the usage of appengine-specific
    httplib, httplib2, socket, etc.
    """
    from google.appengine.tools.devappserver2.python import sandbox

    for name in list(sys.modules):
        if name in sandbox.dist27.MODULE_OVERRIDES:
            del sys.modules[name]
    sys.meta_path.insert(0, sandbox.StubModuleImportHook())
    sys.path_importer_cache = {}