summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormathieui <mathieui@mathieui.net>2014-10-30 19:55:19 +0100
committermathieui <mathieui@mathieui.net>2014-10-30 19:55:19 +0100
commitcedc5a6ec80a46437f42464415fd1806049c593d (patch)
tree32c9ea7be08504587dfe6624988e5b9fc8112ff6
parent076b899b459925f9e5b9ee68adc507183f2cbe2f (diff)
downloadpoezio-cedc5a6ec80a46437f42464415fd1806049c593d.tar.gz
poezio-cedc5a6ec80a46437f42464415fd1806049c593d.tar.bz2
poezio-cedc5a6ec80a46437f42464415fd1806049c593d.tar.xz
poezio-cedc5a6ec80a46437f42464415fd1806049c593d.zip
Fix the ssl check for asyncio
-rw-r--r--src/core/handlers.py42
1 files changed, 28 insertions, 14 deletions
diff --git a/src/core/handlers.py b/src/core/handlers.py
index b46b949f..4e2fcfd3 100644
--- a/src/core/handlers.py
+++ b/src/core/handlers.py
@@ -5,10 +5,12 @@ XMPP-related handlers for the Core class
import logging
log = logging.getLogger(__name__)
+import asyncio
import curses
+import functools
import ssl
+import sys
import time
-import functools
from hashlib import sha1, sha512
from gettext import gettext as _
@@ -1127,19 +1129,31 @@ def validate_ssl(self, pem):
input.resize(1, self.current_tab().width, self.current_tab().height-1, 0)
input.refresh()
self.doupdate()
- self.paused = True
- while input.value is None:
- self.event.wait()
- self.current_tab().input = saved_input
- self.paused = False
- if input.value:
- self.information('Setting new certificate: old: %s, new: %s' % (cert, sha2_found_cert), 'Info')
- log.debug('Setting certificate to %s', sha2_found_cert)
- if not config.silent_set('certificate', sha2_found_cert):
- self.information(_('Unable to write in the config file'), 'Error')
- else:
- self.information('You refused to validate the certificate. You are now disconnected', 'Info')
- self.xmpp.disconnect()
+ old_loop = asyncio.get_event_loop()
+ new_loop = asyncio.new_event_loop()
+ asyncio.set_event_loop(new_loop)
+ new_loop.add_reader(sys.stdin, self.on_input_readable)
+ future = asyncio.Future()
+ @asyncio.coroutine
+ def check_input(future):
+ while input.value is None:
+ yield from asyncio.sleep(0.01)
+ self.current_tab().input = saved_input
+ self.paused = False
+ if input.value:
+ self.information('Setting new certificate: old: %s, new: %s' % (cert, sha2_found_cert), 'Info')
+ log.debug('Setting certificate to %s', sha2_found_cert)
+ if not config.silent_set('certificate', sha2_found_cert):
+ self.information(_('Unable to write in the config file'), 'Error')
+ else:
+ self.information('You refused to validate the certificate. You are now disconnected', 'Info')
+ self.xmpp.disconnect()
+ new_loop.stop()
+ asyncio.set_event_loop(old_loop)
+ asyncio.async(check_input(future))
+ new_loop.run_forever()
+
+
else:
log.debug('First time. Setting certificate to %s', sha2_found_cert)
if not config.silent_set('certificate', sha2_found_cert):