feat(helper/url): init url helper
This commit is contained in:
parent
315f07c5ae
commit
9c5c9d743d
1 changed files with 20 additions and 0 deletions
20
src/httpaste/helper/url.py
Normal file
20
src/httpaste/helper/url.py
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
from urllib.parse import urlparse, parse_qs
|
||||
|
||||
|
||||
def url_query_string(fields:dict):
|
||||
|
||||
return '&'.join([f'{k}={v}' for k,v in fields.items()])
|
||||
|
||||
|
||||
def url_append_query_param(url:str, name: str, value:str):
|
||||
|
||||
urlcomps = urlparse(url)
|
||||
|
||||
q = parse_qs(urlcomps.query)
|
||||
|
||||
q[name] = value
|
||||
|
||||
qs = url_query_string(q)
|
||||
|
||||
return urlcomps._replace(query=qs).geturl()
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue