Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1ff6b6a

Browse files
committed
merge heads
2 parents ad45ab8 + b030991 commit 1ff6b6a

2 files changed

Lines changed: 19 additions & 18 deletions

File tree

Doc/library/struct.rst

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -62,25 +62,25 @@ The module defines the following exception and functions:
6262

6363
Unpack from the buffer *buffer* (presumably packed by ``pack(fmt, ...)``)
6464
according to the format string *fmt*. The result is a tuple even if it
65-
contains exactly one item. The buffer must contain exactly the amount of
66-
data required by the format (``len(bytes)`` must equal ``calcsize(fmt)``).
65+
contains exactly one item. The buffer's size in bytes must match the
66+
size required by the format, as reflected by :func:`calcsize`.
6767

6868

6969
.. function:: unpack_from(fmt, buffer, offset=0)
7070

7171
Unpack from *buffer* starting at position *offset*, according to the format
7272
string *fmt*. The result is a tuple even if it contains exactly one
73-
item. *buffer* must contain at least the amount of data required by the
74-
format (``len(buffer[offset:])`` must be at least ``calcsize(fmt)``).
73+
item. The buffer's size in bytes, minus *offset*, must be at least
74+
the size required by the format, as reflected by :func:`calcsize`.
7575

7676

7777
.. function:: iter_unpack(fmt, buffer)
7878

7979
Iteratively unpack from the buffer *buffer* according to the format
8080
string *fmt*. This function returns an iterator which will read
8181
equally-sized chunks from the buffer until all its contents have been
82-
consumed. The buffer's size in bytes must be a multiple of the amount
83-
of data required by the format, as reflected by :func:`calcsize`.
82+
consumed. The buffer's size in bytes must be a multiple of the size
83+
required by the format, as reflected by :func:`calcsize`.
8484

8585
Each iteration yields a tuple as specified by the format string.
8686

@@ -389,7 +389,7 @@ The :mod:`struct` module also defines the following type:
389389
.. method:: pack(v1, v2, ...)
390390

391391
Identical to the :func:`pack` function, using the compiled format.
392-
(``len(result)`` will equal :attr:`self.size`.)
392+
(``len(result)`` will equal :attr:`size`.)
393393

394394

395395
.. method:: pack_into(buffer, offset, v1, v2, ...)
@@ -400,19 +400,20 @@ The :mod:`struct` module also defines the following type:
400400
.. method:: unpack(buffer)
401401

402402
Identical to the :func:`unpack` function, using the compiled format.
403-
(``len(buffer)`` must equal :attr:`self.size`).
403+
The buffer's size in bytes must equal :attr:`size`.
404404

405405

406406
.. method:: unpack_from(buffer, offset=0)
407407

408408
Identical to the :func:`unpack_from` function, using the compiled format.
409-
(``len(buffer[offset:])`` must be at least :attr:`self.size`).
409+
The buffer's size in bytes, minus *offset*, must be at least
410+
:attr:`size`.
410411

411412

412413
.. method:: iter_unpack(buffer)
413414

414415
Identical to the :func:`iter_unpack` function, using the compiled format.
415-
(``len(buffer)`` must be a multiple of :attr:`self.size`).
416+
The buffer's size in bytes must be a multiple of :attr:`size`.
416417

417418
.. versionadded:: 3.4
418419

Modules/_struct.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1497,8 +1497,8 @@ PyDoc_STRVAR(s_unpack__doc__,
14971497
"S.unpack(buffer) -> (v1, v2, ...)\n\
14981498
\n\
14991499
Return a tuple containing values unpacked according to the format\n\
1500-
string S.format. Requires len(buffer) == S.size. See help(struct)\n\
1501-
for more on format strings.");
1500+
string S.format. The buffer's size in bytes must be S.size. See\n\
1501+
help(struct) for more on format strings.");
15021502

15031503
static PyObject *
15041504
s_unpack(PyObject *self, PyObject *input)
@@ -1527,8 +1527,8 @@ PyDoc_STRVAR(s_unpack_from__doc__,
15271527
"S.unpack_from(buffer, offset=0) -> (v1, v2, ...)\n\
15281528
\n\
15291529
Return a tuple containing values unpacked according to the format\n\
1530-
string S.format. Requires len(buffer[offset:]) >= S.size. See\n\
1531-
help(struct) for more on format strings.");
1530+
string S.format. The buffer's size in bytes, minus offset, must be at\n\
1531+
least S.size. See help(struct) for more on format strings.");
15321532

15331533
static PyObject *
15341534
s_unpack_from(PyObject *self, PyObject *args, PyObject *kwds)
@@ -2130,8 +2130,8 @@ PyDoc_STRVAR(unpack_doc,
21302130
"unpack(fmt, buffer) -> (v1, v2, ...)\n\
21312131
\n\
21322132
Return a tuple containing values unpacked according to the format string\n\
2133-
fmt. Requires len(buffer) == calcsize(fmt). See help(struct) for more\n\
2134-
on format strings.");
2133+
fmt. The buffer's size in bytes must be calcsize(fmt). See help(struct)\n\
2134+
for more on format strings.");
21352135

21362136
static PyObject *
21372137
unpack(PyObject *self, PyObject *args)
@@ -2153,8 +2153,8 @@ PyDoc_STRVAR(unpack_from_doc,
21532153
"unpack_from(fmt, buffer, offset=0) -> (v1, v2, ...)\n\
21542154
\n\
21552155
Return a tuple containing values unpacked according to the format string\n\
2156-
fmt. Requires len(buffer[offset:]) >= calcsize(fmt). See help(struct)\n\
2157-
for more on format strings.");
2156+
fmt. The buffer's size, minus offset, must be at least calcsize(fmt).\n\
2157+
See help(struct) for more on format strings.");
21582158

21592159
static PyObject *
21602160
unpack_from(PyObject *self, PyObject *args, PyObject *kwds)

0 commit comments

Comments
 (0)