6. Url

6.1. Synopsis

>>> from http.url import Url
>>> url = Url('http://pypi.python.org')
>>> print url.netloc
pypi.python.org
>>> url.path.append('pypi')
>>> print url.path
/pypi
>>> print url
http://pypi.python.org/pypi

6.2. Interface

Url instances have the following methods:

class http.url.Url

Handles URLs.

Construct and deconstruct an URL in a simple and easy manner. Path is a list of path elements. Query is a list of 2-uples (key, value). User can either configure netloc as a whole or username, password, host, and port independently. String representation of Url instance is the URL string itself.

class Path(path)
SEP = '/'
append(path)
canonify()
is_absolute
is_relative
Url.abs_path

Return a string representing the absolute path. (“/” if self.path is empty)

Url.abs_path_query

Return the absolute path and query components as a single string. The path and the query are separated by a ”?” character.

Url.is_absolute
Url.is_relative
Url.is_secure
Url.netloc

Reconstruct netloc. Not to be called directly.

Url.netloc_re = <_sre.SRE_Pattern object>
Url.path