asynchat e ssl?

Stato
Discussione chiusa ad ulteriori risposte.

Chuzz

Utente Silver
11 Giugno 2007
64
2
0
70
ok sto usando python 3.1, devo usare asynchat su un socket ssl:
Codice:
class IRCClient(asynchat.async_chat):
    '''Abstract base for an asinchronous irc client'''
    def __init__(self, host, encoding, is_ssl=False, debug=False):
        super().__init__()
        self.create_socket(socket.AF_INET,  socket.SOCK_STREAM)
        if is_ssl:
            self.set_socket(ssl.wrap_socket(self.socket))
        self.encoding = encoding
        self.inbuf = bytearray()
        self.set_terminator(b'\r\n')
        self.server = host[0]
        self._debug = debug
        self.connect(host)

non c'è documentazione, ma ho trovato in test/ssl.py una prova di asyncore con ssl, dove più o meno faceva come ho fatto io (wrap_socket su self.socket).
ho provato in diversi modi, il meglio che sono riuscito ad ottenere è
Codice:
Traceback (most recent call last):
  File "C:\Users\Utente\irc_async\develbot.py", line 36, in <module>
    asyncore.loop()
  File "C:\Python31\lib\asyncore.py", line 206, in loop
    poll_fun(timeout, map)
  File "C:\Python31\lib\asyncore.py", line 136, in poll
    r, w, e = select.select(r, w, e, timeout)
select.error: (10038, 'Tentativo di operazione su un elemento diverso dal socket
')
:( help me :(

questo sembra il modo più corretto:
Codice:
class IRCClient(asynchat.async_chat):
    def __init__(self, host, encoding, is_ssl=False, debug=False):
        mysock= socket.socket(socket.AF_INET,  socket.SOCK_STREAM)
        if is_ssl:
            mysock = ssl.wrap_socket(mysock)
        super().__init__(sock=mysock)
        self.encoding = encoding
        self.inbuf = bytearray()
        self.set_terminator(b'\r\n')
        self.server = host[0]
        self._debug = debug
        self.connect(host)

ebbene, così esce senza dire nulla! sadness ;(
 
Stato
Discussione chiusa ad ulteriori risposte.