parameters: (self, fqname, globals=None, locals=None, fromlist=None)
docstring: Python calls this hook to locate and import a module.
docstring_summary: Python calls this hook to locate and import a module.
docstring_tokens: Python calls this hook to locate and import a module .
function: def _import_hook(self, fqname, globals=None, locals=None, fromlist=None):
          """Python calls this hook to locate and import a module."""
  
          parts = fqname.split('.')
  
          # determine the context of this import
          parent = self._determine_import_context(globals)
  
          # if there is a parent, then its importer should manage this import
          if parent:
              module = parent.__importer__._do_import(parent, parts, fromlist)
              if module:
                  return module
  
          # has the top module already been imported?
          try:
              top_module = sys.modules[parts[0]]
          except KeyError:
  
              # look for the topmost module
              top_module = self._import_top_module(parts[0])
              if not top_module:
                  # the topmost module wasn't found at all.
                  raise ImportError, 'No module named ' + fqname
  
          # fast-path simple imports
          if len(parts) == 1:
              if not fromlist:
                  return top_module
  
              if not top_module.__dict__.get('__ispkg__'):
                  # __ispkg__ isn't defined (the module was not imported by us),
                  # or it is zero.
                  #
                  # In the former case, there is no way that we could import
                  # sub-modules that occur in the fromlist (but we can't raise an
                  # error because it may just be names) because we don't know how
                  # to deal with packages that were imported by other systems.
                  #
                  # In the latter case (__ispkg__ == 0), there can't be any sub-
                  # modules present, so we can just return.
                  #
                  # In both cases, since len(parts) == 1, the top_module is also
                  # the "bottom" which is the defined return when a fromlist
                  # exists.
                  return top_module
  
          importer = top_module.__dict__.get('__importer__')
          if importer:
              return importer._finish_import(top_module, parts[1:], fromlist)
  
          # Grrr, some people "import os.path" or do "from os.path import ..."
          if len(parts) == 2 and hasattr(top_module, parts[1]):
              if fromlist:
                  return getattr(top_module, parts[1])
              else:
                  return top_module
  
          # If the importer does not exist, then we have to bail. A missing
          # importer means that something else imported the module, and we have
          # no knowledge of how to get sub-modules out of the thing.
          raise ImportError, 'No module named ' + fqname
function_tokens: def _import_hook ( self , fqname , globals = None , locals = None , fromlist = None ) : parts = fqname . split ( '.' ) # determine the context of this import parent = self . _determine_import_context ( globals ) # if there is a parent, then its importer should manage this import if parent : module = parent . __importer__ . _do_import ( parent , parts , fromlist ) if module : return module # has the top module already been imported? try : top_module = sys . modules [ parts [ 0 ] ] except KeyError : # look for the topmost module top_module = self . _import_top_module ( parts [ 0 ] ) if not top_module : # the topmost module wasn't found at all. raise ImportError , 'No module named ' + fqname # fast-path simple imports if len ( parts ) == 1 : if not fromlist : return top_module if not top_module . __dict__ . get ( '__ispkg__' ) : # __ispkg__ isn't defined (the module was not imported by us), # or it is zero. # # In the former case, there is no way that we could import # sub-modules that occur in the fromlist (but we can't raise an # error because it may just be names) because we don't know how # to deal with packages that were imported by other systems. # # In the latter case (__ispkg__ == 0), there can't be any sub- # modules present, so we can just return. # # In both cases, since len(parts) == 1, the top_module is also # the "bottom" which is the defined return when a fromlist # exists. return top_module importer = top_module . __dict__ . get ( '__importer__' ) if importer : return importer . _finish_import ( top_module , parts [ 1 : ] , fromlist ) # Grrr, some people "import os.path" or do "from os.path import ..." if len ( parts ) == 2 and hasattr ( top_module , parts [ 1 ] ) : if fromlist : return getattr ( top_module , parts [ 1 ] ) else : return top_module # If the importer does not exist, then we have to bail. A missing # importer means that something else imported the module, and we have # no knowledge of how to get sub-modules out of the thing. raise ImportError , 'No module named ' + fqname