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): def etree_to_list(t):
d = [] d = []
k = t.tag.split('}')[-1] 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: if len(v) == 1:
v = v[0] v = v[0]
elif v and not isinstance(v[0], dict): elif v and not isinstance(v[0], dict):
@ -47,7 +47,7 @@ def etree_to_list(t):
def etree_to_dict(t): def etree_to_dict(t):
d = {} d = {}
k = t.tag.split('}')[-1] 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: if len(v) == 1:
v = v[0] v = v[0]
#elif v and not isinstance(v[0], dict): #elif v and not isinstance(v[0], dict):
@ -127,20 +127,12 @@ class Camera:
return {} return {}
def get(self, method): def get(self, method):
while True:
try:
return requests.get(self.url(method), auth=self.auth).text return requests.get(self.url(method), auth=self.auth).text
except requests.exceptions.ConnectionError:
time.sleep(0.1)
def put(self, method, data): def put(self, method, data):
if isinstance(data, dict): if isinstance(data, dict):
data = PTZData(data) data = PTZData(data)
while True:
try:
return requests.put(self.url(method), data=data, auth=self.auth).text 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): def momentary(self, cmd, duration=None):
if duration: if duration:

View File

@ -209,7 +209,9 @@ class RPCHandler(tornado.web.RequestHandler):
error = {'error': {'code': -32700, 'message': 'Parse error'}} error = {'error': {'code': -32700, 'message': 'Parse error'}}
if not error: if not error:
try: 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: except KeyboardInterrupt:
raise raise
except: except: