personalization: refactor SmspTpScAddr

Refactor SmspTpScAddr to the new ConfigurableParameter implementation
style.

Change-Id: I2600369e195e9f5aed7f4e6ff99ae273ed3ab3bf
This commit is contained in:
Neels Hofmeyr
2026-01-08 01:49:44 +01:00
committed by laforge
parent 1e98856105
commit 1c082da0ee

View File

@@ -338,10 +338,17 @@ class Imsi(DecimalParam):
class SmspTpScAddr(ConfigurableParameter): class SmspTpScAddr(ConfigurableParameter):
"""Configurable SMSC (SMS Service Centre) TP-SC-ADDR. Expects to be a phone number in national or """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 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] == '+': if addr_str[0] == '+':
digits = addr_str[1:] digits = addr_str[1:]
international = True international = True
@@ -349,13 +356,17 @@ class SmspTpScAddr(ConfigurableParameter):
digits = addr_str digits = addr_str
international = False international = False
if len(digits) > 20: 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(): if not digits.isdecimal():
raise ValueError('TP-SC-ADDR must only contain decimal digits') raise ValueError(f'TP-SC-ADDR must only contain decimal digits: {digits!r}')
self.value = (international, digits) return (international, digits)
def apply(self, pes: ProfileElementSequence): @classmethod
international, digits = self.value 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'): for pe in pes.get_pes_for_type('usim'):
# obtain the File instance from the ProfileElementUSIM # obtain the File instance from the ProfileElementUSIM
f_smsp = pe.files['ef-smsp'] f_smsp = pe.files['ef-smsp']