[issue3982] support .format for bytes

2011-03-07 Thread Arjen Nienhuis
Arjen Nienhuis added the comment: struct.pack does not work with variable length data. Something like: b'{0:x}\r\n{1}\r\n'.format(len(block), block) or b'%x\r\n%s\r\n' % (len(block), block) is not possible with struct.pack -- __

[issue3982] support .format for bytes

2009-07-11 Thread Arjen Nienhuis
Arjen Nienhuis added the comment: > def chunk(block): >   return hex(len(block)).encode('ascii') + b'\r\n' + block + b'\r\n' hex(10) returns '0xa' instead of 'a'. > This doesn't need any format call, and describes adequatly how t

[issue3982] support .format for bytes

2009-07-11 Thread Arjen Nienhuis
Arjen Nienhuis 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