Modules¶
wheezy.routing¶
wheezy.routing.builders¶
builders
module.
wheezy.routing.choice¶
plain
module.
wheezy.routing.config¶
config
module.
wheezy.routing.curly¶
curly
module.
-
wheezy.routing.curly.
convert_single
(s)[source]¶ Convert curly expression into regex with named groups.
-
wheezy.routing.curly.
parse
(s)[source]¶ Parse
s
according togroup_name:pattern_name
.There is just
group_name
, return defaultpattern_name
.
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 ofself.kwargs
.
-
wheezy.routing.regex¶
-
class
wheezy.routing.regex.
RegexRoute
(pattern, finishing=True, kwargs=None, name=None)[source]¶ Route based on regular expression matching.
-
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.route¶
route
module.
wheezy.routing.router¶
router
module.
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'