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.

29 lines
996 B

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