tool.py.ed   [plain text]


/def main/i
class NullsInString(Exception):
    """Nulls in string."""

_FILTER=''.join([(len(repr(chr(x)))==3) and chr(x) or '.' for x in range(256)])

def _dump(src, length=16):
    result=[]
    for i in xrange(0, len(src), length):
        s = src[i:i+length]
        hexa = ' '.join(["%02X"%ord(x) for x in s])
        printable = s.translate(_FILTER)
        result.append("%04X   %-*s   %s\n" % (i, length*3, hexa, printable))
    return ''.join(result)

.
/print ""\.join((file_prefix, "/s/^/    /
i
                        try:
                            if attrs[attr_name].find('\0') >= 0:
                                raise NullsInString;
.
.+1a
                        except (UnicodeDecodeError, NullsInString):
                            print "".join((file_prefix, "%s:" % (attr_name,)))
                            print _dump(attrs[attr_name])
.
w