laforge has submitted this change. (
https://gerrit.osmocom.org/c/pysim/+/41779?usp=email )
Change subject: personalization: refactor SmspTpScAddr
......................................................................
personalization: refactor SmspTpScAddr
Refactor SmspTpScAddr to the new ConfigurableParameter implementation
style.
Change-Id: I2600369e195e9f5aed7f4e6ff99ae273ed3ab3bf
---
M pySim/esim/saip/personalization.py
1 file changed, 19 insertions(+), 8 deletions(-)
Approvals:
Jenkins Builder: Verified
laforge: Looks good to me, approved
diff --git a/pySim/esim/saip/personalization.py
b/pySim/esim/saip/personalization.py
index 8415d64..75a43aa 100644
--- a/pySim/esim/saip/personalization.py
+++ b/pySim/esim/saip/personalization.py
@@ -338,10 +338,17 @@
class SmspTpScAddr(ConfigurableParameter):
"""Configurable SMSC (SMS Service Centre) TP-SC-ADDR. Expects to be a
phone number in national or
international format (designated by a leading +). Automatically sets the
NPI to E.164 and the TON based on
- presence or absence of leading +"""
+ presence or absence of leading +."""
+ allow_chars = '+0123456789'
+ strip_chars = ' \t\r\n'
+ max_len = 21 # '+' and 20 digits
+ min_len = 1
- def validate(self):
- addr_str = str(self.input_value)
+
+ @classmethod
+ def validate_val(cls, val):
+ val = super().validate_val(val)
+ addr_str = str(val)
if addr_str[0] == '+':
digits = addr_str[1:]
international = True
@@ -349,13 +356,17 @@
digits = addr_str
international = False
if len(digits) > 20:
- raise ValueError('TP-SC-ADDR must not exceed 20 digits')
+ raise ValueError(f'TP-SC-ADDR must not exceed 20 digits:
{digits!r}')
if not digits.isdecimal():
- raise ValueError('TP-SC-ADDR must only contain decimal digits')
- self.value = (international, digits)
+ raise ValueError(f'TP-SC-ADDR must only contain decimal digits:
{digits!r}')
+ return (international, digits)
- def apply(self, pes: ProfileElementSequence):
- international, digits = self.value
+ @classmethod
+ def apply_val(cls, pes: ProfileElementSequence, val):
+ """val must be a tuple (international[bool], digits[str]).
+ For example, an input of "+1234" corresponds to (True, "1234");
+ An input of "1234" corresponds to (False, "1234")."""
+ international, digits = val
for pe in pes.get_pes_for_type('usim'):
# obtain the File instance from the ProfileElementUSIM
f_smsp = pe.files['ef-smsp']
--
To view, visit https://gerrit.osmocom.org/c/pysim/+/41779?usp=email
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings?usp=email
Gerrit-MessageType: merged
Gerrit-Project: pysim
Gerrit-Branch: master
Gerrit-Change-Id: I2600369e195e9f5aed7f4e6ff99ae273ed3ab3bf
Gerrit-Change-Number: 41779
Gerrit-PatchSet: 5
Gerrit-Owner: neels <[email protected]>
Gerrit-Reviewer: Jenkins Builder
Gerrit-Reviewer: laforge <[email protected]>