From 686e516bcb26a2811185bce85cc7678ee64d9559 Mon Sep 17 00:00:00 2001 From: j Date: Fri, 18 Aug 2023 09:26:44 +0200 Subject: [PATCH] update for new python/tornado versions --- camera.py | 16 ++++------------ server.py | 4 +++- 2 files changed, 7 insertions(+), 13 deletions(-) diff --git a/camera.py b/camera.py index 2e2e1f0..49ff0cd 100644 --- a/camera.py +++ b/camera.py @@ -31,7 +31,7 @@ def PTZData(d, root="PTZData"): def etree_to_list(t): d = [] k = t.tag.split('}')[-1] - v = list(map(etree_to_dict, t.getchildren())) + v = list(map(etree_to_dict, list(t))) if len(v) == 1: v = v[0] elif v and not isinstance(v[0], dict): @@ -47,7 +47,7 @@ def etree_to_list(t): def etree_to_dict(t): d = {} k = t.tag.split('}')[-1] - v = list(map(etree_to_dict, t.getchildren())) + v = list(map(etree_to_dict, list(t))) if len(v) == 1: v = v[0] #elif v and not isinstance(v[0], dict): @@ -127,20 +127,12 @@ class Camera: return {} def get(self, method): - while True: - try: - return requests.get(self.url(method), auth=self.auth).text - except requests.exceptions.ConnectionError: - time.sleep(0.1) + return requests.get(self.url(method), auth=self.auth).text def put(self, method, data): if isinstance(data, dict): data = PTZData(data) - while True: - try: - return requests.put(self.url(method), data=data, auth=self.auth).text - except requests.exceptions.ConnectionError: - time.sleep(0.1) + return requests.put(self.url(method), data=data, auth=self.auth).text def momentary(self, cmd, duration=None): if duration: diff --git a/server.py b/server.py index 7644850..e39b473 100755 --- a/server.py +++ b/server.py @@ -209,7 +209,9 @@ class RPCHandler(tornado.web.RequestHandler): error = {'error': {'code': -32700, 'message': 'Parse error'}} if not error: try: - response = yield tornado.gen.Task(api_task, request) + future = tornado.concurrent.Future() + api_task(request, callback=future.set_result) + response = yield future except KeyboardInterrupt: raise except: