lib.Uri.query_dict: Add property
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:
parent
53c45e11de
commit
64f5246d78
1 changed files with 15 additions and 0 deletions
|
|
@ -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]
|
||||
|
|
|
|||
Loading…
Reference in a new issue