index.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334
  1. from pip._vendor.six.moves.urllib import parse as urllib_parse
  2. class PackageIndex(object):
  3. """Represents a Package Index and provides easier access to endpoints
  4. """
  5. __slots__ = ['url', 'netloc', 'simple_url', 'pypi_url',
  6. 'file_storage_domain']
  7. def __init__(self, url, file_storage_domain):
  8. # type: (str, str) -> None
  9. super(PackageIndex, self).__init__()
  10. self.url = url
  11. self.netloc = urllib_parse.urlsplit(url).netloc
  12. self.simple_url = self._url_for_path('simple')
  13. self.pypi_url = self._url_for_path('pypi')
  14. # This is part of a temporary hack used to block installs of PyPI
  15. # packages which depend on external urls only necessary until PyPI can
  16. # block such packages themselves
  17. self.file_storage_domain = file_storage_domain
  18. def _url_for_path(self, path):
  19. # type: (str) -> str
  20. return urllib_parse.urljoin(self.url, path)
  21. PyPI = PackageIndex(
  22. 'https://pypi.org/', file_storage_domain='files.pythonhosted.org'
  23. )
  24. TestPyPI = PackageIndex(
  25. 'https://test.pypi.org/', file_storage_domain='test-files.pythonhosted.org'
  26. )