Exemplo n.º 1
0
def abort(code):
    if code == 400: return web.HTTPBadRequest()
    elif code == 401: return web.HTTPUnauthorized()
    elif code == 402: return web.HTTPPaymentRequired()
    elif code == 403: return web.HTTPForbidden()
    elif code == 404: return web.HTTPNotFound()
    elif code == 405: return web.HTTPMethodNotAllowed()
    elif code == 406: return web.HTTPNotAcceptable()
    elif code == 407: return web.HTTPProxyAuthenticationRequired()
    elif code == 408: return web.HTTPRequestTimeout()
    elif code == 409: return web.HTTPConflict()
    elif code == 410: return web.HTTPGone()
    elif code == 411: return web.HTTPLengthRequired()
    elif code == 412: return web.HTTPPreconditionFailed()
    elif code == 413: return web.HTTPRequestEntityTooLarge()
    elif code == 414: return web.HTTPRequestURITooLong()
    elif code == 415: return web.HTTPUnsupportedMediaType()
    elif code == 416: return web.HTTPRequestRangeNotSatisfiable()
    elif code == 417: return web.HTTPExpectationFailed()
    elif code == 421: return web.HTTPMisdirectedRequest()
    elif code == 422: return web.HTTPUnprocessableEntity()
    elif code == 424: return web.HTTPFailedDependency()
    elif code == 426: return web.HTTPUpgradeRequired()
    elif code == 428: return web.HTTPPreconditionRequired()
    elif code == 429: return web.HTTPTooManyRequests()
    elif code == 431: return web.HTTPRequestHeaderFieldsTooLarge()
    elif code == 451: return web.HTTPUnavailableForLegalReasons()
    else: return web.HTTPBadRequest()
Exemplo n.º 2
0
async def subtract(request: web.Request, uuid: str, how_much: int) -> web.Response:
    """Пополнить баланс указанного клиента.

    :param request: запрос
    :param uuid: идентификатор клиента
    :param how_much: количество копеек, которые нужно снять с баланса клиента
    """
    async with request.app["pg"].acquire() as connection:
        try:
            row = await query_subtract(connection, uuid, how_much)
        except NotEnoughMoneyError:
            raise web.HTTPPaymentRequired()

        if not row:
            raise web.HTTPNotFound()
        return json_response(dict(row.items()))
Exemplo n.º 3
0
 async def f(*args, **kwargs):
     raise web.HTTPPaymentRequired()
Exemplo n.º 4
0
 def payment_required(self, code, reason):
     """Default response for Error code 402"""
     error = {"code": code, "reason": reason}
     logging.warning("Payment required error: %s", error)
     raise web.HTTPPaymentRequired(text=json.dumps(error),
                                   content_type="application/json")