/usr/share/pyshared/tests/test_server.py is in python-poster 0.8.1-0.1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 36 37 38 39 40 41 42 43 | #!/usr/bin/env python
import webob
def app(environ, start_response):
request = webob.Request(environ)
if request.path == '/redirect':
start_response("301 MOVED", [("Location", "/foo")])
return "301 MOVED"
elif request.path == '/needs_auth':
auth = request.headers.get('Authorization')
if auth and auth.startswith("Basic"):
user,passwd = auth.split()[-1].decode("base64").split(":")
else:
user = None
if user != 'john':
start_response("401 Unauthorized", [('WWW-Authenticate', "Basic realm=\"default\"")])
return "401 Unauthorized"
start_response("200 OK", [("Content-Type", "text/plain")])
retval = ["Path: %s" % request.path]
keys = request.params.keys()
keys.sort()
for k in keys:
v = request.params[k]
if hasattr(v, 'file'):
v = v.file.read()
retval.append("%s: %s" % (k, v))
return "\n".join(retval)
if __name__ == '__main__':
import sys
from paste.httpserver import serve
port = int(sys.argv[1])
if len(sys.argv) == 3 and sys.argv[2] == "ssl":
ssl_pem = "*"
else:
ssl_pem = None
try:
serve(app, "localhost", port, ssl_pem=ssl_pem)
except KeyboardInterrupt:
pass
|