@Trace
  def 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.
    """
    if search_path is None:


      search_path = [None] + sys.path
      search_path += ['/usr/local/lib/python2.7/dist-packages/lxml-3.2.3-py2.7-linux-x86_64.egg']

    py27_optional = False
    py27_enabled = False
    topmodule = None
    if self._config and self._config.runtime == 'python27':


      topmodule = submodule_fullname.split('.')[0]
      if topmodule in self.__PY27_OPTIONAL_ALLOWED_MODULES:
        py27_optional = True
        py27_enabled = topmodule in self._enabled_modules



      elif topmodule == 'Crypto':
        py27_optional = True
        py27_enabled = 'pycrypto' in self._enabled_modules






    import_error = None
    for path_entry in search_path:
      result = self.FindPathHook(submodule, submodule_fullname, path_entry)
      if result is not None:
        source_file, pathname, description = result
        if description == (None, None, None):

          return result




















        suffix, mode, file_type = description

        try:
          if (file_type not in (self._imp.C_BUILTIN, self._imp.C_EXTENSION)):
            pkg_pathname = pathname
            if file_type == self._imp.PKG_DIRECTORY:


              pkg_pathname = os.path.join(pkg_pathname, '__init__.py')
            # AppScale: disables the whitelist and lets you import anything
            # installed, as long as it's in your path.
            #if not FakeFile.IsFileAccessible(
            #    pkg_pathname, py27_optional=py27_optional):
            #  error_message = 'Access to module file denied: %s' % pathname
            #  logging.debug(error_message)
            #  raise ImportError(error_message)

          if (file_type not in self._ENABLED_FILE_TYPES and
              submodule not in self._white_list_c_modules):
            error_message = ('Could not import "%s": Disallowed C-extension '
                             'or built-in module' % submodule_fullname)
            logging.debug(error_message)
            raise ImportError(error_message)

          if (py27_optional and not py27_enabled and
              not pathname.startswith(self._app_code_path)):
            error_message = ('Third party package %s not enabled.' % topmodule)
            logging.debug(error_message)
            raise ImportError(error_message)

          return source_file, pathname, description
        except __HOLE__, e:


          import_error = e



    if py27_optional and submodule_fullname == topmodule:
      if py27_enabled:
        msg = ('Third party package %s was enabled in app.yaml '
               'but not found on import. You may have to download '
               'and install it.' % topmodule)
      else:
        msg = ('Third party package %s must be included in the '
               '"libraries:" clause of your app.yaml file '
               'in order to be imported.' % topmodule)



      logging.debug(msg)
      raise Py27OptionalModuleError(msg)

    if import_error:




      raise import_error




    self.log('Could not find module "%s"', submodule_fullname)
    raise CouldNotFindModuleError()
dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/tools/dev_appserver_import_hook.py/HardenedModulesHook.FindModuleRestricted