diff --git a/libpathod/cmdline.py b/libpathod/cmdline.py index 3323716c8..bd6a43608 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 7aa6565c0..5c53453d5 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 08efdb3d5..616550fae 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 + resp = None + else: + if self.explain: + print >> self.fp, ">> Spec:", r.spec() - 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 de6bde3a8..07354aa8c 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 598b2c81c..90f798c95 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 3638960ef..c32f6e84c 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 c1e55a613..18b5fb782 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