fix content pattern regex

-fixes `<?xml version="1.0" encoding="utf-8"?>` breaking vs typical `<?xml version="1.0"?>`
-fixes motorola mg7550
This commit is contained in:
Jack Robison 2020-10-15 18:34:49 -04:00
parent 59dc075f39
commit c44b856060
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
2 changed files with 4 additions and 3 deletions

View file

@ -2,6 +2,7 @@ POST = "POST"
ROOT = "root"
SPEC_VERSION = "specVersion"
XML_VERSION = "<?xml version=\"1.0\"?>"
XML_VERSION_PREFIX = "<?xml version=\"1.0\""
FAULT = "{http://schemas.xmlsoap.org/soap/envelope/}Fault"
ENVELOPE = "{http://schemas.xmlsoap.org/soap/envelope/}Envelope"
BODY = "{http://schemas.xmlsoap.org/soap/envelope/}Body"

View file

@ -1,13 +1,13 @@
import re
from typing import Dict, Any, List, Tuple
from aioupnp.fault import UPnPError
from aioupnp.constants import XML_VERSION
from aioupnp.constants import XML_VERSION_PREFIX
from aioupnp.serialization.xml import xml_to_dict
from aioupnp.util import flatten_keys
CONTENT_PATTERN = re.compile(
"(\<\?xml version=\"1\.0\"\?\>(\s*.)*|\>)"
"(\<\?xml version=\"1\.0\"[^>]*\?\>(\s*.)*|\>)"
)
XML_ROOT_SANITY_PATTERN = re.compile(
@ -38,7 +38,7 @@ def serialize_scpd_get(path: str, address: str) -> bytes:
def deserialize_scpd_get_response(content: bytes) -> Dict[str, Any]:
if XML_VERSION.encode() in content:
if XML_VERSION_PREFIX.encode() in content:
parsed: List[Tuple[bytes, bytes]] = CONTENT_PATTERN.findall(content.decode())
xml_dict = xml_to_dict('' if not parsed else parsed[0][0])
return parse_device_dict(xml_dict)