Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add proper XML preamble in server communication #243

Merged
merged 3 commits into from
Sep 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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>
Loading