Route

The Route object holds a route recognition and generation routine.

See Route.__init__ docs for usage.


Methods

f __init__(self, routepath, **kargs) ...

Initialize a route, with a given routepath for matching/generation

The set of keyword args will be used as defaults.

Usage:

>>> from routes.base import Route
>>> newroute = Route(':controller/:action/:id')
>>> newroute.defaults
{'action': 'index', 'id': None}
>>> newroute = Route('date/:year/:month/:day', controller="blog",
...     action="view")
>>> newroute = Route('archives/:page', controller="blog",
...     action="by_page", requirements = { 'page':'\d{1,2}' })
>>> newroute.reqs
{'page': '\\d{1,2}'}

Note

Route is generally not called directly, a Mapper instance connect method should be used to add routes.

f makeregexp(self, clist) ...

Create a regular expression for matching purposes

Note: This MUST be called before match can function properly.

clist should be a list of valid controller strings that can be matched, for this reason makeregexp should be called by the web framework after it knows all available controllers that can be utilized.

f buildnextreg(self, path, clist) ...

Recursively build our regexp given a path, and a controller list.

Returns the regular expression string, and two booleans that can be ignored as they're only used internally by buildnextreg.

f match(self, url, environ=None, sub_domains=False, sub_domains_ignore=None, domain_match='') ...

Match a url to our regexp.

While the regexp might match, this operation isn't guaranteed as there's other factors that can cause a match to fail even though the regexp succeeds (Default that was relied on wasn't given, requirement regexp doesn't pass, etc.).

Therefore the calling function shouldn't assume this will return a valid dict, the other possible return is False if a match doesn't work out.

f generate(self, _ignore_req_list=False, _append_slash=False, **kargs) ...

Generate a URL from ourself given a set of keyword arguments

Toss an exception if this set of keywords would cause a gap in the url.

See the source for more information.