Beispiel #1
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
Beispiel #2
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", "")
Beispiel #3
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
Beispiel #4
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)
        stripped_netloc = \
            purl.netloc.split('@')[-1]

        # stripped url
        url_pieces = (purl.scheme, stripped_netloc, purl.path, purl.query,
                      purl.fragment)
        surl = urllib_parse.urlunsplit(url_pieces)
        return surl
Beispiel #5
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
Beispiel #6
0
 def scheme(self):
     return urllib_parse.urlsplit(self.url)[0]
Beispiel #7
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
Beispiel #8
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))
Beispiel #9
0
 def path(self):
     return urllib_parse.unquote(urllib_parse.urlsplit(self.url)[2])
Beispiel #10
0
 def netloc(self):
     return urllib_parse.urlsplit(self.url)[1]
Beispiel #11
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')