Modules

wheezy.routing

wheezy.routing.url(pattern, handler, kwargs=None, name=None)[source]

Converts parameters to tupple of length four. Used for convenience to name parameters and skip unused.

wheezy.routing.builders

builders module.

wheezy.routing.builders.build_route(pattern, finishing, kwargs, name, route_builders)[source]

Try to find suitable route builder to create a route. Raises LookupError if none found.

wheezy.routing.choice

plain module.

class wheezy.routing.choice.ChoiceRoute(pattern, finishing=True, kwargs=None, name=None)[source]

Route based on choice match, e.g. {locale:(en|ru)}.

match(path)[source]

If the path matches, return the end of substring matched and kwargs. Otherwise return (-1, None).

path(values=None)[source]

Build the path for given route.

wheezy.routing.choice.try_build_choice_route(pattern, finishing=True, kwargs=None, name=None)[source]

If the choince route regular expression match the pattern than create a ChoiceRoute instance.

wheezy.routing.config

config module.

wheezy.routing.curly

curly module.

wheezy.routing.curly.convert(s)[source]

Convert curly expression into regex with named groups.

wheezy.routing.curly.convert_single(s)[source]

Convert curly expression into regex with named groups.

wheezy.routing.curly.parse(s)[source]

Parse s according to group_name:pattern_name.

There is just group_name, return default pattern_name.

wheezy.routing.curly.replace(val)[source]

Replace {group_name:pattern_name} by regex with named groups.

wheezy.routing.curly.try_build_curly_route(pattern, finishing=True, kwargs=None, name=None)[source]

Convert pattern expression into regex with named groups and create regex route.

wheezy.routing.plain

plain module.

class wheezy.routing.plain.PlainRoute(pattern, finishing, kwargs=None, name=None)[source]

Route based on string equalty operation.

equals_match(path)[source]

If the path exactly equals pattern string, return end index of substring matched and a copy of self.kwargs.

path(values=None)[source]

Build the path for given route by simply returning the pattern used during initialization.

startswith_match(path)[source]

If the path starts with pattern string, return the end of substring matched and self.kwargs.

wheezy.routing.plain.try_build_plain_route(pattern, finishing=True, kwargs=None, name=None)[source]

If the plain route regular expression match the pattern than create a PlainRoute instance.

wheezy.routing.regex

class wheezy.routing.regex.RegexRoute(pattern, finishing=True, kwargs=None, name=None)[source]

Route based on regular expression matching.

match_no_kwargs(path)[source]

If the path match the regex pattern.

match_no_kwargs_finishing(path)[source]

If the path match the regex pattern.

match_with_kwargs(path)[source]

If the path match the regex pattern.

path_no_kwargs(values)[source]

Build the path for the given route by substituting the named places of the regual expression.

Specialization case: route was initialized with no default kwargs.

path_with_kwargs(values=None)[source]

Build the path for the given route by substituting the named places of the regual expression.

Specialization case: route was initialized with default kwargs.

wheezy.routing.regex.parse_pattern(pattern)[source]

Returns path_format and names.

>>> parse_pattern(r'abc/(?P<id>[^/]+)')
('abc/%(id)s', ['id'])
>>> parse_pattern(r'abc/(?P<n>[^/]+)/(?P<x>\\w+)')
('abc/%(n)s/%(x)s', ['n', 'x'])
>>> parse_pattern(r'(?P<locale>(en|ru))/home')
('%(locale)s/home', ['locale'])
>>> from wheezy.routing.curly import convert
>>> parse_pattern(convert(r'[{locale:(en|ru)}/]home'))
('%(locale)s/home', ['locale'])
>>> parse_pattern(convert(r'item[/{id:i}]'))
('item/%(id)s', ['id'])
>>> p = convert('{controller:w}[/{action:w}[/{id:i}]]')
>>> parse_pattern(p)
('%(controller)s/%(action)s/%(id)s', ['controller', 'action', 'id'])
wheezy.routing.regex.strip_optional(pattern)[source]

Strip optional regex group flag.

at the beginning

>>> strip_optional('((?P<locale>(en|ru))/)?home')
'(?P<locale>(en|ru))/home'

at the end

>>> strip_optional('item(/(?P<id>\\d+))?')
'item/(?P<id>\\d+)'

nested:

>>> p = '(?P<controller>\\w+)(/(?P<action>\\w+)(/(?P<id>\\d+))?)?'
>>> strip_optional(p)
'(?P<controller>\\w+)/(?P<action>\\w+)/(?P<id>\\d+)'
wheezy.routing.regex.try_build_regex_route(pattern, finishing=True, kwargs=None, name=None)[source]

There is no special tests to match regex selection strategy.

wheezy.routing.route

route module.

class wheezy.routing.route.Route[source]

Route abstract contract.

match(path)[source]

if the path matches, return the end of substring matched and kwargs. Otherwise return (-1, None).

path(values=None)[source]

Build the path for given route.

wheezy.routing.router

router module.

wheezy.routing.router.url(pattern, handler, kwargs=None, name=None)[source]

Converts parameters to tupple of length four. Used for convenience to name parameters and skip unused.

wheezy.routing.utils

utils module.

wheezy.routing.utils.camelcase_to_underscore(s)[source]

Convert CamelCase to camel_case.

>>> camelcase_to_underscore('MainPage')
'main_page'
>>> camelcase_to_underscore('Login')
'login'
wheezy.routing.utils.outer_split(expression, sep='()')[source]

Splits given expression by outer most separators.

>>> outer_split('123')
['123']
>>> outer_split('123(45(67)89)123(45)67')
['123', '45(67)89', '123', '45', '67']

If expression is not balanced raises ValueError.

>>> outer_split('123(') # doctest: +ELLIPSIS
Traceback (most recent call last):
    ...
ValueError: ...
wheezy.routing.utils.route_name(handler)[source]

Return a name for the given handler. handler can be an object, class or callable.

>>> class Login: pass
>>> route_name(Login)
'login'
>>> l = Login()
>>> route_name(l)
'login'
wheezy.routing.utils.strip_name(s)[source]

Strips the name per RE_STRIP_NAME regex.

>>> strip_name('Login')
'Login'
>>> strip_name('LoginHandler')
'Login'
>>> strip_name('LoginController')
'Login'
>>> strip_name('LoginPage')
'Login'
>>> strip_name('LoginView')
'Login'
>>> strip_name('LoginHandler2')
'LoginHandler2'