This commit is contained in:
Suby Raman 2017-02-13 11:45:55 -05:00
parent d614823013
commit 4d6f9ffd7c
2 changed files with 4 additions and 8 deletions

View File

@ -151,16 +151,11 @@ class Router:
properties = {"unhashable": None} properties = {"unhashable": None}
def add_parameter(match): def add_parameter(match):
# We could receive NAME or NAME:PATTERN
name = match.group(1) name = match.group(1)
pattern = 'string' name, _type, pattern = self.parse_parameter_string(name)
if ':' in name:
name, pattern = name.split(':', 1)
default = (str, pattern) parameter = Parameter(
# Pull from pre-configured types name=name, cast=_type)
_type, pattern = REGEX_TYPES.get(pattern, default)
parameter = Parameter(name=name, cast=_type)
parameters.append(parameter) parameters.append(parameter)
# Mark the whole route as unhashable if it has the hash key in it # Mark the whole route as unhashable if it has the hash key in it

View File

@ -240,6 +240,7 @@ def test_composition_view_runs_methods_as_expected():
request, response = sanic_endpoint_test(app, uri='/', method=method) request, response = sanic_endpoint_test(app, uri='/', method=method)
assert response.text == 'second method' assert response.text == 'second method'
def test_composition_view_rejects_invalid_methods(): def test_composition_view_rejects_invalid_methods():
app = Sanic('test_composition_view') app = Sanic('test_composition_view')