本文整理汇总了Python中flask.Request方法的典型用法代码示例。如果您正苦于以下问题:Python flask.Request方法的具体用法?Python flask.Request怎么用?Python flask.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类flask
的用法示例。
在下文中一共展示了flask.Request方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_19_papertoken_count
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def test_19_papertoken_count(self):
g.logged_in_user = {"username": "admin1",
"realm": "",
"role": "admin"}
builder = EnvironBuilder(method='POST',
headers={})
env = builder.get_environ()
# Set the remote address so that we can filter for it
env["REMOTE_ADDR"] = "10.0.0.1"
g.client_ip = env["REMOTE_ADDR"]
req = Request(env)
set_policy(name="paperpol",
scope=SCOPE.ENROLL,
action="{0!s}=10".format(PAPERACTION.PAPERTOKEN_COUNT))
g.policy_object = PolicyClass()
# request, that matches the policy
req.all_data = {}
req.User = User()
papertoken_count(req)
# Check if the papertoken count is set
self.assertEqual(req.all_data.get("papertoken_count"), "10")
# finally delete policy
delete_policy("paperpol")
示例2: test_08_check_conditions_serial
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def test_08_check_conditions_serial(self):
uhandler = UserNotificationEventHandler()
# check a serial with regexp
builder = EnvironBuilder(method='POST',
data={'user': "cornelius@realm1"},
headers={})
env = builder.get_environ()
req = Request(env)
req.all_data = {"user": "cornelius@realm1",
"serial": "OATH123456"}
req.User = User("cornelius", "realm1")
resp = Response()
resp.data = """{"result": {"value": true}}"""
r = uhandler.check_condition(
{"g": {},
"handler_def": {"conditions": {"serial": "^OATH.*"}},
"request": req,
"response": resp
}
)
# Serial matches the regexp
self.assertEqual(r, True)
示例3: test_02_loggingevent_default
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def test_02_loggingevent_default(self, capture):
# simple logging event with default values
g = FakeFlaskG()
g.audit_object = FakeAudit()
env = EnvironBuilder(method='POST', headers={}, path='/auth').get_environ()
req = Request(env)
req.all_data = {}
resp = Response(response="""{"result": {"value": true}}""")
options = {
"g": g,
"request": req,
"response": resp,
"handler_def": {
}
}
log_handler = LoggingEventHandler()
res = log_handler.do("logging", options=options)
self.assertTrue(res)
capture.check(
('pi-eventlogger', 'INFO', 'event=/auth triggered')
)
示例4: __call__
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def __call__(self, environ: Dict, start_response: Callable) -> Callable:
response = None
request = Request(environ)
session = self.session_interface.open_session( # type: ignore
self.proxy_app, request
)
# callback request
if request.base_url == self.callback_url:
response = self.callback(session, request)
return self._response(environ, start_response, session, response)
# logout request
elif request.path == self.logout_uri:
self.logout(session)
return self.app(environ, start_response)
# unauthorized request
elif "user" not in session:
response = self.login(session)
return self._response(environ, start_response, session, response)
# authorized request
else:
return self.app(environ, start_response)
示例5: callback
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def callback(self, session: Dict, request: Request) -> Response:
""" Authentication callback handler """
# validate state
state = request.args.get("state", "unknown")
_state = session.pop("state", None)
if state != _state:
return Response("Invalid state", status=403)
# fetch user tokens
code: str = request.args.get("code", "unknown")
tokens = self.kc.callback(code)
session["tokens"] = json.dumps(tokens)
# fetch user info
access_token = tokens["access_token"]
user = self.kc.fetch_userinfo(access_token)
session["user"] = json.dumps(user)
return redirect(self.redirect_uri)
示例6: handle_request
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def handle_request(self, request: flask.Request, func):
if request.content_type == "text/csv":
csv_string = StringIO(request.get_data(as_text=True))
df = pd.read_csv(csv_string)
else:
# Optimistically assuming Content-Type to be "application/json"
try:
df = pd.read_json(
request.get_data(as_text=True),
orient=self.orient,
typ=self.typ,
dtype=False,
)
except ValueError:
raise BadInput(
"Failed parsing request data, only Content-Type application/json "
"and text/csv are supported in BentoML DataframeInput"
)
if self.typ == "frame" and self.input_dtypes is not None:
check_dataframe_column_contains(self.input_dtypes, df)
result = func(df)
return self.output_adapter.to_response(result, request)
示例7: __init__
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def __init__(
self, service, name, doc, handler, func, mb_max_latency, mb_max_batch_size
):
"""
:param service: ref to service containing this API
:param name: API name
:param handler: A InputAdapter that transforms HTTP Request and/or
CLI options into parameters for API func
:param func: API func contains the actual API callback, this is
typically the 'predict' method on a model
:param mb_max_latency: The latency goal of your service in milliseconds.
Default: 300.
:param mb_max_batch_size: The maximum size of any batch. This parameter
governs the throughput/latency tradeoff, and also avoids having
batches that are so large they exceed some resource constraint (e.g.
GPU memory to hold a batch's data). Default: 1000.
"""
self._service = service
self._name = name
self._doc = doc
self._handler = handler
self._func = func
self._wrapped_func = None
self.mb_max_latency = mb_max_latency
self.mb_max_batch_size = mb_max_batch_size
示例8: get_scopes
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def get_scopes(request: flask.Request) -> Set[Scope]:
scope_strs = _split_arg(request.args.getlist("scope"))
return set([Scope(scope_str) for scope_str in scope_strs])
示例9: get_response_types
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def get_response_types(request: flask.Request) -> Set[ResponseType]:
response_type_strs = _split_arg(request.args.getlist("response_type"))
return set([ResponseType(r) for r in response_type_strs if r])
示例10: test_10_api_endpoint
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def test_10_api_endpoint(self):
fixed = "ebedeeefegeheiej"
otpkey = "cc17a4d77eaed96e9d14b5c87a02e718"
uid = "000000000000"
otps = ["ebedeeefegeheiejtjtrutblehenfjljrirgdihrfuetljtt",
"ebedeeefegeheiejlekvlrlkrcluvctenlnnjfknrhgtjned",
"ebedeeefegeheiejktudedbktcnbuntrhdueikggtrugckij",
"ebedeeefegeheiejjvjncbnffdrvjcvrbgdfufjgndfetieu",
"ebedeeefegeheiejdruibhvlvktcgfjiruhltketifnitbuk"
]
token = init_token({"type": "yubikey",
"otpkey": otpkey,
"otplen": len(otps[0]),
"yubikey.prefix": fixed,
"serial": "UBAM12345678_1"})
builder = EnvironBuilder(method='GET',
headers={})
env = builder.get_environ()
# Set the remote address so that we can filter for it
env["REMOTE_ADDR"] = "10.0.0.1"
g.client_ip = env["REMOTE_ADDR"]
req = Request(env)
nonce = "random nonce"
apiid = "hallo"
apikey = "1YMEbMZijD3DzL21UfKGnOOI13c="
set_privacyidea_config("yubikey.apiid.{0!s}".format(apiid), apikey)
req.all_data = {'id': apiid,
"otp": otps[0],
"nonce": nonce}
text_type, result = YubikeyTokenClass.api_endpoint(req, g)
self.assertEqual(text_type, "plain")
self.assertTrue("status=OK" in result, result)
self.assertTrue("nonce={0!s}".format(nonce) in result, result)
示例11: test_11_strip_whitespace
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def test_11_strip_whitespace(self):
fixed = "ebedeeefegeheiej"
# The backend automatically strips whitespace from the OTP key
otpkey = "cc 17 a4 d7 7e ae d9 6e 9d 14 b5 c8 7a 02 e7 18"
uid = "000000000000"
otps = ["ebedeeefegeheiejtjtrutblehenfjljrirgdihrfuetljtt",
"ebedeeefegeheiejlekvlrlkrcluvctenlnnjfknrhgtjned",
"ebedeeefegeheiejktudedbktcnbuntrhdueikggtrugckij",
"ebedeeefegeheiejjvjncbnffdrvjcvrbgdfufjgndfetieu",
"ebedeeefegeheiejdruibhvlvktcgfjiruhltketifnitbuk"
]
token = init_token({"type": "yubikey",
"otpkey": otpkey,
"otplen": len(otps[0]),
"yubikey.prefix": fixed,
"serial": "UBAM12345678_1"})
builder = EnvironBuilder(method='GET',
headers={})
env = builder.get_environ()
# Set the remote address so that we can filter for it
env["REMOTE_ADDR"] = "10.0.0.1"
g.client_ip = env["REMOTE_ADDR"]
req = Request(env)
nonce = "random nonce"
apiid = "hallo"
apikey = "1YMEbMZijD3DzL21UfKGnOOI13c="
set_privacyidea_config("yubikey.apiid.{0!s}".format(apiid), apikey)
req.all_data = {'id': apiid,
"otp": otps[0],
"nonce": nonce}
text_type, result = YubikeyTokenClass.api_endpoint(req, g)
self.assertEqual(text_type, "plain")
self.assertTrue("status=OK" in result, result)
self.assertTrue("nonce={0!s}".format(nonce) in result, result)
示例12: test_01a_admin_realms
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def test_01a_admin_realms(self):
admin1 = {"username": "admin1",
"role": "admin",
"realm": "realm1"}
admin2 = {"username": "admin1",
"role": "admin",
"realm": "realm2"}
set_policy(name="pol",
scope=SCOPE.ADMIN,
action="*", adminrealm="realm1")
g.policy_object = PolicyClass()
builder = EnvironBuilder(method='POST',
data={'serial': "OATH123456"},
headers={})
env = builder.get_environ()
# Set the remote address so that we can filter for it
env["REMOTE_ADDR"] = "10.0.0.1"
g.client_ip = env["REMOTE_ADDR"]
req = Request(env)
req.User = User()
req.all_data = {}
# admin1 is allowed to do everything
g.logged_in_user = admin1
r = check_base_action(req, action="delete")
self.assertTrue(r)
# admin2 is not allowed.
g.logged_in_user = admin2
self.assertRaises(PolicyError, check_base_action, req, action="delete")
delete_policy("pol")
示例13: test_03_check_token_upload
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def test_03_check_token_upload(self):
g.logged_in_user = {"username": "admin1",
"realm": "",
"role": "admin"}
builder = EnvironBuilder(method='POST',
data={'serial': "OATH123456"},
headers={})
env = builder.get_environ()
# Set the remote address so that we can filter for it
env["REMOTE_ADDR"] = "10.0.0.1"
g.client_ip = env["REMOTE_ADDR"]
req = Request(env)
req.all_data = {"filename": "token.xml"}
req.User = User()
# Set a policy, that does allow the action
set_policy(name="pol1",
scope=SCOPE.ADMIN,
action="enrollTOTP, enrollHOTP, {0!s}".format(ACTION.IMPORT),
client="10.0.0.0/8")
g.policy_object = PolicyClass()
# Try to import tokens
r = check_token_upload(req)
self.assertTrue(r)
# The admin can not upload from another IP address
# An exception is raised
env["REMOTE_ADDR"] = "192.168.0.1"
g.client_ip = env["REMOTE_ADDR"]
req = Request(env)
req.all_data = {"filename": "token.xml"}
req.User = User()
self.assertRaises(PolicyError,
check_token_upload, req)
# finally delete policy
delete_policy("pol1")
示例14: test_08_encrypt_pin
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def test_08_encrypt_pin(self):
g.logged_in_user = {"username": "admin1",
"realm": "",
"role": "admin"}
builder = EnvironBuilder(method='POST',
data={'serial': "OATH123456"},
headers={})
env = builder.get_environ()
# Set the remote address so that we can filter for it
env["REMOTE_ADDR"] = "10.0.0.1"
g.client_ip = env["REMOTE_ADDR"]
req = Request(env)
# Set a policy that defines the PIN to be encrypted
set_policy(name="pol1",
scope=SCOPE.ENROLL,
action=ACTION.ENCRYPTPIN)
g.policy_object = PolicyClass()
# request, that matches the policy
req.all_data = {
"user": "cornelius",
"realm": "home"}
encrypt_pin(req)
# Check, if the tokenlabel was added
self.assertEqual(req.all_data.get("encryptpin"), "True")
# finally delete policy
delete_policy("pol1")
示例15: test_08b_enroll_pin_user
# 需要导入模块: import flask [as 别名]
# 或者: from flask import Request [as 别名]
def test_08b_enroll_pin_user(self):
g.logged_in_user = {"username": "cornelius",
"realm": self.realm1,
"role": "user"}
builder = EnvironBuilder(method='POST',
data={'serial': "OATH123456"},
headers={})
env = builder.get_environ()
# Set the remote address so that we can filter for it
env["REMOTE_ADDR"] = "10.0.0.1"
g.client_ip = env["REMOTE_ADDR"]
req = Request(env)
# Set a policy that defines the PIN to be encrypted
set_policy(name="pol1",
scope=SCOPE.USER,
action="enrollHOTP, enrollpin")
g.policy_object = PolicyClass()
# request, that matches the policy
req.all_data = {"pin": "test",
"user": "cornelius",
"realm": self.realm1}
req.User = User("cornelius", self.realm1)
enroll_pin(req)
# Check, if the PIN was removed
self.assertEqual(req.all_data.get("pin"), "test")
# finally delete policy
delete_policy("pol1")