You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

32 lines
611 B
Python

#!/usr/bin/env python3
import json
import select
import sys
import urllib.parse
def main(args=(), stdin=()):
for arg in args:
print(parse(arg))
for line in stdin:
print(parse(line))
def parse(params):
qs = urllib.parse.parse_qs(params.strip(), keep_blank_values=True)
obj = {}
for key, value in qs.items():
obj[key] = value[0] if len(value) == 1 else value
return json.dumps(obj)
def get_stdin():
found = select.select((sys.stdin,), (), (), 0.0)[0]
return found[0] if found else ()
if __name__ == "__main__":
main(sys.argv[1:], get_stdin())