pkg_resources.py 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. from pip._vendor.pkg_resources import yield_lines
  2. from pip._vendor.six import ensure_str
  3. from pip._internal.utils.typing import MYPY_CHECK_RUNNING
  4. if MYPY_CHECK_RUNNING:
  5. from typing import Dict, Iterable, List
  6. class DictMetadata(object):
  7. """IMetadataProvider that reads metadata files from a dictionary.
  8. """
  9. def __init__(self, metadata):
  10. # type: (Dict[str, bytes]) -> None
  11. self._metadata = metadata
  12. def has_metadata(self, name):
  13. # type: (str) -> bool
  14. return name in self._metadata
  15. def get_metadata(self, name):
  16. # type: (str) -> str
  17. try:
  18. return ensure_str(self._metadata[name])
  19. except UnicodeDecodeError as e:
  20. # Mirrors handling done in pkg_resources.NullProvider.
  21. e.reason += " in {} file".format(name)
  22. raise
  23. def get_metadata_lines(self, name):
  24. # type: (str) -> Iterable[str]
  25. return yield_lines(self.get_metadata(name))
  26. def metadata_isdir(self, name):
  27. # type: (str) -> bool
  28. return False
  29. def metadata_listdir(self, name):
  30. # type: (str) -> List[str]
  31. return []
  32. def run_script(self, script_name, namespace):
  33. # type: (str, str) -> None
  34. pass