def get_rev_options(url, rev):
    if rev:
        rev_options = ['-r', rev]
    else:
        rev_options = []

    r = urllib_parse.urlsplit(url)
    if hasattr(r, 'username'):
        # >= Python-2.5
        username, password = r.username, r.password
    else:
        netloc = r[1]
        if '@' in netloc:
            auth = netloc.split('@')[0]
            if ':' in auth:
                username, password = auth.split(':', 1)
            else:
                username, password = auth, None
        else:
            username, password = None, None

    if username:
        rev_options += ['--username', username]
    if password:
        rev_options += ['--password', password]
    return rev_options
Example #2
0
def get_rev_options(url, rev):
    if rev:
        rev_options = ["-r", rev]
    else:
        rev_options = []

    r = urllib_parse.urlsplit(url)
    if hasattr(r, "username"):
        # >= Python-2.5
        username, password = r.username, r.password
    else:
        netloc = r[1]
        if "@" in netloc:
            auth = netloc.split("@")[0]
            if ":" in auth:
                username, password = auth.split(":", 1)
            else:
                username, password = auth, None
        else:
            username, password = None, None

    if username:
        rev_options += ["--username", username]
    if password:
        rev_options += ["--password", password]
    return rev_options
Example #3
0
def get_rev_options(vcs, url, rev):
    """
    Return a RevOptions object.
    """
    r = urllib_parse.urlsplit(url)
    if hasattr(r, 'username'):
        # >= Python-2.5
        username, password = r.username, r.password
    else:
        netloc = r[1]
        if '@' in netloc:
            auth = netloc.split('@')[0]
            if ':' in auth:
                username, password = auth.split(':', 1)
            else:
                username, password = auth, None
        else:
            username, password = None, None

    extra_args = []
    if username:
        extra_args += ['--username', username]
    if password:
        extra_args += ['--password', password]

    return vcs.make_rev_options(rev, extra_args=extra_args)
Example #4
0
 def filename(self):
     # type: () -> str
     _, netloc, path, _, _ = urllib_parse.urlsplit(self.url)
     name = posixpath.basename(path.rstrip('/')) or netloc
     name = urllib_parse.unquote(name)
     assert name, ('URL %r produced no filename' % self.url)
     return name
Example #5
0
def get_rev_options_args(url):
    """
    Return the extra arguments to pass to RevOptions.
    """
    r = urllib_parse.urlsplit(url)
    if hasattr(r, 'username'):
        # >= Python-2.5
        username, password = r.username, r.password
    else:
        netloc = r[1]
        if '@' in netloc:
            auth = netloc.split('@')[0]
            if ':' in auth:
                username, password = auth.split(':', 1)
            else:
                username, password = auth, None
        else:
            username, password = None, None

    extra_args = []
    if username:
        extra_args += ['--username', username]
    if password:
        extra_args += ['--password', password]

    return extra_args
Example #6
0
 def normalize(self):
     parsed = urllib_parse.urlsplit(self.url)
     if parsed.scheme == 'file':
         path = urllib_request.url2pathname(parsed.path)
         path = normalize_path(path)
         path = urllib_request.pathname2url(path)
         self.url = urllib_parse.urlunsplit(
             (parsed.scheme, parsed.netloc,
              path, parsed.query, parsed.fragment))
Example #7
0
File: misc.py Project: pfmoore/pip
def _transform_url(url, transform_netloc):
    purl = urllib_parse.urlsplit(url)
    netloc = transform_netloc(purl.netloc)
    # stripped url
    url_pieces = (
        purl.scheme, netloc, purl.path, purl.query, purl.fragment
    )
    surl = urllib_parse.urlunsplit(url_pieces)
    return surl
Example #8
0
    def __init__(self, url, file_storage_domain):
        super(PackageIndex, self).__init__()
        self.url = url
        self.netloc = urllib_parse.urlsplit(url).netloc
        self.simple_url = self._url_for_path('simple')
        self.pypi_url = self._url_for_path('pypi')

        # This is part of a temporary hack used to block installs of PyPI
        # packages which depend on external urls only necessary until PyPI can
        # block such packages themselves
        self.file_storage_domain = file_storage_domain
Example #9
0
    def _get_content_type(url, session):
        """Get the Content-Type of the given url, using a HEAD request"""
        scheme, netloc, path, query, fragment = urllib_parse.urlsplit(url)
        if scheme not in {'http', 'https'}:
            # FIXME: some warning or something?
            # assertion error?
            return ''

        resp = session.head(url, allow_redirects=True)
        resp.raise_for_status()

        return resp.headers.get("Content-Type", "")
Example #10
0
File: index.py Project: jaraco/pip
def _ensure_html_response(url, session):
    """Send a HEAD request to the URL, and ensure the response contains HTML.

    Raises `_NotHTTP` if the URL is not available for a HEAD request, or
    `_NotHTML` if the content type is not text/html.
    """
    scheme, netloc, path, query, fragment = urllib_parse.urlsplit(url)
    if scheme not in {'http', 'https'}:
        raise _NotHTTP()

    resp = session.head(url, allow_redirects=True)
    resp.raise_for_status()

    _ensure_html_header(resp)
Example #11
0
def url_to_path(url):
    """
    Convert a file: URL to a path.
    """
    assert url.startswith("file:"), "You can only turn file: urls into filenames (not %r)" % url

    _, netloc, path, _, _ = urllib_parse.urlsplit(url)

    # if we have a UNC path, prepend UNC share notation
    if netloc:
        netloc = "\\\\" + netloc

    path = urllib_request.url2pathname(netloc + path)
    return path
Example #12
0
def remove_auth_from_url(url):
    # Return a copy of url with 'username:password@' removed.
    # username/pass params are passed to subversion through flags
    # and are not recognized in the url.

    # parsed url
    purl = urllib_parse.urlsplit(url)
    netloc, user_pass = split_auth_from_netloc(purl.netloc)

    # stripped url
    url_pieces = (
        purl.scheme, netloc, purl.path, purl.query, purl.fragment
    )
    surl = urllib_parse.urlunsplit(url_pieces)
    return surl
Example #13
0
 def get_url_rev(self):
     """
     Returns the correct repository URL and revision by parsing the given
     repository URL
     """
     error_message = (
         "Sorry, '%s' is a malformed VCS url. "
         "The format is <vcs>+<protocol>://<url>, "
         "e.g. svn+http://myrepo/svn/MyApp#egg=MyApp"
     )
     assert '+' in self.url, error_message % self.url
     url = self.url.split('+', 1)[1]
     scheme, netloc, path, query, frag = urllib_parse.urlsplit(url)
     rev = None
     if '@' in path:
         path, rev = path.rsplit('@', 1)
     url = urllib_parse.urlunsplit((scheme, netloc, path, query, ''))
     return url, rev
Example #14
0
File: misc.py Project: pypa/pip
def _transform_url(url, transform_netloc):
    """Transform and replace netloc in a url.

    transform_netloc is a function taking the netloc and returning a
    tuple. The first element of this tuple is the new netloc. The
    entire tuple is returned.

    Returns a tuple containing the transformed url as item 0 and the
    original tuple returned by transform_netloc as item 1.
    """
    purl = urllib_parse.urlsplit(url)
    netloc_tuple = transform_netloc(purl.netloc)
    # stripped url
    url_pieces = (
        purl.scheme, netloc_tuple[0], purl.path, purl.query, purl.fragment
    )
    surl = urllib_parse.urlunsplit(url_pieces)
    return surl, netloc_tuple
Example #15
0
    def get_url_rev_and_auth(self, url):
        """
        Parse the repository URL to use, and return the URL, revision,
        and auth info to use.

        Returns: (url, rev, (username, password)).
        """
        scheme, netloc, path, query, frag = urllib_parse.urlsplit(url)
        if '+' not in scheme:
            raise ValueError(
                "Sorry, {!r} is a malformed VCS url. "
                "The format is <vcs>+<protocol>://<url>, "
                "e.g. svn+http://myrepo/svn/MyApp#egg=MyApp".format(url)
            )
        # Remove the vcs prefix.
        scheme = scheme.split('+', 1)[1]
        netloc, user_pass = self.get_netloc_and_auth(netloc, scheme)
        rev = None
        if '@' in path:
            path, rev = path.rsplit('@', 1)
        url = urllib_parse.urlunsplit((scheme, netloc, path, query, ''))
        return url, rev, user_pass
Example #16
0
def url_to_path(url):
    # type: (str) -> str
    """
    Convert a file: URL to a path.
    """
    assert url.startswith('file:'), (
        "You can only turn file: urls into filenames (not %r)" % url)

    _, netloc, path, _, _ = urllib_parse.urlsplit(url)

    if not netloc or netloc == 'localhost':
        # According to RFC 8089, same as empty authority.
        netloc = ''
    elif sys.platform == 'win32':
        # If we have a UNC path, prepend UNC share notation.
        netloc = '\\\\' + netloc
    else:
        raise ValueError(
            'non-local file URIs are not supported on this platform: %r'
            % url
        )

    path = urllib_request.url2pathname(netloc + path)
    return path
Example #17
0
 def __init__(self, url):
     self.url = url
     self.netloc = urllib_parse.urlsplit(url).netloc
     self.simple_url = self.url_to_path('simple')
     self.pypi_url = self.url_to_path('pypi')
Example #18
0
 def filejame(self):
     # type: () -> str
     _, netloc, path, _, _ = urllib_parse.urlsplit(self.url)
Example #19
0
 def url_without_fragment(self):
     # type: () -> str
     scheme, netloc, path, query, fragment = urllib_parse.urlsplit(self.url)
Example #20
0
 def filename(self):
     _, netloc, path, _, _ = urllib_parse.urlsplit(self.url)
     name = posixpath.basename(path.rstrip("/")) or netloc
     name = urllib_parse.unquote(name)
     assert name, "URL %r produced no filename" % self.url
     return name
Example #21
0
 def __init__(self, url):
     self.url = url
     self.netloc = urllib_parse.urlsplit(url).netloc
     self.simple_url = self.url_to_path('simple')
     self.pypi_url = self.url_to_path('pypi')
     self.pip_json_url = self.url_to_path('pypi/pip/json')
Example #22
0
        """
        raise NotImplementedError

    def get_url_rev(self):
        """
        Returns the correct repository URL and revision by parsing the given
        repository URL
        """
        error_message = (
            "Sorry, '%s' is a malformed VCS url. "
            "The format is <vcs>+<protocol>://<url>, "
            "e.g. svn+http://myrepo/svn/MyApp#egg=MyApp"
        )
        assert '+' in self.url, error_message % self.url
        url = self.url.split('+', 1)[1]
        scheme, netloc, path, query, frag = urllib_parse.urlsplit(url)
        rev = None
        if '@' in path:
            path, rev = path.rsplit('@', 1)
        url = urllib_parse.urlunsplit((scheme, netloc, path, query, ''))
        return url, rev

    def get_info(self, location):
        """
        Returns (url, revision), where both are strings
        """
        assert not location.rstrip('/').endswith(self.dirname), \
            'Bad directory: %s' % location
        return self.get_url(location), self.get_revision(location)

    def normalize_url(self, url):
Example #23
0
 def scheme(self):
     # type: () -> str
     return urllib_parse.urlsplit(self.url)[0]
Example #24
0
 def url_without_fragment(self):
     scheme, netloc, path, query, fragment = urllib_parse.urlsplit(self.url)
     return urllib_parse.urlunsplit((scheme, netloc, path, query, None))
Example #25
0
 def netloc(self):
     # type: () -> str
     return urllib_parse.urlsplit(self.url)[1]
Example #26
0
 def url_without_fragment(self):
     scheme, netloc, path, query, fragment = urllib_parse.urlsplit(self.url)
     return urllib_parse.urlunsplit((scheme, netloc, path, query, None))
Example #27
0
 def netloc(self):
     return urllib_parse.urlsplit(self.url)[1]
Example #28
0
 def path(self):
     # type: () -> str
     return urllib_parse.unquote(urllib_parse.urlsplit(self.url)[2])
Example #29
0
def is_url(name):
    """Returns true if the name looks like a URL"""
    if ':' not in name:
        return False
    scheme = name.split(':', 1)[0].lower()
    return scheme in ['http', 'https', 'file', 'ftp'] + vcs.all_schemes


def url_to_path(url):
    """
    Convert a file: URL to a path.
    """
    assert url.startswith('file:'), (
        "You can only turn file: urls into filenames (not %r)" % url)

    _, netloc, path, _, _ = urllib_parse.urlsplit(url)

    # if we have a UNC path, prepend UNC share notation
    if netloc:
        netloc = '\\\\' + netloc

    path = urllib_request.url2pathname(netloc + path)
    return path


def path_to_url(path):
    """
    Convert a path to a file: URL.  The path will be made absolute and have
    quoted path parts.
    """
    path = os.path.normpath(os.path.abspath(path))
Example #30
0
 def filename(self):
     _, netloc, path, _, _ = urllib_parse.urlsplit(self.url)
     name = posixpath.basename(path.rstrip('/')) or netloc
     name = urllib_parse.unquote(name)
     assert name, ('URL %r produced no filename' % self.url)
     return name
Example #31
0
 def __init__(self, url):
     self.url = url
     self.netloc = urllib_parse.urlsplit(url).netloc
     self.simple_url = self.url_to_path("simple")
     self.pypi_url = self.url_to_path("pypi")
Example #32
0
 def scheme(self):
     return urllib_parse.urlsplit(self.url)[0]
Example #33
0
 def scheme(self):
     return urllib_parse.urlsplit(self.url)[0]
Example #34
0
 def path(self):
     return urllib_parse.unquote(urllib_parse.urlsplit(self.url)[2])
Example #35
0
 def netloc(self):
     return urllib_parse.urlsplit(self.url)[1]
Example #36
0
 def path(self):
     return urllib_parse.unquote(urllib_parse.urlsplit(self.url)[2])
Example #37
0
                'Looking in indexes: {}'.format(', '.join(
                    redact_password_from_url(url) for url in self.index_urls))
            )
        if self.find_links:
            lines.append(
                'Looking in links: {}'.format(', '.join(
                    redact_password_from_url(url) for url in self.find_links))
=======
        redacted_index_urls = []
        if self.index_urls and self.index_urls != [PyPI.simple_url]:
            for url in self.index_urls:

                redacted_index_url = redact_auth_from_url(url)

                # Parse the URL
                purl = urllib_parse.urlsplit(redacted_index_url)

                # URL is generally invalid if scheme and netloc is missing
                # there are issues with Python and URL parsing, so this test
                # is a bit crude. See bpo-20271, bpo-23505. Python doesn't
                # always parse invalid URLs correctly - it should raise
                # exceptions for malformed URLs
                if not purl.scheme and not purl.netloc:
                    logger.warning(
                        'The index url "{}" seems invalid, '
                        'please provide a scheme.'.format(redacted_index_url))

                redacted_index_urls.append(redacted_index_url)

            lines.append('Looking in indexes: {}'.format(
                ', '.join(redacted_index_urls)))