aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAldo Cortesi <aldo@nullcube.com>2015-04-20 08:56:47 +1200
committerAldo Cortesi <aldo@nullcube.com>2015-04-20 08:56:47 +1200
commitbe450cf9db1d819b1023029c8d403f401e010c98 (patch)
tree2f69ceb926cb95b809a5a0e1aa851e3401e709b2
parent3891fe56385b323b435392aadb3f55848ee30857 (diff)
downloadmitmproxy-be450cf9db1d819b1023029c8d403f401e010c98.tar.gz
mitmproxy-be450cf9db1d819b1023029c8d403f401e010c98.tar.bz2
mitmproxy-be450cf9db1d819b1023029c8d403f401e010c98.zip
Whitespace, small fixes.
-rw-r--r--libpathod/cmdline.py2
-rw-r--r--libpathod/language.py9
-rw-r--r--libpathod/pathoc.py37
-rw-r--r--libpathod/pathod.py3
-rw-r--r--test/test_pathoc.py8
-rw-r--r--test/test_pathod.py2
-rw-r--r--test/tutils.py24
7 files changed, 45 insertions, 40 deletions
diff --git a/libpathod/cmdline.py b/libpathod/cmdline.py
index 3323716c..bd6a4360 100644
--- a/libpathod/cmdline.py
+++ b/libpathod/cmdline.py
@@ -4,8 +4,8 @@ import os
import os.path
import sys
import re
-from . import pathoc, pathod, version, utils, language
from netlib import http_uastrings
+from . import pathoc, pathod, version, utils, language
def args_pathoc(argv, stdout=sys.stdout, stderr=sys.stderr):
diff --git a/libpathod/language.py b/libpathod/language.py
index 7aa6565c..5c53453d 100644
--- a/libpathod/language.py
+++ b/libpathod/language.py
@@ -51,7 +51,7 @@ def send_chunk(fp, val, blocksize, start, end):
return end-start
-def write_values(fp, vals, actions, sofar=0, skip=0, blocksize=BLOCKSIZE):
+def write_values(fp, vals, actions, sofar=0, blocksize=BLOCKSIZE):
"""
vals: A list of values, which may be strings or Value objects.
@@ -235,7 +235,7 @@ class _Token(object):
"""
__metaclass__ = abc.ABCMeta
- @abc.abstractmethod
+ @classmethod
def expr(klass): # pragma: no cover
"""
A parse expression.
@@ -709,7 +709,7 @@ class _Action(_Token):
pass
@abc.abstractmethod
- def intermediate(self): # pragma: no cover
+ def intermediate(self, settings): # pragma: no cover
pass
@@ -791,6 +791,7 @@ class InjectAt(_Action):
class _Message(object):
__metaclass__ = abc.ABCMeta
version = "HTTP/1.1"
+ logattrs = []
def __init__(self, tokens):
self.tokens = tokens
@@ -873,7 +874,7 @@ class _Message(object):
def preamble(self, settings): # pragma: no cover
pass
- @abc.abstractmethod
+ @classmethod
def expr(klass): # pragma: no cover
pass
diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py
index 08efdb3d..616550fa 100644
--- a/libpathod/pathoc.py
+++ b/libpathod/pathoc.py
@@ -116,6 +116,7 @@ class Pathoc(tcp.TCPClient):
self.clientcert = clientcert
self.sslversion = utils.SSLVERSIONS[sslversion]
self.ciphers = ciphers
+ self.sslinfo = None
self.showreq = showreq
self.showresp = showresp
@@ -187,6 +188,8 @@ class Pathoc(tcp.TCPClient):
r: A language.Request object, or a string representing one request.
Returns True if we have a non-ignored response.
+
+ May raise http.HTTPError, tcp.NetLibError
"""
if isinstance(r, basestring):
r = language.parse_requests(r)[0]
@@ -203,7 +206,6 @@ class Pathoc(tcp.TCPClient):
self.address.host
)
self.wfile.flush()
-
resp = list(http.read_response(self.rfile, r.method.string(), None))
resp.append(self.sslinfo)
resp = Response(*resp)
@@ -224,22 +226,25 @@ class Pathoc(tcp.TCPClient):
finally:
if req:
if self.ignorecodes and resp and resp.status_code in self.ignorecodes:
- return None
-
- if self.explain:
- print >> self.fp, ">> Spec:", r.spec()
+ resp = None
+ else:
+ if self.explain:
+ print >> self.fp, ">> Spec:", r.spec()
- if self.showreq:
- self._show(
- self.fp, ">> Request", self.wfile.get_log(), self.hexdump
- )
+ if self.showreq:
+ self._show(
+ self.fp, ">> Request", self.wfile.get_log(), self.hexdump
+ )
- if self.showsummary and resp:
- self._show_summary(self.fp, resp)
- if self.showresp:
- self._show(
- self.fp, "<< Response", self.rfile.get_log(), self.hexdump
- )
+ if self.showsummary and resp:
+ self._show_summary(self.fp, resp)
+ if self.showresp:
+ self._show(
+ self.fp,
+ "<< Response",
+ self.rfile.get_log(),
+ self.hexdump
+ )
return resp
@@ -310,7 +315,7 @@ def main(args): # pragma: nocover
sys.stdout.flush()
if ret and args.oneshot:
return
- except (http.HttpError, tcp.NetlibError), v:
+ except (http.HttpError, tcp.NetLibError), v:
pass
except KeyboardInterrupt:
pass
diff --git a/libpathod/pathod.py b/libpathod/pathod.py
index de6bde3a..07354aa8 100644
--- a/libpathod/pathod.py
+++ b/libpathod/pathod.py
@@ -233,7 +233,7 @@ class PathodHandler(tcp.BaseHandler):
def handle(self):
if self.server.ssl:
try:
- cert, key, chain_file = self.server.ssloptions.get_cert(None)
+ cert, key, _ = self.server.ssloptions.get_cert(None)
self.convert_to_ssl(
cert, key,
handle_sni=self.handle_sni,
@@ -276,7 +276,6 @@ class Pathod(tcp.TCPServer):
def __init__(
self,
addr,
- confdir=CONFDIR,
ssl=False,
ssloptions=None,
craftanchor="/p/",
diff --git a/test/test_pathoc.py b/test/test_pathoc.py
index 598b2c81..90f798c9 100644
--- a/test/test_pathoc.py
+++ b/test/test_pathoc.py
@@ -18,10 +18,10 @@ class _TestDaemon:
@classmethod
def setUpAll(self):
self.d = test.Daemon(
- ssl=self.ssl,
- ssloptions=self.ssloptions,
- staticdir=tutils.test_data.path("data"),
- anchors=[
+ ssl = self.ssl,
+ ssloptions = self.ssloptions,
+ staticdir = tutils.test_data.path("data"),
+ anchors = [
(re.compile("/anchor/.*"), language.parse_response("202"))
]
)
diff --git a/test/test_pathod.py b/test/test_pathod.py
index 3638960e..c32f6e84 100644
--- a/test/test_pathod.py
+++ b/test/test_pathod.py
@@ -3,7 +3,7 @@ from netlib import tcp, http
import tutils
-class TestPathod:
+class TestPathod(object):
def test_logging(self):
p = pathod.Pathod(("127.0.0.1", 0))
assert len(p.get_log()) == 0
diff --git a/test/tutils.py b/test/tutils.py
index c1e55a61..18b5fb78 100644
--- a/test/tutils.py
+++ b/test/tutils.py
@@ -7,7 +7,7 @@ from libpathod import utils, test, pathoc, pathod, language
import requests
-class DaemonTests:
+class DaemonTests(object):
noweb = False
noapi = False
nohang = False
@@ -17,24 +17,24 @@ class DaemonTests:
ssloptions = None
@classmethod
- def setUpAll(self):
- opts = self.ssloptions or {}
- self.confdir = tempfile.mkdtemp()
- opts["confdir"] = self.confdir
+ def setUpAll(klass):
+ opts = klass.ssloptions or {}
+ klass.confdir = tempfile.mkdtemp()
+ opts["confdir"] = klass.confdir
so = pathod.SSLOptions(**opts)
- self.d = test.Daemon(
+ klass.d = test.Daemon(
staticdir=test_data.path("data"),
anchors=[
(re.compile("/anchor/.*"), language.parse_response("202:da"))
],
- ssl = self.ssl,
+ ssl = klass.ssl,
ssloptions = so,
sizelimit=1*1024*1024,
- noweb = self.noweb,
- noapi = self.noapi,
- nohang = self.nohang,
- timeout = self.timeout,
- hexdump = self.hexdump,
+ noweb = klass.noweb,
+ noapi = klass.noapi,
+ nohang = klass.nohang,
+ timeout = klass.timeout,
+ hexdump = klass.hexdump,
logreq = True,
logresp = True,
explain = True