python3.6 fixes
This commit is contained in:
parent
5aa03900a1
commit
2215222e0b
3 changed files with 20 additions and 8 deletions
|
@ -7,7 +7,7 @@ class SOAPCommands:
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def AddPortMapping(NewRemoteHost: str, NewExternalPort: int, NewProtocol: str, NewInternalPort: int,
|
async def AddPortMapping(NewRemoteHost: str, NewExternalPort: int, NewProtocol: str, NewInternalPort: int,
|
||||||
NewInternalClient: str, NewEnabled: int, NewPortMappingDescription: str,
|
NewInternalClient: str, NewEnabled: int, NewPortMappingDescription: str,
|
||||||
NewLeaseDuration: str = '0') -> None:
|
NewLeaseDuration: str) -> None:
|
||||||
"""Returns None"""
|
"""Returns None"""
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
|
@ -17,7 +17,7 @@ class SOAPCommands:
|
||||||
raise NotImplementedError()
|
raise NotImplementedError()
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
async def GetGenericPortMappingEntry(NewPortMappingIndex: int) -> Tuple[none_or_str, int, str, int, str,
|
async def GetGenericPortMappingEntry(NewPortMappingIndex: int) -> Tuple[str, int, str, int, str,
|
||||||
bool, str, int]:
|
bool, str, int]:
|
||||||
"""
|
"""
|
||||||
Returns (NewRemoteHost, NewExternalPort, NewProtocol, NewInternalPort, NewInternalClient, NewEnabled,
|
Returns (NewRemoteHost, NewExternalPort, NewProtocol, NewInternalPort, NewInternalClient, NewEnabled,
|
||||||
|
|
|
@ -2,7 +2,7 @@ import logging
|
||||||
import socket
|
import socket
|
||||||
import asyncio
|
import asyncio
|
||||||
from collections import OrderedDict
|
from collections import OrderedDict
|
||||||
from typing import Dict, List, Union, Type, Set
|
from typing import Dict, List, Union, Type
|
||||||
from aioupnp.util import get_dict_val_case_insensitive, BASE_PORT_REGEX, BASE_ADDRESS_REGEX
|
from aioupnp.util import get_dict_val_case_insensitive, BASE_PORT_REGEX, BASE_ADDRESS_REGEX
|
||||||
from aioupnp.constants import SPEC_VERSION, SERVICE
|
from aioupnp.constants import SPEC_VERSION, SERVICE
|
||||||
from aioupnp.commands import SOAPCommands
|
from aioupnp.commands import SOAPCommands
|
||||||
|
@ -221,10 +221,10 @@ class Gateway:
|
||||||
annotations = current.__annotations__
|
annotations = current.__annotations__
|
||||||
return_types = annotations.get('return', None)
|
return_types = annotations.get('return', None)
|
||||||
if return_types:
|
if return_types:
|
||||||
if isinstance(return_types, type):
|
if hasattr(return_types, '__args__'):
|
||||||
return_types = (return_types, )
|
|
||||||
else:
|
|
||||||
return_types = tuple([return_type_lambas.get(a, a) for a in return_types.__args__])
|
return_types = tuple([return_type_lambas.get(a, a) for a in return_types.__args__])
|
||||||
|
elif isinstance(return_types, type):
|
||||||
|
return_types = (return_types, )
|
||||||
return_types = {r: t for r, t in zip(outputs, return_types)}
|
return_types = {r: t for r, t in zip(outputs, return_types)}
|
||||||
param_types = {}
|
param_types = {}
|
||||||
for param_name, param_type in annotations.items():
|
for param_name, param_type in annotations.items():
|
||||||
|
|
|
@ -8,6 +8,18 @@ from aioupnp.fault import UPnPError
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
|
|
||||||
|
def safe_type(t):
|
||||||
|
if t is typing.Tuple:
|
||||||
|
return tuple
|
||||||
|
if t is typing.List:
|
||||||
|
return list
|
||||||
|
if t is typing.Dict:
|
||||||
|
return dict
|
||||||
|
if t is typing.Set:
|
||||||
|
return set
|
||||||
|
return t
|
||||||
|
|
||||||
|
|
||||||
class SOAPCommand:
|
class SOAPCommand:
|
||||||
def __init__(self, gateway_address: str, service_port: int, control_url: str, service_id: bytes, method: str,
|
def __init__(self, gateway_address: str, service_port: int, control_url: str, service_id: bytes, method: str,
|
||||||
param_types: dict, return_types: dict, param_order: list, return_order: list,
|
param_types: dict, return_types: dict, param_order: list, return_order: list,
|
||||||
|
@ -28,7 +40,7 @@ class SOAPCommand:
|
||||||
if set(kwargs.keys()) != set(self.param_types.keys()):
|
if set(kwargs.keys()) != set(self.param_types.keys()):
|
||||||
raise Exception("argument mismatch: %s vs %s" % (kwargs.keys(), self.param_types.keys()))
|
raise Exception("argument mismatch: %s vs %s" % (kwargs.keys(), self.param_types.keys()))
|
||||||
close_after_send = not self.return_types or self.return_types == [None]
|
close_after_send = not self.return_types or self.return_types == [None]
|
||||||
soap_kwargs = {n: self.param_types[n](kwargs[n]) for n in self.param_types.keys()}
|
soap_kwargs = {n: safe_type(self.param_types[n])(kwargs[n]) for n in self.param_types.keys()}
|
||||||
try:
|
try:
|
||||||
response, xml_bytes = await scpd_post(
|
response, xml_bytes = await scpd_post(
|
||||||
self.control_url, self.gateway_address, self.service_port, self.method, self.param_order, self.service_id,
|
self.control_url, self.gateway_address, self.service_port, self.method, self.param_order, self.service_id,
|
||||||
|
@ -40,7 +52,7 @@ class SOAPCommand:
|
||||||
self._requests.append((soap_kwargs, xml_bytes))
|
self._requests.append((soap_kwargs, xml_bytes))
|
||||||
if not response:
|
if not response:
|
||||||
return None
|
return None
|
||||||
result = tuple([self.return_types[n](response.get(n)) for n in self.return_order])
|
result = tuple([safe_type(self.return_types[n])(response.get(n)) for n in self.return_order])
|
||||||
if len(result) == 1:
|
if len(result) == 1:
|
||||||
return result[0]
|
return result[0]
|
||||||
return result
|
return result
|
||||||
|
|
Loading…
Reference in a new issue