Пример #1
0
    def _get_module_with_soft_routing(self, module_name, version):
        """Uses soft-routing to find the specified module.

    Soft-routing is an attempt to match the production resolution order, which
    is slightly more permissive than the Modules API behavior. Here are the
    rules allowed:
    1. If a module is requested that doesn't exist, use the default module.
    2. If a module is requested that doesn't exist, and there is no default
    module, use any module.

    Args:
      module_name: The name of the module.
      version: The version id.
    Returns:
      Module object.
    Raises:
      request_info.ModuleDoesNotExistError: The module doesn't exist.
      request_info.VersionDoesNotExistError: The version doesn't exist.
    """
        if not module_name or module_name not in self._module_name_to_module:
            if appinfo.DEFAULT_MODULE in self._module_name_to_module:
                module_name = appinfo.DEFAULT_MODULE
            elif self._module_name_to_module:
                # If there is no default module, but there are other modules, take any.
                # This is somewhat of a hack, and can be removed if we ever enforce the
                # existence of a default module.
                module_name = self._module_name_to_module.keys()[0]
            else:
                raise request_info.ModuleDoesNotExistError(module_name)
        if (version is not None and version !=
                self._module_configurations[module_name].major_version):
            raise request_info.VersionDoesNotExistError()
        return self._module_name_to_module[module_name]
Пример #2
0
 def _get_server(self, server_name, version):
     if not server_name:
         server_name = 'default'
     if server_name not in self._server_name_to_server:
         raise request_info.ServerDoesNotExistError(server_name)
     elif (version is not None and version !=
           self._server_configurations[server_name].major_version):
         raise request_info.VersionDoesNotExistError()
     return self._server_name_to_server[server_name]
Пример #3
0
 def _get_module(self, module_name, version):
   if not module_name or module_name not in self._module_name_to_module:
     if 'default' in self._module_name_to_module:
       module_name = 'default'
     elif self._module_name_to_module:
       # If there is no default module, but there are other modules, take any.
       # This is somewhat of a hack, and can be removed if we ever enforce the
       # existence of a default module.
       module_name = self._module_name_to_module.keys()[0]
     else:
       raise request_info.ModuleDoesNotExistError(module_name)
   elif (version is not None and
         version != self._module_configurations[module_name].major_version):
     raise request_info.VersionDoesNotExistError()
   return self._module_name_to_module[module_name]
Пример #4
0
    def _get_module(self, module_name, version):
        """Attempts to find the specified module.

    Args:
      module_name: The name of the module.
      version: The version id.
    Returns:
      Module object.
    Raises:
      request_info.ModuleDoesNotExistError: The module doesn't exist.
      request_info.VersionDoesNotExistError: The version doesn't exist.
    """
        if not module_name:
            module_name = appinfo.DEFAULT_MODULE
        if module_name not in self._module_name_to_module:
            raise request_info.ModuleDoesNotExistError()
        if (version is not None and version !=
                self._module_configurations[module_name].major_version):
            raise request_info.VersionDoesNotExistError()
        return self._module_name_to_module[module_name]