Пример #1
0
async def _preflight_cors(request):
    """Respond to preflight CORS requests and load parameters."""
    if request.method == "OPTIONS":
        return textify("ok", headers=generate_cors_headers(request))
    request['args'] = {}
    if request.form:
        for key in request.form:
            key_lower = key.lower()
            if key_lower in _MUST_BE_GET_PARAM:
                raise UserException(CANNOT_BE_POST_PARAM % key)
            request['args'][key_lower] = request.form[key][0]
    elif request.json:
        for key in request.json:
            key_lower = key.lower()
            if key_lower in _MUST_BE_GET_PARAM:
                raise UserException(CANNOT_BE_POST_PARAM % key)
            # Make all url parameters strings
            if isinstance(request.json[key], list):
                request['args'][key_lower] = json.dumps(request.json[key])
            else:
                request['args'][key_lower] = str(request.json[key])
    # Take all Get parameters
    for key, value in list(request.raw_args.items()):
        key_lower = key.lower()
        if key_lower in _MUST_BE_POST_PARAM:
            raise UserException(CANNOT_BE_GET_PARAM % key)
        request['args'][key_lower] = value
Пример #2
0
async def _before_request(request):
    """Respond to preflight CORS requests and load parameters."""
    if request.method == "OPTIONS":
        return textify("ok", headers=generate_cors_headers(request))
    request['args'] = {}
    if request.form:
        for key in request.form:
            key_lower = key.lower()
            if key_lower in _MUST_BE_GET_PARAM and not request.path.startswith(URL_BASE + '/email/'):
                raise UserException(CANNOT_BE_POST_PARAM % key)
            request['args'][key_lower] = request.form[key][0]
    elif request.json:
        slack_message = ('type' in request.json and request.json['type'] in _SLACK_TYPES)
        for key in request.json:
            key_lower = key.lower()
            if slack_message:
                request['args'][key_lower] = request.json[key]
            else:
                if key_lower in _MUST_BE_GET_PARAM and not request.path.startswith('/hangouts/'):
                    raise UserException(CANNOT_BE_POST_PARAM % key)
                # Make all url parameters strings
                if isinstance(request.json[key], dict):
                    request['args'][key_lower] = json.dumps(request.json[key])
                elif isinstance(request.json[key], list):
                    request['args'][key_lower] = json.dumps(request.json[key])
                else:
                    request['args'][key_lower] = str(request.json[key])
    # Take all Get parameters
    for key, value in list(request.raw_args.items()):
        key_lower = key.lower()
        if key_lower in _MUST_BE_POST_PARAM:
            raise UserException(CANNOT_BE_GET_PARAM % key)
        request['args'][key_lower] = value
Пример #3
0
def _timeout(request, exception):
    return textify('RequestTimeout from error_handler.', 408)
Пример #4
0
 def wrapper(request, *args, **kw):
     status = 200
     result = decorated(request, *args, **kw)
     return textify(result, status=status, headers=generate_cors_headers(request))
Пример #5
0
async def _all(request, tag):
    await asyncio.sleep(86400)
    return textify(ERROR_TEXT)