[Python-3000-checkins] r54802 - python/branches/p3yk/Modules/_struct.c
guido.van.rossum
python-3000-checkins at python.org
Fri Apr 13 05:34:00 CEST 2007
Author: guido.van.rossum
Date: Fri Apr 13 05:33:53 2007
New Revision: 54802
Modified:
python/branches/p3yk/Modules/_struct.c
Log:
struct.unpack() allows a bytes string too (if it has the right size).
Modified: python/branches/p3yk/Modules/_struct.c
==============================================================================
--- python/branches/p3yk/Modules/_struct.c (original)
+++ python/branches/p3yk/Modules/_struct.c Fri Apr 13 05:33:53 2007
@@ -1523,10 +1523,10 @@
PyDoc_STRVAR(s_unpack__doc__,
-"S.unpack(str) -> (v1, v2, ...)\n\
+"S.unpack(buffer) -> (v1, v2, ...)\n\
\n\
Return tuple containing values unpacked according to this Struct's format.\n\
-Requires len(str) == self.size. See struct.__doc__ for more on format\n\
+Requires len(buffer) == self.size. See struct.__doc__ for more on format\n\
strings.");
static PyObject *
@@ -1535,6 +1535,10 @@
PyStructObject *soself = (PyStructObject *)self;
assert(PyStruct_Check(self));
assert(soself->s_codes != NULL);
+ if (inputstr != NULL && PyBytes_Check(inputstr) &&
+ PyBytes_GET_SIZE(inputstr) == soself->s_size) {
+ return s_unpack_internal(soself, PyBytes_AS_STRING(inputstr));
+ }
if (inputstr == NULL || !PyString_Check(inputstr) ||
PyString_GET_SIZE(inputstr) != soself->s_size) {
PyErr_Format(StructError,
More information about the Python-3000-checkins
mailing list