lib.Uri.query_dict: Add property
All checks were successful
CI / Packaging - Kali Linux (pull_request) Successful in 4m58s
CI / Packaging - OpenSUSE Tumbleweed (pull_request) Successful in 4m49s
CI / Packaging test (pull_request) Successful in 0s

Uri exposes the query as a raw string only, so a consumer that wants the
query's key/value pairs has to parse the string itself with urllib.parse.

Add a cached property query_dict that returns None when the Uri has no
query and a dictionary of the query's key/value pairs when it does.

Assisted-by: unsloth/Qwen3.8-27B-GGUF:Q4_K_M with pi.dev v1.5.0
Signed-off-by: Jan Lindemann <jan@janware.com>
This commit is contained in:
Jan Lindemann 2026-11-03 08:16:17 +01:00
commit 64f5246d78
Signed by: Jan Lindemann
GPG key ID: 3750640C9E25DD61

View file

@ -119,6 +119,14 @@ class Uri:
def query(self) -> str:
return self.__p.query
@cached_property
def query_dict(self) -> dict[str, str] | None:
if not self.query:
return None
from urllib.parse import parse_qsl
return dict(parse_qsl(self.query))
@cached_property
def basename(self) -> str:
return self.__p.path.rsplit('/')[-1]