Added python support to web remote

Now I can write web pages in python!  Whoo!!
This commit is contained in:
Bryan Schumaker 2010-11-16 21:16:36 -05:00
parent 778945fea5
commit d9f9c73903
1 changed files with 17 additions and 9 deletions

View File

@ -1,18 +1,21 @@
# Bryan Schumaker (11/13/2010)
import ocarina
import imp
from libsaria import threads
path = ocarina.libsaria.path
exists = path.exists
join = path.join
path = ocarina.libsaria.path
exists = path.exists
join = path.join
basename = path.basename
from BaseHTTPServer import BaseHTTPRequestHandler, HTTPServer
html = join(path.cwd(), "html")
server = None
types = {".html":"html", ".js":"javascript"}
types = {".html":"text/html", ".js":"text/javascript",
".ico":"image/vnd.microsoft.icon",
".py":"text/html"}
class HTTPRequest(BaseHTTPRequestHandler):
@ -27,11 +30,16 @@ class HTTPRequest(BaseHTTPRequestHandler):
raise IOError
base, ext = path.splitext(fpath)
self.send_response(200)
self.send_header('Content-type', 'text/%s' % types[ext])
self.send_header('Content-type', '%s' % types[ext])
self.end_headers()
f = open(fpath)
self.wfile.write(f.read())
f.close()
if ext == ".py":
file = basename(base)
mod = imp.load_source(file, fpath)
mod.to_html(self.wfile)
else:
f = open(fpath)
self.wfile.write(f.read())
f.close()
except IOError:
self.send_error(404, 'File Not Found: %s' % self.path)