From 2c52f9b5612540070db8e08f566d79f865b8e645 Mon Sep 17 00:00:00 2001 From: Yusur Princeps Date: Wed, 30 Jul 2025 20:19:31 +0200 Subject: [PATCH] add twocolon_list() --- CHANGELOG.md | 2 +- src/suou/__init__.py | 6 +++--- src/suou/codecs.py | 12 +++++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index b89014a..6dafe7d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,7 +4,7 @@ + `sqlalchemy`: add `unbound_fk()`, `bound_fk()` + Add `sqlalchemy_async` module with `SQLAlchemy()` -+ Add `timed_cache()`, `TimedDict()`, `none_pass` ++ Add `timed_cache()`, `TimedDict()`, `none_pass()`, `twocolon_list()` + Add module `calendar` with `want_*` date type conversion utilities and `age_and_days()` + Move obsolete stuff to `obsolete` package (includes configparse 0.3 as of now) + Add `redact` module with `redact_url_password()` diff --git a/src/suou/__init__.py b/src/suou/__init__.py index b769b40..9108eac 100644 --- a/src/suou/__init__.py +++ b/src/suou/__init__.py @@ -18,7 +18,7 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. from .iding import Siq, SiqCache, SiqType, SiqGen from .codecs import (StringCase, cb32encode, cb32decode, b32lencode, b32ldecode, b64encode, b64decode, b2048encode, b2048decode, - jsonencode, want_bytes, want_str, ssv_list, want_urlsafe, want_urlsafe_bytes) + jsonencode, twocolon_list, want_bytes, want_str, ssv_list, want_urlsafe, want_urlsafe_bytes) from .bits import count_ones, mask_shift, split_bits, join_bits, mod_ceil, mod_floor from .calendar import want_datetime, want_isodate, want_timestamp, age_and_days from .configparse import MissingConfigError, MissingConfigWarning, ConfigOptions, ConfigParserConfigSource, ConfigSource, DictConfigSource, ConfigValue, EnvConfigSource @@ -47,6 +47,6 @@ __all__ = ( 'jsonencode', 'kwargs_prefix', 'lex', 'ltuple', 'makelist', 'mask_shift', 'matches', 'mod_ceil', 'mod_floor', 'none_pass', 'not_implemented', 'redact_url_password', 'rtuple', 'split_bits', 'ssv_list', 'symbol_table', - 'timed_cache', 'want_bytes', 'want_datetime', 'want_isodate', 'want_str', - 'want_timestamp', 'want_urlsafe', 'want_urlsafe_bytes' + 'timed_cache', 'twocolon_list', 'want_bytes', 'want_datetime', 'want_isodate', + 'want_str', 'want_timestamp', 'want_urlsafe', 'want_urlsafe_bytes' ) diff --git a/src/suou/codecs.py b/src/suou/codecs.py index 9740024..22e52f5 100644 --- a/src/suou/codecs.py +++ b/src/suou/codecs.py @@ -294,6 +294,16 @@ def ssv_list(s: str, *, sep_chars = ',;') -> list[str]: l.pop() return l +def twocolon_list(s: str | None) -> list[str]: + """ + Parse a string on a single line as multiple lines, each line separated by double colon (::). + + Returns a list. + """ + if not s: + return [] + return [x.strip() for x in s.split('::')] + class StringCase(enum.Enum): """ Enum values used by regex validators and storage converters. @@ -329,5 +339,5 @@ class StringCase(enum.Enum): __all__ = ( 'cb32encode', 'cb32decode', 'b32lencode', 'b32ldecode', 'b64encode', 'b64decode', 'jsonencode' - 'StringCase', 'want_bytes', 'want_str', 'jsondecode', 'ssv_list', 'want_urlsafe', 'want_urlsafe_bytes' + 'StringCase', 'want_bytes', 'want_str', 'jsondecode', 'ssv_list', 'twocolon_list', 'want_urlsafe', 'want_urlsafe_bytes' ) \ No newline at end of file