From 50e4dd167e465af2c26ff4d092b49bbf5edd71d6 Mon Sep 17 00:00:00 2001 From: John Piasetzki Date: Wed, 19 Oct 2016 23:43:31 -0400 Subject: [PATCH] Extract constant --- sanic/router.py | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/sanic/router.py b/sanic/router.py index a4ac68bb..0d04365a 100644 --- a/sanic/router.py +++ b/sanic/router.py @@ -5,6 +5,13 @@ from .exceptions import NotFound, InvalidUsage Route = namedtuple("Route", ['handler', 'methods', 'pattern', 'parameters']) Parameter = namedtuple("Parameter", ['name', 'cast']) +REGEX_TYPES = { + "string": (None, "[^/]+"), + "int": (int, "\d+"), + "number": (float, "[0-9\\.]+"), + "alpha": (None, "[A-Za-z]+"), +} + class Router: """ @@ -25,12 +32,6 @@ class Router: I should feel bad """ routes = None - regex_types = { - "string": (None, "[^/]+"), - "int": (int, "\d+"), - "number": (float, "[0-9\\.]+"), - "alpha": (None, "[A-Za-z]+"), - } def __init__(self): self.routes = [] @@ -63,7 +64,7 @@ class Router: parameter_pattern = 'string' # Pull from pre-configured types - parameter_regex = self.regex_types.get(parameter_pattern) + parameter_regex = REGEX_TYPES.get(parameter_pattern) if parameter_regex: parameter_type, parameter_pattern = parameter_regex else: