aboutsummaryrefslogtreecommitdiffstats
path: root/libpathod
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2012-06-24 16:38:32 +1200
committerAldo Cortesi <aldo@nullcube.com>2012-06-24 16:38:32 +1200
commit4fc64ac04ffbec8e3a51ea3f7a129f17530ee3ef (patch)
tree377ad164d9bb860ddba4fc1b1134828f38feebed /libpathod
parente6aa9ff67582c00d2de03f65b47dd776cd602fb7 (diff)
downloadmitmproxy-4fc64ac04ffbec8e3a51ea3f7a129f17530ee3ef.tar.gz
mitmproxy-4fc64ac04ffbec8e3a51ea3f7a129f17530ee3ef.tar.bz2
mitmproxy-4fc64ac04ffbec8e3a51ea3f7a129f17530ee3ef.zip
Enable anchors on command line.
Diffstat (limited to 'libpathod')
-rw-r--r--libpathod/pathod.py14
-rw-r--r--libpathod/utils.py21
2 files changed, 15 insertions, 20 deletions
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index 1491072c..ba537768 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -2,6 +2,8 @@ import urllib, threading, re
from netlib import tcp, http, odict, wsgi
import version, app, rparse
+class PathodError(Exception): pass
+
class PathodHandler(tcp.BaseHandler):
def handle(self):
@@ -73,7 +75,7 @@ class Pathod(tcp.TCPServer):
addr: (address, port) tuple. If port is 0, a free port will be
automatically chosen.
ssloptions: a dictionary containing certfile and keyfile specifications.
- prefix: string specifying the prefix at which to anchor response generation.
+ prefix: string specifying the prefix at which to anchor response generation.
staticdir: path to a directory of static resources, or None.
anchors: A list of (regex, spec) tuples, or None.
"""
@@ -88,8 +90,14 @@ class Pathod(tcp.TCPServer):
self.anchors = []
if anchors:
for i in anchors:
- arex = re.compile(i[0])
- aresp = rparse.parse(self.request_settings, i[1])
+ try:
+ arex = re.compile(i[0])
+ except re.error:
+ raise PathodError("Invalid regex in anchor: %s"%i[0])
+ try:
+ aresp = rparse.parse(self.request_settings, i[1])
+ except rparse.ParseException, v:
+ raise PathodError("Invalid page spec in anchor: '%s', %s"%(i[1], str(v)))
self.anchors.append((arex, aresp))
@property
diff --git a/libpathod/utils.py b/libpathod/utils.py
index f421b8a6..39732849 100644
--- a/libpathod/utils.py
+++ b/libpathod/utils.py
@@ -1,27 +1,14 @@
import os, re
import rparse
-class AnchorError(Exception): pass
-
-def parse_anchor_spec(s, settings):
+def parse_anchor_spec(s):
"""
- For now, this is very simple, and you can't have an '=' in your regular
- expression.
+ Return a tuple, or None on error.
"""
if not "=" in s:
- raise AnchorError("Invalid anchor definition: %s"%s)
- rex, spec = s.split("=", 1)
- try:
- re.compile(rex)
- except re.error:
- raise AnchorError("Invalid regex in anchor: %s"%s)
- try:
- rparse.parse(settings, spec)
- except rparse.ParseException, v:
- raise AnchorError("Invalid page spec in anchor: '%s', %s"%(s, str(v)))
-
- return rex, spec
+ return None
+ return tuple(s.split("=", 1))
class Data: