From 8bb81be2b07b4b93a8ec7c088bf1ff4728fcec21 Mon Sep 17 00:00:00 2001 From: Aldo Cortesi Date: Fri, 28 Sep 2012 11:38:49 +1200 Subject: [PATCH] Add pathoc -T to ignore timeouts. Also move -c to -C for consistency. --- libpathod/pathoc.py | 4 +++- pathoc | 9 +++++++-- test/test_pathoc.py | 3 ++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 90f3b98bd..7551c589f 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -38,7 +38,7 @@ class Pathoc(tcp.TCPClient): print >> fp, "%s (unprintables escaped):"%header print >> fp, netlib.utils.cleanBin(data) - def print_request(self, spec, showreq, showresp, explain, hexdump, ignorecodes, fp=sys.stdout): + def print_request(self, spec, showreq, showresp, explain, hexdump, ignorecodes, ignoretimeout, fp=sys.stdout): """ Performs a series of requests, and prints results to the specified file descriptor. @@ -74,6 +74,8 @@ class Pathoc(tcp.TCPClient): except http.HttpError, v: print >> fp, "<< HTTP Error:", v.msg except tcp.NetLibTimeout: + if ignoretimeout: + return print >> fp, "<<", "Timeout" except tcp.NetLibDisconnect: # pragma: nocover print >> fp, "<<", "Disconnect" diff --git a/pathoc b/pathoc index a2749a599..5932d4a45 100755 --- a/pathoc +++ b/pathoc @@ -35,7 +35,7 @@ if __name__ == "__main__": ) group = parser.add_argument_group('Controlling Output') group.add_argument( - "-c", dest="ignorecodes", type=str, default="", + "-C", dest="ignorecodes", type=str, default="", help="Comma-separated list of response codes to ignore" ) group.add_argument( @@ -54,6 +54,10 @@ if __name__ == "__main__": "-r", dest="showresp", action="store_true", default=False, help="Print full response" ) + group.add_argument( + "-T", dest="ignoretimeout", action="store_true", default=False, + help="Ignore timeouts" + ) group.add_argument( "-x", dest="hexdump", action="store_true", default=False, help="Output in hexdump format" @@ -94,7 +98,8 @@ if __name__ == "__main__": showresp=args.showresp, explain=args.explain, hexdump=args.hexdump, - ignorecodes=codes + ignorecodes=codes, + ignoretimeout=args.ignoretimeout ) sys.stdout.flush() if ret and args.oneshot: diff --git a/test/test_pathoc.py b/test/test_pathoc.py index e9690dd58..1c64f076f 100644 --- a/test/test_pathoc.py +++ b/test/test_pathoc.py @@ -24,7 +24,7 @@ class TestDaemon: _, _, _, _, content = c.request("get:/api/info") assert tuple(json.loads(content)["version"]) == version.IVERSION - def tval(self, requests, showreq=False, showresp=False, explain=False, hexdump=False, timeout=None, ignorecodes=None): + def tval(self, requests, showreq=False, showresp=False, explain=False, hexdump=False, timeout=None, ignorecodes=None, ignoretimeout=None): c = pathoc.Pathoc("127.0.0.1", self.d.port) c.connect() if timeout: @@ -38,6 +38,7 @@ class TestDaemon: explain = explain, hexdump = hexdump, ignorecodes = ignorecodes, + ignoretimeout = ignoretimeout, fp = s ) return s.getvalue()