(Temporary) fix for python 3.5

This will work until the old ssl implementation is finally deprecated.
Hopefully, new features to painlessy implement starttls will be around
by then.
This commit is contained in:
mathieui 2015-09-14 23:14:53 +02:00
parent 1aa15792b4
commit 82e549c0e9
No known key found for this signature in database
GPG Key ID: C59F84CEEFD616E3
2 changed files with 10 additions and 7 deletions

View File

@ -6,6 +6,8 @@
See the file LICENSE for copying permission. See the file LICENSE for copying permission.
""" """
import asyncio
asyncio.sslproto._is_sslproto_available=lambda: False
import logging import logging
logging.getLogger(__name__).addHandler(logging.NullHandler()) logging.getLogger(__name__).addHandler(logging.NullHandler())

View File

@ -287,9 +287,8 @@ class XMLStream(asyncio.BaseProtocol):
def _connect_routine(self): def _connect_routine(self):
self.event_when_connected = "connected" self.event_when_connected = "connected"
try: record = yield from self.pick_dns_answer(self.default_domain)
record = yield from self.pick_dns_answer(self.default_domain) if record is None:
except StopIteration:
# No more DNS records to try # No more DNS records to try
self.dns_answers = None self.dns_answers = None
return return
@ -497,14 +496,14 @@ class XMLStream(asyncio.BaseProtocol):
ssl_connect_routine = self.loop.create_connection(lambda: self, ssl=self.ssl_context, ssl_connect_routine = self.loop.create_connection(lambda: self, ssl=self.ssl_context,
sock=self.socket, sock=self.socket,
server_hostname=self.address[0]) server_hostname=self.default_domain)
@asyncio.coroutine @asyncio.coroutine
def ssl_coro(): def ssl_coro():
try: try:
transp, prot = yield from ssl_connect_routine transp, prot = yield from ssl_connect_routine
except ssl.SSLError as e: except ssl.SSLError as e:
log.error('CERT: Invalid certificate trust chain.')
log.debug('SSL: Unable to connect', exc_info=True) log.debug('SSL: Unable to connect', exc_info=True)
log.error('CERT: Invalid certificate trust chain.')
if not self.event_handled('ssl_invalid_chain'): if not self.event_handled('ssl_invalid_chain'):
self.disconnect() self.disconnect()
else: else:
@ -513,7 +512,6 @@ class XMLStream(asyncio.BaseProtocol):
der_cert = transp.get_extra_info("socket").getpeercert(True) der_cert = transp.get_extra_info("socket").getpeercert(True)
pem_cert = ssl.DER_cert_to_PEM_cert(der_cert) pem_cert = ssl.DER_cert_to_PEM_cert(der_cert)
self.event('ssl_cert', pem_cert) self.event('ssl_cert', pem_cert)
self.socket = self.transport.get_extra_info("socket")
asyncio.async(ssl_coro()) asyncio.async(ssl_coro())
@ -663,7 +661,10 @@ class XMLStream(asyncio.BaseProtocol):
dns_records = yield from self.get_dns_records(domain, port) dns_records = yield from self.get_dns_records(domain, port)
self.dns_answers = iter(dns_records) self.dns_answers = iter(dns_records)
return next(self.dns_answers) try:
return next(self.dns_answers)
except StopIteration:
return
def add_event_handler(self, name, pointer, disposable=False): def add_event_handler(self, name, pointer, disposable=False):
"""Add a custom event handler that will be executed whenever """Add a custom event handler that will be executed whenever