Comments (6)
The issue seems to stem from the fact that the group of regex paths that must be evaluated at the end (self._get_non_static_non_path_groups(True)
) defaults to router[0]
without the method check. It should mirror the method check inside the tree. The patch is to do something like this:
# Inject regex matching that could not be in the tree
for group in self._get_non_static_non_path_groups(True):
route_container = (
"regex_routes" if group.regex else "dynamic_routes"
)
route_idx = 0
if len(group.routes) > 1:
route_idx = "route_idx"
Node._inject_method_check(src, 1, group)
src.extend(
[
Line(
(
"match = router.matchers"
f"[{group.pattern_idx}].match(path)"
),
1,
),
Line("if match:", 1),
Line("basket['__params__'] = match.groupdict()", 2),
Line(
(
f"return router.{route_container}"
f"[{group.segments}][{route_idx}], basket"
),
2,
),
]
)
from sanic-routing.
Just tried the above fixes you suggested and I'm getting the following output when printing router.find_route_src
. It's currently raising NoMethod
on line 126 in sanic_routing/router.py
def find_route(path, method, router, basket, extra):
parts = tuple(path[1:].split(router.delimiter))
num = len(parts)
if method in frozenset({'POST'}):
route_idx = 0
elif method in frozenset({'GET', 'OPTIONS'}):
route_idx = 1
else:
raise NoMethod
match = router.matchers[0].match(path)
if match:
basket['__params__'] = match.groupdict()
return router.regex_routes[('<__dynamic__:path>',)][0], basket
raise NotFound
matchers = [
re.compile(r'^/(?P<foo>[^/]?.*?)$'),
]
from sanic-routing.
Interestingly it looks like the methods aren't being added correctly and only the POST methods are being applied to the Routes when using the path type.
<Route: path=blorp/<bar:float> methods=frozenset({'POST'})>
<Route: path=blorp/<bar:float> methods=frozenset({'OPTIONS', 'GET'})>
<Route: path=frank/<foo:path> methods=frozenset({'POST'})>
<Route: path=frank/<foo:path> methods=frozenset({'POST'})>
from sanic-routing.
Another weird thing, if I try to print the tree with path routes it'll basically show up with nothing:
<Node: level=0>
However if I add another type those will be populated
<Node: level=0>
<Node: part=blorp, level=1>
<Node: part=__dynamic__:float, level=2, groups=[<RouteGroup: path=blorp/<bar:float> len=2>], dynamic=True>
from sanic-routing.
Okay. Will take a look. Path params are handled differently than all the others.
from sanic-routing.
@ahopkins Here's my current work in progress to help speed up your work https://github.com/robd003/sanic-routing/tree/fix_issue_43
from sanic-routing.
Related Issues (20)
- `RouteExists` thrown when registering a directory and a missing file to the same route. HOT 1
- path_to_parts parsing bug HOT 6
- Pattern registration auto-compile HOT 1
- Context managed code generation
- Regex params not type cast
- `404`s with parameter type `path` HOT 11
- Invalid declaration: <entity_id>:meta HOT 4
- Incorrect handling of `pattern` argument for `register_pattern` HOT 2
- Unique route names
- [Feature] Fallback route when none match HOT 2
- Colon in uri generate response 404 HOT 2
- parts_to_path, raises exception for part with multiple parameters without type hint HOT 1
- Websocket conflicts with http GET
- Unquoted URLs should be case-insensitive
- Parameter types are broken when using <something:path>
- "unquote=True" breaks int path parameters HOT 1
- Parameterized Route returns 404 instead of 405 HOT 2
- Expandable routes have more priority than static routes when adding a trailing slash to the path HOT 2
- Requirements based on equality
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from sanic-routing.