diff options
author | Guido van Rossum <guido@python.org> | 2007-04-13 03:33:53 (GMT) |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2007-04-13 03:33:53 (GMT) |
commit | 913dd0be52f28fbc5036d95722b80222880706fd (patch) | |
tree | ea58f81cd1650c849ce638d316628a1855040e12 | |
parent | 98f9746740e95bd0307a4a1a1f1adf69cc585e61 (diff) | |
download | cpython-913dd0be52f28fbc5036d95722b80222880706fd.zip cpython-913dd0be52f28fbc5036d95722b80222880706fd.tar.gz cpython-913dd0be52f28fbc5036d95722b80222880706fd.tar.bz2 |
struct.unpack() allows a bytes string too (if it has the right size).
-rw-r--r-- | Modules/_struct.c | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Modules/_struct.c b/Modules/_struct.c index 3418c30..5fc9991 100644 --- a/Modules/_struct.c +++ b/Modules/_struct.c @@ -1523,10 +1523,10 @@ fail: 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 @@ s_unpack(PyObject *self, PyObject *inputstr) 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, |