example updates

This commit is contained in:
dave 2018-10-07 14:06:51 -07:00
parent 5d50ccedf4
commit f26f80ee95
3 changed files with 8 additions and 25 deletions

View File

@ -44,6 +44,3 @@ ENTRYPOINT ["/start"]
EXPOSE 80 EXPOSE 80
EXPOSE 22 EXPOSE 22
RUN sed -i -E 's/error_log .+/error_log \/var\/log\/nginx\/error.log debug;/' /etc/nginx/nginx.conf

View File

@ -1,25 +1,12 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import cgitb
from urllib.parse import parse_qs cgitb.enable()
import traceback from nexus.cgi import start_response, parse_qs
def start_response(content_type="text/html", status_code=("200", "OK",)):
print('Status: %s %s' % (status_code))
print("Content-Type: %s" % content_type)
print()
if __name__ == "__main__": if __name__ == "__main__":
try: start_response()
data = parse_qs()
data = parse_qs(os.environ["QUERY_STRING"]) assert "yo" in data, "Must pass parameter 'yo' in query string"
print("you passed: ?yo=%s" % data["yo"])
assert "yo" in data, "Must pass parameter 'yo' in query string"
start_response()
print("you passed: ?yo=%s" % data["yo"][0])
except Exception as e:
start_response(status_code=('500', "you fucked up"))
tb = traceback.format_exc()
print('<pre>{}</pre>'.format(tb))

View File

@ -22,12 +22,11 @@ def start_response(content_type="text/html", status_code=("200", "OK",), extra_h
def parse_qs(): def parse_qs():
""" """
Parse the request's query string into a dict Parse the request's query string into a dict
TODO parse arrays
""" """
GET = {} GET = {}
if "QUERY_STRING" in os.environ: if "QUERY_STRING" in os.environ:
GET = _parse_qs(os.environ["QUERY_STRING"]) GET = _parse_qs(os.environ["QUERY_STRING"])
GET = {k: v[0] for k, v in GET.items()} GET = {k: v[0] if len(v) == 1 else v for k, v in GET.items()}
return GET return GET