Advertisement
Guest User

Untitled

a guest
Jun 20th, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. @classmethod
  2. def _get_spec(cls, fullname, path, target=None):
  3. """Find the loader or namespace_path for this module/package name."""
  4. # If this ends up being a namespace package, namespace_path is
  5. # the list of paths that will become its __path__
  6. namespace_path = []
  7. for entry in path:
  8. if not isinstance(entry, (str, bytes)):
  9. continue
  10. finder = cls._path_importer_cache(entry)
  11. if finder is not None:
  12. if hasattr(finder, 'find_spec'):
  13. spec = finder.find_spec(fullname, target)
  14. else:
  15. spec = cls._legacy_get_spec(fullname, finder)
  16. if spec is None:
  17. continue
  18. if spec.loader is not None:
  19. return spec
  20. portions = spec.submodule_search_locations
  21. if portions is None:
  22. raise ImportError('spec missing loader')
  23. # This is possibly part of a namespace package.
  24. # Remember these path entries (if any) for when we
  25. # create a namespace package, and continue iterating
  26. # on path.
  27. namespace_path.extend(portions)
  28. else:
  29. spec = _bootstrap.ModuleSpec(fullname, None)
  30. spec.submodule_search_locations = namespace_path
  31. return spec
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement