Runnable with both Python3 and Python2, with PyQt4 #2249
|
@ -6,6 +6,7 @@ import os
|
||||||
import socket
|
import socket
|
||||||
import ssl
|
import ssl
|
||||||
import sys
|
import sys
|
||||||
|
import six
|
||||||
|
|
||||||
import network.asyncore_pollchoose as asyncore
|
import network.asyncore_pollchoose as asyncore
|
||||||
import paths
|
import paths
|
||||||
|
@ -58,7 +59,7 @@ class TLSDispatcher(AdvancedDispatcher):
|
||||||
self.tlsDone = False
|
self.tlsDone = False
|
||||||
self.tlsVersion = "N/A"
|
self.tlsVersion = "N/A"
|
||||||
self.isSSL = False
|
self.isSSL = False
|
||||||
if ssl.OPENSSL_VERSION_NUMBER >= 0x30000000:
|
if six.PY3 or ssl.OPENSSL_VERSION_NUMBER >= 0x30000000:
|
||||||
self.tlsPrepared = False
|
self.tlsPrepared = False
|
||||||
|
|
||||||
def state_tls_init(self):
|
def state_tls_init(self):
|
||||||
|
@ -66,7 +67,7 @@ class TLSDispatcher(AdvancedDispatcher):
|
||||||
self.isSSL = True
|
self.isSSL = True
|
||||||
self.tlsStarted = True
|
self.tlsStarted = True
|
||||||
|
|
||||||
if ssl.OPENSSL_VERSION_NUMBER >= 0x30000000:
|
if six.PY3 or ssl.OPENSSL_VERSION_NUMBER >= 0x30000000:
|
||||||
self.want_read = self.want_write = True
|
self.want_read = self.want_write = True
|
||||||
self.set_state("tls_handshake")
|
self.set_state("tls_handshake")
|
||||||
return False
|
return False
|
||||||
|
@ -107,7 +108,7 @@ class TLSDispatcher(AdvancedDispatcher):
|
||||||
ciphers=self.ciphers, do_handshake_on_connect=False)
|
ciphers=self.ciphers, do_handshake_on_connect=False)
|
||||||
self.sslSocket.setblocking(0)
|
self.sslSocket.setblocking(0)
|
||||||
self.want_read = self.want_write = True
|
self.want_read = self.want_write = True
|
||||||
if ssl.OPENSSL_VERSION_NUMBER >= 0x30000000:
|
if six.PY3 or ssl.OPENSSL_VERSION_NUMBER >= 0x30000000:
|
||||||
self.tlsPrepared = True
|
self.tlsPrepared = True
|
||||||
else:
|
else:
|
||||||
self.set_state("tls_handshake")
|
self.set_state("tls_handshake")
|
||||||
|
@ -158,7 +159,7 @@ class TLSDispatcher(AdvancedDispatcher):
|
||||||
try:
|
try:
|
||||||
# wait for write buffer flush
|
# wait for write buffer flush
|
||||||
if self.tlsStarted and not self.tlsDone and not self.write_buf:
|
if self.tlsStarted and not self.tlsDone and not self.write_buf:
|
||||||
if ssl.OPENSSL_VERSION_NUMBER >= 0x30000000:
|
if six.PY3 or ssl.OPENSSL_VERSION_NUMBER >= 0x30000000:
|
||||||
if not self.tlsPrepared:
|
if not self.tlsPrepared:
|
||||||
self.do_tls_init()
|
self.do_tls_init()
|
||||||
return
|
return
|
||||||
|
@ -184,7 +185,7 @@ class TLSDispatcher(AdvancedDispatcher):
|
||||||
try:
|
try:
|
||||||
# wait for write buffer flush
|
# wait for write buffer flush
|
||||||
if self.tlsStarted and not self.tlsDone and not self.write_buf:
|
if self.tlsStarted and not self.tlsDone and not self.write_buf:
|
||||||
if ssl.OPENSSL_VERSION_NUMBER >= 0x30000000:
|
if six.PY3 or ssl.OPENSSL_VERSION_NUMBER >= 0x30000000:
|
||||||
if not self.tlsPrepared:
|
if not self.tlsPrepared:
|
||||||
self.do_tls_init()
|
self.do_tls_init()
|
||||||
return
|
return
|
||||||
|
|
Reference in New Issue
Block a user