本文整理汇总了Python中envi.Request类的典型用法代码示例。如果您正苦于以下问题:Python Request类的具体用法?Python Request怎么用?Python Request使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Request类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_json_rpc_type_detection
def test_json_rpc_type_detection(self):
""" JsonRPC запрос определяется по наличию аргумента q в запросе и только по нему одному """
request = Request({"q": "{}"})
self.assertEqual(Request.Types.JSON_RPC, request.type())
request = Request({"q": "{}"}, environ={"HTTP_X_REQUESTED_WITH": "XMLHttpRequest"})
self.assertEqual(Request.Types.JSON_RPC, request.type())
示例2: test_getter_default
def test_getter_default(self):
request = Request({'a': 1}, {'b': 2}, {'c': 3}, {'d': 4})
self.assertRaises(Request.RequiredArgumentIsMissing, request.get, 'x')
self.assertEqual("xxx", request.get('x', "xxx"))
self.assertEqual("xxx", request.get('x', default="xxx"))
self.assertEqual(None, request.get('x', None))
self.assertEqual(None, request.get('x', default=None))
示例3: ajax_auth
def ajax_auth(cls, user, request: Request, **kwargs):
request.set("login", Phone(request.get("login")).get_value())
if AuthController.auth(request, **kwargs):
return {
"user": user.stringify(["position_name", "name", "phone", "phone_verified", "email", "email_verified"]),
"preview_randomizer": datetime.now().microsecond
}
示例4: recover_password
def recover_password(cls, user, request: Request, **kwargs):
phone = Phone(request.get("phone")).get_value()
target_user = cls.users_collection().get_item({"account.login": phone, "phone_verified": True})
if target_user.email_verified:
cls.auth_service().change_password(target_user.email)
return True
if target_user.verification_code == request.get("vc1") and target_user.verification_code2 == request.get("vc2"):
target_user.email_verified = True
target_user.verification_code = None
target_user.verification_code_failed_attempts = 0
target_user.save()
cls.auth_service().change_password(target_user.email)
return True
else:
target_user.verification_code_failed_attempts += 1
if target_user.verification_code_failed_attempts < 3:
target_user.save()
raise IncorrectVerificationCode()
else:
target_user.email = None
target_user.email_verified = False
target_user.verification_code = None
target_user.verification_code2 = None
target_user.verification_code_failed_attempts = 0
target_user.save()
raise IncorrectVerificationCodeFatal()
示例5: confirm_email_and_auth
def confirm_email_and_auth(cls, user, request: Request, **kwargs):
phone = Phone(request.get("phone")).get_value()
target_user = cls.users_collection().get_item({"account.login": phone, "phone_verified": True})
if target_user.verification_code == request.get("vc1") and target_user.verification_code2 == request.get("vc2"):
target_user.email_verified = True
target_user.verification_code = None
target_user.verification_code_failed_attempts = 0
target_user.save()
user.refresh()
cls.auth_service().send_email_confirmation_success(target_user.email)
return {
"user": user.stringify(["position_name", "name", "phone", "phone_verified", "email", "email_verified"]),
"preview_randomizer": datetime.now().microsecond
}
else:
target_user.verification_code_failed_attempts += 1
if target_user.verification_code_failed_attempts < 3:
target_user.save()
raise IncorrectVerificationCode()
else:
target_user.email = None
target_user.email_verified = False
target_user.verification_code = None
target_user.verification_code2 = None
target_user.verification_code_failed_attempts = 0
target_user.save()
raise IncorrectVerificationCodeFatal()
示例6: send_sms
def send_sms(cls, request: Request, **kwargs):
"""
:param request:
:param kwargs:
:return:
"""
return service.send_sms(request.get("address"), request.get("text"))
示例7: test_getter
def test_getter(self):
""" Запрос инициализируется любым количеством словарей """
request = Request({'a': 1}, {'b': 2}, {'c': 3}, {'d': 4})
self.assertEqual(1, request.get('a'))
self.assertEqual(2, request.get('b'))
self.assertEqual(3, request.get('c'))
self.assertEqual(4, request.get('d'))
示例8: new_default_account
def new_default_account(cls, request: Request, do_auth=True, auto_register=False) -> Account:
account = Account({"login": AuthentificationService.gen_password(), "password": AuthentificationService.gen_password()})
if do_auth:
request.set("token", account.set_new_token())
cls.auth(request)
if auto_register:
cls.users_collection().get_new_item().load_from_array({"name": "Анонимный пользователь", "account": account}).save()
return account
示例9: send_email
def send_email(cls, request: Request, **kwargs):
"""
:param request:
:param kwargs:
:return:
"""
html = base64.b64decode(request.get("base64").replace(" ", "+").encode()).decode()
return service.send_email(request.get("address"), request.get("subject"), html)
示例10: get_wishlist
def get_wishlist(cls, request: Request, *args, **kwargs):
""" Метод для получения списка избранных товаров покупателя
:param request:
:param args:
:param kwargs:
:return:
"""
wishlist = carts.get_cart(int(request.get("wishlist_id")) if request.get("wishlist_id", None) else None)
return {"wishlist": wishlist.get_data() if wishlist else None}
示例11: upload
def upload(request: Request, *args, **kwargs):
import requests
import json
payload = {'base64': request.get("img")}
r = requests.post("http://z9s3/upload", data=payload)
if r.status_code == 200:
return json.loads(r.text).get("url")
else:
return request.get("img")
示例12: create_category
def create_category(cls, request: Request, *args, **kwargs):
""" Метод для создания новых рубрик
:param request:
:param args:
:param kwargs:
:return:
"""
catalog.create_category(request.get("category_name"), request.get("slug"))
return {"categories": catalog.get_categories()}
示例13: scale
def scale(cls, request: Request, **kwargs):
""" Метод для изменения размера изображения (масштабирование)
:param request:
:param kwargs:
:return:
"""
bytes_object = BytesIO(base64.b64decode(request.get("base64").replace(" ", "+").encode()))
converted = ImageProcessor(bytes_object).scale(request.get("size"))
return {"base64": base64.b64encode(converted.getvalue()).decode()}
示例14: send_sms
def send_sms(cls, request: Request, **kwargs):
"""
:param request:
:param kwargs:
:return:
"""
as_json = request.get("as_json", False)
result = service.send_sms(request.get("address"), request.get("text"))
return result if not as_json else {"result": result}
示例15: authenticate_vk
def authenticate_vk(cls, request: Request, **kwargs):
""" Метод для выполнения аутентификации через Вк
:param request:
:param kwargs:
:return:
"""
code = request.get("code")
redirect_url = request.get("redirect_url", None)
return service.authenticate_vk(cls.build_credentials(request), code, redirect_url)