[Python-checkins] cpython (merge 3.5 -> default): Issue #26535: Merge struct doc from 3.5

martin.panter python-checkins at python.org
Fri Apr 15 19:45:29 EDT 2016


https://hg.python.org/cpython/rev/39dc2f39373d
changeset: 100993:39dc2f39373d
parent: 100991:b3e3efc5afa4
parent: 100992:7889fcb0697b
user: Martin Panter <vadmium+py at gmail.com>
date: Fri Apr 15 23:16:51 2016 +0000
summary:
 Issue #26535: Merge struct doc from 3.5
files:
 Doc/library/struct.rst | 21 +++++++++++----------
 Modules/_struct.c | 16 ++++++++--------
 2 files changed, 19 insertions(+), 18 deletions(-)
diff --git a/Doc/library/struct.rst b/Doc/library/struct.rst
--- a/Doc/library/struct.rst
+++ b/Doc/library/struct.rst
@@ -62,16 +62,16 @@
 
 Unpack from the buffer *buffer* (presumably packed by ``pack(fmt, ...)``)
 according to the format string *fmt*. The result is a tuple even if it
- contains exactly one item. The buffer must contain exactly the amount of
- data required by the format (``len(bytes)`` must equal ``calcsize(fmt)``).
+ contains exactly one item. The buffer's size in bytes must match the
+ size required by the format, as reflected by :func:`calcsize`.
 
 
 .. function:: unpack_from(fmt, buffer, offset=0)
 
 Unpack from *buffer* starting at position *offset*, according to the format
 string *fmt*. The result is a tuple even if it contains exactly one
- item. *buffer* must contain at least the amount of data required by the
- format (``len(buffer[offset:])`` must be at least ``calcsize(fmt)``).
+ item. The buffer's size in bytes, minus *offset*, must be at least
+ the size required by the format, as reflected by :func:`calcsize`.
 
 
 .. function:: iter_unpack(fmt, buffer)
@@ -79,8 +79,8 @@
 Iteratively unpack from the buffer *buffer* according to the format
 string *fmt*. This function returns an iterator which will read
 equally-sized chunks from the buffer until all its contents have been
- consumed. The buffer's size in bytes must be a multiple of the amount
- of data required by the format, as reflected by :func:`calcsize`.
+ consumed. The buffer's size in bytes must be a multiple of the size
+ required by the format, as reflected by :func:`calcsize`.
 
 Each iteration yields a tuple as specified by the format string.
 
@@ -389,7 +389,7 @@
 .. method:: pack(v1, v2, ...)
 
 Identical to the :func:`pack` function, using the compiled format.
- (``len(result)`` will equal :attr:`self.size`.)
+ (``len(result)`` will equal :attr:`size`.)
 
 
 .. method:: pack_into(buffer, offset, v1, v2, ...)
@@ -400,19 +400,20 @@
 .. method:: unpack(buffer)
 
 Identical to the :func:`unpack` function, using the compiled format.
- (``len(buffer)`` must equal :attr:`self.size`).
+ The buffer's size in bytes must equal :attr:`size`.
 
 
 .. method:: unpack_from(buffer, offset=0)
 
 Identical to the :func:`unpack_from` function, using the compiled format.
- (``len(buffer[offset:])`` must be at least :attr:`self.size`).
+ The buffer's size in bytes, minus *offset*, must be at least
+ :attr:`size`.
 
 
 .. method:: iter_unpack(buffer)
 
 Identical to the :func:`iter_unpack` function, using the compiled format.
- (``len(buffer)`` must be a multiple of :attr:`self.size`).
+ The buffer's size in bytes must be a multiple of :attr:`size`.
 
 .. versionadded:: 3.4
 
diff --git a/Modules/_struct.c b/Modules/_struct.c
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -1497,8 +1497,8 @@
 "S.unpack(buffer) -> (v1, v2, ...)\n\
 \n\
 Return a tuple containing values unpacked according to the format\n\
-string S.format. Requires len(buffer) == S.size. See help(struct)\n\
-for more on format strings.");
+string S.format. The buffer's size in bytes must be S.size. See\n\
+help(struct) for more on format strings.");
 
 static PyObject *
 s_unpack(PyObject *self, PyObject *input)
@@ -1527,8 +1527,8 @@
 "S.unpack_from(buffer, offset=0) -> (v1, v2, ...)\n\
 \n\
 Return a tuple containing values unpacked according to the format\n\
-string S.format. Requires len(buffer[offset:]) >= S.size. See\n\
-help(struct) for more on format strings.");
+string S.format. The buffer's size in bytes, minus offset, must be at\n\
+least S.size. See help(struct) for more on format strings.");
 
 static PyObject *
 s_unpack_from(PyObject *self, PyObject *args, PyObject *kwds)
@@ -2130,8 +2130,8 @@
 "unpack(fmt, buffer) -> (v1, v2, ...)\n\
 \n\
 Return a tuple containing values unpacked according to the format string\n\
-fmt. Requires len(buffer) == calcsize(fmt). See help(struct) for more\n\
-on format strings.");
+fmt. The buffer's size in bytes must be calcsize(fmt). See help(struct)\n\
+for more on format strings.");
 
 static PyObject *
 unpack(PyObject *self, PyObject *args)
@@ -2153,8 +2153,8 @@
 "unpack_from(fmt, buffer, offset=0) -> (v1, v2, ...)\n\
 \n\
 Return a tuple containing values unpacked according to the format string\n\
-fmt. Requires len(buffer[offset:]) >= calcsize(fmt). See help(struct)\n\
-for more on format strings.");
+fmt. The buffer's size, minus offset, must be at least calcsize(fmt).\n\
+See help(struct) for more on format strings.");
 
 static PyObject *
 unpack_from(PyObject *self, PyObject *args, PyObject *kwds)
-- 
Repository URL: https://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /