diff options
Diffstat (limited to 'libpathod/pathoc.py')
-rw-r--r-- | libpathod/pathoc.py | 26 |
1 files changed, 18 insertions, 8 deletions
diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index f79ed3af..7af5a288 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -6,11 +6,11 @@ class PathocError(Exception): pass def print_short(fp, httpversion, code, msg, headers, content): - print >> fp, "%s %s: %s bytes"%(code, msg, len(content)) + print >> fp, "<< %s %s: %s bytes"%(code, msg, len(content)) def print_full(fp, httpversion, code, msg, headers, content): - print >> fp, "HTTP%s/%s %s %s"%(httpversion[0], httpversion[1], code, msg) + print >> fp, "<< HTTP%s/%s %s %s"%(httpversion[0], httpversion[1], code, msg) print >> fp, headers print >> fp, content @@ -26,18 +26,28 @@ class Pathoc(tcp.TCPClient): May raise rparse.ParseException and netlib.http.HttpError. """ r = rparse.parse_request({}, spec) - r.serve(self.wfile) + ret = r.serve(self.wfile) self.wfile.flush() return http.read_response(self.rfile, r.method, None) - def print_requests(self, reqs, verbose, fp=sys.stdout): + def print_requests(self, reqs, respdump, reqdump, fp=sys.stdout): """ Performs a series of requests, and prints results to the specified file pointer. """ for i in reqs: try: - ret = self.request(i) + r = rparse.parse_request({}, i) + req = r.serve(self.wfile) + if reqdump: + print >> fp, ">>", req["method"], req["path"] + for a in req["actions"]: + print >> fp, "\t", + for x in a: + print x, + print + self.wfile.flush() + resp = self.request(i) except rparse.ParseException, v: print >> fp, "Error parsing request spec: %s"%v.msg print >> fp, v.marked() @@ -48,7 +58,7 @@ class Pathoc(tcp.TCPClient): except tcp.NetLibTimeout: print >> fp, "Timeout" else: - if verbose: - print_full(fp, *ret) + if respdump: + print_full(fp, *resp) else: - print_short(fp, *ret) + print_short(fp, *resp) |