[issue3982] support .format for bytes

2012-06-21 Thread Uoti Urpala

Uoti Urpala uoti.urp...@pp1.inet.fi added the comment:

I've hit this limitation a couple more times, and none of the proposed 
workarounds are adequate. Working with protocols and file formats that use 
human-readable markup is significantly clumsier than it was with Python 2 
(using either the % operator, which also lost its support for byte strings in 
Python 3, or .format()).

This bug report was closed by its original creator, after early posts where IMO 
nobody made as good a case for the feature as they could have. Is it possible 
to reopen this bug or is it necessary to file a new one?

Is there any clear argument AGAINST having .format() for bytes, other than work 
needed to implement it? Some posts mention mixing characters and bytes, but I 
see no reason why this would be much of a real practical concern if it's a 
method on bytes objects producing bytes output.

--

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue3982
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue3982] support .format for bytes

2011-01-27 Thread Uoti Urpala

Uoti Urpala uoti.urp...@pp1.inet.fi added the comment:

This kind of formatting is needed quite often when working on network protocols 
or file formats, and I think the replies here fail to address important issues. 
In general you can't encode after formatting, as that doesn't work with binary 
data, and often it's not appropriate for the low-level routines doing the 
formatting to know what charset the data is in even if it is text (so it should 
be fed in already encoded as bytes). The replies from Martin v. Löwis seem to 
argue that you could use methods other than formatting; that would work almost 
as well as an argument to remove formatting support from text strings, and IMO 
cases where formatting is the best option are common.

Here's an example (based on real use but simplified):

template = b
stuff here
header1: {}
header2: {}
more stuff


def lowlevel_send(s, b1, b2):  # s socket, b1 and b2 bytes
s.send(template.format(b1, b2))

To clarify the requirements a bit, the issue is not so much about having a 
.format method on byte string objects (that's just the most natural-looking way 
of solving it); the core requirement is to have a formatting operator that can 
take byte strings as *arguments* and produce byte string *output* where the 
arguments can be placed unchanged.

--
nosy: +uau

___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue3982
___
___
Python-bugs-list mailing list
Unsubscribe: 
http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com