mirror of
https://github.com/kennethreitz/responder.git
synced 2026-06-05 23:00:17 +00:00
Add routes specifiers
This commit is contained in:
+17
-2
@@ -1,7 +1,22 @@
|
||||
import re
|
||||
import functools
|
||||
import inspect
|
||||
from parse import parse
|
||||
from parse import parse, with_pattern
|
||||
|
||||
|
||||
def _make_convertor(type, pattern):
|
||||
@with_pattern(pattern)
|
||||
def inner(value):
|
||||
return type(value)
|
||||
|
||||
return inner
|
||||
|
||||
|
||||
_convertors = {
|
||||
"int": _make_convertor(int, r"\d+"),
|
||||
"str": _make_convertor(str, r"[^/]+"),
|
||||
"float": _make_convertor(float, r"\d+(.\d+)?"),
|
||||
}
|
||||
|
||||
|
||||
class Route:
|
||||
@@ -46,7 +61,7 @@ class Route:
|
||||
|
||||
@functools.lru_cache(maxsize=None)
|
||||
def incoming_matches(self, s):
|
||||
results = parse(self.route, s)
|
||||
results = parse(self.route, s, _convertors)
|
||||
return results.named if results else {}
|
||||
|
||||
def url(self, **params):
|
||||
|
||||
Reference in New Issue
Block a user