tests.py
def pprint_buf(buf):
    """ Dirty & convenient function to display the hexademical
        repr. of a buffer.
    """

    DEFAULT_SIZE = 4

    def hex2(i, l = None):
        l = l if l is not None else DEFAULT_SIZE

        h = hex(i).upper()[2:]
        
        if len(h) != l:
            h = "0" * (l - len(h)) + h
        
        return h

    def displayable_char(c):
        if ord(c) < 0x20 or ord(c) >= 0x7f:
            c = "."

        return c

    print " " * DEFAULT_SIZE,
    for i in range(16): print hex2(i, 2),
    print

    raws = []
    for i, c in enumerate(buf):
        if i % 16 == 0:
            if i:
                print "\t" + "".join(raws)
                raws = []

            print hex2(i),
        raws.append(displayable_char(c))
        
        print hex2(ord(c), 2),

    print "   " * (15 - (i % 16)) + "\t" + "".join(raws)
 Dirty & convenient function to display the hexademical
        repr. of a buffer.
    
Dirty & convenient function to display the hexademical
repr. of a buffer.
Dirty & convenient function to display the hexademical repr . of a buffer .
def pprint_buf(buf):
    DEFAULT_SIZE = 4
    def hex2(i, l = None):
        l = l if l is not None else DEFAULT_SIZE
        h = hex(i).upper()[2:]
        if len(h) != l:
            h = "0" * (l - len(h)) + h
        return h
    def displayable_char(c):
        if ord(c) < 0x20 or ord(c) >= 0x7f:
            c = "."
        return c
    print " " * DEFAULT_SIZE,
    for i in range(16): print hex2(i, 2),
    print
    raws = []
    for i, c in enumerate(buf):
        if i % 16 == 0:
            if i:
                print "\t" + "".join(raws)
                raws = []
            print hex2(i),
        raws.append(displayable_char(c))
        print hex2(ord(c), 2),
    print "   " * (15 - (i % 16)) + "\t" + "".join(raws)
def pprint_buf ( buf ) : DEFAULT_SIZE = 4 def hex2 ( i , l = None ) : l = l if l is not None else DEFAULT_SIZE h = hex ( i ) . upper ( ) [ 2 : ] if len ( h ) != l : h = "0" * ( l - len ( h ) ) + h return h def displayable_char ( c ) : if ord ( c ) < 0x20 or ord ( c ) >= 0x7f : c = "." return c print " " * DEFAULT_SIZE , for i in range ( 16 ) : print hex2 ( i , 2 ) , print raws = [ ] for i , c in enumerate ( buf ) : if i % 16 == 0 : if i : print "\t" + "" . join ( raws ) raws = [ ] print hex2 ( i ) , raws . append ( displayable_char ( c ) ) print hex2 ( ord ( c ) , 2 ) , print "   " * ( 15 - ( i % 16 ) ) + "\t" + "" . join ( raws )
Dirty & convenient function to display the hexademical
repr.
Dirty & convenient function to display the hexademical repr .
""" Dirty & convenient function to display the hexademical
        repr. of a buffer.
    """
buf