Extract constant
This commit is contained in:
parent
f2cc404d7f
commit
50e4dd167e
|
@ -5,6 +5,13 @@ from .exceptions import NotFound, InvalidUsage
|
||||||
Route = namedtuple("Route", ['handler', 'methods', 'pattern', 'parameters'])
|
Route = namedtuple("Route", ['handler', 'methods', 'pattern', 'parameters'])
|
||||||
Parameter = namedtuple("Parameter", ['name', 'cast'])
|
Parameter = namedtuple("Parameter", ['name', 'cast'])
|
||||||
|
|
||||||
|
REGEX_TYPES = {
|
||||||
|
"string": (None, "[^/]+"),
|
||||||
|
"int": (int, "\d+"),
|
||||||
|
"number": (float, "[0-9\\.]+"),
|
||||||
|
"alpha": (None, "[A-Za-z]+"),
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
class Router:
|
class Router:
|
||||||
"""
|
"""
|
||||||
|
@ -25,12 +32,6 @@ class Router:
|
||||||
I should feel bad
|
I should feel bad
|
||||||
"""
|
"""
|
||||||
routes = None
|
routes = None
|
||||||
regex_types = {
|
|
||||||
"string": (None, "[^/]+"),
|
|
||||||
"int": (int, "\d+"),
|
|
||||||
"number": (float, "[0-9\\.]+"),
|
|
||||||
"alpha": (None, "[A-Za-z]+"),
|
|
||||||
}
|
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.routes = []
|
self.routes = []
|
||||||
|
@ -63,7 +64,7 @@ class Router:
|
||||||
parameter_pattern = 'string'
|
parameter_pattern = 'string'
|
||||||
|
|
||||||
# Pull from pre-configured types
|
# Pull from pre-configured types
|
||||||
parameter_regex = self.regex_types.get(parameter_pattern)
|
parameter_regex = REGEX_TYPES.get(parameter_pattern)
|
||||||
if parameter_regex:
|
if parameter_regex:
|
||||||
parameter_type, parameter_pattern = parameter_regex
|
parameter_type, parameter_pattern = parameter_regex
|
||||||
else:
|
else:
|
||||||
|
|
Loading…
Reference in New Issue
Block a user