Changes by Martin Panter :
--
dependencies: +struct.Struct.format is bytes, but should be str -Document
whether it's safe to use bytes for struct format string
___
Python tracker
Martin Panter added the comment:
I think the direction to take for this depends on the outcome of Issue 21071.
First we have to decide if the “format” attribute is blessed as a byte string
(and not deprecated), or whether it is deprecated or changed to a text string.
Serhiy pointed out that
Changes by Arfrever Frehtes Taifersar Arahesis arfrever@gmail.com:
--
nosy: +Arfrever
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16349
___
Martin Panter added the comment:
Assuming it is intended to support byte strings, here is a patch that documents
them being allowed, and adds a test case
--
keywords: +patch
Added file: http://bugs.python.org/file37489/format-bytes.patch
___
Python
Martin Panter added the comment:
Actually the “struct” module doc string seems to already hint that format
strings can be byte strings:
“Python bytes objects are used to hold the data representing the C struct and
also as format strings . . .”
--
Martin Panter added the comment:
The issue of Struct.format being a byte string has been raised separately in
Issue 21071.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16349
___
Thomas Kluyver added the comment:
I'm happy to put together a docs patch, but I don't have any indication of the
right answer (is it a safe feature to use, or an implementation detail?) Is
there another venue where I should raise the question?
--
Serhiy Storchaka added the comment:
Python 2 supports only str. Support for unicode objects has been added in
r59687 (merged with other unrelated changes in changeset 13aabc23cf2e). Maybe
Raymond can explain why the type for the Struct.format was chosen bytes, not
unicode.
--
Serhiy Storchaka added the comment:
No, this is not r59687. I can't found from which revision in 59680-59695 it
came.
--
nosy: +christian.heimes
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16349
Mark Dickinson added the comment:
but also discovered that example outputs are wrong
That's documented to some extent: there's a line in the docs that says:
All examples assume a native byte order, size, and alignment with a big-endian
machine.
Given that little-endian machines are much
Mark Dickinson added the comment:
Also it would be nice to clarify if struct.Struct.format is meant to be a
byte string.
Hmm. That seems wrong to me. After all, the format string is supposed to be a
piece of human-readable text rather than a collection of bytes. I think it's
borderline
Terry J. Reedy added the comment:
I think the example should be switched *and* the formats should specify the
endianess so the examples work on all systems.
--
___
Python tracker rep...@bugs.python.org
http://bugs.python.org/issue16349
Terry J. Reedy added the comment:
For 3.3, I verified that adding b prefix to first three doc examples gives same
output as without, but also discovered that example outputs are wrong, at least
on windows, because of byte ordering issues.
pack('hhl', 1, 2, 3)
New submission from Thomas Kluyver:
At least in CPython, format strings can be given as bytes, as an alternative to
str. E.g.
struct.unpack(b'hhl', b'\x00\x01\x00\x02\x00\x00\x00\x03')
(1, 2, 3)
Looking at the source code [1], this appears to be consciously accounted for.
But it doesn't
Martin Panter added the comment:
Also it would be nice to clarify if struct.Struct.format is meant to be a byte
string. Reading the documentation and examples I expected a character string.
It was an issue for me when embedding one structure within another:
HSF_VOL_DESC = Struct( B 5s B)
#
15 matches
Mail list logo