本文整理汇总了Python中flask.request.full_path方法的典型用法代码示例。如果您正苦于以下问题:Python request.full_path方法的具体用法?Python request.full_path怎么用?Python request.full_path使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask.request
的用法示例。
在下文中一共展示了request.full_path方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: authed_only
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def authed_only(f):
"""
Decorator that requires the user to be authenticated
:param f:
:return:
"""
@functools.wraps(f)
def authed_only_wrapper(*args, **kwargs):
if authed():
return f(*args, **kwargs)
else:
if (
request.content_type == "application/json"
or request.accept_mimetypes.best == "text/event-stream"
):
abort(403)
else:
return redirect(url_for("auth.login", next=request.full_path))
return authed_only_wrapper
示例2: admins_only
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def admins_only(f):
"""
Decorator that requires the user to be authenticated and an admin
:param f:
:return:
"""
@functools.wraps(f)
def admins_only_wrapper(*args, **kwargs):
if is_admin():
return f(*args, **kwargs)
else:
if request.content_type == "application/json":
abort(403)
else:
return redirect(url_for("auth.login", next=request.full_path))
return admins_only_wrapper
示例3: check_account_visibility
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def check_account_visibility(f):
@functools.wraps(f)
def _check_account_visibility(*args, **kwargs):
v = get_config(ConfigTypes.ACCOUNT_VISIBILITY)
if v == AccountVisibilityTypes.PUBLIC:
return f(*args, **kwargs)
elif v == AccountVisibilityTypes.PRIVATE:
if authed():
return f(*args, **kwargs)
else:
if request.content_type == "application/json":
abort(403)
else:
return redirect(url_for("auth.login", next=request.full_path))
elif v == AccountVisibilityTypes.ADMINS:
if is_admin():
return f(*args, **kwargs)
else:
abort(404)
return _check_account_visibility
示例4: get_current_user
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def get_current_user():
if authed():
user = Users.query.filter_by(id=session["id"]).first()
# Check if the session is still valid
session_hash = session.get("hash")
if session_hash:
if session_hash != hmac(user.password):
logout_user()
if request.content_type == "application/json":
error = 401
else:
error = redirect(url_for("auth.login", next=request.full_path))
abort(error)
return user
else:
return None
示例5: before_request
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def before_request():
''' Pre-request hander '''
logger.debug("Incoming Web Request: {0}".format(request.full_path))
g.dbc = connect_db(app.config)
示例6: log_begin_request
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def log_begin_request():
log.debug(u"Begin handling of request {!r}".format(request.full_path))
示例7: teardown_request
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def teardown_request(exc):
call_finalizers()
log.debug(u"End handling of request {!r}".format(request.full_path))
示例8: after_request
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def after_request(response):
timestamp = strftime('[%Y-%b-%d %H:%M]')
logger.error('%s %s %s %s %s %s',timestamp , request.remote_addr , \
request.method , request.scheme , request.full_path , response.status)
return response
示例9: exceptions
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def exceptions(e):
tb = traceback.format_exc()
timestamp = strftime('[%Y-%b-%d %H:%M]')
logger.error('%s %s %s %s %s 5xx INTERNAL SERVER ERROR\n%s',
timestamp, request.remote_addr, request.method,
request.scheme, request.full_path, tb)
return make_response(e , 405)
示例10: catch_all
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def catch_all(path):
# Load the config file
config=load_config()
# Honeytoken alerts
if request.path in config['traps'] and request.path != "/favicon.ico":
# Preparing the alert message
alertMessage = alert_msg(request, config)
# Slack alert
if config['alert']['slack']['enabled'] == "true":
WEBHOOK_URL = config['alert']['slack']['webhook-url']
slack_alerter(alertMessage, WEBHOOK_URL)
# Email alert
if config['alert']['email']['enabled'] == "true":
email_alerter(alertMessage, config)
# SMS alert
#TODO: Complete and test the SMS alert
#if config['alert']['sms']['enabled'] == "true":
# sms_alerter(alertMessage, config)
#TODO: HTTP Endpoint Support
# Honeypot event logs
if request.headers.getlist("X-Forwarded-For"):
source_ip = request.headers.getlist("X-Forwarded-For")[0]
else:
source_ip = request.remote_addr
logger.info('{{"sourceip":"{}","host":"{}","request":"{}","http_method":"{}","body":"{}","user_agent":"{}"}}'.format(
source_ip, request.url_root, request.full_path, request.method, request.data, request.user_agent.string))
# Prepare and send the custom HTTP response
contype, body = generate_http_response(request, config)
# Customize the response using a template (in case you want to return a dynamic response, etc.)
# You can comment the next 2 lines if you don't want to use this. /Just an example/
if body == "custom.html":
return (render_template(body, browser = request.user_agent.browser, ua = request.user_agent.string))
return (send_file(body, mimetype=contype) if "image" in contype else render_template(body))
示例11: after_request
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def after_request(response):
logger.info('%s %s %s %s %s', request.method,
request.environ.get('HTTP_X_REAL_IP', request.remote_addr),
request.scheme, request.full_path, response.status)
return response
示例12: exceptions
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def exceptions(e):
tb = traceback.format_exc()
tb = tb.decode('utf-8')
logger.error('%s %s %s %s 5xx INTERNAL SERVER ERROR\n%s',
request.environ.get('HTTP_X_REAL_IP', request.remote_addr),
request.method, request.scheme, request.full_path, tb)
return '500 INTERNAL SERVER ERROR', 500
示例13: after_request
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def after_request(response):
"""After request handler."""
service_log.info(
'{0} {1} {2} {3} {4}'.format(
request.remote_addr, request.method, request.scheme,
request.full_path, response.status
)
)
return response
示例14: exceptions
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def exceptions(e):
"""App exception logger."""
tb = traceback.format_exc()
service_log.error(
'{} {} {} {} 5xx INTERNAL SERVER ERROR\n{}'.format(
request.remote_addr, request.method, request.scheme,
request.full_path, tb
)
)
return e.status_code
示例15: after_request
# 需要导入模块: from flask import request [as 别名]
# 或者: from flask.request import full_path [as 别名]
def after_request(response):
if response.status_code != 500:
ts = strftime('[%Y-%b-%d %H:%M]')
logger.info('%s %s %s %s %s %s',
ts,
request.remote_addr,
request.method,
request.scheme,
request.full_path,
response.status)
return(response)