Browse Source

update for new python/tornado versions

master
j 9 months ago
parent
commit
686e516bcb
  1. 16
      camera.py
  2. 4
      server.py

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

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

Loading…
Cancel
Save