bpo-36345: Update wsgiref example (GH-12562)

Use literalinclude markup to include Tools/scripts/serve.py code.
Tools/scripts/serve.py first argument on the command line is now optional.
This commit is contained in:
Stéphane Wirtel 2019-04-16 14:52:54 +02:00 committed by GitHub
parent 6fa84bd12c
commit 2b7f93b99a
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 31 deletions

View file

@ -25,11 +25,12 @@ def app(environ, respond):
return [b'not found']
if __name__ == '__main__':
path = sys.argv[1]
path = sys.argv[1] if len(sys.argv) > 1 else os.getcwd()
port = int(sys.argv[2]) if len(sys.argv) > 2 else 8000
httpd = simple_server.make_server('', port, app)
print("Serving {} on port {}, control-C to stop".format(path, port))
try:
httpd.serve_forever()
except KeyboardInterrupt:
print("\b\bShutting down.")
print("Shutting down.")
httpd.server_close()