[issue3982] support .format for bytes
Arjen Nienhuis
report at bugs.python.org
Sat Jul 11 15:54:40 CEST 2009
Arjen Nienhuis <a.g.nienhuis at gmail.com> added the comment:
There are many binary formats that use ASCII numbers.
'HTTP chunking' uses ASCII mixed with binary (octets).
With 2.6 you could write:
def chunk(block):
return b'{0:x}\r\n{1}\r\n'.format(len(block), block)
With 3.0 you'd have to write this:
def chunk(block):
return format(len(block), 'x').encode('ascii') + b'\r\n' + block +
b'\r\n'
You cannot convert to ascii at the end of the pipeline as there are
bytes > 127 in the data blocks.
----------
nosy: +arjennienhuis
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3982>
_______________________________________
More information about the Python-bugs-list
mailing list