2022-12-01 14:29:01 +01:00
|
|
|
import json
|
2026-06-10 13:28:35 +02:00
|
|
|
import re
|
2022-12-01 14:29:01 +01:00
|
|
|
import shlex
|
2024-01-18 12:22:08 +01:00
|
|
|
import traceback
|
2022-12-01 14:29:01 +01:00
|
|
|
|
2026-06-10 13:28:35 +02:00
|
|
|
from collections import OrderedDict
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
from typing import Any, override
|
2026-06-10 13:28:35 +02:00
|
|
|
|
|
|
|
|
from .log import ERR, get_caller_pos, slog, slog_m
|
|
|
|
|
|
|
|
|
|
class Options: # export
|
2022-12-01 14:29:01 +01:00
|
|
|
|
2023-01-17 13:33:44 +01:00
|
|
|
class OrderedData:
|
|
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def __init__(self, pairs: list[tuple[str, str]] | None = None) -> None:
|
2023-01-17 13:33:44 +01:00
|
|
|
self.__pairs = [] if pairs is None else pairs
|
|
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def add(self, lhs: str, rhs: str) -> None:
|
2023-01-17 13:33:44 +01:00
|
|
|
self.__pairs.append((lhs, rhs))
|
|
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def dump(self) -> None:
|
2023-01-17 13:33:44 +01:00
|
|
|
for p in self.__pairs:
|
|
|
|
|
print(p)
|
|
|
|
|
|
|
|
|
|
@property
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def pairs(self) -> list[tuple[str, str]]:
|
2023-01-17 13:33:44 +01:00
|
|
|
return self.__pairs
|
|
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def __parse_json(self, spec: str, cls: Any) -> Any:
|
2022-12-01 14:29:01 +01:00
|
|
|
spec = spec.strip()
|
|
|
|
|
if len(spec) < 3:
|
|
|
|
|
return None
|
|
|
|
|
if spec[0] != '{':
|
|
|
|
|
spec = '{' + spec + '}'
|
|
|
|
|
try:
|
2026-06-10 13:28:35 +02:00
|
|
|
return json.loads(spec, object_pairs_hook = cls)
|
|
|
|
|
except Exception:
|
2022-12-01 14:29:01 +01:00
|
|
|
pass
|
|
|
|
|
return None
|
|
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def __parse(self, opts_str: str, cls: Any) -> Any:
|
2023-01-17 13:33:44 +01:00
|
|
|
r = self.__parse_json(opts_str, cls)
|
2022-12-01 14:29:01 +01:00
|
|
|
if r is not None:
|
|
|
|
|
return r
|
2023-01-17 13:33:44 +01:00
|
|
|
r = cls()
|
2024-01-18 12:22:08 +01:00
|
|
|
try:
|
|
|
|
|
opt_strs = shlex.split(opts_str)
|
2026-06-10 13:28:35 +02:00
|
|
|
except Exception:
|
2024-01-18 12:22:08 +01:00
|
|
|
slog_m(ERR, traceback.format_exc())
|
|
|
|
|
slog(ERR, 'Failed to split options string >{}<'.format(opts_str))
|
|
|
|
|
raise
|
2022-12-01 14:29:01 +01:00
|
|
|
for opt_str in opt_strs:
|
2025-11-02 09:42:21 +01:00
|
|
|
opt_str = re.sub(r'\s*=\s*', '=', opt_str)
|
2022-12-01 14:29:01 +01:00
|
|
|
sides = opt_str.split('=')
|
|
|
|
|
lhs = sides[0].strip()
|
|
|
|
|
if not len(lhs):
|
|
|
|
|
continue
|
2026-06-10 13:28:35 +02:00
|
|
|
if self.__allowed_keys and lhs not in self.__allowed_keys:
|
2022-12-01 14:29:01 +01:00
|
|
|
raise Exception('Field "{}" not supported'.format(lhs))
|
|
|
|
|
rhs = ' '.join(sides[1:]).strip() if len(sides) > 1 else self.__true_val
|
2023-01-17 13:33:44 +01:00
|
|
|
if cls == OrderedDict:
|
|
|
|
|
r[lhs] = rhs
|
|
|
|
|
elif cls == self.OrderedData:
|
|
|
|
|
r.add(lhs, rhs)
|
2022-12-01 14:29:01 +01:00
|
|
|
return r
|
|
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def __recache(self) -> None:
|
2022-12-01 14:29:01 +01:00
|
|
|
self.__list.clear()
|
2023-01-17 13:33:44 +01:00
|
|
|
self.__dict.clear()
|
|
|
|
|
for key, val in self.__data.pairs:
|
|
|
|
|
self.__list.append(key)
|
|
|
|
|
if key not in self.__dict.keys():
|
|
|
|
|
self.__dict[key] = val
|
|
|
|
|
else:
|
|
|
|
|
cur = self.__dict[key]
|
|
|
|
|
if isinstance(cur, str):
|
|
|
|
|
cur = [cur, val]
|
|
|
|
|
elif isinstance(cur, set):
|
|
|
|
|
cur.add(val)
|
|
|
|
|
elif isinstance(cur, list):
|
|
|
|
|
cur.append(val)
|
|
|
|
|
else:
|
|
|
|
|
cur = [cur, val]
|
|
|
|
|
self.__dict[key] = cur
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
self.__str_cache = self.__str__()
|
2022-12-01 14:29:01 +01:00
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def __getitem__(self, key: str) -> Any:
|
2026-06-10 13:28:35 +02:00
|
|
|
if key not in self.__dict.keys():
|
2022-12-01 14:29:01 +01:00
|
|
|
return None
|
|
|
|
|
return self.__dict[key]
|
|
|
|
|
|
2026-07-21 20:57:30 +02:00
|
|
|
@override
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def __str__(self) -> str:
|
2023-01-17 13:33:44 +01:00
|
|
|
return ', '.join(str(p[0]) + ': ' + str(p[1]) for p in self.__data.pairs)
|
2022-12-01 14:29:01 +01:00
|
|
|
|
2026-07-21 20:57:30 +02:00
|
|
|
@override
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def __repr__(self) -> str:
|
2023-01-17 13:33:44 +01:00
|
|
|
return self.__str__()
|
2022-12-01 14:29:01 +01:00
|
|
|
|
2026-07-21 20:57:30 +02:00
|
|
|
@override
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def __format__(self, fmt: str) -> str:
|
2023-01-17 13:33:44 +01:00
|
|
|
return self.__str__()
|
2022-12-01 14:29:01 +01:00
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def __len__(self) -> int:
|
2023-01-17 13:33:44 +01:00
|
|
|
return len(self.__data.pairs)
|
2022-12-01 14:29:01 +01:00
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def __contains__(self, keys: Any) -> bool:
|
2026-06-10 13:28:35 +02:00
|
|
|
if type(keys) not in [list, set]:
|
2022-12-01 14:29:01 +01:00
|
|
|
return keys in self.__dict.keys()
|
|
|
|
|
for key in keys:
|
2026-06-10 13:28:35 +02:00
|
|
|
if key not in self.__dict.keys():
|
2022-12-01 14:29:01 +01:00
|
|
|
return False
|
|
|
|
|
return True
|
|
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def __iter__(self) -> Any:
|
2022-12-01 14:29:01 +01:00
|
|
|
return iter(self.__list)
|
|
|
|
|
|
2026-06-10 13:28:35 +02:00
|
|
|
#def __next__(self):
|
|
|
|
|
# return next(self.__list)
|
2022-12-01 14:29:01 +01:00
|
|
|
|
2026-06-10 13:28:35 +02:00
|
|
|
def __init__(
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
self,
|
|
|
|
|
spec: Any = None,
|
|
|
|
|
delimiter: str = ',',
|
|
|
|
|
allowed_keys: Any = None,
|
|
|
|
|
true_val: Any = True
|
|
|
|
|
) -> None:
|
2022-12-01 14:29:01 +01:00
|
|
|
self.__true_val = true_val
|
2026-11-13 14:40:14 +01:00
|
|
|
self.__allowed_keys: Any = None
|
2022-12-01 14:29:01 +01:00
|
|
|
self.__delimiter = delimiter
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
self.__data = (
|
|
|
|
|
self.__class__.OrderedData()
|
|
|
|
|
if spec is None else self.__parse(spec, self.__class__.OrderedData)
|
|
|
|
|
)
|
|
|
|
|
self.__dict: dict[str, Any] = {}
|
2026-06-10 13:28:35 +02:00
|
|
|
#self.__dict = OrderedDict() if spec is None else self.__parse(spec,OrderedDict)
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
self.__list: list[str] = []
|
|
|
|
|
self.__str_cache = None # type: ignore[assignment]
|
2022-12-01 14:29:01 +01:00
|
|
|
self.__recache()
|
|
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def dump(self, prio: int, caller: Any = None) -> None:
|
2023-01-17 13:33:44 +01:00
|
|
|
if caller is None:
|
|
|
|
|
caller = get_caller_pos()
|
|
|
|
|
for key, val in self.__data.pairs:
|
2026-06-10 13:28:35 +02:00
|
|
|
slog(prio, "{}=\"{}\"".format(key, val), caller = caller)
|
2022-12-01 14:29:01 +01:00
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def keys(self) -> Any:
|
2022-12-01 14:29:01 +01:00
|
|
|
return self.__dict.keys()
|
|
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def items(self) -> Any:
|
2023-01-17 13:33:44 +01:00
|
|
|
#return self.__dict.items()
|
|
|
|
|
return self.__data.pairs
|
2022-12-01 14:29:01 +01:00
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def get(self, key: Any, default: Any = None, by_index: bool = False) -> Any:
|
2022-12-01 14:29:01 +01:00
|
|
|
if by_index:
|
Options.get(): Fix inverted by_index check
The by_index branch of Options.get() raises KeyError for every integer
index, because the first isinstance guard is inverted: it fires for exactly
the keys the branch is supposed to handle, so the range check and the
lookup in the list of parsed keys below it are dead code. A non-integer key
with by_index set slips past the guard and falls through to the regular key
lookup instead. A previous make-check fallout commit flipped the original
type(key) != int test into a positive isinstance test, and a later mypy fix
then added redundant isinstance guards to the unreachable branches,
cementing the broken flow.
Invert the guard back to not isinstance(key, int), so that a non-integer
key raises KeyError, an in-range integer index returns the key stored at
that position in the option string, and an out-of-range index returns the
default or raises KeyError. Drop the redundant isinstance guards from the
now-reachable branches.
TODO: The bug actually made "make -C test/parse_opts run" fail, but since
jw-python's nightly CI doesn't run that, this has gone unnoticed. The test
now passes, but should be replaced with a better test (executed by "make
test", and pytest-based).
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-09-18 09:05:53 +02:00
|
|
|
if not isinstance(key, int):
|
2026-06-10 13:28:35 +02:00
|
|
|
raise KeyError(
|
|
|
|
|
'Tried to get value from options string with ' +
|
|
|
|
|
'index {} of type "{}": {}'.format(key, type(key), str(self))
|
|
|
|
|
)
|
Options.get(): Fix inverted by_index check
The by_index branch of Options.get() raises KeyError for every integer
index, because the first isinstance guard is inverted: it fires for exactly
the keys the branch is supposed to handle, so the range check and the
lookup in the list of parsed keys below it are dead code. A non-integer key
with by_index set slips past the guard and falls through to the regular key
lookup instead. A previous make-check fallout commit flipped the original
type(key) != int test into a positive isinstance test, and a later mypy fix
then added redundant isinstance guards to the unreachable branches,
cementing the broken flow.
Invert the guard back to not isinstance(key, int), so that a non-integer
key raises KeyError, an in-range integer index returns the key stored at
that position in the option string, and an out-of-range index returns the
default or raises KeyError. Drop the redundant isinstance guards from the
now-reachable branches.
TODO: The bug actually made "make -C test/parse_opts run" fail, but since
jw-python's nightly CI doesn't run that, this has gone unnoticed. The test
now passes, but should be replaced with a better test (executed by "make
test", and pytest-based).
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-09-18 09:05:53 +02:00
|
|
|
if key >= len(self.__data.pairs):
|
2022-12-01 14:29:01 +01:00
|
|
|
if default is not None:
|
|
|
|
|
return default
|
2026-06-10 13:28:35 +02:00
|
|
|
raise KeyError(
|
|
|
|
|
'Tried to get value from options string with ' +
|
|
|
|
|
'index {} of {}: {}'.format(key, len(self.__data.pairs), str(self))
|
|
|
|
|
)
|
Options.get(): Fix inverted by_index check
The by_index branch of Options.get() raises KeyError for every integer
index, because the first isinstance guard is inverted: it fires for exactly
the keys the branch is supposed to handle, so the range check and the
lookup in the list of parsed keys below it are dead code. A non-integer key
with by_index set slips past the guard and falls through to the regular key
lookup instead. A previous make-check fallout commit flipped the original
type(key) != int test into a positive isinstance test, and a later mypy fix
then added redundant isinstance guards to the unreachable branches,
cementing the broken flow.
Invert the guard back to not isinstance(key, int), so that a non-integer
key raises KeyError, an in-range integer index returns the key stored at
that position in the option string, and an out-of-range index returns the
default or raises KeyError. Drop the redundant isinstance guards from the
now-reachable branches.
TODO: The bug actually made "make -C test/parse_opts run" fail, but since
jw-python's nightly CI doesn't run that, this has gone unnoticed. The test
now passes, but should be replaced with a better test (executed by "make
test", and pytest-based).
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-09-18 09:05:53 +02:00
|
|
|
return self.__list[key]
|
2022-12-01 14:29:01 +01:00
|
|
|
if key in self.__dict.keys():
|
|
|
|
|
return self.__dict[key]
|
|
|
|
|
if default is not None:
|
|
|
|
|
return default
|
2026-06-10 13:28:35 +02:00
|
|
|
raise KeyError(
|
|
|
|
|
'Key "{}" is not present in options string: {}'.format(key, str(self))
|
|
|
|
|
)
|
2022-12-01 14:29:01 +01:00
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def update(self, rhs: Any) -> None:
|
2022-12-01 14:29:01 +01:00
|
|
|
if hasattr(rhs, 'items'):
|
|
|
|
|
for key, val in rhs.items():
|
|
|
|
|
self.__dict[key] = val
|
|
|
|
|
return
|
|
|
|
|
if isinstance(rhs, str):
|
2026-06-10 13:28:35 +02:00
|
|
|
self.update(self.__parse(rhs, self.OrderedData))
|
2022-12-01 14:29:01 +01:00
|
|
|
return
|
2026-06-10 13:28:35 +02:00
|
|
|
raise Exception(
|
|
|
|
|
'Tried to update options with object of incompatible type {}'.format(
|
|
|
|
|
type(rhs)
|
|
|
|
|
)
|
|
|
|
|
)
|
2022-12-01 14:29:01 +01:00
|
|
|
|
mypy: Fix no_untyped_defs
Add type annotations to 30 files across jw.util, resolving all
191 'no-untyped-def' mypy errors in strict mode.
The changes cover Signals, CppState, Bunch, RedirectStdIO, StopWatch,
Process, Options, ArgsContainer, Object, multi_key_dict, ldap, Session,
rows, ShuntingYard, TableIoHandler, DataBase, Queries, Query, QueryResult,
and all db/schema files (Column, Table, ColumnSet, DataType, Schema,
SingleForeignKey, CompositeForeignKey), plus asyncio variants and
ev/base/Object and auth/dummy/Auth.
Additionally, unreachable code and type annotation conflicts were
resolved in StopWatch.py, Options.py, rows.py, and Table.py.
Assisted-by: unsloth/Qwen3.6-35B-A3B-GGUF:IQ4_NL with pi.dev v0.82.0
Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-25 10:24:57 +02:00
|
|
|
def append_to(self, obj: Any) -> None:
|
2022-12-01 14:29:01 +01:00
|
|
|
for opt in self.__list:
|
|
|
|
|
setattr(obj, opt[0], opt[1])
|