fix response parse error
add get_external_ip to txupnp-cli
This commit is contained in:
parent
74180ceb2e
commit
a3a0496c4c
4 changed files with 11 additions and 7 deletions
|
@ -1,4 +1,4 @@
|
|||
__version__ = "0.0.1a1"
|
||||
__version__ = "0.0.1a2"
|
||||
__name__ = "txupnp"
|
||||
__author__ = "Jack Robison"
|
||||
__maintainer__ = "Jack Robison"
|
||||
|
|
|
@ -15,7 +15,10 @@ def run_command(found, u, command):
|
|||
return
|
||||
if command == "debug_device":
|
||||
print(u.get_debug_info())
|
||||
if command == "list_mappings":
|
||||
elif command == "get_external_ip":
|
||||
ip = yield u.get_external_ip()
|
||||
print(ip)
|
||||
elif command == "list_mappings":
|
||||
redirects = yield u.get_redirects()
|
||||
print("found {} redirects".format(len(redirects)))
|
||||
for redirect in redirects:
|
||||
|
@ -33,7 +36,7 @@ def main():
|
|||
observer.start()
|
||||
log.setLevel(logging.DEBUG)
|
||||
command = args.command
|
||||
if command not in ['debug_device', 'list_mappings']:
|
||||
if command not in ['debug_device', 'list_mappings', 'get_external_ip']:
|
||||
return sys.exit(0)
|
||||
|
||||
def show(err):
|
||||
|
|
|
@ -32,7 +32,7 @@ class CaseInsensitive(object):
|
|||
except AttributeError as err:
|
||||
not_evaluated[k] = v
|
||||
if not_evaluated:
|
||||
log.error("%s did not apply kwargs: %s", self.__class__.__name__, not_evaluated)
|
||||
log.warning("%s did not apply kwargs: %s", self.__class__.__name__, not_evaluated)
|
||||
|
||||
def _get_attr_name(self, case_insensitive):
|
||||
for k, v in self.__dict__.items():
|
||||
|
@ -87,6 +87,7 @@ class Device(CaseInsensitive):
|
|||
modelURL = None
|
||||
serialNumber = None
|
||||
udn = None
|
||||
upc = None
|
||||
presentationURL = None
|
||||
iconList = None
|
||||
|
||||
|
@ -165,7 +166,7 @@ class Gateway(object):
|
|||
response = yield treq.get(self.location)
|
||||
self.xml_response = yield response.content()
|
||||
if not self.xml_response:
|
||||
log.error("service sent an empty reply\n%s", self.debug_device())
|
||||
log.warning("service sent an empty reply\n%s", self.debug_device())
|
||||
xml_dict = etree_to_dict(ElementTree.fromstring(self.xml_response))
|
||||
schema_key = DEVICE
|
||||
root = ROOT
|
||||
|
|
|
@ -55,10 +55,10 @@ class _SCPDCommand(object):
|
|||
self.param_names = param_names
|
||||
self.returns = returns
|
||||
|
||||
def extract_body(self, xml_response, service_key=IP_SCHEMA):
|
||||
def extract_body(self, xml_response):
|
||||
content_dict = etree_to_dict(ElementTree.fromstring(xml_response))
|
||||
envelope = content_dict[ENVELOPE]
|
||||
return flatten_keys(envelope[BODY], "{%s}" % service_key)
|
||||
return flatten_keys(envelope[BODY], "{%s}" % self.service_id)
|
||||
|
||||
def extract_response(self, body):
|
||||
body = handle_fault(body) # raises UPnPError if there is a fault
|
||||
|
|
Loading…
Reference in a new issue