From 25ca35f4200bedb6df7dc27c9746547c3b223d84 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 6 Jun 2016 21:33:28 +0100 Subject: [PATCH] Fix up to work with python 3.4 and 3.5 take 2 --- openlp/core/lib/api/wsserver.py | 88 +++++++++++---------------------- 1 file changed, 29 insertions(+), 59 deletions(-) diff --git a/openlp/core/lib/api/wsserver.py b/openlp/core/lib/api/wsserver.py index 4c450cca9..cf4a055c2 100644 --- a/openlp/core/lib/api/wsserver.py +++ b/openlp/core/lib/api/wsserver.py @@ -111,65 +111,35 @@ class OpenWSServer(RegistryProperties, OpenLPMixin): loop += 1 time.sleep(0.1) - if sys.version_info >= (3, 5): - @staticmethod - async def handle_websocket(request, path): - """ - Handle web socket requests and return the poll information. - Check ever 0.5 seconds to get the latest postion and send if changed. - Only gets triggered when 1st client attaches - :param request: request from client - :param path: not used - future to register for a different end point - :return: - """ - log.debug("web socket handler registered with client") - previous_poll = None - previous_main_poll = None - openlppoll = Registry().get('OpenLPPoll') - if path == '/poll': - while True: - current_poll = openlppoll.poll() - if current_poll != previous_poll: - await request.send(current_poll) - previous_poll = current_poll - await asyncio.sleep(0.2) - elif path == '/main_poll': - while True: - main_poll = openlppoll.main_poll() - if main_poll != previous_main_poll: - await request.send(main_poll) - previous_main_poll = main_poll - await asyncio.sleep(0.2) - else: - @staticmethod - @asyncio.coroutine - def handle_websocket(request, path): - """ - Handle web socket requests and return the poll information. - Check ever 0.5 seconds to get the latest postion and send if changed. - Only gets triggered when 1st client attaches - :param request: request from client - :param path: not used - future to register for a different end point - :return: - """ - log.debug("web socket handler registered with client") - previous_poll = None - previous_main_poll = None - openlppoll = Registry().get('OpenLPPoll') - if path == '/poll': - while True: - current_poll = openlppoll.poll() - if current_poll != previous_poll: - yield from request.send(current_poll) - previous_poll = current_poll - yield from asyncio.sleep(0.2) - elif path == '/main_poll': - while True: - main_poll = openlppoll.main_poll() - if main_poll != previous_main_poll: - yield from request.send(main_poll) - previous_main_poll = main_poll - yield from asyncio.sleep(0.2) + @staticmethod + @asyncio.coroutine + def handle_websocket(request, path): + """ + Handle web socket requests and return the poll information. + Check ever 0.5 seconds to get the latest postion and send if changed. + Only gets triggered when 1st client attaches + :param request: request from client + :param path: not used - future to register for a different end point + :return: + """ + log.debug("web socket handler registered with client") + previous_poll = None + previous_main_poll = None + openlppoll = Registry().get('OpenLPPoll') + if path == '/poll': + while True: + current_poll = openlppoll.poll() + if current_poll != previous_poll: + yield from request.send(current_poll) + previous_poll = current_poll + yield from asyncio.sleep(0.2) + elif path == '/main_poll': + while True: + main_poll = openlppoll.main_poll() + if main_poll != previous_main_poll: + yield from request.send(main_poll) + previous_main_poll = main_poll + yield from asyncio.sleep(0.2) def stop_server(self): """