-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.py
35 lines (22 loc) · 810 Bytes
/
utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import json
from urllib import parse
from .types import DictQuerystring
def get_json(resp):
"""
:param response:returned response as json when sending a request
using 'requests' module.
:return:response's content with json format
"""
return json.loads(resp.content.decode("utf-8"))
def append_querystring(url: str, params: dict) -> str:
url_parts = list(parse.urlparse(url))
query = dict(parse.parse_qsl(url_parts[4]))
query.update(params)
url_parts[4] = parse.urlencode(query)
return parse.urlunparse(url_parts)
def split_to_dict_querystring(url: str) -> DictQuerystring:
url_parts = list(parse.urlparse(url))
query = dict(parse.parse_qsl(url_parts[4]))
url_parts[4] = ""
url_parts[5] = ""
return parse.urlunparse(url_parts), query