Ok, here's some news, in case they can be of some interest.
I managed to write an asyncore disptacher which seems to work.
I used my test suite against it and 70 tests passed and 2 failed.
The tests failed because at a certain point a call to do_handhsake
results in an EOF exception, which is very strange since it is
supposed to raise SSL_ERROR_WANT_READ or SSL_ERROR_WANT_WRITE only.
I'll keep you updated in case I have some news.



--- Exception ---

  File "C:\python26\lib\ssl.py", line 293, in do_handshake
    self._sslobj.do_handshake()
SSLError: [Errno 8] _ssl.c:480: EOF occurred in violation of protocol



--- SSL dispatcher ----

class SSLConnection(asyncore.dispatcher):

    def __init__(self):
        self.ssl_handshake_pending = False

    def do_ssl_handshake(self):
        try:
            self.socket.do_handshake()
        except ssl.SSLError, err:
            if err.args[0] == ssl.SSL_ERROR_WANT_READ:
                self.ssl_handshake_pending = 'read'
            elif err.args[0] == ssl.SSL_ERROR_WANT_WRITE:
                self.ssl_handshake_pending = 'write'
            else:
                raise
        else:
            self.ssl_handshake_pending = False

    def handle_read_event(self):
        if self.ssl_handshake_pending == 'read':
            self.do_ssl_handshake()
##            if not self.ssl_handshake_pending:
##                asyncore.dispatcher.handle_read_event(self)
        else:
            asyncore.dispatcher.handle_read_event(self)

    def handle_write_event(self):
        if self.ssl_handshake_pending == 'write':
            self.do_ssl_handshake()
##            if not self.ssl_handshake_pending:
##                asyncore.dispatcher.handle_write_event(self)
        else:
            asyncore.dispatcher.handle_write_event(self)



--- Giampaolo
http://code.google.com/p/pyftpdlib/
_______________________________________________
Python-Dev mailing list
Python-Dev@python.org
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe: 
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com

Reply via email to