From b32635af031b6bd6cc9aff7b2e0633169abf4ea9 Mon Sep 17 00:00:00 2001 From: Jack Robison Date: Sat, 28 Jul 2018 23:06:17 -0400 Subject: [PATCH] fix more things --- txupnp/gateway.py | 2 +- txupnp/soap.py | 7 +++++-- txupnp/ssdp.py | 30 +++++++++++++++++++++++------- 3 files changed, 29 insertions(+), 10 deletions(-) diff --git a/txupnp/gateway.py b/txupnp/gateway.py index 7f017b7..b56c51a 100644 --- a/txupnp/gateway.py +++ b/txupnp/gateway.py @@ -91,5 +91,5 @@ class Gateway(object): def get_service(self, service_type): for service in self._device.services: - if service.service_type == service_type: + if service.service_type.lower() == service_type.lower(): return service diff --git a/txupnp/soap.py b/txupnp/soap.py index 13e5f1b..0d97d5b 100644 --- a/txupnp/soap.py +++ b/txupnp/soap.py @@ -4,6 +4,7 @@ from txupnp.util import get_lan_info from txupnp.ssdp import SSDPFactory from txupnp.scpd import SCPDCommandRunner from txupnp.gateway import Gateway +from txupnp.fault import UPnPError from txupnp.constants import GATEWAY_SCHEMA log = logging.getLogger(__name__) @@ -42,8 +43,10 @@ class SOAPServiceManager(object): self._command_runners = urn def get_runner(self): - if self._selected_runner and self._command_runners and self._selected_runner not in self._command_runners: - self._selected_runner = self._command_runners.keys()[0] + if self._command_runners and not self._selected_runner in self._command_runners: + self._selected_runner = list(self._command_runners.keys())[0] + if not self._command_runners: + raise UPnPError("not devices found") return self._command_runners[self._selected_runner] def get_available_runners(self): diff --git a/txupnp/ssdp.py b/txupnp/ssdp.py index 177dff5..53139b8 100644 --- a/txupnp/ssdp.py +++ b/txupnp/ssdp.py @@ -9,13 +9,29 @@ log = logging.getLogger(__name__) def parse_http_fields(content_lines): - return { - (k.lower().rstrip(":".encode()).replace("-".encode(), "_".encode())).decode(): v.decode() - for k, v in { - l.split(": ".encode())[0]: "".encode().join(l.split(": ".encode())[1:]) - for l in content_lines - }.items() if k - } + def flatten(s, lower=True): + r = s.rstrip(":").rstrip(" ").lstrip(" ").replace("-", "_") + if lower: + return r.lower() + return r + + result = {} + for l in content_lines: + split = l.decode().split(":") + if split and split[0]: + k = split[0] + v = ":".join(split[1:]) + result[flatten(k)] = flatten(v, lower=False) + return result + + # + # return { + # (k.lower().rstrip(":".encode()).replace("-".encode(), "_".encode())).decode(): v.decode() + # for k, v in { + # l.split(": ".encode())[0]: "".encode().join(l.split(": ".encode())[1:]) + # + # }.items() if k + # } def parse_ssdp_request(operation, port, protocol, content_lines):