mirror of
https://gitea.osmocom.org/sim-card/pysim.git
synced 2026-03-24 06:18:33 +03:00
saip: add numeric_base indicator to ConfigurableParameter and ParamSource
By default, numeric_base = None, to indicate that there are no explicit limitations on the number space. For parameters that are definitely decimal, set numeric_base = 10. For definitely hexadecimal, set numeric_base = 16. Do the same for ConfigurableParameter as well as ParamSource, so callers can match them up: if a parameter is numeric_base = 10, then omit sources that are numeric_base = 16, and vice versa. Change-Id: Ib0977bbdd9a85167be7eb46dd331fedd529dae01
This commit is contained in:
@@ -35,6 +35,7 @@ class ParamSource:
|
|||||||
|
|
||||||
# This name should be short but descriptive, useful for a user interface, like 'random decimal digits'.
|
# This name should be short but descriptive, useful for a user interface, like 'random decimal digits'.
|
||||||
name = "none"
|
name = "none"
|
||||||
|
numeric_base = None # or 10 or 16
|
||||||
|
|
||||||
def __init__(self, input_val:str):
|
def __init__(self, input_val:str):
|
||||||
"""Subclasses must implement a constructor with this signature. The input_val is typically a user entered string
|
"""Subclasses must implement a constructor with this signature. The input_val is typically a user entered string
|
||||||
@@ -89,6 +90,8 @@ class InputExpandingParamSource(ParamSource):
|
|||||||
class DecimalRangeSource(InputExpandingParamSource):
|
class DecimalRangeSource(InputExpandingParamSource):
|
||||||
"""abstract: decimal numbers with a value range"""
|
"""abstract: decimal numbers with a value range"""
|
||||||
|
|
||||||
|
numeric_base = 10
|
||||||
|
|
||||||
def __init__(self, num_digits, first_value, last_value):
|
def __init__(self, num_digits, first_value, last_value):
|
||||||
"""
|
"""
|
||||||
See also from_str().
|
See also from_str().
|
||||||
@@ -148,6 +151,7 @@ class RandomDigitSource(DecimalRangeSource, RandomSourceMixin):
|
|||||||
class RandomHexDigitSource(InputExpandingParamSource, RandomSourceMixin):
|
class RandomHexDigitSource(InputExpandingParamSource, RandomSourceMixin):
|
||||||
"""return a different sequence of random hexadecimal digits each"""
|
"""return a different sequence of random hexadecimal digits each"""
|
||||||
name = "random hexadecimal digits"
|
name = "random hexadecimal digits"
|
||||||
|
numeric_base = 16
|
||||||
used_keys = set()
|
used_keys = set()
|
||||||
|
|
||||||
def __init__(self, num_digits):
|
def __init__(self, num_digits):
|
||||||
|
|||||||
@@ -72,6 +72,7 @@ class ConfigurableParameter(abc.ABC, metaclass=ClassVarMeta):
|
|||||||
min_len: minimum length of an input str; min_len = 4
|
min_len: minimum length of an input str; min_len = 4
|
||||||
max_len: maximum length of an input str; max_len = 8
|
max_len: maximum length of an input str; max_len = 8
|
||||||
allow_len: permit only specific lengths; allow_len = (8, 16, 32)
|
allow_len: permit only specific lengths; allow_len = (8, 16, 32)
|
||||||
|
numeric_base: indicate hex / decimal, if any; numeric_base = None; numeric_base = 10; numeric_base = 16
|
||||||
|
|
||||||
Subclasses may change the meaning of these by overriding validate_val(), for example that the length counts
|
Subclasses may change the meaning of these by overriding validate_val(), for example that the length counts
|
||||||
resulting bytes instead of a hexstring length. Most subclasses will be covered by the default validate_val().
|
resulting bytes instead of a hexstring length. Most subclasses will be covered by the default validate_val().
|
||||||
@@ -127,6 +128,7 @@ class ConfigurableParameter(abc.ABC, metaclass=ClassVarMeta):
|
|||||||
allow_len = None # a list of specific lengths
|
allow_len = None # a list of specific lengths
|
||||||
example_input = None
|
example_input = None
|
||||||
default_source = None # a param_source.ParamSource subclass
|
default_source = None # a param_source.ParamSource subclass
|
||||||
|
numeric_base = None # or 10 or 16
|
||||||
|
|
||||||
def __init__(self, input_value=None):
|
def __init__(self, input_value=None):
|
||||||
self.input_value = input_value # the raw input value as given by caller
|
self.input_value = input_value # the raw input value as given by caller
|
||||||
@@ -302,6 +304,7 @@ class DecimalParam(ConfigurableParameter):
|
|||||||
"""
|
"""
|
||||||
allow_types = (str, int)
|
allow_types = (str, int)
|
||||||
allow_chars = '0123456789'
|
allow_chars = '0123456789'
|
||||||
|
numeric_base = 10
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def validate_val(cls, val):
|
def validate_val(cls, val):
|
||||||
@@ -346,6 +349,7 @@ class DecimalHexParam(DecimalParam):
|
|||||||
class IntegerParam(ConfigurableParameter):
|
class IntegerParam(ConfigurableParameter):
|
||||||
allow_types = (str, int)
|
allow_types = (str, int)
|
||||||
allow_chars = '0123456789'
|
allow_chars = '0123456789'
|
||||||
|
numeric_base = 10
|
||||||
|
|
||||||
# two integers, if the resulting int should be range limited
|
# two integers, if the resulting int should be range limited
|
||||||
min_val = None
|
min_val = None
|
||||||
@@ -378,6 +382,7 @@ class BinaryParam(ConfigurableParameter):
|
|||||||
allow_types = (str, io.BytesIO, bytes, bytearray, int)
|
allow_types = (str, io.BytesIO, bytes, bytearray, int)
|
||||||
allow_chars = '0123456789abcdefABCDEF'
|
allow_chars = '0123456789abcdefABCDEF'
|
||||||
strip_chars = ' \t\r\n'
|
strip_chars = ' \t\r\n'
|
||||||
|
numeric_base = 16
|
||||||
default_source = param_source.RandomHexDigitSource
|
default_source = param_source.RandomHexDigitSource
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@@ -549,6 +554,7 @@ class SmspTpScAddr(ConfigurableParameter):
|
|||||||
name = 'SMSP-TP-SC-ADDR'
|
name = 'SMSP-TP-SC-ADDR'
|
||||||
allow_chars = '+0123456789'
|
allow_chars = '+0123456789'
|
||||||
strip_chars = ' \t\r\n'
|
strip_chars = ' \t\r\n'
|
||||||
|
numeric_base = 10
|
||||||
max_len = 21 # '+' and 20 digits
|
max_len = 21 # '+' and 20 digits
|
||||||
min_len = 1
|
min_len = 1
|
||||||
example_input = '+49301234567'
|
example_input = '+49301234567'
|
||||||
|
|||||||
Reference in New Issue
Block a user