Fix routes conflict

This commit is contained in:
taoufik07
2018-11-05 14:47:46 +01:00
parent 0c9bc5a3af
commit c4f5b0e7c2
2 changed files with 8 additions and 2 deletions
+3 -1
View File
@@ -290,8 +290,9 @@ class API:
# Get the route.
route = self.path_matches_route(req.url.path)
print(route)
route = self.routes.get(route)
print(route)
if route:
if route.uses_websocket:
resp = WebSocket(**options)
@@ -414,6 +415,7 @@ class API:
self.routes = dict(
sorted(self.routes.items(), key=lambda item: item[1]._weight())
)
print(self.routes)
def default_response(self, req, resp, notfound=False, error=False):
if resp.status_code is None:
+5 -1
View File
@@ -37,6 +37,7 @@ class Route:
@functools.lru_cache(maxsize=None)
def does_match(self, s):
print(s, self.route)
if s == self.route:
return True
@@ -46,6 +47,7 @@ class Route:
@functools.lru_cache(maxsize=None)
def incoming_matches(self, s):
results = parse(self.route, s)
print("RR", results)
return results.named if results else {}
def url(self, **params):
@@ -54,7 +56,9 @@ class Route:
def _weight(self):
params = set(self._param_pattern.findall(self.route))
params_count = len(params)
return params_count != 0, -params_count
w = len(self.route.rsplit('}', 1)[-1].strip('/'))
print(self.route, w)
return params_count != 0, w == 0, -params_count
@property
def is_class_based(self):