es2p.py: also allow 18 digit ICCID

While at it, also use tuples (const) instead of lists (var).

Tweaked-by: nhofmeyr@sysmocom.de (docstring, tuples)
Change-Id: Iaa6e710132e3f4c6cecc5ff786922f6c0fcfb54e
This commit is contained in:
Harald Welte
2025-05-09 21:35:36 +00:00
committed by laforge
parent a297cdba73
commit 07a3978748

View File

@@ -33,7 +33,7 @@ logger.setLevel(logging.DEBUG)
class param: class param:
class Iccid(ApiParamString): class Iccid(ApiParamString):
"""String representation of 19 or 20 digits, where the 20th digit MAY optionally be the padding """String representation of 18 to 20 digits, where the 20th digit MAY optionally be the padding
character F.""" character F."""
@classmethod @classmethod
def _encode(cls, data): def _encode(cls, data):
@@ -46,7 +46,7 @@ class param:
@classmethod @classmethod
def verify_encoded(cls, data): def verify_encoded(cls, data):
if len(data) not in [19, 20]: if len(data) not in (18, 19, 20):
raise ValueError('ICCID (%s) length (%u) invalid' % (data, len(data))) raise ValueError('ICCID (%s) length (%u) invalid' % (data, len(data)))
@classmethod @classmethod
@@ -59,7 +59,7 @@ class param:
@classmethod @classmethod
def verify_decoded(cls, data): def verify_decoded(cls, data):
data = str(data) data = str(data)
if len(data) not in [19, 20]: if len(data) not in (18, 19, 20):
raise ValueError('ICCID (%s) length (%u) invalid' % (data, len(data))) raise ValueError('ICCID (%s) length (%u) invalid' % (data, len(data)))
if len(data) == 19: if len(data) == 19:
decimal_part = data decimal_part = data