def print_codepoint_stream(codepoint_stream, display_block_count=8, no_repr=False):
    """
    >>> def g(txt):
    ...     for c in txt: yield ord(c)
    >>> codepoint_stream = g("HELLO!")
    >>> print_codepoint_stream(codepoint_stream)
    ... # doctest: +NORMALIZE_WHITESPACE
       6 | 0x48 'H' | 0x45 'E' | 0x4c 'L' | 0x4c 'L' | 0x4f 'O' | 0x21 '!' |
    """
    in_line_count = 0

    line = []
    for no, codepoint in enumerate(codepoint_stream, 1):
        r = repr(chr(codepoint))
        if "\\x" in r: # FIXME
            txt = "%s %i" % (hex(codepoint), codepoint)
        else:
            txt = "%s %s" % (hex(codepoint), r)

        line.append(txt.center(8))

        in_line_count += 1
        if in_line_count >= display_block_count:
            in_line_count = 0
            print "%4s | %s |" % (no, " | ".join(line))
            line = []
    if line:
        print "%4s | %s |" % (no, " | ".join(line))

    if in_line_count > 0:
        print
def print_codepoint_stream ( codepoint_stream , display_block_count = 8 , no_repr = False ) : in_line_count = 0 line = [ ] for no , codepoint in enumerate ( codepoint_stream , 1 ) : r = repr ( chr ( codepoint ) ) if "\\x" in r : txt = "%s %i" % ( hex ( codepoint ) , codepoint ) else : txt = "%s %s" % ( hex ( codepoint ) , r ) line . append ( txt . center ( 8 ) ) in_line_count += 1 if in_line_count >= display_block_count : in_line_count = 0 print "%4s | %s |" % ( no , " | " . join ( line ) ) line = [ ] if line : print "%4s | %s |" % ( no , " | " . join ( line ) ) if in_line_count > 0 : print
>>> def g(txt):
    ...     for c in txt: yield ord(c)
    >>> codepoint_stream = g("HELLO!")
    >>> print_codepoint_stream(codepoint_stream)
    ... # doctest: +NORMALIZE_WHITESPACE
       6 | 0x48 'H' | 0x45 'E' | 0x4c 'L' | 0x4c 'L' | 0x4f 'O' | 0x21 '!' |