diff options
author | Harald Welte <laforge@osmocom.org> | 2021-04-10 11:01:56 +0200 |
---|---|---|
committer | Harald Welte <laforge@osmocom.org> | 2021-04-10 18:41:15 +0200 |
commit | eb05b2f60e6ced605beb0c976cc526d2d3c63fc9 (patch) | |
tree | b415678046c6d513abe87856780b04ad34542af3 | |
parent | c34f9405f131e9b9c42c893dcdf57f373880dc5e (diff) |
transport: Pass arbitrary kwargs to base-class constructor
Change-Id: I3cd5ba87cf53409ea97196d5789ed28eef072c68
-rw-r--r-- | pySim/transport/__init__.py | 13 | ||||
-rw-r--r-- | pySim/transport/calypso.py | 3 | ||||
-rw-r--r-- | pySim/transport/modem_atcmd.py | 3 | ||||
-rw-r--r-- | pySim/transport/pcsc.py | 3 | ||||
-rw-r--r-- | pySim/transport/serial.py | 3 |
5 files changed, 15 insertions, 10 deletions
diff --git a/pySim/transport/__init__.py b/pySim/transport/__init__.py index 923787b..c176f8a 100644 --- a/pySim/transport/__init__.py +++ b/pySim/transport/__init__.py @@ -28,7 +28,8 @@ from pySim.utils import sw_match class LinkBase(object): """Base class for link/transport to card.""" - sw_interpreter = None + def __init__(self, sw_interpreter=None): + self.sw_interpreter = sw_interpreter def set_sw_interpreter(self, interp): """Set an (optional) status word interpreter.""" @@ -112,7 +113,7 @@ class LinkBase(object): raise SwMatchError(rv[1], sw.lower(), self.sw_interpreter) return rv -def init_reader(opts) -> Optional[LinkBase]: +def init_reader(opts, **kwargs) -> Optional[LinkBase]: """ Init card reader driver """ @@ -121,19 +122,19 @@ def init_reader(opts) -> Optional[LinkBase]: if opts.pcsc_dev is not None: print("Using PC/SC reader interface") from pySim.transport.pcsc import PcscSimLink - sl = PcscSimLink(opts.pcsc_dev) + sl = PcscSimLink(opts.pcsc_dev, **kwargs) elif opts.osmocon_sock is not None: print("Using Calypso-based (OsmocomBB) reader interface") from pySim.transport.calypso import CalypsoSimLink - sl = CalypsoSimLink(sock_path=opts.osmocon_sock) + sl = CalypsoSimLink(sock_path=opts.osmocon_sock, **kwargs) elif opts.modem_dev is not None: print("Using modem for Generic SIM Access (3GPP TS 27.007)") from pySim.transport.modem_atcmd import ModemATCommandLink - sl = ModemATCommandLink(device=opts.modem_dev, baudrate=opts.modem_baud) + sl = ModemATCommandLink(device=opts.modem_dev, baudrate=opts.modem_baud, **kwargs) else: # Serial reader is default print("Using serial reader interface") from pySim.transport.serial import SerialSimLink - sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate) + sl = SerialSimLink(device=opts.device, baudrate=opts.baudrate, **kwargs) return sl except Exception as e: print("Card reader initialization failed with exception:\n" + str(e)) diff --git a/pySim/transport/calypso.py b/pySim/transport/calypso.py index 3c223e6..b55a089 100644 --- a/pySim/transport/calypso.py +++ b/pySim/transport/calypso.py @@ -71,7 +71,8 @@ class L1CTLMessageSIM(L1CTLMessage): class CalypsoSimLink(LinkBase): """Transport Link for Calypso based phones.""" - def __init__(self, sock_path:str = "/tmp/osmocom_l2"): + def __init__(self, sock_path:str = "/tmp/osmocom_l2", **kwargs): + super().__init__(**kwargs) # Make sure that a given socket path exists if not os.path.exists(sock_path): raise ReaderError("There is no such ('%s') UNIX socket" % sock_path) diff --git a/pySim/transport/modem_atcmd.py b/pySim/transport/modem_atcmd.py index f5a0f23..ecf463c 100644 --- a/pySim/transport/modem_atcmd.py +++ b/pySim/transport/modem_atcmd.py @@ -29,7 +29,8 @@ from pySim.exceptions import * class ModemATCommandLink(LinkBase): """Transport Link for 3GPP TS 27.007 compliant modems.""" - def __init__(self, device:str='/dev/ttyUSB0', baudrate:int=115200): + def __init__(self, device:str='/dev/ttyUSB0', baudrate:int=115200, **kwargs): + super().__init__(**kwargs) self._sl = serial.Serial(device, baudrate, timeout=5) self._device = device self._atr = None diff --git a/pySim/transport/pcsc.py b/pySim/transport/pcsc.py index 2433e79..73a99e8 100644 --- a/pySim/transport/pcsc.py +++ b/pySim/transport/pcsc.py @@ -30,7 +30,8 @@ from pySim.utils import h2i, i2h class PcscSimLink(LinkBase): """ pySim: PCSC reader transport link.""" - def __init__(self, reader_number:int=0): + def __init__(self, reader_number:int=0, **kwargs): + super().__init__(**kwargs) r = readers() self._reader = r[reader_number] self._con = self._reader.createConnection() diff --git a/pySim/transport/serial.py b/pySim/transport/serial.py index 22788a9..4f2b28f 100644 --- a/pySim/transport/serial.py +++ b/pySim/transport/serial.py @@ -29,7 +29,8 @@ class SerialSimLink(LinkBase): """ pySim: Transport Link for serial (RS232) based readers included with simcard""" def __init__(self, device:str='/dev/ttyUSB0', baudrate:int=9600, rst:str='-rts', - debug:bool=False): + debug:bool=False, **kwargs): + super().__init__(**kwargs) if not os.path.exists(device): raise ValueError("device file %s does not exist -- abort" % device) self._sl = serial.Serial( |