![]() |
App Engine Python SDK
v1.6.9 rev.445
The Python runtime is available as an experimental Preview feature.
|
Public Member Functions | |
def | log |
def | __init__ |
def | find_module |
def | StubModuleExists |
def | ImportStubModule |
def | FixModule |
def | FindModuleRestricted |
def | FindPathHook |
def | LoadModuleRestricted |
def | FindAndLoadModule |
def | GetParentPackage |
def | GetParentSearchPath |
def | GetModuleInfo |
def | load_module |
def | is_package |
def | get_source |
def | get_code |
Static Public Attributes | |
ENABLE_LOGGING = False | |
Meta import hook that restricts the modules used by applications to match the production environment. Module controls supported: - Disallow native/extension modules from being loaded - Disallow built-in and/or Python-distributed modules from being loaded - Replace modules with completely empty modules - Override specific module attributes - Replace one module with another After creation, this object should be added to the front of the sys.meta_path list (which may need to be created). The sys.path_importer_cache dictionary should also be cleared, to prevent loading any non-restricted modules. See PEP302 for more info on how this works: http://www.python.org/dev/peps/pep-0302/
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.__init__ | ( | self, | |
config, | |||
module_dict, | |||
app_code_path, | |||
imp_module = imp , |
|||
os_module = os , |
|||
dummy_thread_module = dummy_thread , |
|||
pickle_module = pickle |
|||
) |
Initializer. Args: config: AppInfoExternal instance representing the parsed app.yaml file. module_dict: Module dictionary to use for managing system modules. Should be sys.modules. app_code_path: The absolute path to the application code on disk. imp_module, os_module, dummy_thread_module, etc.: References to modules that exist in the dev_appserver that must be used by this class in order to function, even if these modules have been unloaded from sys.modules.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.find_module | ( | self, | |
fullname, | |||
path = None |
|||
) |
See PEP 302.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.FindAndLoadModule | ( | self, | |
submodule, | |||
submodule_fullname, | |||
search_path | |||
) |
Finds and loads a module, loads it, and adds it to the module dictionary. Args: submodule: Name of the module to import (e.g., baz). submodule_fullname: Full name of the module to import (e.g., foo.bar.baz). search_path: Path to use for searching for this submodule. For top-level modules this should be None; otherwise it should be the __path__ attribute from the parent package. Returns: A new module instance that has been inserted into the module dictionary supplied to __init__. Raises: ImportError exception if the module could not be loaded for whatever reason (e.g., missing, not allowed).
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.FindModuleRestricted | ( | self, | |
submodule, | |||
submodule_fullname, | |||
search_path | |||
) |
Locates a module while enforcing module import restrictions. Args: submodule: The short name of the submodule (i.e., the last section of the fullname; for 'foo.bar' this would be 'bar'). submodule_fullname: The fully qualified name of the module to find (e.g., 'foo.bar'). search_path: List of paths to search for to find this module. Should be None if the current sys.path should be used. Returns: Tuple (source_file, pathname, description) where: source_file: File-like object that contains the module; in the case of packages, this will be None, which implies to look at __init__.py. pathname: String containing the full path of the module on disk. description: Tuple returned by imp.find_module(). However, in the case of an import using a path hook (e.g. a zipfile), source_file will be a PEP-302-style loader object, pathname will be None, and description will be a tuple filled with None values. Raises: ImportError exception if the requested module was found, but importing it is disallowed. CouldNotFindModuleError exception if the request module could not even be found for import.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.FindPathHook | ( | self, | |
submodule, | |||
submodule_fullname, | |||
path_entry | |||
) |
Helper for FindModuleRestricted to find a module in a sys.path entry. Args: submodule: submodule_fullname: path_entry: A single sys.path entry, or None representing the builtins. Returns: Either None (if nothing was found), or a triple (source_file, path_name, description). See the doc string for FindModuleRestricted() for the meaning of the latter.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.FixModule | ( | self, | |
module | |||
) |
Prunes and overrides restricted module attributes. Args: module: The module to prune. This should be a new module whose attributes reference back to the real module's __dict__ members.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.get_code | ( | self, | |
fullname | |||
) |
See PEP 302 extensions.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.get_source | ( | self, | |
fullname | |||
) |
See PEP 302 extensions.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.GetModuleInfo | ( | self, | |
fullname | |||
) |
Determines the path on disk and the search path of a module or package. Args: fullname: Full name of the module to look up (e.g., foo.bar). Returns: Tuple (pathname, search_path, submodule) where: pathname: String containing the full path of the module on disk, or None if the module wasn't loaded from disk (e.g. from a zipfile). search_path: List of paths that belong to the found package's search path or None if found module is not a package. submodule: The relative name of the submodule that's being imported.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.GetParentPackage | ( | self, | |
fullname | |||
) |
Retrieves the parent package of a fully qualified module name. Args: fullname: Full name of the module whose parent should be retrieved (e.g., foo.bar). Returns: Module instance for the parent or None if there is no parent module. Raise: ImportError exception if the module's parent could not be found.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.GetParentSearchPath | ( | self, | |
fullname | |||
) |
Determines the search path of a module's parent package. Args: fullname: Full name of the module to look up (e.g., foo.bar). Returns: Tuple (submodule, search_path) where: submodule: The last portion of the module name from fullname (e.g., if fullname is foo.bar, then this is bar). search_path: List of paths that belong to the parent package's search path or None if there is no parent package. Raises: ImportError exception if the module or its parent could not be found.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.ImportStubModule | ( | self, | |
name | |||
) |
Import the stub module replacement for the specified module.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.is_package | ( | self, | |
fullname | |||
) |
See PEP 302 extensions.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.load_module | ( | self, | |
fullname | |||
) |
See PEP 302.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.LoadModuleRestricted | ( | self, | |
submodule_fullname, | |||
source_file, | |||
pathname, | |||
description | |||
) |
Loads a module while enforcing module import restrictions. As a byproduct, the new module will be added to the module dictionary. Args: submodule_fullname: The fully qualified name of the module to find (e.g., 'foo.bar'). source_file: File-like object that contains the module's source code, or a PEP-302-style loader object. pathname: String containing the full path of the module on disk. description: Tuple returned by imp.find_module(), or (None, None, None) in case source_file is a PEP-302-style loader object. Returns: The new module. Raises: ImportError exception of the specified module could not be loaded for whatever reason.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.log | ( | self, | |
message, | |||
args | |||
) |
Logs an import-related message to stderr, with indentation based on current call-stack depth. Args: message: Logging format string. args: Positional format parameters for the logging message.
def google.appengine.tools.dev_appserver_import_hook.HardenedModulesHook.StubModuleExists | ( | self, | |
name | |||
) |
Check if the named module has a stub replacement.