Coverage for requests.packages.urllib3.util.url : 52%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" Datastructure for representing an HTTP URL. Used as a return value for :func:`parse_url`. """
query=None, fragment=None): query, fragment)
def hostname(self): """For backwards-compatibility with urlparse. We're nice like that.""" return self.host
def request_uri(self): """Absolute path including the query string.""" uri = self.path or '/'
if self.query is not None: uri += '?' + self.query
return uri
def netloc(self): """Network location including host and port""" if self.port: return '%s:%d' % (self.host, self.port) return self.host
def url(self): """ Convert self into a url
This function should more or less round-trip with :func:`.parse_url`. The returned url may not be exactly the same as the url inputted to :func:`.parse_url`, but it should be equivalent by the RFC (e.g., urls with a blank port will have : removed).
Example: ::
>>> U = parse_url('http://google.com/mail/') >>> U.url 'http://google.com/mail/' >>> Url('http', 'username:password', 'host.com', 80, ... '/path', 'query', 'fragment').url 'http://username:password@host.com:80/path?query#fragment' """ scheme, auth, host, port, path, query, fragment = self url = ''
# We use "is not None" we want things to happen with empty strings (or 0 port) if scheme is not None: url += scheme + '://' if auth is not None: url += auth + '@' if host is not None: url += host if port is not None: url += ':' + str(port) if path is not None: url += path if query is not None: url += '?' + query if fragment is not None: url += '#' + fragment
return url
return self.url
""" Given a string and an iterable of delimiters, split on the first found delimiter. Return two split parts and the matched delimiter.
If not found, then the first part is the full input string.
Example::
>>> split_first('foo/bar?baz', '?/=') ('foo', 'bar?baz', '/') >>> split_first('foo/bar?baz', '123') ('foo/bar?baz', '', None)
Scales linearly with number of delims. Not ideal for large number of delims. """
return s, '', None
""" Given a url, return a parsed :class:`.Url` namedtuple. Best-effort is performed to parse incomplete urls. Fields not provided will be None.
Partly backwards-compatible with :mod:`urlparse`.
Example::
>>> parse_url('http://google.com/mail/') Url(scheme='http', host='google.com', port=None, path='/mail/', ...) >>> parse_url('google.com:80') Url(scheme=None, host='google.com', port=80, path=None, ...) >>> parse_url('/foo?bar') Url(scheme=None, host=None, port=None, path='/foo', query='bar', ...) """
# While this code has overlap with stdlib's urlparse, it is much # simplified for our needs and less annoying. # Additionally, this implementations does silly things to be optimal # on CPython.
# Empty return Url()
# Scheme
# Find the earliest Authority Terminator # (http://tools.ietf.org/html/rfc3986#section-3.2)
# Reassemble the path
# Auth # Last '@' denotes end of auth part auth, url = url.rsplit('@', 1)
# IPv6 host, url = url.split(']', 1) host += ']'
# Port _host, port = url.split(':', 1)
if not host: host = _host
if port: # If given, ports must be integers. if not port.isdigit(): raise LocationParseError(url) port = int(port) else: # Blank ports are cool, too. (rfc3986#section-3.2.3) port = None
return Url(scheme, auth, host, port, path, query, fragment)
# Fragment path, fragment = path.split('#', 1)
# Query path, query = path.split('?', 1)
""" Deprecated. Use :func:`.parse_url` instead. """ p = parse_url(url) return p.scheme or 'http', p.hostname, p.port |