[PR jw/#166] lib.Uri.query_dict: Add property
All checks were successful
CI / Packaging - Kali Linux (push) Successful in 5m11s
CI / Packaging - OpenSUSE Tumbleweed (push) Successful in 5m8s
CI / Packaging test (push) Successful in 0s

Merge pull request "lib.Uri.query_dict: Add property"

Upstream-repo: ssh://git@code.janware.com/janware/jw-pkg
Source-branch: jan/feature/20261103-lib-uri-query-dict-add-property
Target-branch: master
Reviewed-on: #166
This commit is contained in:
Jan Lindemann 2026-11-03 18:30:37 +01:00 • committed by janware Code
commit 49c37f5d79
Signed by: Code Bot
GPG key ID: 66A5D2B295EE1224
2 changed files with 15 additions and 0 deletions

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]

View file

@ -109,4 +109,11 @@ assert u.new_replace_path('etc').to_string == \
assert 'pkg-filter=url=~jw.dev' in u.full
assert Uri('ssh://host/path').query == ''
# query_dict is None without a query and a key/value dict with one
assert Uri('ssh://host/path').query_dict is None
u = Uri('kvfile://host/?pkg-filter=url=~jw.dev')
assert u.query_dict == {'pkg-filter': 'url=~jw.dev'}
u = Uri('https://example.com/?a=1&b=two')
assert u.query_dict == {'a': '1', 'b': 'two'}
print('All Uri tests passed')