summaryrefslogtreecommitdiff
path: root/pom_parser
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2025-09-23 01:24:06 -0400
committerpommicket <pommicket@gmail.com>2025-09-23 01:24:06 -0400
commitb5cdae01c4186f7b52ca1966267a8c735756a891 (patch)
treee0b693fa4fa47538903afb3856be52c2924dbd6a /pom_parser
parenta042aded798fa33ce39a195a89e161aa6c80679f (diff)
list parsing
Diffstat (limited to 'pom_parser')
-rw-r--r--pom_parser/__init__.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/pom_parser/__init__.py b/pom_parser/__init__.py
index 29bf843..c179158 100644
--- a/pom_parser/__init__.py
+++ b/pom_parser/__init__.py
@@ -92,6 +92,26 @@ class Item:
return False
return None
+ def _parse_list(self) -> list[str]:
+ chars = iter(self.value)
+ list_ = []
+ entry: list[str] = []
+ while (c := next(chars, '')):
+ if c == ',':
+ list_.append(''.join(entry).strip(' \t'))
+ entry = []
+ elif c == '\\':
+ c = next(chars, '')
+ if c not in ',\\':
+ entry.append('\\')
+ entry.append(c)
+ else:
+ entry.append(c)
+ last_entry = ''.join(entry).strip(' \t')
+ if last_entry:
+ list_.append(last_entry)
+ return list_
+
class Configuration:
_items: dict[str, Item]
def __repr__(self) -> str:
@@ -156,6 +176,14 @@ class Configuration:
raise item._error(f'Value {repr(item.value)} for {item.key} is invalid (want on/off/yes/no/true/false)')
return boolv
+ def get_list(self, key: str, default: Optional[list[str]] = None) -> Optional[list[str]]:
+ item = self._items.get(key)
+ if item is None:
+ return None if default is None else default
+ item.read = True
+ return item._parse_list()
+
+
def items(self) -> Iterable[Item]:
import copy
return map(copy.copy, self._items.values())