8
8
9
9
10
10
class Resolver :
11
- """A simple route resolver that uses regex to match paths"""
11
+ """A simple route resolver that uses regex to match paths. """
12
12
13
13
def __init__ (
14
14
self ,
15
15
route : Route ,
16
16
param_pattern = r"{(?P<name>\w+)(?P<type>:\w+)?}" ,
17
+ match_any_identifier = r"\*$" ,
17
18
converters : dict [str , ConversionInfo ] | None = None ,
18
19
) -> None :
19
20
self .element = route .element
20
21
self .pattern , self .converter_mapping = self .parse_path (route .path )
21
22
self .converters = converters or CONVERTERS
22
23
self .key = self .pattern .pattern
23
24
self .param_regex = re .compile (param_pattern )
25
+ self .match_any = match_any_identifier
24
26
25
27
def parse_path (self , path : str ) -> tuple [re .Pattern [str ], ConverterMapping ]:
26
28
pattern = "^"
@@ -39,8 +41,8 @@ def parse_path(self, path: str) -> tuple[re.Pattern[str], ConverterMapping]:
39
41
last_match_end = match .end ()
40
42
pattern += f"{ re .escape (path [last_match_end :])} $"
41
43
42
- # Replace literal `*` with "match anything" regex pattern, if it's at the end of the path
43
- if pattern .endswith (r"\*$" ):
44
+ # Replace "match anything" pattern with regex , if it's at the end of the path
45
+ if pattern .endswith (self . match_any ):
44
46
pattern = f"{ pattern [:- 3 ]} .*$"
45
47
46
48
return re .compile (pattern ), converter_mapping
0 commit comments