update for new python/tornado versions

This commit is contained in:
j 2023-08-18 09:26:44 +02:00
parent e7ba46e4e6
commit 686e516bcb
2 changed files with 7 additions and 13 deletions

View File

@ -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)
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)
def momentary(self, cmd, duration=None):
if duration:

View File

@ -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: