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

Skip to content

Commit cf297e4

Browse files
committed
Merged revisions 53623-53858 via svnmerge from
svn+ssh://[email protected]/python/trunk ........ r53624 | peter.astrand | 2007-02-02 20:06:36 +0100 (Fri, 02 Feb 2007) | 1 line We had several if statements checking the value of a fd. This is unsafe, since valid fds might be zero. We should check for not None instead. ........ r53635 | kurt.kaiser | 2007-02-05 07:03:18 +0100 (Mon, 05 Feb 2007) | 2 lines Add 'raw' support to configHandler. Patch 1650174 Tal Einat. ........ r53641 | kurt.kaiser | 2007-02-06 00:02:16 +0100 (Tue, 06 Feb 2007) | 5 lines 1. Calltips now 'handle' tuples in the argument list (display '<tuple>' :) Suggested solution by Christos Georgiou, Bug 791968. 2. Clean up tests, were not failing when they should have been. 4. Remove some camelcase and an unneeded try/except block. ........ r53644 | kurt.kaiser | 2007-02-06 04:21:40 +0100 (Tue, 06 Feb 2007) | 2 lines Clean up ModifiedInterpreter.runcode() structure ........ r53646 | peter.astrand | 2007-02-06 16:37:50 +0100 (Tue, 06 Feb 2007) | 1 line Applied patch 1124861.3.patch to solve bug #1124861: Automatically create pipes on Windows, if GetStdHandle fails. Will backport. ........ r53648 | lars.gustaebel | 2007-02-06 19:38:13 +0100 (Tue, 06 Feb 2007) | 4 lines Patch #1652681: create nonexistent files in append mode and allow appending to empty files. ........ r53649 | kurt.kaiser | 2007-02-06 20:09:43 +0100 (Tue, 06 Feb 2007) | 4 lines Updated patch (CodeContext.061217.patch) to [ 1362975 ] CodeContext - Improved text indentation Tal Einat 16Dec06 ........ r53650 | kurt.kaiser | 2007-02-06 20:21:19 +0100 (Tue, 06 Feb 2007) | 2 lines narrow exception per [ 1540849 ] except too broad ........ r53653 | kurt.kaiser | 2007-02-07 04:39:41 +0100 (Wed, 07 Feb 2007) | 4 lines [ 1621265 ] Auto-completion list placement Move AC window below input line unless not enough space, then put it above. Patch: Tal Einat ........ r53654 | kurt.kaiser | 2007-02-07 09:07:13 +0100 (Wed, 07 Feb 2007) | 2 lines Handle AttributeError during calltip lookup ........ r53656 | raymond.hettinger | 2007-02-07 21:08:22 +0100 (Wed, 07 Feb 2007) | 3 lines SF #1615701: make d.update(m) honor __getitem__() and keys() in dict subclasses ........ r53658 | raymond.hettinger | 2007-02-07 22:04:20 +0100 (Wed, 07 Feb 2007) | 1 line SF: 1397711 Set docs conflated immutable and hashable ........ r53660 | raymond.hettinger | 2007-02-07 22:42:17 +0100 (Wed, 07 Feb 2007) | 1 line Check for a common user error with defaultdict(). ........ r53662 | raymond.hettinger | 2007-02-07 23:24:07 +0100 (Wed, 07 Feb 2007) | 1 line Bug #1575169: operator.isSequenceType() now returns False for subclasses of dict. ........ r53664 | raymond.hettinger | 2007-02-08 00:49:03 +0100 (Thu, 08 Feb 2007) | 1 line Silence compiler warning ........ r53666 | raymond.hettinger | 2007-02-08 01:07:32 +0100 (Thu, 08 Feb 2007) | 1 line Do not let overflows in enumerate() and count() pass silently. ........ r53668 | raymond.hettinger | 2007-02-08 01:50:39 +0100 (Thu, 08 Feb 2007) | 1 line Bypass set specific optimizations for set and frozenset subclasses. ........ r53670 | raymond.hettinger | 2007-02-08 02:42:35 +0100 (Thu, 08 Feb 2007) | 1 line Fix docstring bug ........ r53671 | martin.v.loewis | 2007-02-08 10:13:36 +0100 (Thu, 08 Feb 2007) | 3 lines Bug #1653736: Complain about keyword arguments to time.isoformat. Will backport to 2.5. ........ r53679 | kurt.kaiser | 2007-02-08 23:58:18 +0100 (Thu, 08 Feb 2007) | 6 lines Corrected some bugs in AutoComplete. Also, Page Up/Down in ACW implemented; mouse and cursor selection in ACWindow implemented; double Tab inserts current selection and closes ACW (similar to double-click and Return); scroll wheel now works in ACW. Added AutoComplete instructions to IDLE Help. ........ r53689 | martin.v.loewis | 2007-02-09 13:19:32 +0100 (Fri, 09 Feb 2007) | 3 lines Bug #1653736: Properly discard third argument to slot_nb_inplace_power. Will backport. ........ r53691 | martin.v.loewis | 2007-02-09 13:36:48 +0100 (Fri, 09 Feb 2007) | 4 lines Bug #1600860: Search for shared python library in LIBDIR, not lib/python/config, on "linux" and "gnu" systems. Will backport. ........ r53693 | martin.v.loewis | 2007-02-09 13:58:49 +0100 (Fri, 09 Feb 2007) | 2 lines Update broken link. Will backport to 2.5. ........ r53697 | georg.brandl | 2007-02-09 19:48:41 +0100 (Fri, 09 Feb 2007) | 2 lines Bug #1656078: typo in in profile docs. ........ r53731 | brett.cannon | 2007-02-11 06:36:00 +0100 (Sun, 11 Feb 2007) | 3 lines Change a very minor inconsistency (that is purely cosmetic) in the AST definition. ........ r53735 | skip.montanaro | 2007-02-11 19:24:37 +0100 (Sun, 11 Feb 2007) | 1 line fix trace.py --ignore-dir ........ r53741 | brett.cannon | 2007-02-11 20:44:41 +0100 (Sun, 11 Feb 2007) | 3 lines Check in changed Python-ast.c from a cosmetic change to Python.asdl (in r53731). ........ r53751 | brett.cannon | 2007-02-12 04:51:02 +0100 (Mon, 12 Feb 2007) | 5 lines Modify Parser/asdl_c.py so that the __version__ number for Python/Python-ast.c is specified at the top of the file. Also add a note that Python/Python-ast.c needs to be committed separately after a change to the AST grammar to capture the revision number of the change (which is what __version__ is set to). ........ r53752 | lars.gustaebel | 2007-02-12 10:25:53 +0100 (Mon, 12 Feb 2007) | 3 lines Bug #1656581: Point out that external file objects are supposed to be at position 0. ........ r53754 | martin.v.loewis | 2007-02-12 13:21:10 +0100 (Mon, 12 Feb 2007) | 3 lines Patch 1463026: Support default namespace in XMLGenerator. Fixes #847665. Will backport. ........ r53757 | armin.rigo | 2007-02-12 17:23:24 +0100 (Mon, 12 Feb 2007) | 4 lines Fix the line to what is my guess at the original author's meaning. (The line has no effect anyway, but is present because it's customary call the base class __init__). ........ r53763 | martin.v.loewis | 2007-02-13 09:34:45 +0100 (Tue, 13 Feb 2007) | 3 lines Patch #685268: Consider a package's __path__ in imputil. Will backport. ........ r53765 | martin.v.loewis | 2007-02-13 10:49:38 +0100 (Tue, 13 Feb 2007) | 2 lines Patch #698833: Support file decryption in zipfile. ........ r53766 | martin.v.loewis | 2007-02-13 11:10:39 +0100 (Tue, 13 Feb 2007) | 3 lines Patch #1517891: Make 'a' create the file if it doesn't exist. Fixes #1514451. ........ r53767 | martin.v.loewis | 2007-02-13 13:08:24 +0100 (Tue, 13 Feb 2007) | 3 lines Bug #1658794: Remove extraneous 'this'. Will backport to 2.5. ........ r53769 | martin.v.loewis | 2007-02-13 13:14:19 +0100 (Tue, 13 Feb 2007) | 3 lines Patch #1657276: Make NETLINK_DNRTMSG conditional. Will backport. ........ r53771 | lars.gustaebel | 2007-02-13 17:09:24 +0100 (Tue, 13 Feb 2007) | 4 lines Patch #1647484: Renamed GzipFile's filename attribute to name. The filename attribute is still accessible as a property that emits a DeprecationWarning. ........ r53772 | lars.gustaebel | 2007-02-13 17:24:00 +0100 (Tue, 13 Feb 2007) | 3 lines Strip the '.gz' extension from the filename that is written to the gzip header. ........ r53774 | martin.v.loewis | 2007-02-14 11:07:37 +0100 (Wed, 14 Feb 2007) | 2 lines Patch #1432399: Add HCI sockets. ........ r53775 | martin.v.loewis | 2007-02-14 12:30:07 +0100 (Wed, 14 Feb 2007) | 2 lines Update 1432399 to removal of _BT_SOCKADDR_MEMB. ........ r53776 | martin.v.loewis | 2007-02-14 12:30:56 +0100 (Wed, 14 Feb 2007) | 3 lines Ignore directory time stamps when considering whether to rerun libffi configure. ........ r53778 | lars.gustaebel | 2007-02-14 15:45:12 +0100 (Wed, 14 Feb 2007) | 4 lines A missing binary mode in AppendTest caused failures in Windows Buildbot. ........ r53782 | martin.v.loewis | 2007-02-15 10:51:35 +0100 (Thu, 15 Feb 2007) | 2 lines Patch #1397848: add the reasoning behind no-resize-on-shrinkage. ........ r53783 | georg.brandl | 2007-02-15 11:37:59 +0100 (Thu, 15 Feb 2007) | 2 lines Make functools.wraps() docs a bit clearer. ........ r53785 | georg.brandl | 2007-02-15 12:29:04 +0100 (Thu, 15 Feb 2007) | 2 lines Patch #1494140: Add documentation for the new struct.Struct object. ........ r53787 | georg.brandl | 2007-02-15 12:29:55 +0100 (Thu, 15 Feb 2007) | 2 lines Add missing \versionadded. ........ r53800 | brett.cannon | 2007-02-15 23:54:39 +0100 (Thu, 15 Feb 2007) | 11 lines Update the encoding package's search function to use absolute imports when calling __import__. This helps make the expected search locations for encoding modules be more explicit. One could use an explicit value for __path__ when making the call to __import__ to force the exact location searched for encodings. This would give the most strict search path possible if one is worried about malicious code being imported. The unfortunate side-effect of that is that if __path__ was modified on 'encodings' on purpose in a safe way it would not be picked up in future __import__ calls. ........ r53801 | brett.cannon | 2007-02-16 20:33:01 +0100 (Fri, 16 Feb 2007) | 2 lines Make the __import__ call in encodings.__init__ absolute with a level 0 call. ........ r53809 | vinay.sajip | 2007-02-16 23:36:24 +0100 (Fri, 16 Feb 2007) | 1 line Minor fix for currentframe (SF #1652788). ........ r53818 | raymond.hettinger | 2007-02-19 03:03:19 +0100 (Mon, 19 Feb 2007) | 3 lines Extend work on revision 52962: Eliminate redundant calls to PyObject_Hash(). ........ r53820 | raymond.hettinger | 2007-02-19 05:08:43 +0100 (Mon, 19 Feb 2007) | 1 line Add merge() function to heapq. ........ r53821 | raymond.hettinger | 2007-02-19 06:28:28 +0100 (Mon, 19 Feb 2007) | 1 line Add tie-breaker count to preserve sort stability. ........ r53822 | raymond.hettinger | 2007-02-19 07:59:32 +0100 (Mon, 19 Feb 2007) | 1 line Use C heapreplace() instead of slower _siftup() in pure python. ........ r53823 | raymond.hettinger | 2007-02-19 08:30:21 +0100 (Mon, 19 Feb 2007) | 1 line Add test for merge stability ........ r53824 | raymond.hettinger | 2007-02-19 10:14:10 +0100 (Mon, 19 Feb 2007) | 1 line Provide an example of defaultdict with non-zero constant factory function. ........ r53825 | lars.gustaebel | 2007-02-19 10:54:47 +0100 (Mon, 19 Feb 2007) | 2 lines Moved misplaced news item. ........ r53826 | martin.v.loewis | 2007-02-19 11:55:19 +0100 (Mon, 19 Feb 2007) | 3 lines Patch #1490190: posixmodule now includes os.chflags() and os.lchflags() functions on platforms where the underlying system calls are available. ........ r53827 | raymond.hettinger | 2007-02-19 19:15:04 +0100 (Mon, 19 Feb 2007) | 1 line Fixup docstrings for merge(). ........ r53829 | raymond.hettinger | 2007-02-19 21:44:04 +0100 (Mon, 19 Feb 2007) | 1 line Fixup set/dict interoperability. ........ r53837 | raymond.hettinger | 2007-02-21 06:20:38 +0100 (Wed, 21 Feb 2007) | 1 line Add itertools.izip_longest(). ........ r53838 | raymond.hettinger | 2007-02-21 18:22:05 +0100 (Wed, 21 Feb 2007) | 1 line Remove filler struct item and fix leak. ........
1 parent 63eecc7 commit cf297e4

69 files changed

Lines changed: 1454 additions & 283 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Doc/lib/emailgenerator.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
line. This is the only guaranteed portable way to avoid having such
3434
lines be mistaken for a \UNIX{} mailbox format envelope header separator (see
3535
\ulink{WHY THE CONTENT-LENGTH FORMAT IS BAD}
36-
{http://home.netscape.com/eng/mozilla/2.0/relnotes/demo/content-length.html}
36+
{http://www.jwz.org/doc/content-length.html}
3737
for details). \var{mangle_from_} defaults to \code{True}, but you
3838
might want to set this to \code{False} if you are not writing \UNIX{}
3939
mailbox format files.

Doc/lib/libcollections.tex

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -311,16 +311,20 @@ \subsubsection{\class{defaultdict} Examples \label{defaultdict-examples}}
311311
When a letter is first encountered, it is missing from the mapping, so the
312312
\member{default_factory} function calls \function{int()} to supply a default
313313
count of zero. The increment operation then builds up the count for each
314-
letter. This technique makes counting simpler and faster than an equivalent
315-
technique using \method{dict.get()}:
314+
letter.
316315

317-
\begin{verbatim}
318-
>>> d = {}
319-
>>> for k in s:
320-
d[k] = d.get(k, 0) + 1
316+
The function \function{int()} which always returns zero is just a special
317+
case of constant functions. A faster and more flexible way to create
318+
constant functions is to use \function{itertools.repeat()} which can supply
319+
any constant value (not just zero):
321320

322-
>>> d.items()
323-
[('i', 4), ('p', 2), ('s', 4), ('m', 1)]
321+
\begin{verbatim}
322+
>>> def constant_factory(value):
323+
... return itertools.repeat(value).next
324+
>>> d = defaultdict(constant_factory('<missing>'))
325+
>>> d.update(name='John', action='ran')
326+
>>> '%(name)s %(action)s to %(object)s' % d
327+
'John ran to <missing>'
324328
\end{verbatim}
325329

326330
Setting the \member{default_factory} to \class{set} makes the

Doc/lib/libfunctools.tex

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,16 @@ \section{\module{functools} ---
6666

6767
\begin{funcdesc}{update_wrapper}
6868
{wrapper, wrapped\optional{, assigned}\optional{, updated}}
69-
Update a wrapper function to look like the wrapped function. The optional
70-
arguments are tuples to specify which attributes of the original
69+
Update a \var{wrapper} function to look like the \var{wrapped} function.
70+
The optional arguments are tuples to specify which attributes of the original
7171
function are assigned directly to the matching attributes on the wrapper
7272
function and which attributes of the wrapper function are updated with
7373
the corresponding attributes from the original function. The default
7474
values for these arguments are the module level constants
75-
\var{WRAPPER_ASSIGNMENTS} (which assigns to the wrapper function's name,
76-
module and documentation string) and \var{WRAPPER_UPDATES} (which
77-
updates the wrapper function's instance dictionary).
75+
\var{WRAPPER_ASSIGNMENTS} (which assigns to the wrapper function's
76+
\var{__name__}, \var{__module__} and \var{__doc__}, the documentation string)
77+
and \var{WRAPPER_UPDATES} (which updates the wrapper function's \var{__dict__},
78+
i.e. the instance dictionary).
7879

7980
The main intended use for this function is in decorator functions
8081
which wrap the decorated function and return the wrapper. If the
@@ -98,16 +99,20 @@ \section{\module{functools} ---
9899
...
99100
>>> @my_decorator
100101
... def example():
102+
... """Docstring"""
101103
... print 'Called example function'
102104
...
103105
>>> example()
104106
Calling decorated function
105107
Called example function
106108
>>> example.__name__
107109
'example'
110+
>>> example.__doc__
111+
'Docstring'
108112
\end{verbatim}
109113
Without the use of this decorator factory, the name of the example
110-
function would have been \code{'wrapper'}.
114+
function would have been \code{'wrapper'}, and the docstring of the
115+
original \function{example()} would have been lost.
111116
\end{funcdesc}
112117

113118

Doc/lib/libheapq.tex

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,18 @@ \section{\module{heapq} ---
8888
>>>
8989
\end{verbatim}
9090

91-
The module also offers two general purpose functions based on heaps.
91+
The module also offers three general purpose functions based on heaps.
92+
93+
\begin{funcdesc}{merge}{*iterables}
94+
Merge multiple sorted inputs into a single sorted output (for example, merge
95+
timestamped entries from multiple log files). Returns an iterator over
96+
over the sorted values.
97+
98+
Similar to \code{sorted(itertools.chain(*iterables))} but returns an iterable,
99+
does not pull the data into memory all at once, and assumes that each of the
100+
input streams is already sorted (smallest to largest).
101+
\versionadded{2.6}
102+
\end{funcdesc}
92103

93104
\begin{funcdesc}{nlargest}{n, iterable\optional{, key}}
94105
Return a list with the \var{n} largest elements from the dataset defined
@@ -110,7 +121,7 @@ \section{\module{heapq} ---
110121
\versionchanged[Added the optional \var{key} argument]{2.5}
111122
\end{funcdesc}
112123

113-
Both functions perform best for smaller values of \var{n}. For larger
124+
The latter two functions perform best for smaller values of \var{n}. For larger
114125
values, it is more efficient to use the \function{sorted()} function. Also,
115126
when \code{n==1}, it is more efficient to use the builtin \function{min()}
116127
and \function{max()} functions.

Doc/lib/libitertools.tex

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,33 @@ \subsection{Itertool functions \label{itertools-functions}}
302302
don't care about trailing, unmatched values from the longer iterables.
303303
\end{funcdesc}
304304

305+
\begin{funcdesc}{izip_longest}{*iterables\optional{, fillvalue}}
306+
Make an iterator that aggregates elements from each of the iterables.
307+
If the iterables are of uneven length, missing values are filled-in
308+
with \var{fillvalue}. Iteration continues until the longest iterable
309+
is exhausted. Equivalent to:
310+
311+
\begin{verbatim}
312+
def izip_longest(*args, **kwds):
313+
fillvalue = kwds.get('fillvalue')
314+
def sentinel(counter = ([fillvalue]*(len(args)-1)).pop):
315+
yield counter() # yields the fillvalue, or raises IndexError
316+
fillers = repeat(fillvalue)
317+
iters = [chain(it, sentinel(), fillers) for it in args]
318+
try:
319+
for tup in izip(*iters):
320+
yield tup
321+
except IndexError:
322+
pass
323+
\end{verbatim}
324+
325+
If one of the iterables is potentially infinite, then the
326+
\function{izip_longest()} function should be wrapped with something
327+
that limits the number of calls (for example \function{islice()} or
328+
\function{take()}).
329+
\versionadded{2.6}
330+
\end{funcdesc}
331+
305332
\begin{funcdesc}{repeat}{object\optional{, times}}
306333
Make an iterator that returns \var{object} over and over again.
307334
Runs indefinitely unless the \var{times} argument is specified.

Doc/lib/liblocale.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ \subsection{Background, details, hints, tips and caveats}
481481
locale settings. When a call to the \function{setlocale()} function
482482
changes the \constant{LC_CTYPE} settings, the variables
483483
\code{string.lowercase}, \code{string.uppercase} and
484-
\code{string.letters} are recalculated. Note that this code that uses
484+
\code{string.letters} are recalculated. Note that code that uses
485485
these variable through `\keyword{from} ... \keyword{import} ...',
486486
e.g.\ \code{from string import letters}, is not affected by subsequent
487487
\function{setlocale()} calls.

Doc/lib/libos.tex

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,26 @@ \subsection{Files and Directories \label{os-file-dir}}
758758
\versionadded{2.3}
759759
\end{funcdesc}
760760

761+
\begin{funcdesc}{chflags}{path, flags}
762+
Set the flags of \var{path} to the numeric \var{flags}.
763+
\var{flags} may take a combination (bitwise OR) of the following values
764+
(as defined in the \module{stat} module):
765+
\begin{itemize}
766+
\item \code{UF_NODUMP}
767+
\item \code{UF_IMMUTABLE}
768+
\item \code{UF_APPEND}
769+
\item \code{UF_OPAQUE}
770+
\item \code{UF_NOUNLINK}
771+
\item \code{SF_ARCHIVED}
772+
\item \code{SF_IMMUTABLE}
773+
\item \code{SF_APPEND}
774+
\item \code{SF_NOUNLINK}
775+
\item \code{SF_SNAPSHOT}
776+
\end{itemize}
777+
Availability: Macintosh, \UNIX.
778+
\versionadded{2.6}
779+
\end{funcdesc}
780+
761781
\begin{funcdesc}{chroot}{path}
762782
Change the root directory of the current process to \var{path}.
763783
Availability: Macintosh, \UNIX.
@@ -804,6 +824,13 @@ \subsection{Files and Directories \label{os-file-dir}}
804824
Availability: Macintosh, \UNIX.
805825
\end{funcdesc}
806826

827+
\begin{funcdesc}{lchflags}{path, flags}
828+
Set the flags of \var{path} to the numeric \var{flags}, like
829+
\function{chflags()}, but do not follow symbolic links.
830+
Availability: \UNIX.
831+
\versionadded{2.6}
832+
\end{funcdesc}
833+
807834
\begin{funcdesc}{lchown}{path, uid, gid}
808835
Change the owner and group id of \var{path} to the numeric \var{uid}
809836
and gid. This function will not follow symbolic links.

Doc/lib/libshutil.tex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ \section{\module{shutil} ---
4444
\end{funcdesc}
4545

4646
\begin{funcdesc}{copystat}{src, dst}
47-
Copy the permission bits, last access time, and last modification
48-
time from \var{src} to \var{dst}. The file contents, owner, and
47+
Copy the permission bits, last access time, last modification time,
48+
and flags from \var{src} to \var{dst}. The file contents, owner, and
4949
group are unaffected. \var{src} and \var{dst} are path names given
5050
as strings.
5151
\end{funcdesc}

Doc/lib/libstdtypes.tex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1212,7 +1212,7 @@ \section{Set Types ---
12121212
\label{types-set}}
12131213
\obindex{set}
12141214

1215-
A \dfn{set} object is an unordered collection of immutable values.
1215+
A \dfn{set} object is an unordered collection of distinct hashable objects.
12161216
Common uses include membership testing, removing duplicates from a sequence,
12171217
and computing mathematical operations such as intersection, union, difference,
12181218
and symmetric difference.

Doc/lib/libstruct.tex

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,15 @@ \section{\module{struct} ---
2929
exactly.
3030
\end{funcdesc}
3131

32+
\begin{funcdesc}{pack_into}{fmt, buffer, offset, v1, v2, \moreargs}
33+
Pack the values \code{\var{v1}, \var{v2}, \textrm{\ldots}} according to the given
34+
format, write the packed bytes into the writable \var{buffer} starting at
35+
\var{offset}.
36+
Note that the offset is not an optional argument.
37+
38+
\versionadded{2.5}
39+
\end{funcdesc}
40+
3241
\begin{funcdesc}{unpack}{fmt, string}
3342
Unpack the string (presumably packed by \code{pack(\var{fmt},
3443
\textrm{\ldots})}) according to the given format. The result is a
@@ -37,6 +46,16 @@ \section{\module{struct} ---
3746
(\code{len(\var{string})} must equal \code{calcsize(\var{fmt})}).
3847
\end{funcdesc}
3948

49+
\begin{funcdesc}{unpack_from}{fmt, buffer\optional{,offset \code{= 0}}}
50+
Unpack the \var{buffer} according to tthe given format.
51+
The result is a tuple even if it contains exactly one item. The
52+
\var{buffer} must contain at least the amount of data required by the
53+
format (\code{len(buffer[offset:])} must be at least
54+
\code{calcsize(\var{fmt})}).
55+
56+
\versionadded{2.5}
57+
\end{funcdesc}
58+
4059
\begin{funcdesc}{calcsize}{fmt}
4160
Return the size of the struct (and hence of the string)
4261
corresponding to the given format.
@@ -208,3 +227,43 @@ \section{\module{struct} ---
208227
\seemodule{array}{Packed binary storage of homogeneous data.}
209228
\seemodule{xdrlib}{Packing and unpacking of XDR data.}
210229
\end{seealso}
230+
231+
\subsection{Struct Objects \label{struct-objects}}
232+
233+
The \module{struct} module also defines the following type:
234+
235+
\begin{classdesc}{Struct}{format}
236+
Return a new Struct object which writes and reads binary data according to
237+
the format string \var{format}. Creating a Struct object once and calling
238+
its methods is more efficient than calling the \module{struct} functions
239+
with the same format since the format string only needs to be compiled once.
240+
241+
\versionadded{2.5}
242+
\end{classdesc}
243+
244+
Compiled Struct objects support the following methods and attributes:
245+
246+
\begin{methoddesc}[Struct]{pack}{v1, v2, \moreargs}
247+
Identical to the \function{pack()} function, using the compiled format.
248+
(\code{len(result)} will equal \member{self.size}.)
249+
\end{methoddesc}
250+
251+
\begin{methoddesc}[Struct]{pack_into}{buffer, offset, v1, v2, \moreargs}
252+
Identical to the \function{pack_into()} function, using the compiled format.
253+
\end{methoddesc}
254+
255+
\begin{methoddesc}[Struct]{unpack}{string}
256+
Identical to the \function{unpack()} function, using the compiled format.
257+
(\code{len(string)} must equal \member{self.size}).
258+
\end{methoddesc}
259+
260+
\begin{methoddesc}[Struct]{unpack_from}{buffer\optional{,offset
261+
\code{= 0}}}
262+
Identical to the \function{unpack_from()} function, using the compiled format.
263+
(\code{len(buffer[offset:])} must be at least \member{self.size}).
264+
\end{methoddesc}
265+
266+
\begin{memberdesc}[Struct]{format}
267+
The format string used to construct this Struct object.
268+
\end{memberdesc}
269+

0 commit comments

Comments
 (0)