You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

index.py 1.0KB

5 years ago
12345678910111213141516171819202122232425262728293031
  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. def __init__(self, url, file_storage_domain):
  6. # type: (str, str) -> None
  7. super(PackageIndex, self).__init__()
  8. self.url = url
  9. self.netloc = urllib_parse.urlsplit(url).netloc
  10. self.simple_url = self._url_for_path('simple')
  11. self.pypi_url = self._url_for_path('pypi')
  12. # This is part of a temporary hack used to block installs of PyPI
  13. # packages which depend on external urls only necessary until PyPI can
  14. # block such packages themselves
  15. self.file_storage_domain = file_storage_domain
  16. def _url_for_path(self, path):
  17. # type: (str) -> str
  18. return urllib_parse.urljoin(self.url, path)
  19. PyPI = PackageIndex(
  20. 'https://pypi.org/', file_storage_domain='files.pythonhosted.org'
  21. )
  22. TestPyPI = PackageIndex(
  23. 'https://test.pypi.org/', file_storage_domain='test-files.pythonhosted.org'
  24. )