from indexpy.routing.tree import RadixTree
t = RadixTree()
def donothing():
pass
def donothing2():
pass
# 交换下面两个路由的顺序,断言可以通过
t.append("/app/{hello}/", donothing)
t.append("/app/hello/", donothing2)
ret = t.search("/app/world/")
print(ret) # ({'hello': 'world'}, <function donothing at 0x7f12c94931f0>)
assert ret[1] == donothing
ret = t.search("/app/hello/")
print(ret) # ({'hello': 'hello'}, <function donothing at 0x7f12c94931f0>)
assert ret[1] == donothing2
期望的行为应该类似于 flask 如下:
curl xxxx/a1/hello/ ==> hello2
curl xxxx/a1/world/ ==> hello1
from flask import Flask
app = Flask(__name__)
@app.route("/a1/<hello>/")
def hello1(hello):
return "hello1"
@app.route("/a1/hello/")
def hello2():
return "hello2"
app.run()
另外这里
https://github.com/abersheeran/index.py/blob/e895d06ec26bdb4196f919229417b424f5e066a2/indexpy/routing/tree.py#L57-L66
检查路由冲突的地方
第 60 行的 if (node.re_pattern == re_pattern) != (node.characters == param_name):
会不会有 re_pattern 不同, 而 characters == param_name 相同的情况?(这一块没太看懂)