这是werkzeug路线优化功能。见Map.add
,Map.update
并且Rule.match_compare_key
:
def match_compare_key(self):
"""The match compare key for sorting.
Current implementation:
1. rules without any arguments come first for performance
reasons only as we expect them to match faster and some
common ones usually don't have any arguments (index pages etc.)
2. The more complex rules come first so the second argument is the
negative length of the number of weights.
3. lastly we order by the actual weights.
:internal:
"""
return bool(self.arguments), -len(self._weights), self._weights
有self.arguments
-当前参数self._weights
-路径深度。
因为'/<var_1>/<var_2>/<var3>/'
我们有(True, -3, [(1, 100), (1, 100), (1, 100)])
。有(1, 100)
-最大长度为100的默认字符串参数。
因为'/static/<path:filename>'
我们有(True, -2, [(0, -6), (1, 200)])
。有(0, 1)
-路径非参数字符串长度static
,(1, 200)
-路径字符串参数最大长度200。