def makeBody(self, attrs, child, status):
body = ET.Element("subsonic-response")
attrs_ = {"status": "ok" if status is True else "failed",
"xmlns": "http://subsonic.org/restapi",
"version": PROTOCOL_VERSION,
"unsonic": UNSONIC_PROTOCOL_VERSION}
attrs_.update(attrs)
for key, value in attrs_.items():
body.set(key, value)
if status is not True and status is not False:
error = ET.Element("error")
if isinstance(status[0], tuple):
error.set("code", status[0][0])
error.set("message", "%s: %s" % (status[0][1], status[1]))
else:
error.set("code", status[0])
error.set("message", status[1])
body.append(error)
if child is not None:
body.append(child)
return "%s%s\n" % (XML_HEADER, ET.tostring(body).decode("utf-8"))
评论列表
文章目录