def urllib2_request(u2req, timeout=None):
    """\
    Translate a urllib2.Request to something we can pass to our
    request() function, and translate our Response to a
    urllib2.addinfourl object
    """
    # TODO: proxy support?
    method = u2req.get_method()
    url = u2req._Request__original
    body = u2req.get_data()
    headers = dict(u2req.unredirected_hdrs)
    headers.update((k, v) for k, v in u2req.headers.items()
                   if k not in headers)
    try:
        kwargs = {}
        if timeout is not None:
            kwargs['timeout'] = timeout
        resp = request(method, url, body, headers, **kwargs)
        hr = resp.http_response
        hr.recv = hr.read
        fp = socket._fileobject(hr, close=True)
        aiu = urllib2.addinfourl(fp=fp,
                                 headers=hr.msg,
                                 url=resp.request.url)
        aiu.code = hr.status
        aiu.msg = hr.reason
        return aiu
    except ValueError as e:
        raise urllib2.URLError(e.msg)
dataset/ETHPy150Open paypal/support/support/http_client.py/urllib2_request/original