Runs a simple HTTP server hosting WSGI app `func`. The directory `static/` is hosted statically. Based on [WsgiServer][ws] from [Colin Stewart][cs]. [ws]: http://www.owlfish.com/software/wsgiutils/documentation/wsgi-server-api.html [cs]: http://www.owlfish.com/
(func, server_address=("0.0.0.0", 8080))
| 12 | |
| 13 | |
| 14 | def runbasic(func, server_address=("0.0.0.0", 8080)): |
| 15 | """ |
| 16 | Runs a simple HTTP server hosting WSGI app `func`. The directory `static/` |
| 17 | is hosted statically. |
| 18 | |
| 19 | Based on [WsgiServer][ws] from [Colin Stewart][cs]. |
| 20 | |
| 21 | [ws]: http://www.owlfish.com/software/wsgiutils/documentation/wsgi-server-api.html |
| 22 | [cs]: http://www.owlfish.com/ |
| 23 | """ |
| 24 | # Copyright (c) 2004 Colin Stewart (http://www.owlfish.com/) |
| 25 | # Modified somewhat for simplicity |
| 26 | # Used under the modified BSD license: |
| 27 | # http://www.xfree86.org/3.3.6/COPYRIGHT2.html#5 |
| 28 | |
| 29 | import errno |
| 30 | import traceback |
| 31 | |
| 32 | import SocketServer |
| 33 | |
| 34 | class WSGIHandler(SimpleHTTPRequestHandler): |
| 35 | def run_wsgi_app(self): |
| 36 | protocol, host, path, parameters, query, fragment = urlparse( |
| 37 | "http://dummyhost%s" % self.path |
| 38 | ) |
| 39 | |
| 40 | # we only use path, query |
| 41 | env = { |
| 42 | "wsgi.version": (1, 0), |
| 43 | "wsgi.url_scheme": "http", |
| 44 | "wsgi.input": self.rfile, |
| 45 | "wsgi.errors": sys.stderr, |
| 46 | "wsgi.multithread": 1, |
| 47 | "wsgi.multiprocess": 0, |
| 48 | "wsgi.run_once": 0, |
| 49 | "REQUEST_METHOD": self.command, |
| 50 | "REQUEST_URI": self.path, |
| 51 | "PATH_INFO": path, |
| 52 | "QUERY_STRING": query, |
| 53 | "CONTENT_TYPE": self.headers.get("Content-Type", ""), |
| 54 | "CONTENT_LENGTH": self.headers.get("Content-Length", ""), |
| 55 | "REMOTE_ADDR": self.client_address[0], |
| 56 | "SERVER_NAME": self.server.server_address[0], |
| 57 | "SERVER_PORT": str(self.server.server_address[1]), |
| 58 | "SERVER_PROTOCOL": self.request_version, |
| 59 | } |
| 60 | |
| 61 | for http_header, http_value in self.headers.items(): |
| 62 | env["HTTP_%s" % http_header.replace("-", "_").upper()] = http_value |
| 63 | |
| 64 | # Setup the state |
| 65 | self.wsgi_sent_headers = 0 |
| 66 | self.wsgi_headers = [] |
| 67 | |
| 68 | try: |
| 69 | # We have there environment, now invoke the application |
| 70 | result = self.server.app(env, self.wsgi_start_response) |
| 71 | try: |
nothing calls this directly
no test coverage detected