Better handling of binary data output by pathoc.
This commit is contained in:
parent
a950a4d7a3
commit
2dd2137d44
|
@ -1,18 +1,18 @@
|
||||||
import sys, os
|
import sys, os
|
||||||
from netlib import tcp, http
|
from netlib import tcp, http
|
||||||
import rparse
|
import rparse, utils
|
||||||
|
|
||||||
class PathocError(Exception): pass
|
class PathocError(Exception): pass
|
||||||
|
|
||||||
|
|
||||||
def print_short(fp, httpversion, code, msg, headers, content):
|
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):
|
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, utils.xrepr(msg))
|
||||||
print >> fp, headers
|
print >> fp, utils.escape_unprintables(str(headers))
|
||||||
print >> fp, content
|
print >> fp, utils.escape_unprintables(content)
|
||||||
|
|
||||||
|
|
||||||
class Pathoc(tcp.TCPClient):
|
class Pathoc(tcp.TCPClient):
|
||||||
|
|
|
@ -41,6 +41,10 @@ def parse_anchor_spec(s):
|
||||||
return tuple(s.split("=", 1))
|
return tuple(s.split("=", 1))
|
||||||
|
|
||||||
|
|
||||||
|
def xrepr(s):
|
||||||
|
return repr(s)[1:-1]
|
||||||
|
|
||||||
|
|
||||||
def escape_unprintables(s):
|
def escape_unprintables(s):
|
||||||
s = s.replace("\r\n", "PATHOD_MARKER_RN")
|
s = s.replace("\r\n", "PATHOD_MARKER_RN")
|
||||||
s = s.replace("\n", "PATHOD_MARKER_N")
|
s = s.replace("\n", "PATHOD_MARKER_N")
|
||||||
|
|
Loading…
Reference in New Issue