Author serhiy.storchaka
Recipients Pam.McANulty, fdrake, pitrou, serhiy.storchaka
Date 2015-02-14.13:10:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1423919445.35.0.834841125804.issue17530@psf.upfronthosting.co.za>
In-reply-to
Content
Here is a patch based on current str formatting code (i.e. parenthesis are added only if needed, the space at the right is used more efficiently). It adds pprint support for bytes and bytearrays. Bytes are broken only at positions divisible by 4, so packed 32-bit ints are never broken.

Examples:

>>> pprint.pprint(bytes(range(128)))
(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f\x10\x11\x12\x13'
 b'\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./01234567'
 b'89:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefghijklmnopqrstuvwxyz{'
 b'|}~\x7f')
>>> pprint.pprint({'abcdefgh': bytes(range(128))})
{'abcdefgh': b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
             b'\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
             b' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ['
             b'\\]^_`abcdefghijklmnopqrstuvwxyz{|}~\x7f'}
>>> pprint.pprint(bytearray(range(128)))
bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b\x0c\r\x0e\x0f'
          b'\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f'
          b' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_'
          b'`abcdefghijklmnopqrstuvwxyz{|}~\x7f')
>>> pprint.pprint({'abcdefgh': bytearray(range(128))})
{'abcdefgh': bytearray(b'\x00\x01\x02\x03\x04\x05\x06\x07\x08\t\n\x0b'
                       b'\x0c\r\x0e\x0f\x10\x11\x12\x13\x14\x15\x16\x17'
                       b'\x18\x19\x1a\x1b\x1c\x1d\x1e\x1f !"#$%&\'()*+,-./0123'
                       b'456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\]^_`abcdefg'
                       b'hijklmnopqrstuvwxyz{|}~\x7f')}
History
Date User Action Args
2015-02-14 13:10:45serhiy.storchakasetrecipients: + serhiy.storchaka, fdrake, pitrou, Pam.McANulty
2015-02-14 13:10:45serhiy.storchakasetmessageid: <1423919445.35.0.834841125804.issue17530@psf.upfronthosting.co.za>
2015-02-14 13:10:45serhiy.storchakalinkissue17530 messages
2015-02-14 13:10:45serhiy.storchakacreate