Files
fission-src/environments/python3/server.py
T
Soam Vasani 1a86078fc0 Very rudimentary Python support
Create a python environment.  Only supports GET; doesn't support any
parameters etc. yet.  Basically just enough for a hello world demo.
2016-11-09 10:02:03 -08:00

43 lines
999 B
Python

#!/usr/bin/env python
import imp
from http.server import BaseHTTPRequestHandler, HTTPServer
#
# Load the file.
#
codepath = '/userfunc/user'
userfunc = None
class testHTTPServer_RequestHandler(BaseHTTPRequestHandler):
def do_POST(self):
global userfunc
userfunc = (imp.load_source('user', codepath)).main
self.send_response(200)
self.end_headers()
self.wfile.write(bytes("ok\n", "utf8"))
return
# GET
def do_GET(self):
global userfunc
try:
print("GET request")
message = userfunc(None)
self.send_response(200)
self.end_headers()
self.wfile.write(bytes(message, "utf8"))
return
except:
self.send_response(500)
self.end_headers()
def run():
print('starting server...')
server_address = ('0.0.0.0', 8888)
httpd = HTTPServer(server_address, testHTTPServer_RequestHandler)
httpd.serve_forever()
run()