Skip to content

Commit e6a0b02

Browse files
committed
Minor refactor of passing URL parameters to handler
1 parent 8ee162d commit e6a0b02

File tree

1 file changed

+4
-6
lines changed

1 file changed

+4
-6
lines changed

adafruit_httpserver/route.py

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -98,13 +98,13 @@ def match(self, other: "Route") -> Tuple[bool, List[str]]:
9898
"""
9999

100100
if not other.methods.issubset(self.methods):
101-
return False, []
101+
return False, dict()
102102

103103
regex_match = re.match(f"^{self.path}$", other.path)
104104
if regex_match is None:
105-
return False, []
105+
return False, dict()
106106

107-
return True, regex_match.groups()
107+
return True, dict(zip(self.parameters_names, regex_match.groups()))
108108

109109
def __repr__(self) -> str:
110110
path = repr(self.path)
@@ -141,7 +141,7 @@ def route_func(request, my_parameter):
141141
found_route, _route = False, None
142142

143143
for _route in self._routes:
144-
matches, parameters_values = _route.match(route)
144+
matches, keyword_parameters = _route.match(route)
145145

146146
if matches:
147147
found_route = True
@@ -152,8 +152,6 @@ def route_func(request, my_parameter):
152152

153153
handler = _route.handler
154154

155-
keyword_parameters = dict(zip(_route.parameters_names, parameters_values))
156-
157155
def wrapped_handler(request):
158156
return handler(request, **keyword_parameters)
159157

0 commit comments

Comments
 (0)