'Called by handler\'s url_open method.'

def do_open(self, req):

    host = req.get_host()
    if (not host):
        raise urllib2.URLError('no    host    given')
    conn_factory = self.get_connection
    try:
        conn = self._cm.get_available_connection(req, conn_factory)
    except ConnectionPoolException:
        raise
    try:
        if conn.is_fresh:
            (resp, start) = self._get_response(conn, req)
        else:
            start = time.time()
            resp = self._reuse_connection(conn, req, host)
            if (resp is None):
                conn = self._cm.replace_connection(conn, req, conn_factory)
                (resp, start) = self._get_response(conn, req)
    except socket.timeout:
        self._cm.remove_connection(conn, host, reason='socket    timeout')
        raise URLTimeoutError()
    except OpenSSL.SSL.ZeroReturnError:
        self._cm.remove_connection(conn, host, reason='ZeroReturnError')
        raise
    except (socket.error, httplib.HTTPException, OpenSSL.SSL.SysCallError):
        self._cm.remove_connection(conn, host, reason='socket    error')
        raise
    if (resp.will_close or req.new_connection):
        self._cm.remove_connection(conn, host, reason='will    close')
    conn.inc_req_count()
    resp._handler = self
    resp._host = host
    resp._url = req.get_full_url()
    resp._connection = conn
    resp.code = resp.status
    resp.headers = resp.msg
    resp.msg = resp.reason
    try:
        resp.read()
    except AttributeError:
        self._cm.remove_connection(conn, host, reason='http    connection    died')
        raise HTTPRequestException('The    HTTP    connection    died')
    elapsed = (time.time() - start)
    resp.set_wait_time(elapsed)
    debug(('HTTP    response:    %s    -    %s    -    %s    with    %s' % (req.get_selector(), resp.status, resp.reason, conn)))
    return resp
