Collections
provide.foundation.parsers.collections
¶
TODO: Add module docstring.
Functions¶
parse_comma_list
¶
parse_dict
¶
parse_dict(
value: str | dict[str, str],
item_separator: str = ",",
key_separator: str = "=",
strip: bool = True,
) -> dict[str, str]
Parse a dictionary from a string.
Format: "key1=value1,key2=value2"
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | dict[str, str]
|
String or dict to parse |
required |
item_separator
|
str
|
Separator between items |
','
|
key_separator
|
str
|
Separator between key and value |
'='
|
strip
|
bool
|
Whether to strip whitespace |
True
|
Returns:
| Type | Description |
|---|---|
dict[str, str]
|
Dictionary of string keys and values |
Raises:
| Type | Description |
|---|---|
ValueError
|
If format is invalid |
Source code in provide/foundation/parsers/collections.py
parse_list
¶
Parse a list from a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | list[str]
|
String or list to parse |
required |
separator
|
str
|
Separator character |
','
|
strip
|
bool
|
Whether to strip whitespace from items |
True
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of strings |
Source code in provide/foundation/parsers/collections.py
parse_set
¶
Parse a set from a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | set[str]
|
String or set to parse |
required |
separator
|
str
|
Separator character |
','
|
strip
|
bool
|
Whether to strip whitespace from items |
True
|
Returns:
| Type | Description |
|---|---|
set[str]
|
Set of strings (duplicates removed) |
Source code in provide/foundation/parsers/collections.py
parse_tuple
¶
parse_tuple(
value: str | tuple[str, ...],
separator: str = ",",
strip: bool = True,
) -> tuple[str, ...]
Parse a tuple from a string.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
value
|
str | tuple[str, ...]
|
String or tuple to parse |
required |
separator
|
str
|
Separator character |
','
|
strip
|
bool
|
Whether to strip whitespace from items |
True
|
Returns:
| Type | Description |
|---|---|
tuple[str, ...]
|
Tuple of strings |