Exemple #1
0
    def __init__(self, uris, session_auth_manager=None, **kwargs):

        if not uris:
            raise ValueError('invalid HTTP service URIs: expecting a sequence'
                              ' of HTTP URIs')

        canon_uris = []
        for uri in uris:
            uri_parts = _urlsplit(uri)
            netloc = uri_parts.netloc if uri_parts.port is not None \
                                      else '{}:{}'.format(uri_parts.netloc,
                                                          _httplib.HTTP_PORT)
            canon_uris.append(_urlunsplit((uri_parts.scheme, netloc,
                                           uri_parts.path, uri_parts.query,
                                           uri_parts.fragment)))

        super(HttpService, self).__init__(uris=canon_uris, **kwargs)

        self._session_auth_manager = \
            session_auth_manager \
            or _http_auth.HttpSessionManager(service=self)
Exemple #2
0
    def from_string(cls, purl):
        """
        Return a PackageURL object parsed from a string.
        Raise ValueError on errors.
        """
        if (not purl or not isinstance(purl, basestring) or not purl.strip()):
            raise ValueError('A purl string argument is required.')

        scheme, sep, remainder = purl.partition(':')
        if not sep or scheme != 'pkg':
            raise ValueError('purl is missing the required '
                             '"pkg" scheme component: {}.'.format(repr(purl)))

        # this strip '/, // and /// as possible in :// or :///
        remainder = remainder.strip().lstrip('/')

        type, sep, remainder = remainder.partition('/')  # NOQA
        if not type or not sep:
            raise ValueError('purl is missing the required '
                             'type component: {}.'.format(repr(purl)))

        scheme, authority, path, qualifiers, subpath = _urlsplit(
            url=remainder, scheme='', allow_fragments=True)

        if scheme or authority:
            msg = ('Invalid purl {} cannot contain a "user:pass@host:port" '
                   'URL Authority component: {}.')
            raise ValueError(msg.format(repr(purl), repr(authority)))

        path = path.lstrip('/')
        remainder, sep, version = path.rpartition('@')
        if not sep:
            remainder = version
            version = None

        ns_name = remainder.strip().strip('/')
        ns_name = ns_name.split('/')
        ns_name = [seg for seg in ns_name if seg and seg.strip()]
        namespace = ''
        name = ''
        if len(ns_name) > 1:
            name = ns_name[-1]
            ns = ns_name[0:-1]
            namespace = '/'.join(ns)
        elif len(ns_name) == 1:
            name = ns_name[0]

        if not name:
            raise ValueError('purl is missing the required '
                             'name component: {}'.format(repr(purl)))

        type, namespace, name, version, qualifiers, subpath = normalize(  # NOQA
            type,
            namespace,
            name,
            version,
            qualifiers,
            subpath,
            encode=False)

        return PackageURL(type, namespace, name, version, qualifiers, subpath)
Exemple #3
0
 def port(self):
     return _urlsplit(self.uri).port
Exemple #4
0
 def hostname(self):
     return _urlsplit(self.uri).hostname