confighelper: add support for optional separators

If "None" is specified as a separator for getdict and the getlist
variants then strings will split along any whitespace character.

Signed-off-by:  Eric Callahan <arksine.code@gmail.com>
This commit is contained in:
Eric Callahan 2022-04-03 17:04:47 -04:00
parent f3b0fbaa34
commit a4019bce8e
No known key found for this signature in database
GPG Key ID: 7027245FBBDDF59A
1 changed files with 6 additions and 6 deletions

View File

@ -208,7 +208,7 @@ class ConfigHelper:
option: str,
default: Union[SentinelClass, _T] = SENTINEL,
list_type: Type = str,
separators: Tuple[str, ...] = ('\n',),
separators: Tuple[Optional[str], ...] = ('\n',),
count: Optional[Tuple[Optional[int], ...]] = None,
deprecate: bool = False
) -> Union[List[Any], _T]:
@ -222,7 +222,7 @@ class ConfigHelper:
def list_parser(value: str,
ltype: Type,
seps: Tuple[str, ...],
seps: Tuple[Optional[str], ...],
expected_cnt: Tuple[Optional[int], ...]
) -> List[Any]:
sep = seps[0]
@ -257,7 +257,7 @@ class ConfigHelper:
def getlist(self,
option: str,
default: Union[SentinelClass, _T] = SENTINEL,
separator: str = '\n',
separator: Optional[str] = '\n',
count: Optional[int] = None,
deprecate: bool = False
) -> Union[List[str], _T]:
@ -267,7 +267,7 @@ class ConfigHelper:
def getintlist(self,
option: str,
default: Union[SentinelClass, _T] = SENTINEL,
separator: str = '\n',
separator: Optional[str] = '\n',
count: Optional[int] = None,
deprecate: bool = False
) -> Union[List[int], _T]:
@ -277,7 +277,7 @@ class ConfigHelper:
def getfloatlist(self,
option: str,
default: Union[SentinelClass, _T] = SENTINEL,
separator: str = '\n',
separator: Optional[str] = '\n',
count: Optional[int] = None,
deprecate: bool = False
) -> Union[List[float], _T]:
@ -287,7 +287,7 @@ class ConfigHelper:
def getdict(self,
option: str,
default: Union[SentinelClass, _T] = SENTINEL,
separators: Tuple[str, str] = ('\n', '='),
separators: Tuple[Optional[str], Optional[str]] = ('\n', '='),
dict_type: Type = str,
allow_empty_fields: bool = False,
deprecate: bool = False