Beispiel #1
0
def construct_wsgi_from_data(request, data, replace_params={}, rewriter=None):
    '''
    Given the data in the format of url, method, body and headers, construct a new
    WSGIRequest object.
    '''
    valid_http_methods = [
        'get', 'post', 'put', 'patch', 'delete', 'head', 'options', 'connect',
        'trace'
    ]

    if rewriter:
        rewriter.rewrite_request(data)

    url = data.get('url', None)
    method = data.get('method', None)

    if url is None or method is None:
        raise BadBatchRequest(
            'Request definition should have url, method defined.')

    if method.lower() not in valid_http_methods:
        raise BadBatchRequest('Invalid request method.')

    body = None
    if method.lower() not in ['get', 'options']:
        body = data.get('body', '')
        for name, value in replace_params.items():
            placeholder = '"{{' + name + '}}"'
            body = json.loads(json.dumps(body).replace(placeholder, value))

    headers = data.get('headers', {})
    onward_variables = data.get('onward_data', {})
    wsgi_request = get_wsgi_request_object(request, method, url, headers, body)
    return (wsgi_request, onward_variables)
    def construct_wsgi_from_data(data):
        '''
            Given the data in the format of url, method, body and headers, construct a new
            WSGIRequest object.
        '''
        url = data.get("url", None)
        method = data.get("method", None)

        if url is None or method is None:
            raise BadBatchRequest("Request definition should have url, method defined.")

        if method.lower() not in valid_http_methods:
            raise BadBatchRequest("Invalid request method.")

        body = data.get("body", "")
        headers = data.get("headers", {})
        return get_wsgi_request_object(request, method, url, headers, body)
Beispiel #3
0
    def construct_wsgi_from_data(data):
        '''
            Given the data in the format of url, method, body and headers, construct a new
            WSGIRequest object.
        '''
        url = data.get("url", None)
        method = data.get("method", None)

        if url is None or method is None:
            raise BadBatchRequest("Request definition should have url, method defined.")

        if method.lower() not in valid_http_methods:
            raise BadBatchRequest("Invalid request method.")

        body = data.get("body", "")
        headers = data.get("headers", {})
        return get_wsgi_request_object(request, method, url, headers, body)
    def construct_wsgi_from_data(data, valid_http_methods=VALID_HTTP_METHODS):
        '''
            Given the data in the format of url, method, body and headers, construct a new
            WSGIRequest object.
        '''
        url = data.get("url", None)
        method = data.get("method", None)

        if url is None or method is None:
            raise BadBatchRequest("Request definition should have url, method defined.")

        method = method.upper()
        if method not in valid_http_methods:
            raise BadBatchRequest("Invalid request method.")

        # support singly/doubly encoded JSON
        body = data.get("body", "")
        if isinstance(body, dict):
            body = json.dumps(body, cls=BytesEncoder)
        headers = data.get("headers", {})
        return get_wsgi_request_object(request, method, url, headers, body)