OpenQuizz
Une application de gestion des contenus pédagogiques
Href Class Reference
Inheritance diagram for Href:
Collaboration diagram for Href:

Public Member Functions

def __init__ (self, base="./", charset="utf-8", sort=False, key=None)
 
def __getattr__ (self, name)
 
def __call__ (self, *path, **query)
 

Data Fields

 base
 
 charset
 
 sort
 
 key
 

Detailed Description

Implements a callable that constructs URLs with the given base. The
function can be called with any number of positional and keyword
arguments which than are used to assemble the URL.  Works with URLs
and posix paths.

Positional arguments are appended as individual segments to
the path of the URL:

>>> href = Href('/foo')
>>> href('bar', 23)
'/foo/bar/23'
>>> href('foo', bar=23)
'/foo/foo?bar=23'

If any of the arguments (positional or keyword) evaluates to `None` it
will be skipped.  If no keyword arguments are given the last argument
can be a :class:`dict` or :class:`MultiDict` (or any other dict subclass),
otherwise the keyword arguments are used for the query parameters, cutting
off the first trailing underscore of the parameter name:

>>> href(is_=42)
'/foo?is=42'
>>> href({'foo': 'bar'})
'/foo?foo=bar'

Combining of both methods is not allowed:

>>> href({'foo': 'bar'}, bar=42)
Traceback (most recent call last):
  ...
TypeError: keyword arguments and query-dicts can't be combined

Accessing attributes on the href object creates a new href object with
the attribute name as prefix:

>>> bar_href = href.bar
>>> bar_href("blub")
'/foo/bar/blub'

If `sort` is set to `True` the items are sorted by `key` or the default
sorting algorithm:

>>> href = Href("/", sort=True)
>>> href(a=1, b=2, c=3)
'/?a=1&b=2&c=3'

.. versionadded:: 0.5
    `sort` and `key` were added.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  base = "./",
  charset = "utf-8",
  sort = False,
  key = None 
)

Member Function Documentation

◆ __call__()

def __call__ (   self,
path,
**  query 
)

◆ __getattr__()

def __getattr__ (   self,
  name 
)

Field Documentation

◆ base

base

◆ charset

charset

◆ key

key

◆ sort

sort

The documentation for this class was generated from the following file: