aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-04-29 10:56:33 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-04-29 10:56:33 +1200
commit77eca33f2695eea690dff7999c0e1bd3df0e1733 (patch)
treed2ee69461276805bb2a5f295c18a5b7b4df2c973 /libpathod
parentee909e265b40743479ca2f3e8b518f76c91f83f8 (diff)
downloadmitmproxy-77eca33f2695eea690dff7999c0e1bd3df0e1733.tar.gz
mitmproxy-77eca33f2695eea690dff7999c0e1bd3df0e1733.tar.bz2
mitmproxy-77eca33f2695eea690dff7999c0e1bd3df0e1733.zip
Refactor application definitions and startup.
Also, create one of the dodgiest web testing trusses in history. Tornado just seems to have no nice way of doing this.
Diffstat (limited to 'libpathod')
-rw-r--r--libpathod/__init__.py20
-rw-r--r--libpathod/app.py83
-rw-r--r--libpathod/handlers.py45
-rw-r--r--libpathod/templates/frame.html4
4 files changed, 85 insertions, 67 deletions
diff --git a/libpathod/__init__.py b/libpathod/__init__.py
index ff1b88f8..8b137891 100644
--- a/libpathod/__init__.py
+++ b/libpathod/__init__.py
@@ -1,21 +1 @@
-from tornado import web, template
-import handlers, utils
-class PathodApp(web.Application):
- def __init__(self, *args, **kwargs):
- self.templates = template.Loader(utils.data.path("templates"))
- web.Application.__init__(self, *args, **kwargs)
-
-
-def application(**settings):
- return PathodApp(
- [
- (r"/", handlers.Index),
- (r"/log", handlers.Log),
- (r"/help", handlers.Help),
- (r"/preview", handlers.Preview),
- (r"/p/.*", handlers.Pathod, settings),
- ],
- static_path = utils.data.path("static"),
- template_path = utils.data.path("templates"),
- )
diff --git a/libpathod/app.py b/libpathod/app.py
new file mode 100644
index 00000000..15d99023
--- /dev/null
+++ b/libpathod/app.py
@@ -0,0 +1,83 @@
+import urllib
+import tornado.web, tornado.template, tornado.ioloop, tornado.httpserver
+import rparse, utils
+
+class _Page(tornado.web.RequestHandler):
+ def render(self, name, **kwargs):
+ b = self.application.templates.load(name + ".html").generate(**kwargs)
+ self.write(b)
+
+
+class Index(_Page):
+ name = "index"
+ section = "main"
+ def get(self):
+ self.render(self.name, section=self.section)
+
+
+class Preview(_Page):
+ name = "preview"
+ section = "main"
+ def get(self):
+ self.render(self.name, section=self.section)
+
+
+class Help(_Page):
+ name = "help"
+ section = "help"
+ def get(self):
+ self.render(self.name, section=self.section)
+
+
+class Log(_Page):
+ name = "log"
+ section = "log"
+ def get(self):
+ self.render(self.name, section=self.section)
+
+
+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.InternalResponse(
+ 800,
+ "Error parsing response spec: %s\n"%v.msg + v.marked()
+ )
+
+ def _execute(self, transforms, *args, **kwargs):
+ self.response.render(self.request)
+
+
+class PathodApp(tornado.web.Application):
+ def __init__(self, **settings):
+ self.templates = tornado.template.Loader(utils.data.path("templates"))
+ tornado.web.Application.__init__(
+ self,
+ [
+ (r"/", Index),
+ (r"/log", Log),
+ (r"/help", Help),
+ (r"/preview", Preview),
+ (r"/p/.*", Pathod, settings),
+ ],
+ static_path = utils.data.path("static"),
+ template_path = utils.data.path("templates"),
+ debug=True
+ )
+
+
+# begin nocover
+def run(application, port, ssl_options):
+ http_server = tornado.httpserver.HTTPServer(
+ application,
+ ssl_options=ssl_options
+ )
+ http_server.listen(port)
+ tornado.ioloop.IOLoop.instance().start()
+
+
diff --git a/libpathod/handlers.py b/libpathod/handlers.py
deleted file mode 100644
index ebf85b03..00000000
--- a/libpathod/handlers.py
+++ /dev/null
@@ -1,45 +0,0 @@
-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.InternalResponse(
- 800,
- "Error parsing response spec: %s\n"%v.msg + v.marked()
- )
-
- def _execute(self, transforms, *args, **kwargs):
- self.response.render(self.request)
diff --git a/libpathod/templates/frame.html b/libpathod/templates/frame.html
index f985aaa1..08dbd1ae 100644
--- a/libpathod/templates/frame.html
+++ b/libpathod/templates/frame.html
@@ -2,7 +2,7 @@
<html lang="en">
<head>
<meta charset="utf-8">
- <title>Omnid</title>
+ <title>Pathod</title>
<link href="/static/bootstrap.min.css" rel="stylesheet">
<style type="text/css">
body {
@@ -16,7 +16,7 @@
<div class="navbar navbar-fixed">
<div class="navbar-inner">
<div class="container">
- <a class="brand" href="#">Omnid</a>
+ <a class="brand" href="#">Pathod</a>
<ul class="nav">
<li {% if section== "main" %} class="active" {% end %}><a href="/">Main</a></li>
<li {% if section== "log" %} class="active" {% end %}><a href="/log">Log</a></li>