restish.url

class restish.url.URL(url)

Bases: str

URL class.

A URL instance is a smart string (Python str). URL instances mostly behave the same as a str instance (with the possible exception of the equality operation) but include attributes to access specific parts of the URL.

URL instances also include methods to manipulate a URL. Each time a URL is modified a new URL instance is resturned.

The URL class tries to be unicode-aware. Unicode path segments and query components are UTF-8 encoded on the way in and always returned as unicode instances. Note however that the URL itself is a byte string.

Create a new URL instance from a str URL.

add_queries(query_list)

Add multiple query args from a list of tuples

Parameters:
  • query_list – list of tuple (key, value) pairs
add_query(name, value=None)

Add a query argument with the given value

Parameters:
  • key – the query key
  • value – The query value. None means do not use a value. e.g. ?key=
anchor(anchor=None)

Modify the fragment/anchor and return a new URL.

Parameters:
  • anchor – An anchor of None (the default) or ‘’ will remove the current anchor.
child(*path)
Construct a url where the given path segment is a child of this url
clear_queries(name=None)

Remove all existing query arguments

Parameters:
  • name – the name of the query arguments to remove, defaults to removing all
click(href)

Modify the path as if href were clicked

Create a url as if the current url was given by self and href was clicked on

clone(scheme=<object object at 0x401e5580>, netloc=<object object at 0x401e5580>, path=<object object at 0x401e5580>, query=<object object at 0x401e5580>, fragment=<object object at 0x401e5580>)

Make a new instance of self, passing along the given arguments to its constructor.

Parameters:
  • scheme
  • netloc
  • path
  • query
  • fragment
fragment
The url fragment (e.g. #anchor)
netloc
The domain or network location
parent()
Pop a URL segment from this url.
path
The path of the url without query string or fragment
path_qs
The path, query string and fragment
path_segments
A list of url segments
query
The query parameters as a string
query_list
The query parameters as a list of tuples
remove_query(name)

Remove all query arguments with the given name

Parameters:
  • name – the name of the query arguments to remove
replace_query(name, value=None)

Remove all existing occurrences of the query argument ‘name’, if it exists, then add the argument with the given value.

Parameters:
  • key – the query key
  • value – The query value. None means do not use a value. e.g. ?key=
root()
Contruct a URL to the root of the web server.
scheme
The url scheme (http, https, etc)
secure(secure=True, port=None)

Modify the scheme to https/http and return the new URL.

Parameters:
  • secure – choose between https and http, default to True (https)
  • port – port, override the scheme’s normal port
sibling(segment)
Construct a url where the given path segment is a sibling of this url
class restish.url.URLAccessor(request)

Bases: object

URL accessor, provides access to useful URLs, often constructed from the accessor’s request.

application_path
Return the path part of the application’s URL.
application_url
Return the WSGI application’s URL.
host_url
Return the host’s URL, i.e. the URL of the HTTP server.
new(url)
Create a new URL instance.
path
Return the path part of the current URL, relative to the root of the web server.
path_qs
Return the path of the current URL, relative to the root of the web server, and the query string.
path_url
Return the path’s URL, i.e. the current URL without the query string.
url
Return the full current (i.e. requested), URL.
restish.url.join_path(path_segments)
Combine a sequence of path segments into a single str.
restish.url.join_query(query_list)
Join a sequence of (name, value) tuples into a single str.
restish.url.normalise_path(path)
Normalise the URL path by resolving segments of ‘.’ and ‘..’.
restish.url.split_path(path)
Split a path of type str into a sequence of unicode segments.
restish.url.split_query(query)
Split a query string (str) into a sequence of (name, value) tuples where name and value are unicode instances.

This Page

Quick search