def debug_routes(self, request): if dric.support.accept.xml_over_json(request): root = etree.Element('routes') for endpoint, route in self.routes: e = etree.SubElement(root, 'route') e.set('endpoint', endpoint) e.text = route return dric.Response(etree.tostring(root, xml_declaration=True, encoding='UTF-8'), content_type="application/xml") elif dric.support.accept.json_over_xml(request): return dric.JSONResponse([{ 'endpoint': endpoint, 'route': route } for endpoint, route in self.routes]) else: raise dric.exceptions.NotAcceptable()
def get_units(self, request): accept = request.accept_mimetypes.best_match(['application/xml', 'text/xml', 'application/json']) if accept == 'application/xml' or accept == 'text/xml': root = ET.Element('types') for name in self.enabled_conversions: messagetype = ET.SubElement(root, 'type') messagetype.set('name', name) conversions = self.enabled_conversions[name] for key in conversions: elemkey = ET.SubElement(messagetype, 'key', {'name': key}) elemkey.text = str(conversions[key][1]) return dric.Response(ET.tostring(root, encoding='UTF-8'), content_type=accept) else: root = {} for name in self.enabled_conversions: root[name] = {} conversions = self.enabled_conversions[name] for key in conversions: root[name][key] = str(conversions[key][1]) return dric.JSONResponse(root)
def debug_routes(self, request): if dric.support.accept.xml_over_json(request): root = etree.Element('websockets') for endpoint, route, protocols in self.wsl: e = etree.SubElement(root, 'websocket') e.set('endpoint', endpoint) e.set('route', route) for protocol in protocols: p = etree.SubElement(e, 'protocol') p.text = protocol return dric.Response(etree.tostring(root, xml_declaration=True, encoding='UTF-8'), content_type="application/xml") elif dric.support.accept.json_over_xml(request): return dric.JSONResponse([{ 'endpoint': endpoint, 'route': route, 'protocols': protocols } for endpoint, route, protocols in self.wsl]) else: raise dric.exceptions.NotAcceptable()
def get_mavlink_message(self, esid, name, n, request=None): try: return dric.Response(self.db.get('key', dict(name=name, n=n, esid=esid))['message']) except KeyError: raise NotFound()
def getResponse(self): dric.Response('ok')
def get_time(self, request): return dric.Response(str(self.time()))
def arm(self, request): self.__arm_disarm(request, 1) return dric.Response('', status=200)
def serve_conversion_js(self, request): return dric.Response(JavascriptFileGenerator( self.conversion_graph, self.quantities).get_file_content(), content_type='application/javascript')