Change in pysim[master]: transport: Pass arbitrary kwargs to base-class constructor

laforge gerrit-no-reply at lists.osmocom.org
Sat Apr 10 22:13:58 UTC 2021


laforge has submitted this change. ( https://gerrit.osmocom.org/c/pysim/+/23697 )

Change subject: transport: Pass arbitrary kwargs to base-class constructor
......................................................................

transport: Pass arbitrary kwargs to base-class constructor

Change-Id: I3cd5ba87cf53409ea97196d5789ed28eef072c68
---
M pySim/transport/__init__.py
M pySim/transport/calypso.py
M pySim/transport/modem_atcmd.py
M pySim/transport/pcsc.py
M pySim/transport/serial.py
5 files changed, 15 insertions(+), 10 deletions(-)

Approvals:
  Jenkins Builder: Verified
  laforge: Looks good to me, approved



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 @@
 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 @@
 			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 @@
 		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 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 @@
 
 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 @@
 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 @@
 	""" 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(

-- 
To view, visit https://gerrit.osmocom.org/c/pysim/+/23697
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I3cd5ba87cf53409ea97196d5789ed28eef072c68
Gerrit-Change-Number: 23697
Gerrit-PatchSet: 3
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <laforge at osmocom.org>
Gerrit-MessageType: merged
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20210410/3c7679e7/attachment.htm>


More information about the gerrit-log mailing list