'Return an addinfourl object for the request, using http_class.
http_class must implement the HTTPConnection API from httplib.
The addinfourl return value is a file-like object.  It also
has methods and attributes including:
- info(): return a mimetools.Message object for the headers
- geturl(): return the original request URL
- code: HTTP status code'

def do_open(self, http_class, req):

    host = req.get_host()
    if (not host):
        raise URLError('no    host    given')
    h = http_class(host, timeout=req.timeout)
    h.set_debuglevel(self._debuglevel)
    headers = dict(req.unredirected_hdrs)
    headers.update(dict(((k, v) for (k, v) in req.headers.items() if (k not in headers))))
    headers['Connection'] = 'close'
    headers = dict(((name.title(), val) for (name, val) in headers.items()))
    if req._tunnel_host:
        tunnel_headers = {}
        proxy_auth_hdr = 'Proxy-Authorization'
        if (proxy_auth_hdr in headers):
            tunnel_headers[proxy_auth_hdr] = headers[proxy_auth_hdr]
            del headers[proxy_auth_hdr]
        h.set_tunnel(req._tunnel_host, headers=tunnel_headers)
    try:
        h.request(req.get_method(), req.get_selector(), req.data, headers)
        try:
            r = h.getresponse(buffering=True)
        except TypeError:
            r = h.getresponse()
    except socket.error as err:
        raise URLError(err)
    r.recv = r.read
    fp = socket._fileobject(r, close=True)
    resp = addinfourl(fp, r.msg, req.get_full_url())
    resp.code = r.status
    resp.msg = r.reason
    return resp
