Browse Source

example updates

master
dave 3 years ago
parent
commit
f26f80ee95
  1. 3
      Dockerfile
  2. 27
      examples/cgi-scripts/basic.py
  3. 3
      scripts/nexus/nexus/cgi.py

3
Dockerfile

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

27
examples/cgi-scripts/basic.py

@ -1,25 +1,12 @@
#!/usr/bin/env python3
import os
from urllib.parse import parse_qs
import traceback
import cgitb
cgitb.enable()
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__":
try:
data = parse_qs(os.environ["QUERY_STRING"])
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))
start_response()
data = parse_qs()
assert "yo" in data, "Must pass parameter 'yo' in query string"
print("you passed: ?yo=%s" % data["yo"])

3
scripts/nexus/nexus/cgi.py

@ -22,12 +22,11 @@ def start_response(content_type="text/html", status_code=("200", "OK",), extra_h
def parse_qs():
"""
Parse the request's query string into a dict
TODO parse arrays
"""
GET = {}
if "QUERY_STRING" in os.environ:
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

Loading…
Cancel
Save