'Specific to Python socket API and required by httplib: convert
response into a file-like object.  This implementation reads using recv
and copies the output into a StringIO buffer to simulate a file object
for consumption by httplib
Nb. Ignoring optional file open mode (StringIO is generic and will
open for read and write unless a string is passed to the constructor)
and buffer size - httplib set a zero buffer size which results in recv
reading nothing
@return: file object for data returned from socket
@rtype: cStringIO.StringO'

def makefile(self, *args):

    self._makefile_refs += 1
    _buf_size = self.buf_size
    i = 0
    stream = StringIO()
    startTime = datetime.utcnow()
    try:
        dat = self.__ssl_conn.recv(_buf_size)
        while dat:
            i += 1
            stream.write(dat)
            dat = self.__ssl_conn.recv(_buf_size)
    except (SSL.ZeroReturnError, SSL.SysCallError):
        pass
    if (log.getEffectiveLevel() <= logging.DEBUG):
        log.debug('Socket.makefile    %d    recv    calls    completed    in    %s', i, (datetime.utcnow() - startTime))
    stream.seek(0)
    return stream
