本文整理汇总了Python中werkzeug.routing.Rule方法的典型用法代码示例。如果您正苦于以下问题:Python routing.Rule方法的具体用法?Python routing.Rule怎么用?Python routing.Rule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类werkzeug.routing
的用法示例。
在下文中一共展示了routing.Rule方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get_rules
# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import Rule [as 别名]
def get_rules(self, map):
for rulefactory in self.rules:
for rule in rulefactory.get_rules(map):
new_defaults = subdomain = None
if rule.defaults:
new_defaults = {}
for key, value in iteritems(rule.defaults):
if isinstance(value, string_types):
value = format_string(value, self.context)
new_defaults[key] = value
if rule.subdomain is not None:
subdomain = format_string(rule.subdomain, self.context)
new_endpoint = rule.endpoint
if isinstance(new_endpoint, string_types):
new_endpoint = format_string(new_endpoint, self.context)
yield Rule(
format_string(rule.rule, self.context),
new_defaults,
subdomain,
rule.methods,
rule.build_only,
new_endpoint,
rule.strict_slashes,
)
示例2: get_rules
# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import Rule [as 别名]
def get_rules(self, map):
for rulefactory in self.rules:
for rule in rulefactory.get_rules(map):
new_defaults = subdomain = None
if rule.defaults:
new_defaults = {}
for key, value in iteritems(rule.defaults):
if isinstance(value, string_types):
value = format_string(value, self.context)
new_defaults[key] = value
if rule.subdomain is not None:
subdomain = format_string(rule.subdomain, self.context)
new_endpoint = rule.endpoint
if isinstance(new_endpoint, string_types):
new_endpoint = format_string(new_endpoint, self.context)
yield Rule(
format_string(rule.rule, self.context),
new_defaults,
subdomain,
rule.methods,
rule.build_only,
new_endpoint,
rule.strict_slashes
)
示例3: get_empty_kwargs
# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import Rule [as 别名]
def get_empty_kwargs(self):
"""
Provides kwargs for instantiating empty copy with empty()
Use this method to provide custom keyword arguments to the subclass of
``Rule`` when calling ``some_rule.empty()``. Helpful when the subclass
has custom keyword arguments that are needed at instantiation.
Must return a ``dict`` that will be provided as kwargs to the new
instance of ``Rule``, following the initial ``self.rule`` value which
is always provided as the first, required positional argument.
"""
defaults = None
if self.defaults:
defaults = dict(self.defaults)
return dict(defaults=defaults, subdomain=self.subdomain,
methods=self.methods, build_only=self.build_only,
endpoint=self.endpoint, strict_slashes=self.strict_slashes,
redirect_to=self.redirect_to, alias=self.alias,
host=self.host)
示例4: url
# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import Rule [as 别名]
def url(url: str, method: str):
"""Show details for a specific URL."""
try:
url_rule, params = (current_app.url_map.bind('localhost')
.match(url, method=method, return_rule=True))
except (NotFound, MethodNotAllowed) as e:
click.secho(str(e), fg='white', bg='red')
else:
headings = ('Method(s)', 'Rule', 'Params', 'Endpoint', 'View', 'Options')
print_table(headings,
[(_get_http_methods(url_rule),
url_rule.rule if url_rule.strict_slashes
else url_rule.rule + '[/]',
_format_dict(params),
url_rule.endpoint,
_get_rule_view(url_rule),
_format_rule_options(url_rule))],
['<' if i > 0 else '>' for i, col in enumerate(headings)],
primary_column_idx=1)
示例5: urls
# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import Rule [as 别名]
def urls(order_by: Optional[str] = None):
"""List all URLs registered with the app."""
url_rules: List[Rule] = current_app.url_map._rules
if not url_rules:
click.echo("No routes found.")
return
# sort the rules. by default they're sorted by priority,
# ie in the order they were registered with the app
if order_by == 'view':
url_rules = sorted(url_rules, key=_get_rule_view)
elif order_by != 'priority':
url_rules = sorted(url_rules, key=lambda rule: getattr(rule, order_by))
headings = ('Method(s)', 'Rule', 'Endpoint', 'View', 'Options')
print_table(headings,
[(_get_http_methods(url_rule),
url_rule.rule if url_rule.strict_slashes
else url_rule.rule.rstrip('/') + '[/]',
url_rule.endpoint,
_get_rule_view(url_rule),
_format_rule_options(url_rule),
) for url_rule in url_rules],
['<' if i > 0 else '>' for i, col in enumerate(headings)],
primary_column_idx=1)
示例6: _get_rule_view
# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import Rule [as 别名]
def _get_rule_view(url_rule: Rule) -> str:
try:
view_fn = current_app.view_functions[url_rule.endpoint]
except KeyError:
return '(None)'
view_class = getattr(view_fn, 'view_class', None)
view_module = inspect.getmodule(view_class if view_class else view_fn)
view_fn_name = view_fn.__name__
if '.as_view.' in view_fn.__qualname__:
view_fn_name = view_class.__name__
elif '.method_as_view.' in view_fn.__qualname__:
view_fn_name = f'{view_class.__name__}.{view_fn.__name__}'
return f'{view_module.__name__}.{view_fn_name}'
示例7: _init_app
# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import Rule [as 别名]
def _init_app(self, middleware=None):
"""Initialize a WSGI application for handling POST to '/'.
`middleware` may be provided as WSGI middleware.
"""
routes = routing.Map([
routing.Rule('/', endpoint=self._handle_inference),
routing.Rule('/ping', endpoint=self._handle_ping),
routing.Rule('/shutdown', endpoint=self._handle_shutdown),
])
def app(env, start_resp):
"""WSGI application to handle server requests.
"""
urls = routes.bind_to_environ(env)
try:
handler, _kw = urls.match()
req = Request(env)
if middleware:
return middleware(handler, req)(env, start_resp)
return handler(req)(env, start_resp)
except HTTPException as e:
return e(env, start_resp)
return app
示例8: get_empty_kwargs
# 需要导入模块: from werkzeug import routing [as 别名]
# 或者: from werkzeug.routing import Rule [as 别名]
def get_empty_kwargs(self):
"""
Provides kwargs for instantiating empty copy with empty()
Use this method to provide custom keyword arguments to the subclass of
``Rule`` when calling ``some_rule.empty()``. Helpful when the subclass
has custom keyword arguments that are needed at instantiation.
Must return a ``dict`` that will be provided as kwargs to the new
instance of ``Rule``, following the initial ``self.rule`` value which
is always provided as the first, required positional argument.
"""
defaults = None
if self.defaults:
defaults = dict(self.defaults)
return dict(
defaults=defaults,
subdomain=self.subdomain,
methods=self.methods,
build_only=self.build_only,
endpoint=self.endpoint,
strict_slashes=self.strict_slashes,
redirect_to=self.redirect_to,
alias=self.alias,
host=self.host,
)