fix more things

This commit is contained in:
Jack Robison 2018-07-28 23:06:17 -04:00
parent dd635a5b7f
commit b32635af03
No known key found for this signature in database
GPG key ID: DF25C68FE0239BB2
3 changed files with 29 additions and 10 deletions

View file

@ -91,5 +91,5 @@ class Gateway(object):
def get_service(self, service_type): def get_service(self, service_type):
for service in self._device.services: for service in self._device.services:
if service.service_type == service_type: if service.service_type.lower() == service_type.lower():
return service return service

View file

@ -4,6 +4,7 @@ from txupnp.util import get_lan_info
from txupnp.ssdp import SSDPFactory from txupnp.ssdp import SSDPFactory
from txupnp.scpd import SCPDCommandRunner from txupnp.scpd import SCPDCommandRunner
from txupnp.gateway import Gateway from txupnp.gateway import Gateway
from txupnp.fault import UPnPError
from txupnp.constants import GATEWAY_SCHEMA from txupnp.constants import GATEWAY_SCHEMA
log = logging.getLogger(__name__) log = logging.getLogger(__name__)
@ -42,8 +43,10 @@ class SOAPServiceManager(object):
self._command_runners = urn self._command_runners = urn
def get_runner(self): def get_runner(self):
if self._selected_runner and self._command_runners and self._selected_runner not in self._command_runners: if self._command_runners and not self._selected_runner in self._command_runners:
self._selected_runner = self._command_runners.keys()[0] 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] return self._command_runners[self._selected_runner]
def get_available_runners(self): def get_available_runners(self):

View file

@ -9,13 +9,29 @@ log = logging.getLogger(__name__)
def parse_http_fields(content_lines): def parse_http_fields(content_lines):
return { def flatten(s, lower=True):
(k.lower().rstrip(":".encode()).replace("-".encode(), "_".encode())).decode(): v.decode() r = s.rstrip(":").rstrip(" ").lstrip(" ").replace("-", "_")
for k, v in { if lower:
l.split(": ".encode())[0]: "".encode().join(l.split(": ".encode())[1:]) return r.lower()
for l in content_lines return r
}.items() if k
} 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): def parse_ssdp_request(operation, port, protocol, content_lines):