Last active
May 12, 2016 07:18
-
-
Save hamilyon/56d5e220896565d4f17429dcbf08578c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ## cd /cygdrive/c/Users/SBT-Shaposhnikov-AA/ | |
| ## /cygdrive/c/programdata/chocolatey/lib/python3/tools/scripts/waitress-serve.exe --port=8998 reserv:hello_world_app | |
| import sys | |
| import re | |
| import urllib | |
| from urllib import parse | |
| from wsgiref.simple_server import make_server | |
| # from waitress import serve | |
| def hello_world_app(environ, start_response): | |
| status = '200 OK' # HTTP Status | |
| # The returned object is going to be printed | |
| qs = environ.get('QUERY_STRING')[2:] | |
| qs = parse.unquote_plus(qs) | |
| if qs: | |
| result = \ | |
| re.sub('\[0x(..)\]\[0x(..)\]', lambda c: bytes.fromhex(c.group(1)+c.group(2)).decode('utf-8', errors='ignore'), qs) | |
| headers = [('Content-type', 'text/plain; charset=utf-8')] # HTTP Headers | |
| start_response(status, headers) | |
| return [result.encode('utf-8')] | |
| else: | |
| headers = [('Content-type', 'text/html; charset=utf-8')] # HTTP Headers | |
| start_response(status, headers) | |
| return [b''' | |
| <form method="get"> | |
| Text: <textarea rows="4" cols="100" name="q"> | |
| </textarea><br> | |
| <input type="submit" value="Submit"> | |
| </form> | |
| '''] | |
| # serve(hello_world_app) | |
| if __name__ == '__main__': | |
| httpd = make_server('', 8998, hello_world_app) | |
| # Serve until process is killed | |
| httpd.serve_forever() | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment