Skip to content

Commit

Permalink
Add proper XML preamble in server communication (#243)
Browse files Browse the repository at this point in the history
  • Loading branch information
StevenLooman authored Sep 1, 2024
1 parent b7eed77 commit aea9eb7
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 8 deletions.
10 changes: 4 additions & 6 deletions async_upnp_client/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
'<?xml version="1.0"?>\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"',
Expand Down Expand Up @@ -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),
)


Expand Down Expand Up @@ -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),
)


Expand Down Expand Up @@ -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)


Expand Down
1 change: 1 addition & 0 deletions changes/243.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add proper XML preamble in server communication.
1 change: 1 addition & 0 deletions tests/fixtures/server/action_response.xml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<?xml version='1.0' encoding='utf-8'?>
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/" s:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><s:Body><st:SetValuesResponse xmlns:st="urn:schemas-upnp-org:service:TestServerService:1"><TestVariable_str>foo</TestVariable_str><EventableTextVariable_ui4>0</EventableTextVariable_ui4></st:SetValuesResponse></s:Body></s:Envelope>
1 change: 1 addition & 0 deletions tests/fixtures/server/device.xml
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
<?xml version='1.0' encoding='utf-8'?>
<root xmlns="urn:schemas-upnp-org:device-1-0"><specVersion><major>1</major><minor>0</minor></specVersion><device xmlns="urn:schemas-upnp-org:device-1-0"><deviceType>:urn:schemas-upnp-org:device:TestServerDevice:1</deviceType><friendlyName>Test Server</friendlyName><manufacturer>Test</manufacturer><manufacturerURL /><modelDescription>Test Server</modelDescription><modelName>TestServer</modelName><modelNumber>v0.0.1</modelNumber><modelURL /><serialNumber>0000001</serialNumber><UDN>uuid:adca2e25-cbe4-427a-a5c3-9b5931e7b79b</UDN><UPC /><presentationURL /><iconList /><serviceList><service><serviceType>urn:schemas-upnp-org:service:TestServerService:1</serviceType><serviceId>urn:upnp-org:serviceId:TestServerService</serviceId><controlURL>/upnp/control/TestServerService</controlURL><eventSubURL>/upnp/event/TestServerService</eventSubURL><SCPDURL>/ContentDirectory.xml</SCPDURL></service></serviceList><deviceList /></device></root>
2 changes: 1 addition & 1 deletion tests/fixtures/server/subscribe_response_0.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0"?>
<?xml version='1.0' encoding='utf-8'?>
<e:propertyset xmlns:e="urn:schemas-upnp-org:event-1-0"><e:property><EventableTextVariable_ui4>0</EventableTextVariable_ui4></e:property></e:propertyset>
2 changes: 1 addition & 1 deletion tests/fixtures/server/subscribe_response_1.xml
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
<?xml version="1.0"?>
<?xml version='1.0' encoding='utf-8'?>
<e:propertyset xmlns:e="urn:schemas-upnp-org:event-1-0"><e:property><EventableTextVariable_ui4>1</EventableTextVariable_ui4></e:property></e:propertyset>

0 comments on commit aea9eb7

Please sign in to comment.