routes.route
– Route¶
Module Contents¶
- class routes.route.Route(name, routepath, **kargs)¶
The Route object holds a route recognition and generation routine.
See Route.__init__ docs for usage.
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(None, ':controller/:action/:id') >>> sorted(newroute.defaults.items()) [('action', 'index'), ('id', None)] >>> newroute = Route(None, 'date/:year/:month/:day', ... controller="blog", action="view") >>> newroute = Route(None, '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.
- buildfullreg(clist, include_names=True)¶
Build the regexp by iterating through the routelist and replacing dicts with the appropriate regexp match
- buildnextreg(path, clist, include_names=True)¶
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.
- done_chars = ('/', ',', ';', '.', '#')¶
- generate(_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.
- generate_minimized(kargs)¶
Generate a minimized version of the URL
- generate_non_minimized(kargs)¶
Generate a non-minimal version of the URL
- make_full_route()¶
Make a full routelist string for use with non-minimized generation
- make_unicode(s)¶
Transform the given argument into a unicode string.
- makeregexp(clist, include_names=True)¶
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.
include_names indicates whether this should be a match regexp assigned to itself using regexp grouping names, or if names should be excluded for use in a single larger regexp to determine if any routes match
- match(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.
- reserved_keys = ['requirements']¶