Make router matcher lazy
This commit is contained in:
@@ -42,8 +42,8 @@ class Route:
|
|||||||
if '}' not in part:
|
if '}' not in part:
|
||||||
raise ValueError(f'Invalid subpath substitute placeholder: {part}')
|
raise ValueError(f'Invalid subpath substitute placeholder: {part}')
|
||||||
re_part = part.replace('(', '\\(').replace(')', '\\)')
|
re_part = part.replace('(', '\\(').replace(')', '\\)')
|
||||||
names = re.findall(r'\{(.*)}', part)
|
names = re.findall(r'\{(.*?)}', part)
|
||||||
re_part = re.sub(r'\{.*}', r'(.*)', re_part)
|
re_part = re.sub(r'\{.*?}', r'(.*?)', re_part)
|
||||||
re_part = re.compile('^' + re_part + '$')
|
re_part = re.compile('^' + re_part + '$')
|
||||||
|
|
||||||
d = self._find_regexp_subroute(re_part)
|
d = self._find_regexp_subroute(re_part)
|
||||||
@@ -100,10 +100,12 @@ class Router:
|
|||||||
def add(self, method: MethodType, path_pattern: str, handler: InternalHandlerType) -> None:
|
def add(self, method: MethodType, path_pattern: str, handler: InternalHandlerType) -> None:
|
||||||
method = typing.cast(MethodType, method.upper())
|
method = typing.cast(MethodType, method.upper())
|
||||||
|
|
||||||
substitutes = re.findall(r'\{(.*)}', path_pattern)
|
substitutes = re.findall(r'\{(.*?)}', path_pattern)
|
||||||
if len(substitutes) > 0:
|
if len(substitutes) > 0:
|
||||||
subst = []
|
subst = []
|
||||||
for s in substitutes:
|
for s in substitutes:
|
||||||
|
if isinstance(s, str):
|
||||||
|
s = [s]
|
||||||
subst += list(s)
|
subst += list(s)
|
||||||
if len(subst) != len(set(subst)):
|
if len(subst) != len(set(subst)):
|
||||||
raise ValueError('Duplicate path substitute names are prohibited')
|
raise ValueError('Duplicate path substitute names are prohibited')
|
||||||
|
|||||||
Reference in New Issue
Block a user