test-platform/server/httputils.py

32 lines
715 B
Python

def decode_url(url):
i = 0
end = len(url)
decode_buffer = ''
char_buffer = bytearray()
while i < end:
if url[i] == '%':
try:
char_buffer.append(int(f'0x{url[i+1:i+3]}', 16))
decode_buffer += char_buffer.decode("UTF-8")
del char_buffer[:]
i += 3
except:
i += 3
else:
decode_buffer += url[i]
i += 1
return decode_buffer
def parse_query(query):
query_items = [i for i in query.split("&") if i]
query_dict = {}
for i in query_items:
k, v = i.split("=")
query_dict[decode_url(k)] = decode_url(v)
return query_dict