SSL problem - followup

Aaron Held aaron at metrony.com
Mon Nov 25 15:02:44 EST 2002


Responding to an old thread.

Another workaround to the IIS / SSL bug 
http://sourceforge.net/tracker/?group_id=5470&atid=105470&func=detail&aid=494762

Using the MixIn class from Webware under Windows:
Python 2.2.1 (#34, Apr  9 2002, 19:34:33) [MSC 32 bit (Intel)] on win32

Call the following before any SSL calls:

import httplib
import socket
from MiscUtils.MixIn import MixIn
from cStringIO import StringIO

class FakeSocketIISFix:
    def makefile(self, mode, bufsize=None):
        """Return a readable file-like object with data from socket.

        This method offers only partial support for the makefile
        interface of a real socket.  It only supports modes 'r' and
        'rb' and the bufsize argument is ignored.

        The returned object contains *all* of the file data
        With IIS EOF Fix - ADH
        """
        if mode != 'r' and mode != 'rb':
            raise UnimplementedFileMode()

        msgbuf = []
        while 1:
            try:
                buf = self._FakeSocket__ssl.read()
            except socket.sslerror, err:
                if err[0] == 5 :
                    #quickbase workaround
                    break
                if (err[0] == socket.SSL_ERROR_WANT_READ
                    or err[0] == socket.SSL_ERROR_WANT_WRITE
                    or 0):
                    continue
                if err[0] == socket.SSL_ERROR_ZERO_RETURN:
                    break
                raise
            except socket.error, err:
                if err[0] == errno.EINTR:
                    continue
                raise
            if buf == '':
                break
            msgbuf.append(buf)
        return StringIO("".join(msgbuf))

MixIn(httplib.FakeSocket,FakeSocketIISFix)


-Aaron



More information about the Python-list mailing list