Change in pysim[master]: Add type annotations and more documentation to card_data.py

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

laforge gerrit-no-reply at lists.osmocom.org
Tue Apr 6 16:03:29 UTC 2021


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

Change subject: Add type annotations and more documentation to card_data.py
......................................................................

Add type annotations and more documentation to card_data.py

Change-Id: Ia09b3ecaa582d62a97c3adac2650686dc19d5ec1
---
M pySim/card_data.py
1 file changed, 30 insertions(+), 26 deletions(-)

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



diff --git a/pySim/card_data.py b/pySim/card_data.py
index ebc63a6..e35df9e 100644
--- a/pySim/card_data.py
+++ b/pySim/card_data.py
@@ -1,35 +1,36 @@
 # coding=utf-8
-"""Abstraction of card data that can be queried from external source
+"""Abstraction of card related data that can be queried from external source."""
 
-(C) 2021 by Sysmocom s.f.m.c. GmbH
-All Rights Reserved
+# (C) 2021 by Sysmocom s.f.m.c. GmbH
+# All Rights Reserved
+#
+# Author: Philipp Maier
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
-Author: Philipp Maier
-
-This program is free software: you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation, either version 2 of the License, or
-(at your option) any later version.
-
-This program is distributed in the hope that it will be useful,
-but WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-GNU General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with this program.  If not, see <http://www.gnu.org/licenses/>.
-"""
+from typing import List, Dict, Optional
 
 import csv
 
-card_data_provider = []
+card_data_provider = [] # type: List[CardData]
 
 class CardData(object):
 
 	VALID_FIELD_NAMES = ['ICCID', 'ADM1', 'IMSI', 'PIN1', 'PIN2', 'PUK1', 'PUK2']
 
 	# check input parameters, but do nothing concrete yet
-	def get_data(self, fields=[], key='ICCID', value=""):
+	def get_data(self, fields:List[str]=[], key:str='ICCID', value:str="") -> Dict[str,str]:
 		"""abstract implementation of get_data that only verifies the function parameters"""
 
 		for f in fields:
@@ -43,25 +44,28 @@
 
 		return {}
 
-	def get_field(self, field, key='ICCID', value=""):
+	def get_field(self, field:str, key:str='ICCID', value:str="") -> Optional[str]:
 		"""get a single field from CSV file using a specified key/value pair"""
 		fields = [field]
 		result = self.get(fields, key, value)
 		return result.get(field)
 
+	def get(self, fields:List[str], key:str, value:str) -> Dict[str,str]:
+		"""get fields from CSV file using a specified key/value pair"""
+		pass
 
 class CardDataCsv(CardData):
 	"""card data class that allows the user to query against a specified CSV file"""
 	csv_file = None
 	filename = None
 
-	def __init__(self, filename):
+	def __init__(self, filename:str):
 		self.csv_file = open(filename, 'r')
 		if not self.csv_file:
 			raise RuntimeError("Could not open CSV-File '%s'" % filename)
 		self.filename = filename
 
-	def get(self, fields, key, value):
+	def get(self, fields:List[str], key:str, value:str) -> Dict[str,str]:
 		"""get fields from CSV file using a specified key/value pair"""
 		super().get_data(fields, key, value)
 
@@ -83,14 +87,14 @@
 		return rc
 
 
-def card_data_register(provider, provider_list=card_data_provider):
+def card_data_register(provider:CardData, provider_list=card_data_provider):
 	"""Register a new card data provider"""
 	if not isinstance(provider, CardData):
 		raise ValueError("provider is not a card data provier")
 	provider_list.append(provider)
 
 
-def card_data_get(fields, key, value, provider_list=card_data_provider):
+def card_data_get(fields, key:str, value:str, provider_list=card_data_provider) -> Dict[str,str]:
 	"""Query all registered card data providers"""
 	for p in provider_list:
 		if not isinstance(p, CardData):
@@ -101,7 +105,7 @@
 	return {}
 
 
-def card_data_get_field(field, key, value, provider_list=card_data_provider):
+def card_data_get_field(field:str, key:str, value:str, provider_list=card_data_provider) -> Optional[str]:
 	"""Query all registered card data providers for a single field"""
 	for p in provider_list:
 		if not isinstance(p, CardData):

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

Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: Ia09b3ecaa582d62a97c3adac2650686dc19d5ec1
Gerrit-Change-Number: 23590
Gerrit-PatchSet: 2
Gerrit-Owner: laforge <laforge at osmocom.org>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: dexter <pmaier at sysmocom.de>
Gerrit-Reviewer: fixeria <vyanitskiy at sysmocom.de>
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/20210406/aacb6560/attachment.htm>


More information about the gerrit-log mailing list