本文整理汇总了Python中flask.request.url_rule方法的典型用法代码示例。如果您正苦于以下问题:Python request.url_rule方法的具体用法?Python request.url_rule怎么用?Python request.url_rule使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.request
的用法示例。
在下文中一共展示了request.url_rule方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: wrapHttpEndpoint
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import url_rule [as 别名]
def wrapHttpEndpoint(f):
@functools.wraps(f)
def wrapper(*args, **kwargs):
context = {
"url": request.base_url,
"args": dict(request.args.items()),
"form": dict(request.form.items()),
"body": request.data.decode("utf-8", "strict"),
"headers": dict(request.headers.items()),
"func": request.endpoint,
"ip": request.remote_addr
}
endpoint_name = str(request.url_rule)
wrapped = measure(f, endpoint_name, request.method, context)
return wrapped(*args, **kwargs)
return wrapper
示例2: request_started
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import url_rule [as 别名]
def request_started(self, app):
if not self.app.debug or self.client.config.debug:
trace_parent = TraceParent.from_headers(request.headers)
self.client.begin_transaction("request", trace_parent=trace_parent)
elasticapm.set_context(
lambda: get_data_from_request(request, self.client.config, constants.TRANSACTION), "request"
)
rule = request.url_rule.rule if request.url_rule is not None else ""
rule = build_name_with_http_method_prefix(rule, request)
elasticapm.set_transaction_name(rule, override=False)
示例3: build_url
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import url_rule [as 别名]
def build_url(self, **kwargs):
arg = request.args.copy()
view_args = request.view_args
arg.update(view_args)
for attr in kwargs.keys():
if attr in arg:
arg.pop(attr)
arg.update(kwargs.items())
rule = request.url_rule
result = rule.build({k: v for k, v in arg.items()})
return result[1]
示例4: load_user_from_session
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import url_rule [as 别名]
def load_user_from_session():
if str(request.url_rule) in ['/logout']:
return None
g.user = User.query.get(session['user_id']) if 'user_id' in session else None
# @todo #2:15min move after_request method to a general place or a middleware
示例5: csrf_protect
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import url_rule [as 别名]
def csrf_protect():
"""
Validate csrf token against the one in session
:return:
"""
if ENABLE_CSRF:
if "dashboard" not in str(request.url_rule):
if request.method == "POST":
token = session.pop('_csrf_token', None)
if not token or token != request.form.get('_csrf_token'):
abort(403)
示例6: __init__
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import url_rule [as 别名]
def __init__(self):
self.endpoint = request.url_rule and request.url_rule.endpoint
self.lines = []
示例7: before_request
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import url_rule [as 别名]
def before_request():
"""This runs before every API request. The function take cares of creating
driver object is not already created. Also it checks for few prerequisits
parameters and set global variables for other functions to use
Required paramters for an API hit are:
auth-key: key string to identify valid request
client_id: to identify for which client the request is to be run
"""
global logger
if not request.url_rule:
abort(404)
if logger == None:
create_logger()
logger.info("API call " + request.method + " " + request.url)
auth_key = request.headers.get("auth-key")
g.client_id = request.headers.get("client_id")
rule_parent = request.url_rule.rule.split("/")[1]
if API_KEY and auth_key != API_KEY:
abort(401, "you must send valid auth-key")
raise Exception()
if not g.client_id and rule_parent != "admin":
abort(400, "client ID is mandatory")
acquire_semaphore(g.client_id)
# Create a driver object if not exist for client requests.
if rule_parent != "admin":
if g.client_id not in drivers:
drivers[g.client_id] = init_client(g.client_id)
g.driver = drivers[g.client_id]
g.driver_status = WhatsAPIDriverStatus.Unknown
if g.driver is not None:
g.driver_status = g.driver.get_status()
# If driver status is unkown, means driver has closed somehow, reopen it
if (
g.driver_status != WhatsAPIDriverStatus.NotLoggedIn
and g.driver_status != WhatsAPIDriverStatus.LoggedIn
):
drivers[g.client_id] = init_client(g.client_id)
g.driver_status = g.driver.get_status()
init_timer(g.client_id)
示例8: enforcer
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import url_rule [as 别名]
def enforcer(self, func):
@wraps(func)
def wrapper(*args, **kwargs):
if self.e.watcher and self.e.watcher.should_reload():
self.e.watcher.update_callback()
# Check sub, obj act against Casbin polices
self.app.logger.debug(
"Enforce Headers Config: %s\nRequest Headers: %s"
% (self.app.config.get("CASBIN_OWNER_HEADERS"), request.headers)
)
for header in self.app.config.get("CASBIN_OWNER_HEADERS"):
if header in request.headers:
# Make Authorization Header Parser standard
if header == "Authorization":
# Get Auth Value then decode and parse for owner
try:
owner = authorization_decoder(request.headers.get(header))
except UnSupportedAuthType:
# Continue if catch unsupported type in the event of
# Other headers needing to be checked
self.app.logger.info(
"Authorization header type requested for "
"decoding is unsupported by flask-casbin at this time"
)
continue
if self.e.enforce(owner, str(request.url_rule), request.method):
return func(*args, **kwargs)
else:
# Split header by ',' in case of groups when groups are
# sent "group1,group2,group3,..." in the header
for owner in self.sanitize_group_headers(
request.headers.get(header)
):
self.app.logger.debug(
"Enforce against owner: %s header: %s"
% (owner.strip('"'), header)
)
if self.e.enforce(
owner.strip('"'), str(request.url_rule), request.method
):
return func(*args, **kwargs)
else:
return (jsonify({"message": "Unauthorized"}), 401)
return wrapper