Example #1
0
def _normalize_python3_urllib_request(request):
    if six.PY3:
        if not isinstance(request, urllib.request.Request):
            raise TypeError("Cannot normalize this request object")
    else:
        raise TypeError("Cannot normalize python2 urllib request object")

    url = request.get_full_url()
    method = request.get_method().lower()
    content_type = request.headers.get('Content-type')
    body = request.data

    return Request(
        url=url,
        body=body,
        method=method,
        content_type=content_type,
        request=request,
    )
Example #2
0
def _normalize_python3_urllib_request(request):
    if six.PY3:
        if not isinstance(request, urllib.request.Request):
            raise TypeError("Cannot normalize this request object")
    else:
        raise TypeError("Cannot normalize python2 urllib request object")

    url = request.get_full_url()
    method = request.get_method().lower()
    content_type = request.headers.get('Content-type')
    body = request.data

    return Request(
        url=url,
        body=body,
        method=method,
        content_type=content_type,
        request=request,
    )