@Trace
  def FindModuleRestricted(self,
                           submodule,
                           submodule_fullname,
                           search_path):
    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 ImportError, 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()
Locates a module while enforcing module import restrictions.
dataset/ETHPy150Open AppScale/appscale/AppServer/google/appengine/tools/dev_appserver_import_hook.py/HardenedModulesHook.FindModuleRestricted