From 1fa64e323d40f2184816f151475f6a7297e49c32 Mon Sep 17 00:00:00 2001 From: Steven Looman Date: Sun, 1 Sep 2024 16:25:34 +0200 Subject: [PATCH 1/3] Add proper XML preamble in server communication --- async_upnp_client/server.py | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/async_upnp_client/server.py b/async_upnp_client/server.py index 7aa3ca5..df4e6e8 100644 --- a/async_upnp_client/server.py +++ b/async_upnp_client/server.py @@ -394,9 +394,7 @@ async def async_send_events( continue prop_el = ET.SubElement(event_el, "e:property") ET.SubElement(prop_el, state_var.name).text = str(state_var.value) - message = ( - '\n' + ET.tostring(event_el, encoding="utf-8").decode() - ) + message = ET.tostring(event_el, encoding="utf-8", xml_declaration=True).decode() headers = { "CONTENT-TYPE": 'text/xml; charset="utf-8"', @@ -1128,7 +1126,7 @@ def _create_action_response( return Response( content_type="text/xml", charset="utf-8", - body=ET.tostring(envelope_el, encoding="utf-8"), + body=ET.tostring(envelope_el, encoding="utf-8", xml_declaration=True), ) @@ -1163,7 +1161,7 @@ def _create_error_action_response( status=500, content_type="text/xml", charset="utf-8", - body=ET.tostring(envelope_el, encoding="utf-8"), + body=ET.tostring(envelope_el, encoding="utf-8", xml_declaration=True), ) @@ -1243,7 +1241,7 @@ async def to_xml( serializer = UpnpXmlSerializer() thing_el = serializer.to_xml(thing) encoding = "utf-8" - thing_xml = ET.tostring(thing_el, encoding=encoding) + thing_xml = ET.tostring(thing_el, encoding=encoding, xml_declaration=True) return Response(content_type="text/xml", charset=encoding, body=thing_xml) From 55e668db26f9602d0e8e8c317b9a005fd41d5ed8 Mon Sep 17 00:00:00 2001 From: Steven Looman Date: Sun, 1 Sep 2024 16:26:18 +0200 Subject: [PATCH 2/3] Add change file --- changes/243.bugfix | 1 + 1 file changed, 1 insertion(+) create mode 100644 changes/243.bugfix diff --git a/changes/243.bugfix b/changes/243.bugfix new file mode 100644 index 0000000..8256a3d --- /dev/null +++ b/changes/243.bugfix @@ -0,0 +1 @@ +Add proper XML preamble in server communication. From 7015fe51d9189f993cc956d28bb7f178d9e2afd5 Mon Sep 17 00:00:00 2001 From: Steven Looman Date: Sun, 1 Sep 2024 16:38:16 +0200 Subject: [PATCH 3/3] Fix tests --- tests/fixtures/server/action_response.xml | 1 + tests/fixtures/server/device.xml | 1 + tests/fixtures/server/subscribe_response_0.xml | 2 +- tests/fixtures/server/subscribe_response_1.xml | 2 +- 4 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tests/fixtures/server/action_response.xml b/tests/fixtures/server/action_response.xml index f9a6ce6..fe968b4 100644 --- a/tests/fixtures/server/action_response.xml +++ b/tests/fixtures/server/action_response.xml @@ -1 +1,2 @@ + foo0 diff --git a/tests/fixtures/server/device.xml b/tests/fixtures/server/device.xml index c058732..6600fce 100644 --- a/tests/fixtures/server/device.xml +++ b/tests/fixtures/server/device.xml @@ -1 +1,2 @@ + 10:urn:schemas-upnp-org:device:TestServerDevice:1Test ServerTestTest ServerTestServerv0.0.10000001uuid:adca2e25-cbe4-427a-a5c3-9b5931e7b79burn:schemas-upnp-org:service:TestServerService:1urn:upnp-org:serviceId:TestServerService/upnp/control/TestServerService/upnp/event/TestServerService/ContentDirectory.xml diff --git a/tests/fixtures/server/subscribe_response_0.xml b/tests/fixtures/server/subscribe_response_0.xml index c4b52e7..663d985 100644 --- a/tests/fixtures/server/subscribe_response_0.xml +++ b/tests/fixtures/server/subscribe_response_0.xml @@ -1,2 +1,2 @@ - + 0 diff --git a/tests/fixtures/server/subscribe_response_1.xml b/tests/fixtures/server/subscribe_response_1.xml index 6cec63d..4203394 100644 --- a/tests/fixtures/server/subscribe_response_1.xml +++ b/tests/fixtures/server/subscribe_response_1.xml @@ -1,2 +1,2 @@ - + 1