本文整理汇总了Python中envi.Request.get方法的典型用法代码示例。如果您正苦于以下问题:Python Request.get方法的具体用法?Python Request.get怎么用?Python Request.get使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类envi.Request
的用法示例。
在下文中一共展示了Request.get方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_getter
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
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'))
示例2: test_getter_default
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
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: send_sms
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
def send_sms(cls, request: Request, **kwargs):
"""
:param request:
:param kwargs:
:return:
"""
return service.send_sms(request.get("address"), request.get("text"))
示例4: recover_password
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
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
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
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_email
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
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)
示例7: get_cart
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
def get_cart(cls, request: Request, *args, **kwargs):
""" Метод для получения объекта корзины покупателя
:param request:
:param args:
:param kwargs:
:return:
"""
cart = carts.get_cart(int(request.get("cart_id")) if request.get("cart_id", None) else None)
return {"cart": cart.get_data()}
示例8: send_sms
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
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}
示例9: scale
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
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()}
示例10: crop
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
def crop(cls, request: Request, **kwargs):
""" Метод для обрезки изображения
:param request:
:param kwargs:
:return:
"""
bytes_object = BytesIO(base64.b64decode(request.get("base64").replace(" ", "+").encode()))
converted = ImageProcessor(bytes_object).crop(request.get("coords"), request.get("from_size"))
return {"base64": base64.b64encode(converted.getvalue()).decode()}
示例11: crop
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
def crop(request: Request, *args, **kwargs):
import requests
import json
payload = {'img': request.get("img"), 'coords': json.dumps(request.get("coords")), "from_size": json.dumps(request.get("from_size"))}
r = requests.post("http://z9img/crop", data=payload)
if r.status_code == 200:
return r.text
else:
return request.get("img")
示例12: upload
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
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")
示例13: create_category
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
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()}
示例14: authenticate_vk
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
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)
示例15: get_wishlist
# 需要导入模块: from envi import Request [as 别名]
# 或者: from envi.Request import get [as 别名]
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}