About Site Map Submit Contact Us Log in | Create an account
Create an account Log In
Average Rating
User Rating:
Visitors Rating:
My rating:

Write review
See full specifications

linux default iconURLObject Publisher's description

A utility class for manipulating URLs

URLObject is an utility class for manipulating URLs.

Example Usage:

Here is how you use the library:

>>> from urlobject import URLObject
>>> url = URLObject(host='example.com')
>>> print url
>>> print url / 'some' / 'path'
>>> print url & ('key', 'value')
>>> print url & ('key', 'value') & ('key2', 'value2')
>>> print url * 'fragment'
>>> url

>>> new_url = url / 'place'
>>> new_url

>>> new_url &= 'key', 'value'
>>> new_url

>>> new_url &= 'key2', 'value2'
>>> new_url

>>> new_url |= 'key', 'newvalue'
>>> new_url

Important points to note

* URLObjects are completely unicode-aware (they subclass unicode). This also means that international hostnames will be encoded to IDNA format, and international characters in pathnames will be automatically escaped. You should continue using unicode values for everything; the various components will be en/decoded on-the-fly.
* url & (key, value) adds key=value to URL, even if key is already present as a query parameter. This allows you to have multiple appearances of key in the query.
* url | (key, value) adds key=value to URL, removing any previous appearance of key in the query parameters.
* url & dictionary and url | dictionary work similarly to their (key, value) counterparts, only they add every key, value pair in the dictionary to the query string. You can also pass in a list of key, value pairs.
* url / 'path' adds 'path' to the current path, quoting special characters if necessary.
* url // 'path' sets the path to 'path', removing the current path if present.
* url * 'fragment' sets the fragment to 'fragment'.
* url ^ 123 sets the port number to 123.
* url.with_*(value) can be done with scheme, host, port, path, query and fragment, returning a new URL object with the value in that place.
* url.without_port(), url.without_path(), url.without_query() and url.without_fragment() all exist and do something obvious.
* Operations return a new URL object (URL objects are immutable).

Hints and tips

* If a URL's scheme is 'http' and you try to set the port to 80, it is equivalent to not specifying the port (same goes for 'https', 'ftp' and 'ftps' for their appropriate ports).
* If you need to end the path with '/', you can do either url / '' or url / 'last_component/'.
* The query parameters are available as a list through the query_list() method and as a dictionary via query_dict(). By default, the latter method will return a dictionary with lists as the values, corresponding to potential multiple occurrences of the same key. You can just take the last value by passing the seq=False keyword argument to the method.
* Since URLObject subclasses directly from Python's built-in unicode, you can pass URL objects straight into urllib2.urlopen(), JSON serializers, templating systems, etc. If you need a plain-old string or Unicode object, you can just call str or unicode on it.

System Requirements:

В· Python
Program Release Status: Minor Update
Program Install Support: Install and Uninstall

URLObject Tags:

Click on a tag to find related softwares

Is URLObject your software?

Manage your software

Most Popular

linux default icon GDB 7.4
GDB, the GNU Project debugger, allows you to see what is going on `inside' another program while it... Read more
linux default icon Coral 0.9.1
Coral is a tool and a development platform to create and transform models and modeling languages.
linux default icon Forum Paid Plus Script 6.1
Forum Paid Pay Per Post Exchange is targeted at forum owners who wish to...
linux default icon sdo 0.6.5
Converts oracle SDO_GEOMETRY objects to WKT and GeoJSON.
linux default icon Get Paid Plus Script 6.1
Get Paid Plus Script

Related Category

» Other (877)
» Tools & Editors (359)
» Web Development (146)