diff options
author | Aldo Cortesi <aldo@nullcube.com> | 2012-07-24 00:00:55 +1200 |
---|---|---|
committer | Aldo Cortesi <aldo@nullcube.com> | 2012-07-24 00:00:55 +1200 |
commit | 2dd2137d44d0bc7e3e25d4ce14610acfe88cb4f2 (patch) | |
tree | 97c49e177c3913adf7ef4fbba73f999c01d20ca3 | |
parent | a950a4d7a3097685d54f325f32a169034e9435f1 (diff) | |
download | mitmproxy-2dd2137d44d0bc7e3e25d4ce14610acfe88cb4f2.tar.gz mitmproxy-2dd2137d44d0bc7e3e25d4ce14610acfe88cb4f2.tar.bz2 mitmproxy-2dd2137d44d0bc7e3e25d4ce14610acfe88cb4f2.zip |
Better handling of binary data output by pathoc.
-rw-r--r-- | libpathod/pathoc.py | 10 | ||||
-rw-r--r-- | libpathod/utils.py | 4 |
2 files changed, 9 insertions, 5 deletions
diff --git a/libpathod/pathoc.py b/libpathod/pathoc.py index 3e5204c2..8fe7b7f6 100644 --- a/libpathod/pathoc.py +++ b/libpathod/pathoc.py @@ -1,18 +1,18 @@ import sys, os from netlib import tcp, http -import rparse +import rparse, utils 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, utils.xrepr(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, headers - print >> fp, content + print >> fp, "<< HTTP%s/%s %s %s"%(httpversion[0], httpversion[1], code, utils.xrepr(msg)) + print >> fp, utils.escape_unprintables(str(headers)) + print >> fp, utils.escape_unprintables(content) class Pathoc(tcp.TCPClient): diff --git a/libpathod/utils.py b/libpathod/utils.py index 40f37cab..1ee50b83 100644 --- a/libpathod/utils.py +++ b/libpathod/utils.py @@ -41,6 +41,10 @@ def parse_anchor_spec(s): return tuple(s.split("=", 1)) +def xrepr(s): + return repr(s)[1:-1] + + def escape_unprintables(s): s = s.replace("\r\n", "PATHOD_MARKER_RN") s = s.replace("\n", "PATHOD_MARKER_N") |