aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod/handlers.py
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-04-28 12:42:03 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-04-28 12:42:03 +1200
commitb4105be21e967f79d819749c44eff6ed4311f65d (patch)
tree723857cc38b59c5ebd35ab6c5b32d72e3a05c9a4 /libpathod/handlers.py
downloadmitmproxy-b4105be21e967f79d819749c44eff6ed4311f65d.tar.gz
mitmproxy-b4105be21e967f79d819749c44eff6ed4311f65d.tar.bz2
mitmproxy-b4105be21e967f79d819749c44eff6ed4311f65d.zip
Initial checkin.
Diffstat (limited to 'libpathod/handlers.py')
-rw-r--r--libpathod/handlers.py45
1 files changed, 45 insertions, 0 deletions
diff --git a/libpathod/handlers.py b/libpathod/handlers.py
new file mode 100644
index 00000000..a697304c
--- /dev/null
+++ b/libpathod/handlers.py
@@ -0,0 +1,45 @@
+import urllib
+import tornado.web
+import rparse
+
+class _Page(tornado.web.RequestHandler):
+ def render(self, name, **kwargs):
+ b = self.application.templates.load(name).generate(**kwargs)
+ self.write(b)
+
+
+class Index(_Page):
+ def get(self):
+ self.render("index.html", section="main")
+
+
+class Preview(_Page):
+ def get(self):
+ self.render("index.html", section="main")
+
+
+class Help(_Page):
+ def get(self):
+ self.render("help.html", section="help")
+
+
+class Log(_Page):
+ def get(self):
+ self.render("log.html", section="log")
+
+
+class Pathod(object):
+ anchor = "/p/"
+ def __init__(self, application, request, **settings):
+ self.application, self.request, self.settings = application, request, settings
+ spec = urllib.unquote(self.request.uri)[len(self.anchor):]
+ try:
+ self.response = rparse.parse(self.settings, spec)
+ except rparse.ParseException, v:
+ self.response = rparse.StubResponse(
+ 800,
+ "Error parsing response spec:" + str(v)
+ )
+
+ def _execute(self, transforms, *args, **kwargs):
+ self.response.render(self.request)