diff --git a/libpathod/cmdline.py b/libpathod/cmdline.py index d89608a2e..22205fb7a 100644 --- a/libpathod/cmdline.py +++ b/libpathod/cmdline.py @@ -1,9 +1,8 @@ #!/usr/bin/env python -import itertools +import sys import argparse import os import os.path -import sys import re from netlib import http_uastrings from . import pathoc, pathod, version, utils, language diff --git a/libpathod/log.py b/libpathod/log.py index 8afb86eb9..523f431c2 100644 --- a/libpathod/log.py +++ b/libpathod/log.py @@ -14,6 +14,7 @@ def write(fp, lines): ) for i in lines: fp.write(i) + fp.write("\n") fp.flush() @@ -44,22 +45,13 @@ class Log: if rlog: self("Bytes read:") self.dump(rlog, self.hex) - if exc_type == netlib.tcp.NetLibTimeout: - self("Timeout") - elif exc_type in ( - netlib.tcp.NetLibDisconnect, - netlib.http.HttpErrorConnClosed - ): - self("Disconnected") - elif exc_type == netlib.http.HttpError: - self("HTTP Error: %s" % exc_value.message) - write( - self.fp, - [ - "\n".join(self.lines), - "\n" - ] - ) + if self.lines: + write( + self.fp, + [ + "\n".join(self.lines), + ] + ) if exc_value: raise exc_value diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 37e921e4a..ecf1d4d9a 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -346,10 +346,14 @@ class Pathoc(tcp.TCPClient): ) resp.append(self.sslinfo) resp = Response(*resp) + except http.HttpError, v: + log("Invalid server response: %s" % v) + raise except tcp.NetLibTimeout: if self.ignoretimeout: log("Timeout (ignored)") return None + log("Timeout") raise finally: if resp: diff --git a/libpathod/pathod.py b/libpathod/pathod.py index 991d3ae8c..3c42573d0 100644 --- a/libpathod/pathod.py +++ b/libpathod/pathod.py @@ -304,9 +304,10 @@ class PathodHandler(tcp.BaseHandler): )]) if anchor_gen: - lg("crafting spec: %s" % anchor_gen) + spec = anchor_gen.next() + lg("crafting spec: %s" % spec) nexthandler, retlog["response"] = self.http_serve_crafted( - anchor_gen.next() + spec ) if nexthandler and websocket_key: return self.handle_websocket, retlog diff --git a/test/test_log.py b/test/test_log.py index 5473236e3..9850654c6 100644 --- a/test/test_log.py +++ b/test/test_log.py @@ -16,7 +16,7 @@ def test_disconnect(): rw = DummyIO() try: with log.Log(outf, False, rw, rw) as lg: - raise netlib.tcp.NetLibDisconnect() + lg("Test") except netlib.tcp.NetLibDisconnect: pass - assert "Disconnected" in outf.getvalue() + assert "Test" in outf.getvalue() diff --git a/test/test_pathoc.py b/test/test_pathoc.py index 556aada51..21e46e8cb 100644 --- a/test/test_pathoc.py +++ b/test/test_pathoc.py @@ -145,7 +145,7 @@ class TestDaemon(_TestDaemon): assert "202" in self.tval(["get:'/p/202:b@1'"], ignorecodes=[200, 201]) def test_timeout(self): - assert "Timeout" in self.tval(["get:'/p/200:p0,10'"], timeout=0.01) + assert "Timeout" in self.tval(["get:'/p/200:p0,100'"], timeout=0.01) assert "HTTP" in self.tval( ["get:'/p/200:p5,100'"], showresp=True,