Esempio n. 1
0
 def normalize_url(self, url):
     # type: (str) -> str
     """
     Normalize a URL for comparison by unquoting it and removing any
     trailing slash.
     """
     return urllib_parse.unquote(url).rstrip('/')
Esempio n. 2
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
Esempio n. 3
0
def get_file_content(url, comes_from=None, session=None):
    # type: (str, Optional[str], Optional[PipSession]) -> Tuple[str, Text]
    """Gets the content of a file; it may be a filename, file: URL, or
    http: URL.  Returns (location, content).  Content is unicode.

    :param url:         File path or url.
    :param comes_from:  Origin description of requirements.
    :param session:     Instance of pip.download.PipSession.
    """
    if session is None:
        raise TypeError(
            "get_file_content() missing 1 required keyword argument: 'session'"
        )

    match = _scheme_re.search(url)
    if match:
        scheme = match.group(1).lower()
        if (scheme == 'file' and comes_from and
                comes_from.startswith('http')):
            raise InstallationError(
                'Requirements file %s references URL %s, which is local'
                % (comes_from, url))
        if scheme == 'file':
            path = url.split(':', 1)[1]
            path = path.replace('\\', '/')
            match = _url_slash_drive_re.match(path)
            if match:
                path = match.group(1) + ':' + path.split('|', 1)[1]
            path = urllib_parse.unquote(path)
            if path.startswith('/'):
                path = '/' + path.lstrip('/')
            url = path
        else:
            # FIXME: catch some errors
            resp = session.get(url)
            resp.raise_for_status()
            return resp.url, resp.text
    try:
        with open(url, 'rb') as f:
            content = auto_decode(f.read())
    except IOError as exc:
        raise InstallationError(
            'Could not open requirements file: %s' % str(exc)
        )
    return url, content
Esempio n. 4
0
def get_file_content(url, comes_from=None, session=None):
    """Gets the content of a file; it may be a filename, file: URL, or
    http: URL.  Returns (location, content).  Content is unicode."""
    if session is None:
        raise TypeError(
            "get_file_content() missing 1 required keyword argument: 'session'"
        )

    match = _scheme_re.search(url)
    if match:
        scheme = match.group(1).lower()
        if (scheme == 'file' and comes_from
                and comes_from.startswith('http')):
            raise InstallationError(
                'Requirements file %s references URL %s, which is local'
                % (comes_from, url))
        if scheme == 'file':
            path = url.split(':', 1)[1]
            path = path.replace('\\', '/')
            match = _url_slash_drive_re.match(path)
            if match:
                path = match.group(1) + ':' + path.split('|', 1)[1]
            path = urllib_parse.unquote(path)
            if path.startswith('/'):
                path = '/' + path.lstrip('/')
            url = path
        else:
            # FIXME: catch some errors
            resp = session.get(url)
            resp.raise_for_status()

            if six.PY3:
                return resp.url, resp.text
            else:
                return resp.url, resp.content
    try:
        with open(url) as f:
            content = f.read()
    except IOError as exc:
        raise InstallationError(
            'Could not open requirements file: %s' % str(exc)
        )
    return url, content
Esempio n. 5
0
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))
Esempio n. 6
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
Esempio n. 7
0
 def path(self):
     # type: () -> str
     return urllib_parse.unquote(urllib_parse.urlsplit(self.url)[2])
Esempio n. 8
0
 def path(self):
     # type: () -> str
     return urllib_parse.unquote(self._parsed_url.path)
Esempio n. 9
0
 def normalize_url(self, url):
     """
     Normalize a URL for comparison by unquoting it and removing any
     trailing slash.
     """
     return urllib_parse.unquote(url).rstrip('/')
Esempio n. 10
0
>>>>>>> b66a76afa15ab74019740676a52a071b85ed8f71
        return resp.url, resp.text

    elif scheme == 'file':
        if comes_from and comes_from.startswith('http'):
            raise InstallationError(
                'Requirements file {} references URL {}, '
                'which is local'.format(comes_from, url)
            )

        path = url.split(':', 1)[1]
        path = path.replace('\\', '/')
        match = _url_slash_drive_re.match(path)
        if match:
            path = match.group(1) + ':' + path.split('|', 1)[1]
        path = urllib_parse.unquote(path)
        if path.startswith('/'):
            path = '/' + path.lstrip('/')
        url = path

    try:
        with open(url, 'rb') as f:
            content = auto_decode(f.read())
    except IOError as exc:
        raise InstallationError(
            'Could not open requirements file: {}'.format(exc)
        )
    return url, content


_url_slash_drive_re = re.compile(r'/*([a-z])\|', re.I)
Esempio n. 11
0
 def normalize_url(url):
     return urllib_parse.unquote(url).rstrip('/')
Esempio n. 12
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
Esempio n. 13
0
        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):
        """
        Normalize a URL for comparison by unquoting it and removing any
        trailing slash.
        """
        return urllib_parse.unquote(url).rstrip('/')

    def compare_urls(self, url1, url2):
        """
        Compare two repo URLs for identity, ignoring incidental differences.
        """
        return (self.normalize_url(url1) == self.normalize_url(url2))

    def obtain(self, dest):
        """
        Called when installing or updating an editable package, takes the
        source path of the checkout.
        """
        raise NotImplementedError

    def switch(self, dest, url, rev_options):
Esempio n. 14
0
 def path(self):
     # type: () -> str
     return urllib_parse.unquote(urllib_parse.urlsplit(self.url)[2])
Esempio n. 15
0
        åmse:          0 rp 5 '&
        if self.cïmes_from:
 "          return '%s (froma%s)%s' ! (redactßpassword_fboiÝurl(self.url),
   `    `        `                     self.comes_fro-, rp)
      ! else:
   *   0 (  rtttr® zedac|_passuord_froI_urì(strhself.url))

    def __repr__(self):
        return '<Link %s>' % self

    @property
    def filejame(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

    @property
    def scheme(self):
        # type: () -> str
        return urllib_parse.urlsplit(self.url)[0]

    @property
    def netloc(self):
        # type: () -> str
        return urllib_parse.urlsplit(self.url)[1]

    @property
    def path(self):
Esempio n. 16
0
 def path(self):
     return urllib_parse.unquote(urllib_parse.urlsplit(self.url)[2])
Esempio n. 17
0
 def path(self):
     return urllib_parse.unquote(urllib_parse.urlsplit(self.url)[2])
Esempio n. 18
0
        if (scheme == 'file' and comes_from and
                comes_from.startswith('http')):
=======
        if (scheme == 'file' and comes_from
                and comes_from.startswith('http')):
>>>>>>> bde4533e29dfedadf6bcf9d451baa615bc828a59
            raise InstallationError(
                'Requirements file %s references URL %s, which is local'
                % (comes_from, url))
        if scheme == 'file':
            path = url.split(':', 1)[1]
            path = path.replace('\\', '/')
            match = _url_slash_drive_re.match(path)
            if match:
                path = match.group(1) + ':' + path.split('|', 1)[1]
            path = urllib_parse.unquote(path)
            if path.startswith('/'):
                path = '/' + path.lstrip('/')
            url = path
        else:
            # FIXME: catch some errors
            resp = session.get(url)
            resp.raise_for_status()

            if six.PY3:
                return resp.url, resp.text
            else:
                return resp.url, resp.content
    try:
        with open(url) as f:
            content = f.read()