def mkurl_pypi_url(url): loc = posixpath.join(url, urllib_parse.quote(canonicalize_name(project_name))) # For maximum compatibility with easy_install, ensure the path # ends in a trailing slash. Although this isn't in the spec # (and PyPI can handle it without the slash) some other index # implementations might break if they relied on easy_install's # behavior. if not loc.endswith("/"): loc = loc + "/" return loc
def mkurl_pypi_url(url): # type: (str) -> str loc = posixpath.join( url, urllib_parse.quote(canonicalize_name(project_name))) # For maximum compatibility with easy_install, ensure the path # ends in a trailing slash. Although this isn't in the spec # (and PyPI can handle it without the slash) some other index # implementations might break if they relied on easy_install's # behavior. if not loc.endswith('/'): loc = loc + '/' return loc
def test_file_index_url_quoting(script, data, with_wheel): """ Test url quoting of file index url with a space """ index_url = data.index_url(urllib_parse.quote("in dex")) result = script.pip( 'install', '-vvv', '--index-url', index_url, 'simple' ) result.did_create(script.site_packages / 'simple') result.did_create( script.site_packages / 'simple-1.0.dist-info' )
def redact_netloc(netloc): """ Replace the password in a netloc with "****", if it exists. For example, "user:[email protected]" returns "user:****@example.com". """ netloc, (user, password) = split_auth_from_netloc(netloc) if user is None: return netloc password = '' if password is None else ':****' return '{user}{password}@{netloc}'.format(user=urllib_parse.quote(user), password=password, netloc=netloc)
def redact_netloc(netloc): """ Replace the password in a netloc with "****", if it exists. For example, "user:[email protected]" returns "user:****@example.com". """ netloc, (user, password) = split_auth_from_netloc(netloc) if user is None: return netloc password = '' if password is None else ':****' return '{user}{password}@{netloc}'.format(user=urllib_parse.quote(user), password=password, netloc=netloc)
def test_file_index_url_quoting(script, data): """ Test url quoting of file index url with a space """ index_url = data.index_url(urllib_parse.quote("in dex")) result = script.pip( 'install', '-vvv', '--index-url', index_url, 'simple' ) assert (script.site_packages / 'simple') in result.files_created, ( str(result.stdout) ) assert ( script.site_packages / 'simple-1.0-py%s.egg-info' % pyversion ) in result.files_created, str(result)
def test_file_index_url_quoting(script, data): """ Test url quoting of file index url with a space """ index_url = data.index_url(urllib_parse.quote("in dex")) result = script.pip( 'install', '-vvv', '--index-url', index_url, 'simple', expect_error=False, ) assert (script.site_packages / 'simple') in result.files_created, ( str(result.stdout) ) assert ( script.site_packages / 'simple-1.0-py%s.egg-info' % pyversion ) in result.files_created, str(result)
def _get_index_urls_locations(self, project_name): """Returns the locations found via self.index_urls Checks the url_name on the main (first in the list) index and use this url_name to produce all locations """ def mkurl_pypi_url(url): loc = posixpath.join(url, project_url_name) # For maximum compatibility with easy_install, ensure the path # ends in a trailing slash. Although this isn't in the spec # (and PyPI can handle it without the slash) some other index # implementations might break if they relied on easy_install's # behavior. if not loc.endswith('/'): loc = loc + '/' return loc project_url_name = urllib_parse.quote(project_name.lower()) if self.index_urls: # Check that we have the url_name correctly spelled: # Only check main index if index URL is given main_index_url = Link( mkurl_pypi_url(self.index_urls[0]), trusted=True, ) page = self._get_page(main_index_url) if page is None and PyPI.netloc not in str(main_index_url): warnings.warn( "Failed to find %r at %s. It is suggested to upgrade " "your index to support normalized names as the name in " "/simple/{name}." % (project_name, main_index_url), RemovedInPip8Warning, ) project_url_name = self._find_url_name( Link(self.index_urls[0], trusted=True), project_url_name, ) or project_url_name if project_url_name is not None: return [mkurl_pypi_url(url) for url in self.index_urls] return []
def _get_index_urls_locations(self, project_name): """Returns the locations found via self.index_urls Checks the url_name on the main (first in the list) index and use this url_name to produce all locations """ def mkurl_pypi_url(url): loc = posixpath.join(url, project_url_name) # For maximum compatibility with easy_install, ensure the path # ends in a trailing slash. Although this isn't in the spec # (and PyPI can handle it without the slash) some other index # implementations might break if they relied on easy_install's # behavior. if not loc.endswith('/'): loc = loc + '/' return loc project_url_name = urllib_parse.quote(project_name.lower()) if self.index_urls: # Check that we have the url_name correctly spelled: # Only check main index if index URL is given main_index_url = Link( mkurl_pypi_url(self.index_urls[0]), trusted=True, ) page = self._get_page(main_index_url) if page is None and PyPI.netloc not in str(main_index_url): warnings.warn( "Failed to find %r at %s. It is suggested to upgrade " "your index to support normalized names as the name in " "/simple/{name}." % (project_name, main_index_url), RemovedInPip8Warning, ) project_url_name = self._find_url_name( Link(self.index_urls[0], trusted=True), project_url_name, ) or project_url_name if project_url_name is not None: return [mkurl_pypi_url(url) for url in self.index_urls] return []
def redact_netloc(netloc): # type: (str) -> str """ Replace the sensitive data in a netloc with "****", if it exists. For example: - "user:[email protected]" returns "user:****@example.com" - "*****@*****.**" returns "****@example.com" """ netloc, (user, password) = split_auth_from_netloc(netloc) if user is None: return netloc if password is None: user = '******' password = '' else: user = urllib_parse.quote(user) password = '******' return '{user}{password}@{netloc}'.format(user=user, password=password, netloc=netloc)
def _clean_link(url): # type: (str) -> str """Makes sure a link is fully encoded. That is, if a ' ' shows up in the link, it will be rewritten to %20 (while not over-quoting % or other characters).""" # Split the URL into parts according to the general structure # `scheme://netloc/path;parameters?query#fragment`. Note that the # `netloc` can be empty and the URI will then refer to a local # filesystem path. result = urllib_parse.urlparse(url) # In both cases below we unquote prior to quoting to make sure # nothing is double quoted. if result.netloc == "": # On Windows the path part might contain a drive letter which # should not be quoted. On Linux where drive letters do not # exist, the colon should be quoted. We rely on urllib.request # to do the right thing here. path = urllib_request.pathname2url( urllib_request.url2pathname(result.path)) else: path = urllib_parse.quote(urllib_parse.unquote(result.path)) return urllib_parse.urlunparse(result._replace(path=path))
def _clean_link(url): # type: (str) -> str """Makes sure a link is fully encoded. That is, if a ' ' shows up in the link, it will be rewritten to %20 (while not over-quoting % or other characters).""" # Split the URL into parts according to the general structure # `scheme://netloc/path;parameters?query#fragment`. Note that the # `netloc` can be empty and the URI will then refer to a local # filesystem path. result = urllib_parse.urlparse(url) # In both cases below we unquote prior to quoting to make sure # nothing is double quoted. if result.netloc == "": # On Windows the path part might contain a drive letter which # should not be quoted. On Linux where drive letters do not # exist, the colon should be quoted. We rely on urllib.request # to do the right thing here. path = urllib_request.pathname2url( urllib_request.url2pathname(result.path)) else: path = urllib_parse.quote(urllib_parse.unquote(result.path)) return urllib_parse.urlunparse(result._replace(path=path))
def url_name(self): if self.req is None: return None return urllib_parse.quote(self.req.project_name.lower())
>>>>>>> e585743114c1741ec20dc76010f96171f3516589 ) return '\n'.join(lines) def get_index_urls_locations(self, project_name): # type: (str) -> List[str] """Returns the locations found via self.index_urls Checks the url_name on the main (first in the list) index and use this url_name to produce all locations """ def mkurl_pypi_url(url): <<<<<<< HEAD ======= # type: (str) -> str >>>>>>> e585743114c1741ec20dc76010f96171f3516589 loc = posixpath.join( url, urllib_parse.quote(canonicalize_name(project_name))) # For maximum compatibility with easy_install, ensure the path # ends in a trailing slash. Although this isn't in the spec # (and PyPI can handle it without the slash) some other index # implementations might break if they relied on easy_install's # behavior. if not loc.endswith('/'): loc = loc + '/' return loc return [mkurl_pypi_url(url) for url in self.index_urls]
def url_name(self): if self.req is None: return None return urllib_parse.quote(self.req.project_name.lower())
def mkurl_pypi_url(url): # type: (str) -> str loc = posixpath.join( url, urllib_parse.quote(canonicalize_name(project_name)))