def _call_and_process(handler, request, device): response = handler.call_upstream(request, device) cookie = None pkcs12 = None alias = None with minidom.parseString(response.body_text()) as doc: x_response = qxml.get_child(doc, 'response') x_alias = qxml.get_child(x_response, 'user_device_name') alias = qxml.get_text(x_alias) x_adp_token = qxml.get_child(x_response, 'adp_token') if x_adp_token: cookie = qxml.get_text(x_adp_token) else: x_cookie = qxml.get_child(x_response, 'store_authentication_cookie') cookie = qxml.get_text(x_cookie) x_key = qxml.get_child(x_response, 'device_private_key') pkcs12 = qxml.get_text(x_key) if pkcs12: try: pkcs12 = b64decode(bytes(pkcs12, 'ascii')) except: logging.exception("failed to decode incoming device key") pkcs12 = None devices.update(device, alias = alias, cookie = cookie, pkcs12_bytes = pkcs12) return response
def doTask(): cmd, trg = task.pop(0) if cmd == 'recalc': devices.update(trg) else: notify.error('task.doTask: Unknown command ' + str(cmd)) notify.info('task.doTask: ' + str(len(task)) + ' tasks left')
def _call_and_process(handler, request, device): response = handler.call_upstream(request, device) cookie = None pkcs12 = None alias = None with minidom.parseString(response.body_text()) as doc: x_response = qxml.get_child(doc, 'response') x_alias = qxml.get_child(x_response, 'user_device_name') alias = qxml.get_text(x_alias) x_adp_token = qxml.get_child(x_response, 'adp_token') if x_adp_token: cookie = qxml.get_text(x_adp_token) else: x_cookie = qxml.get_child(x_response, 'store_authentication_cookie') cookie = qxml.get_text(x_cookie) x_key = qxml.get_child(x_response, 'device_private_key') pkcs12 = qxml.get_text(x_key) if pkcs12: try: pkcs12 = b64decode(bytes(pkcs12, 'ascii')) except: logging.exception("failed to decode incoming device key") pkcs12 = None devices.update(device, alias=alias, cookie=cookie, pkcs12_bytes=pkcs12) return response
def POST(self): data = web.input() if 'create' in data: return devices.create(data.bus_id, data.name, data.addr) if int(data.column) == 1: # bus_id devices.update(data.row_id, data.value, None, None) return devices.bus(data.row_id) if int(data.column) == 2: # name devices.update(data.row_id, None, data.value, None) return devices.name(data.row_id) if int(data.column) == 3: # address m = re.match('(0x)?([0-9a-fA-F]{1,2})', data.value) if m is not None: a = m.groups()[-1].upper() devices.update(data.row_id, None, None, int(a, 16)) return "%X" % devices.address(data.row_id)