2007-08-15 11:28:22 -03:00
|
|
|
:mod:`zipfile` --- Work with ZIP archives
|
|
|
|
=========================================
|
|
|
|
|
|
|
|
.. module:: zipfile
|
|
|
|
:synopsis: Read and write ZIP-format archive files.
|
2016-06-11 16:02:54 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. moduleauthor:: James C. Ahlstrom <jim@interet.com>
|
|
|
|
.. sectionauthor:: James C. Ahlstrom <jim@interet.com>
|
|
|
|
|
2011-01-27 16:38:46 -04:00
|
|
|
**Source code:** :source:`Lib/zipfile.py`
|
|
|
|
|
|
|
|
--------------
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
The ZIP file format is a common archive and compression standard. This module
|
|
|
|
provides tools to create, read, write, append, and list a ZIP file. Any
|
|
|
|
advanced use of this module will require an understanding of the format, as
|
2016-02-26 14:37:12 -04:00
|
|
|
defined in `PKZIP Application Note`_.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-08-02 17:52:10 -03:00
|
|
|
This module does not currently handle multi-disk ZIP files.
|
|
|
|
It can handle ZIP files that use the ZIP64 extensions
|
2013-02-16 11:29:56 -04:00
|
|
|
(that is ZIP files that are more than 4 GiB in size). It supports
|
Merged revisions 58817-58861 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58822 | brett.cannon | 2007-11-02 23:47:02 -0700 (Fri, 02 Nov 2007) | 2 lines
Add a missing quotation mark.
........
r58840 | skip.montanaro | 2007-11-04 07:56:52 -0800 (Sun, 04 Nov 2007) | 2 lines
Note change to get_dialect semantics in 2.5. Will backport to 2.5.
........
r58844 | georg.brandl | 2007-11-04 09:43:49 -0800 (Sun, 04 Nov 2007) | 2 lines
Fix syntax for versionchanged markup.
........
r58850 | gregory.p.smith | 2007-11-04 18:32:26 -0800 (Sun, 04 Nov 2007) | 9 lines
Fixes bug 477182 on pybsddb.sf.net. DB objects now load the flags and
pay attention to them when opening an existing database. This means
that d[] behaves properly even on databases previously created with DB_DUP
or DB_DUPSORT flags to allow duplicate keys.
http://sourceforge.net/tracker/index.php?func=detail&aid=477182&group_id=13900&atid=113900
Do not backport, this bugfix could be considered an API change.
........
r58851 | gregory.p.smith | 2007-11-04 18:56:31 -0800 (Sun, 04 Nov 2007) | 3 lines
Add the bsddb.db.DBEnv.lock_id_free method.
Improve test_lock's tempdir creation and cleanup.
........
r58852 | gregory.p.smith | 2007-11-05 01:06:28 -0800 (Mon, 05 Nov 2007) | 3 lines
* db->get_types is only available in BerkeleyDB >= 4.2
* get compiling with older versions of python again for a stand alone release.
........
r58853 | gregory.p.smith | 2007-11-05 01:07:40 -0800 (Mon, 05 Nov 2007) | 2 lines
* db->get_flags is only available in BerkeleyDB >= 4.2
........
r58854 | mark.summerfield | 2007-11-05 01:22:48 -0800 (Mon, 05 Nov 2007) | 3 lines
Added cross-references between the various archive file formats.
........
r58857 | mark.summerfield | 2007-11-05 06:38:50 -0800 (Mon, 05 Nov 2007) | 5 lines
Clarified the fact that you can have comments for individual archive
members even though comments to the archive itself aren't currently
supported.
........
2007-11-05 15:43:04 -04:00
|
|
|
decryption of encrypted files in ZIP archives, but it currently cannot
|
Merged revisions 60094-60123 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
*** NOTE ***
I haven't merged the files in Doc/c-api/. I got too many conflicts. Georg,
please split them manually.
........
r60095 | andrew.kuchling | 2008-01-19 21:12:04 +0100 (Sat, 19 Jan 2008) | 2 lines
Bug 1277: make Maildir use the user-provided factory instead of hard-wiring MaildirMessage.
2.5.2 bugfix candidate.
........
r60097 | georg.brandl | 2008-01-19 21:22:13 +0100 (Sat, 19 Jan 2008) | 4 lines
#1663329: add os.closerange() to close a range of fds,
ignoring errors, and use this in subprocess to speed up
subprocess creation in close_fds mode. Patch by Mike Klaas.
........
r60099 | georg.brandl | 2008-01-19 21:40:24 +0100 (Sat, 19 Jan 2008) | 2 lines
#1411695: clarify behavior of xml.sax.utils.[un]escape.
........
r60101 | andrew.kuchling | 2008-01-19 21:47:59 +0100 (Sat, 19 Jan 2008) | 7 lines
Patch #1019808 from Federico Schwindt: Return correct socket error when
a default timeout has been set, by using getsockopt() to get the error
condition (instead of trying another connect() call, which seems to be
a Linuxism).
2.5 bugfix candidate, assuming no one reports any problems with this change.
........
r60102 | gregory.p.smith | 2008-01-19 21:49:02 +0100 (Sat, 19 Jan 2008) | 3 lines
fix comment typos, use not arg instead of arg == "", add test coverage
for inside of the final if needquotes: within subprocess.list2cmdline().
........
r60103 | georg.brandl | 2008-01-19 21:53:07 +0100 (Sat, 19 Jan 2008) | 2 lines
#1509: fix sqlite3 docstrings and docs w.r.t. cursor.fetchXXX methods.
........
r60104 | gregory.p.smith | 2008-01-19 21:57:59 +0100 (Sat, 19 Jan 2008) | 6 lines
Fixes issue1336 - a race condition could occur when forking if the gc
kicked in during the critical section. solution: disable gc during
that section. Patch contributed by jpa and updated by me to cover the
race condition still existing what therve from twistedmatrix pointed
out (already seen and fixed in twisted's own subprocess code).
........
r60105 | gregory.p.smith | 2008-01-19 22:00:37 +0100 (Sat, 19 Jan 2008) | 2 lines
note about r60104
........
r60106 | andrew.kuchling | 2008-01-19 22:00:38 +0100 (Sat, 19 Jan 2008) | 1 line
Bug 1296: restore text describing OptionGroup
........
r60109 | georg.brandl | 2008-01-19 23:08:21 +0100 (Sat, 19 Jan 2008) | 2 lines
Split the monstrous C API manual files in smaller parts.
........
r60110 | georg.brandl | 2008-01-19 23:14:27 +0100 (Sat, 19 Jan 2008) | 2 lines
Missed one big file to split up.
........
r60111 | gregory.p.smith | 2008-01-19 23:23:56 +0100 (Sat, 19 Jan 2008) | 12 lines
Undo an unnecessary else: and indentation that r60104 added.
try:
...
except:
...
raise
else:
...
the else: is unecessary due to the blind except: with a raise.
........
r60115 | gregory.p.smith | 2008-01-19 23:49:37 +0100 (Sat, 19 Jan 2008) | 3 lines
Fix issue 1300: Quote command line arguments that contain a '|' character in
subprocess.list2cmdline (windows).
........
r60116 | gregory.p.smith | 2008-01-20 00:10:52 +0100 (Sun, 20 Jan 2008) | 3 lines
Fixes/Accepts Patch for issue1189216 - Work properly with archives
that have file headers past the 2**31 byte boundary.
........
r60119 | andrew.kuchling | 2008-01-20 01:00:38 +0100 (Sun, 20 Jan 2008) | 3 lines
Patch #1048820 from Stefan Wehr: add insert-mode editing to Textbox.
Fix an off-by-one error I noticed.
........
r60120 | andrew.kuchling | 2008-01-20 01:12:19 +0100 (Sun, 20 Jan 2008) | 1 line
Add an interactive test script for exercising curses
........
r60121 | gregory.p.smith | 2008-01-20 02:21:03 +0100 (Sun, 20 Jan 2008) | 7 lines
Fix zipfile decryption. The check for validity only worked on one
type of encrypted zip files. Files using extended local headers
needed to compare the check byte against different values. (according
to reading the infozip unzip crypt.c source code)
Fixes issue1003.
........
r60122 | gregory.p.smith | 2008-01-20 02:26:04 +0100 (Sun, 20 Jan 2008) | 2 lines
note for r60121
........
r60123 | gregory.p.smith | 2008-01-20 02:32:00 +0100 (Sun, 20 Jan 2008) | 4 lines
Document that zipfile decryption is insanely slow and fix a typo and
blatant lie in a docstring (it is not useful for security regardless of
how you spell it).
........
2008-01-20 05:06:41 -04:00
|
|
|
create an encrypted file. Decryption is extremely slow as it is
|
Merged revisions 76259,76326,76376-76377,76430,76471,76517 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
................
r76259 | georg.brandl | 2009-11-14 05:50:51 -0600 (Sat, 14 Nov 2009) | 1 line
Fix terminology.
................
r76326 | georg.brandl | 2009-11-16 10:44:05 -0600 (Mon, 16 Nov 2009) | 1 line
#7302: fix link.
................
r76376 | georg.brandl | 2009-11-18 13:39:14 -0600 (Wed, 18 Nov 2009) | 1 line
upcase Python
................
r76377 | georg.brandl | 2009-11-18 14:05:15 -0600 (Wed, 18 Nov 2009) | 1 line
Fix markup.
................
r76430 | r.david.murray | 2009-11-20 07:29:43 -0600 (Fri, 20 Nov 2009) | 2 lines
Issue 7363: fix indentation in socketserver udpserver example.
................
r76471 | georg.brandl | 2009-11-23 13:53:19 -0600 (Mon, 23 Nov 2009) | 1 line
#7345: fix arguments of formatyear().
................
r76517 | benjamin.peterson | 2009-11-25 12:16:46 -0600 (Wed, 25 Nov 2009) | 29 lines
Merged revisions 76160-76161,76250,76252,76447,76506 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3
........
r76160 | benjamin.peterson | 2009-11-08 18:53:48 -0600 (Sun, 08 Nov 2009) | 1 line
undeprecate the -p option; it's useful for converting python3 sources
........
r76161 | benjamin.peterson | 2009-11-08 19:05:37 -0600 (Sun, 08 Nov 2009) | 1 line
simplify condition
........
r76250 | benjamin.peterson | 2009-11-13 16:56:48 -0600 (Fri, 13 Nov 2009) | 1 line
fix handling of a utf-8 bom #7313
........
r76252 | benjamin.peterson | 2009-11-13 16:58:36 -0600 (Fri, 13 Nov 2009) | 1 line
remove pdb turd
........
r76447 | benjamin.peterson | 2009-11-22 18:17:40 -0600 (Sun, 22 Nov 2009) | 1 line
#7375 fix nested transformations in fix_urllib
........
r76506 | benjamin.peterson | 2009-11-24 18:34:31 -0600 (Tue, 24 Nov 2009) | 1 line
use generator expressions in any()
........
................
2009-11-25 14:34:42 -04:00
|
|
|
implemented in native Python rather than C.
|
Merged revisions 58817-58861 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r58822 | brett.cannon | 2007-11-02 23:47:02 -0700 (Fri, 02 Nov 2007) | 2 lines
Add a missing quotation mark.
........
r58840 | skip.montanaro | 2007-11-04 07:56:52 -0800 (Sun, 04 Nov 2007) | 2 lines
Note change to get_dialect semantics in 2.5. Will backport to 2.5.
........
r58844 | georg.brandl | 2007-11-04 09:43:49 -0800 (Sun, 04 Nov 2007) | 2 lines
Fix syntax for versionchanged markup.
........
r58850 | gregory.p.smith | 2007-11-04 18:32:26 -0800 (Sun, 04 Nov 2007) | 9 lines
Fixes bug 477182 on pybsddb.sf.net. DB objects now load the flags and
pay attention to them when opening an existing database. This means
that d[] behaves properly even on databases previously created with DB_DUP
or DB_DUPSORT flags to allow duplicate keys.
http://sourceforge.net/tracker/index.php?func=detail&aid=477182&group_id=13900&atid=113900
Do not backport, this bugfix could be considered an API change.
........
r58851 | gregory.p.smith | 2007-11-04 18:56:31 -0800 (Sun, 04 Nov 2007) | 3 lines
Add the bsddb.db.DBEnv.lock_id_free method.
Improve test_lock's tempdir creation and cleanup.
........
r58852 | gregory.p.smith | 2007-11-05 01:06:28 -0800 (Mon, 05 Nov 2007) | 3 lines
* db->get_types is only available in BerkeleyDB >= 4.2
* get compiling with older versions of python again for a stand alone release.
........
r58853 | gregory.p.smith | 2007-11-05 01:07:40 -0800 (Mon, 05 Nov 2007) | 2 lines
* db->get_flags is only available in BerkeleyDB >= 4.2
........
r58854 | mark.summerfield | 2007-11-05 01:22:48 -0800 (Mon, 05 Nov 2007) | 3 lines
Added cross-references between the various archive file formats.
........
r58857 | mark.summerfield | 2007-11-05 06:38:50 -0800 (Mon, 05 Nov 2007) | 5 lines
Clarified the fact that you can have comments for individual archive
members even though comments to the archive itself aren't currently
supported.
........
2007-11-05 15:43:04 -04:00
|
|
|
|
|
|
|
The module defines the following items:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-10-28 03:42:33 -03:00
|
|
|
.. exception:: BadZipFile
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2011-08-18 19:44:31 -03:00
|
|
|
The error raised for bad ZIP files.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-10-28 03:42:33 -03:00
|
|
|
.. versionadded:: 3.2
|
|
|
|
|
|
|
|
|
|
|
|
.. exception:: BadZipfile
|
|
|
|
|
2011-08-18 19:44:31 -03:00
|
|
|
Alias of :exc:`BadZipFile`, for compatibility with older Python versions.
|
|
|
|
|
|
|
|
.. deprecated:: 3.2
|
2010-10-28 03:42:33 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. exception:: LargeZipFile
|
|
|
|
|
|
|
|
The error raised when a ZIP file would require ZIP64 functionality but that has
|
|
|
|
not been enabled.
|
|
|
|
|
|
|
|
|
|
|
|
.. class:: ZipFile
|
2010-11-12 02:20:12 -04:00
|
|
|
:noindex:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
The class for reading and writing ZIP files. See section
|
|
|
|
:ref:`zipfile-objects` for constructor details.
|
|
|
|
|
|
|
|
|
|
|
|
.. class:: PyZipFile
|
2010-12-04 06:26:46 -04:00
|
|
|
:noindex:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Class for creating ZIP archives containing Python libraries.
|
|
|
|
|
|
|
|
|
2009-09-16 12:58:14 -03:00
|
|
|
.. class:: ZipInfo(filename='NoName', date_time=(1980,1,1,0,0,0))
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Class used to represent information about a member of an archive. Instances
|
2012-10-06 12:02:05 -03:00
|
|
|
of this class are returned by the :meth:`.getinfo` and :meth:`.infolist`
|
2007-08-15 11:28:22 -03:00
|
|
|
methods of :class:`ZipFile` objects. Most users of the :mod:`zipfile` module
|
|
|
|
will not need to create these, but only use those created by this
|
|
|
|
module. *filename* should be the full name of the archive member, and
|
|
|
|
*date_time* should be a tuple containing six fields which describe the time
|
|
|
|
of the last modification to the file; the fields are described in section
|
|
|
|
:ref:`zipinfo-objects`.
|
|
|
|
|
|
|
|
|
|
|
|
.. function:: is_zipfile(filename)
|
|
|
|
|
|
|
|
Returns ``True`` if *filename* is a valid ZIP file based on its magic number,
|
2008-12-27 11:50:40 -04:00
|
|
|
otherwise returns ``False``. *filename* may be a file or file-like object too.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2009-01-03 20:28:14 -04:00
|
|
|
.. versionchanged:: 3.1
|
|
|
|
Support for file and file-like objects.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-08-17 12:07:14 -03:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. data:: ZIP_STORED
|
|
|
|
|
|
|
|
The numeric constant for an uncompressed archive member.
|
|
|
|
|
|
|
|
|
|
|
|
.. data:: ZIP_DEFLATED
|
|
|
|
|
|
|
|
The numeric constant for the usual ZIP compression method. This requires the
|
2012-10-06 12:10:01 -03:00
|
|
|
:mod:`zlib` module.
|
2012-05-01 02:58:44 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. data:: ZIP_BZIP2
|
|
|
|
|
|
|
|
The numeric constant for the BZIP2 compression method. This requires the
|
2012-10-06 12:10:01 -03:00
|
|
|
:mod:`bz2` module.
|
2012-05-01 02:58:44 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
2012-05-13 05:06:36 -03:00
|
|
|
.. data:: ZIP_LZMA
|
|
|
|
|
|
|
|
The numeric constant for the LZMA compression method. This requires the
|
2012-10-06 12:10:01 -03:00
|
|
|
:mod:`lzma` module.
|
2012-05-13 05:06:36 -03:00
|
|
|
|
|
|
|
.. versionadded:: 3.3
|
|
|
|
|
2012-05-01 02:58:44 -03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
The ZIP file format specification has included support for bzip2 compression
|
2012-05-13 05:06:36 -03:00
|
|
|
since 2001, and for LZMA compression since 2006. However, some tools
|
|
|
|
(including older Python releases) do not support these compression
|
|
|
|
methods, and may either refuse to process the ZIP file altogether,
|
|
|
|
or fail to extract individual files.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. seealso::
|
|
|
|
|
2016-02-26 14:37:12 -04:00
|
|
|
`PKZIP Application Note`_
|
2007-08-15 11:28:22 -03:00
|
|
|
Documentation on the ZIP file format by Phil Katz, the creator of the format and
|
|
|
|
algorithms used.
|
|
|
|
|
|
|
|
`Info-ZIP Home Page <http://www.info-zip.org/>`_
|
|
|
|
Information about the Info-ZIP project's ZIP archive programs and development
|
|
|
|
libraries.
|
|
|
|
|
|
|
|
|
|
|
|
.. _zipfile-objects:
|
|
|
|
|
|
|
|
ZipFile Objects
|
|
|
|
---------------
|
|
|
|
|
|
|
|
|
2018-01-30 01:54:07 -04:00
|
|
|
.. class:: ZipFile(file, mode='r', compression=ZIP_STORED, allowZip64=True, \
|
|
|
|
compresslevel=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-03-08 08:37:51 -04:00
|
|
|
Open a ZIP file, where *file* can be a path to a file (a string), a
|
|
|
|
file-like object or a :term:`path-like object`.
|
2018-01-30 01:54:07 -04:00
|
|
|
|
2017-03-08 08:37:51 -04:00
|
|
|
The *mode* parameter should be ``'r'`` to read an existing
|
2016-01-22 01:06:47 -04:00
|
|
|
file, ``'w'`` to truncate and write a new file, ``'a'`` to append to an
|
|
|
|
existing file, or ``'x'`` to exclusively create and write a new file.
|
2015-03-25 05:09:41 -03:00
|
|
|
If *mode* is ``'x'`` and *file* refers to an existing file,
|
|
|
|
a :exc:`FileExistsError` will be raised.
|
|
|
|
If *mode* is ``'a'`` and *file* refers to an existing ZIP
|
2009-12-30 08:34:59 -04:00
|
|
|
file, then additional files are added to it. If *file* does not refer to a
|
|
|
|
ZIP file, then a new ZIP archive is appended to the file. This is meant for
|
|
|
|
adding a ZIP archive to another file (such as :file:`python.exe`). If
|
2016-09-12 22:49:12 -03:00
|
|
|
*mode* is ``'a'`` and the file does not exist at all, it is created.
|
|
|
|
If *mode* is ``'r'`` or ``'a'``, the file should be seekable.
|
2018-01-30 01:54:07 -04:00
|
|
|
|
2009-12-30 08:34:59 -04:00
|
|
|
*compression* is the ZIP compression method to use when writing the archive,
|
2012-05-13 05:06:36 -03:00
|
|
|
and should be :const:`ZIP_STORED`, :const:`ZIP_DEFLATED`,
|
|
|
|
:const:`ZIP_BZIP2` or :const:`ZIP_LZMA`; unrecognized
|
2018-01-30 01:54:07 -04:00
|
|
|
values will cause :exc:`NotImplementedError` to be raised. If
|
|
|
|
:const:`ZIP_DEFLATED`, :const:`ZIP_BZIP2` or :const:`ZIP_LZMA` is specified
|
|
|
|
but the corresponding module (:mod:`zlib`, :mod:`bz2` or :mod:`lzma`) is not
|
|
|
|
available, :exc:`RuntimeError` is raised. The default is :const:`ZIP_STORED`.
|
|
|
|
|
|
|
|
If *allowZip64* is ``True`` (the default) zipfile will create ZIP files that
|
|
|
|
use the ZIP64 extensions when the zipfile is larger than 4 GiB. If it is
|
|
|
|
``false`` :mod:`zipfile` will raise an exception when the ZIP file would
|
|
|
|
require ZIP64 extensions.
|
|
|
|
|
|
|
|
The *compresslevel* parameter controls the compression level to use when
|
|
|
|
writing files to the archive.
|
|
|
|
When using :const:`ZIP_STORED` or :const:`ZIP_LZMA` it has no effect.
|
|
|
|
When using :const:`ZIP_DEFLATED` integers ``0`` through ``9`` are accepted
|
|
|
|
(see :class:`zlib <zlib.compressobj>` for more information).
|
|
|
|
When using :const:`ZIP_BZIP2` integers ``1`` through ``9`` are accepted
|
|
|
|
(see :class:`bz2 <bz2.BZ2File>` for more information).
|
2009-12-30 08:34:59 -04:00
|
|
|
|
2015-03-25 05:09:41 -03:00
|
|
|
If the file is created with mode ``'w'``, ``'x'`` or ``'a'`` and then
|
2012-10-06 12:02:05 -03:00
|
|
|
:meth:`closed <close>` without adding any files to the archive, the appropriate
|
2010-10-14 03:59:45 -03:00
|
|
|
ZIP structures for an empty archive will be written to the file.
|
|
|
|
|
2009-12-30 08:34:59 -04:00
|
|
|
ZipFile is also a context manager and therefore supports the
|
|
|
|
:keyword:`with` statement. In the example, *myzip* is closed after the
|
|
|
|
:keyword:`with` statement's suite is finished---even if an exception occurs::
|
|
|
|
|
|
|
|
with ZipFile('spam.zip', 'w') as myzip:
|
|
|
|
myzip.write('eggs.txt')
|
|
|
|
|
|
|
|
.. versionadded:: 3.2
|
|
|
|
Added the ability to use :class:`ZipFile` as a context manager.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2012-05-01 02:58:44 -03:00
|
|
|
.. versionchanged:: 3.3
|
2012-10-06 12:10:01 -03:00
|
|
|
Added support for :mod:`bzip2 <bz2>` and :mod:`lzma` compression.
|
2012-05-01 02:58:44 -03:00
|
|
|
|
2013-11-23 09:55:38 -04:00
|
|
|
.. versionchanged:: 3.4
|
|
|
|
ZIP64 extensions are enabled by default.
|
|
|
|
|
2015-03-22 20:09:35 -03:00
|
|
|
.. versionchanged:: 3.5
|
|
|
|
Added support for writing to unseekable streams.
|
2015-03-25 05:09:41 -03:00
|
|
|
Added support for the ``'x'`` mode.
|
2015-03-22 20:09:35 -03:00
|
|
|
|
2016-09-10 15:28:07 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
Previously, a plain :exc:`RuntimeError` was raised for unrecognized
|
|
|
|
compression values.
|
|
|
|
|
2017-03-08 08:37:51 -04:00
|
|
|
.. versionchanged:: 3.6.2
|
|
|
|
The *file* parameter accepts a :term:`path-like object`.
|
|
|
|
|
2018-01-30 01:54:07 -04:00
|
|
|
.. versionchanged:: 3.7
|
|
|
|
Add the *compresslevel* parameter.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: ZipFile.close()
|
|
|
|
|
|
|
|
Close the archive file. You must call :meth:`close` before exiting your program
|
|
|
|
or essential records will not be written.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: ZipFile.getinfo(name)
|
|
|
|
|
|
|
|
Return a :class:`ZipInfo` object with information about the archive member
|
|
|
|
*name*. Calling :meth:`getinfo` for a name not currently contained in the
|
|
|
|
archive will raise a :exc:`KeyError`.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: ZipFile.infolist()
|
|
|
|
|
|
|
|
Return a list containing a :class:`ZipInfo` object for each member of the
|
|
|
|
archive. The objects are in the same order as their entries in the actual ZIP
|
|
|
|
file on disk if an existing archive was opened.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: ZipFile.namelist()
|
|
|
|
|
|
|
|
Return a list of archive members by name.
|
|
|
|
|
|
|
|
|
2016-05-15 06:27:16 -03:00
|
|
|
.. method:: ZipFile.open(name, mode='r', pwd=None, *, force_zip64=False)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-06-11 13:32:44 -03:00
|
|
|
Access a member of the archive as a binary file-like object. *name*
|
|
|
|
can be either the name of a file within the archive or a :class:`ZipInfo`
|
|
|
|
object. The *mode* parameter, if included, must be ``'r'`` (the default)
|
|
|
|
or ``'w'``. *pwd* is the password used to decrypt encrypted ZIP files.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2015-03-13 00:41:06 -03:00
|
|
|
:meth:`~ZipFile.open` is also a context manager and therefore supports the
|
2015-03-12 21:29:54 -03:00
|
|
|
:keyword:`with` statement::
|
|
|
|
|
|
|
|
with ZipFile('spam.zip') as myzip:
|
|
|
|
with myzip.open('eggs.txt') as myfile:
|
|
|
|
print(myfile.read())
|
|
|
|
|
2016-06-11 13:32:44 -03:00
|
|
|
With *mode* ``'r'`` the file-like object
|
2016-05-13 07:52:49 -03:00
|
|
|
(``ZipExtFile``) is read-only and provides the following methods:
|
|
|
|
:meth:`~io.BufferedIOBase.read`, :meth:`~io.IOBase.readline`,
|
2018-01-30 04:51:35 -04:00
|
|
|
:meth:`~io.IOBase.readlines`, :meth:`~io.IOBase.seek`,
|
|
|
|
:meth:`~io.IOBase.tell`, :meth:`__iter__`, :meth:`~iterator.__next__`.
|
|
|
|
These objects can operate independently of the ZipFile.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-05-13 07:52:49 -03:00
|
|
|
With ``mode='w'``, a writable file handle is returned, which supports the
|
|
|
|
:meth:`~io.BufferedIOBase.write` method. While a writable file handle is open,
|
|
|
|
attempting to read or write other files in the ZIP file will raise a
|
2016-09-10 15:28:07 -03:00
|
|
|
:exc:`ValueError`.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-05-13 07:52:49 -03:00
|
|
|
When writing a file, if the file size is not known in advance but may exceed
|
|
|
|
2 GiB, pass ``force_zip64=True`` to ensure that the header format is
|
|
|
|
capable of supporting large files. If the file size is known in advance,
|
|
|
|
construct a :class:`ZipInfo` object with :attr:`~ZipInfo.file_size` set, and
|
|
|
|
use that as the *name* parameter.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
Merged revisions 63412,63445-63447,63449-63450,63452,63454,63459,63463,63465,63470,63483-63484,63496-63497,63499-63501,63530-63531,63540,63614 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63412 | georg.brandl | 2008-05-17 19:57:01 +0200 (Sat, 17 May 2008) | 2 lines
#961805: fix Edit.text_modified().
........
r63445 | georg.brandl | 2008-05-18 10:52:59 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #180 by Michael Schneider: add examples to the socketserver documentation.
........
r63446 | georg.brandl | 2008-05-18 11:12:20 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #134, #171, #137: unit tests for the three HTTPServer modules.
........
r63447 | georg.brandl | 2008-05-18 12:39:26 +0200 (Sun, 18 May 2008) | 3 lines
Take namedtuple item names only from ascii_letters (this blew up on OSX),
and make sure there are no duplicate names.
........
r63449 | georg.brandl | 2008-05-18 13:46:51 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #217: add support for compiling Python with coverage checking enabled.
........
r63450 | georg.brandl | 2008-05-18 13:52:36 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #257: test distutils' build_ext command, written by Josip Dzolonga.
........
r63452 | georg.brandl | 2008-05-18 15:34:06 +0200 (Sun, 18 May 2008) | 2 lines
Add GHOP students.
........
r63454 | georg.brandl | 2008-05-18 18:32:48 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #121: improve test_pydoc, by Benjamin Peterson.
........
r63459 | benjamin.peterson | 2008-05-18 22:48:07 +0200 (Sun, 18 May 2008) | 2 lines
bring test_pydoc up to my high standards (now that I have them)
........
r63463 | georg.brandl | 2008-05-18 23:10:19 +0200 (Sun, 18 May 2008) | 2 lines
Fix test_pyclbr after another platform-dependent function was added to urllib.
........
r63465 | benjamin.peterson | 2008-05-19 01:07:07 +0200 (Mon, 19 May 2008) | 2 lines
change some imports in tests so they will not be skipped in 3.0
........
r63470 | georg.brandl | 2008-05-19 18:47:25 +0200 (Mon, 19 May 2008) | 2 lines
test_httpservers has unpredictable refcount behavior.
........
r63483 | georg.brandl | 2008-05-20 08:15:36 +0200 (Tue, 20 May 2008) | 2 lines
Activate two more test cases in test_httpservers.
........
r63484 | georg.brandl | 2008-05-20 08:47:31 +0200 (Tue, 20 May 2008) | 2 lines
Argh, this is the *actual* test that works under Windows.
........
r63496 | georg.brandl | 2008-05-20 10:07:36 +0200 (Tue, 20 May 2008) | 2 lines
Improve diffing logic and output for test_pydoc.
........
r63497 | georg.brandl | 2008-05-20 10:10:03 +0200 (Tue, 20 May 2008) | 2 lines
Use inspect.getabsfile() to get the documented module's filename.
........
r63499 | georg.brandl | 2008-05-20 10:25:48 +0200 (Tue, 20 May 2008) | 3 lines
Patch #1775025: allow opening zipfile members via ZipInfo instances.
Patch by Graham Horler.
........
r63500 | georg.brandl | 2008-05-20 10:40:43 +0200 (Tue, 20 May 2008) | 2 lines
#2592: delegate nb_index and the floor/truediv slots in weakref.proxy.
........
r63501 | georg.brandl | 2008-05-20 10:48:34 +0200 (Tue, 20 May 2008) | 2 lines
#615772: raise a more explicit error from Tkinter.Misc.__contains__.
........
r63530 | benjamin.peterson | 2008-05-22 02:57:02 +0200 (Thu, 22 May 2008) | 2 lines
use more specific asserts in test_opcode
........
r63531 | benjamin.peterson | 2008-05-22 03:02:23 +0200 (Thu, 22 May 2008) | 2 lines
remove redundant invocation of json doctests
........
r63540 | benjamin.peterson | 2008-05-23 01:09:26 +0200 (Fri, 23 May 2008) | 3 lines
fix test_pydoc so it works on make installed Python installations
Also let it pass when invoked directly
........
r63614 | georg.brandl | 2008-05-25 10:07:37 +0200 (Sun, 25 May 2008) | 2 lines
#2959: allow multiple close() calls for GzipFile.
........
2008-05-25 15:19:30 -03:00
|
|
|
.. note::
|
|
|
|
|
2012-10-06 12:02:05 -03:00
|
|
|
The :meth:`.open`, :meth:`read` and :meth:`extract` methods can take a filename
|
Merged revisions 63412,63445-63447,63449-63450,63452,63454,63459,63463,63465,63470,63483-63484,63496-63497,63499-63501,63530-63531,63540,63614 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63412 | georg.brandl | 2008-05-17 19:57:01 +0200 (Sat, 17 May 2008) | 2 lines
#961805: fix Edit.text_modified().
........
r63445 | georg.brandl | 2008-05-18 10:52:59 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #180 by Michael Schneider: add examples to the socketserver documentation.
........
r63446 | georg.brandl | 2008-05-18 11:12:20 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #134, #171, #137: unit tests for the three HTTPServer modules.
........
r63447 | georg.brandl | 2008-05-18 12:39:26 +0200 (Sun, 18 May 2008) | 3 lines
Take namedtuple item names only from ascii_letters (this blew up on OSX),
and make sure there are no duplicate names.
........
r63449 | georg.brandl | 2008-05-18 13:46:51 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #217: add support for compiling Python with coverage checking enabled.
........
r63450 | georg.brandl | 2008-05-18 13:52:36 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #257: test distutils' build_ext command, written by Josip Dzolonga.
........
r63452 | georg.brandl | 2008-05-18 15:34:06 +0200 (Sun, 18 May 2008) | 2 lines
Add GHOP students.
........
r63454 | georg.brandl | 2008-05-18 18:32:48 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #121: improve test_pydoc, by Benjamin Peterson.
........
r63459 | benjamin.peterson | 2008-05-18 22:48:07 +0200 (Sun, 18 May 2008) | 2 lines
bring test_pydoc up to my high standards (now that I have them)
........
r63463 | georg.brandl | 2008-05-18 23:10:19 +0200 (Sun, 18 May 2008) | 2 lines
Fix test_pyclbr after another platform-dependent function was added to urllib.
........
r63465 | benjamin.peterson | 2008-05-19 01:07:07 +0200 (Mon, 19 May 2008) | 2 lines
change some imports in tests so they will not be skipped in 3.0
........
r63470 | georg.brandl | 2008-05-19 18:47:25 +0200 (Mon, 19 May 2008) | 2 lines
test_httpservers has unpredictable refcount behavior.
........
r63483 | georg.brandl | 2008-05-20 08:15:36 +0200 (Tue, 20 May 2008) | 2 lines
Activate two more test cases in test_httpservers.
........
r63484 | georg.brandl | 2008-05-20 08:47:31 +0200 (Tue, 20 May 2008) | 2 lines
Argh, this is the *actual* test that works under Windows.
........
r63496 | georg.brandl | 2008-05-20 10:07:36 +0200 (Tue, 20 May 2008) | 2 lines
Improve diffing logic and output for test_pydoc.
........
r63497 | georg.brandl | 2008-05-20 10:10:03 +0200 (Tue, 20 May 2008) | 2 lines
Use inspect.getabsfile() to get the documented module's filename.
........
r63499 | georg.brandl | 2008-05-20 10:25:48 +0200 (Tue, 20 May 2008) | 3 lines
Patch #1775025: allow opening zipfile members via ZipInfo instances.
Patch by Graham Horler.
........
r63500 | georg.brandl | 2008-05-20 10:40:43 +0200 (Tue, 20 May 2008) | 2 lines
#2592: delegate nb_index and the floor/truediv slots in weakref.proxy.
........
r63501 | georg.brandl | 2008-05-20 10:48:34 +0200 (Tue, 20 May 2008) | 2 lines
#615772: raise a more explicit error from Tkinter.Misc.__contains__.
........
r63530 | benjamin.peterson | 2008-05-22 02:57:02 +0200 (Thu, 22 May 2008) | 2 lines
use more specific asserts in test_opcode
........
r63531 | benjamin.peterson | 2008-05-22 03:02:23 +0200 (Thu, 22 May 2008) | 2 lines
remove redundant invocation of json doctests
........
r63540 | benjamin.peterson | 2008-05-23 01:09:26 +0200 (Fri, 23 May 2008) | 3 lines
fix test_pydoc so it works on make installed Python installations
Also let it pass when invoked directly
........
r63614 | georg.brandl | 2008-05-25 10:07:37 +0200 (Sun, 25 May 2008) | 2 lines
#2959: allow multiple close() calls for GzipFile.
........
2008-05-25 15:19:30 -03:00
|
|
|
or a :class:`ZipInfo` object. You will appreciate this when trying to read a
|
|
|
|
ZIP file that contains members with duplicate names.
|
|
|
|
|
2016-06-11 13:32:44 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
Removed support of ``mode='U'``. Use :class:`io.TextIOWrapper` for reading
|
2013-11-23 16:12:06 -04:00
|
|
|
compressed text files in :term:`universal newlines` mode.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-05-13 07:52:49 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
:meth:`open` can now be used to write files into the archive with the
|
|
|
|
``mode='w'`` option.
|
|
|
|
|
2016-09-10 15:28:07 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
Calling :meth:`.open` on a closed ZipFile will raise a :exc:`ValueError`.
|
|
|
|
Previously, a :exc:`RuntimeError` was raised.
|
|
|
|
|
|
|
|
|
2009-09-16 12:58:14 -03:00
|
|
|
.. method:: ZipFile.extract(member, path=None, pwd=None)
|
Merged revisions 59822-59841 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59822 | georg.brandl | 2008-01-07 17:43:47 +0100 (Mon, 07 Jan 2008) | 2 lines
Restore "somenamedtuple" as the "class" for named tuple attrs.
........
r59824 | georg.brandl | 2008-01-07 18:09:35 +0100 (Mon, 07 Jan 2008) | 2 lines
Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
........
r59827 | georg.brandl | 2008-01-07 18:25:53 +0100 (Mon, 07 Jan 2008) | 2 lines
patch #1668: clarify envvar docs; rename THREADDEBUG to PYTHONTHREADDEBUG.
........
r59830 | georg.brandl | 2008-01-07 19:16:36 +0100 (Mon, 07 Jan 2008) | 2 lines
Make Python compile with --disable-unicode.
........
r59831 | georg.brandl | 2008-01-07 19:23:27 +0100 (Mon, 07 Jan 2008) | 2 lines
Restructure urllib doc structure.
........
r59833 | georg.brandl | 2008-01-07 19:41:34 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix #define ordering.
........
r59834 | georg.brandl | 2008-01-07 19:47:44 +0100 (Mon, 07 Jan 2008) | 2 lines
#467924, patch by Alan McIntyre: Add ZipFile.extract and ZipFile.extractall.
........
r59835 | raymond.hettinger | 2008-01-07 19:52:19 +0100 (Mon, 07 Jan 2008) | 1 line
Fix inconsistent title levels -- it made the whole doc build crash horribly.
........
r59836 | georg.brandl | 2008-01-07 19:57:03 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix two further doc build warnings.
........
r59837 | georg.brandl | 2008-01-07 20:17:10 +0100 (Mon, 07 Jan 2008) | 2 lines
Clarify metaclass docs and add example.
........
r59838 | vinay.sajip | 2008-01-07 20:40:10 +0100 (Mon, 07 Jan 2008) | 1 line
Added section about adding contextual information to log output.
........
r59839 | christian.heimes | 2008-01-07 20:58:41 +0100 (Mon, 07 Jan 2008) | 1 line
Fixed indention problem that caused the second TIPC test to run on systems without TIPC
........
r59840 | raymond.hettinger | 2008-01-07 21:07:38 +0100 (Mon, 07 Jan 2008) | 1 line
Cleanup named tuple subclassing example.
........
2008-01-07 17:14:23 -04:00
|
|
|
|
Merged revisions 63412,63445-63447,63449-63450,63452,63454,63459,63463,63465,63470,63483-63484,63496-63497,63499-63501,63530-63531,63540,63614 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63412 | georg.brandl | 2008-05-17 19:57:01 +0200 (Sat, 17 May 2008) | 2 lines
#961805: fix Edit.text_modified().
........
r63445 | georg.brandl | 2008-05-18 10:52:59 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #180 by Michael Schneider: add examples to the socketserver documentation.
........
r63446 | georg.brandl | 2008-05-18 11:12:20 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #134, #171, #137: unit tests for the three HTTPServer modules.
........
r63447 | georg.brandl | 2008-05-18 12:39:26 +0200 (Sun, 18 May 2008) | 3 lines
Take namedtuple item names only from ascii_letters (this blew up on OSX),
and make sure there are no duplicate names.
........
r63449 | georg.brandl | 2008-05-18 13:46:51 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #217: add support for compiling Python with coverage checking enabled.
........
r63450 | georg.brandl | 2008-05-18 13:52:36 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #257: test distutils' build_ext command, written by Josip Dzolonga.
........
r63452 | georg.brandl | 2008-05-18 15:34:06 +0200 (Sun, 18 May 2008) | 2 lines
Add GHOP students.
........
r63454 | georg.brandl | 2008-05-18 18:32:48 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #121: improve test_pydoc, by Benjamin Peterson.
........
r63459 | benjamin.peterson | 2008-05-18 22:48:07 +0200 (Sun, 18 May 2008) | 2 lines
bring test_pydoc up to my high standards (now that I have them)
........
r63463 | georg.brandl | 2008-05-18 23:10:19 +0200 (Sun, 18 May 2008) | 2 lines
Fix test_pyclbr after another platform-dependent function was added to urllib.
........
r63465 | benjamin.peterson | 2008-05-19 01:07:07 +0200 (Mon, 19 May 2008) | 2 lines
change some imports in tests so they will not be skipped in 3.0
........
r63470 | georg.brandl | 2008-05-19 18:47:25 +0200 (Mon, 19 May 2008) | 2 lines
test_httpservers has unpredictable refcount behavior.
........
r63483 | georg.brandl | 2008-05-20 08:15:36 +0200 (Tue, 20 May 2008) | 2 lines
Activate two more test cases in test_httpservers.
........
r63484 | georg.brandl | 2008-05-20 08:47:31 +0200 (Tue, 20 May 2008) | 2 lines
Argh, this is the *actual* test that works under Windows.
........
r63496 | georg.brandl | 2008-05-20 10:07:36 +0200 (Tue, 20 May 2008) | 2 lines
Improve diffing logic and output for test_pydoc.
........
r63497 | georg.brandl | 2008-05-20 10:10:03 +0200 (Tue, 20 May 2008) | 2 lines
Use inspect.getabsfile() to get the documented module's filename.
........
r63499 | georg.brandl | 2008-05-20 10:25:48 +0200 (Tue, 20 May 2008) | 3 lines
Patch #1775025: allow opening zipfile members via ZipInfo instances.
Patch by Graham Horler.
........
r63500 | georg.brandl | 2008-05-20 10:40:43 +0200 (Tue, 20 May 2008) | 2 lines
#2592: delegate nb_index and the floor/truediv slots in weakref.proxy.
........
r63501 | georg.brandl | 2008-05-20 10:48:34 +0200 (Tue, 20 May 2008) | 2 lines
#615772: raise a more explicit error from Tkinter.Misc.__contains__.
........
r63530 | benjamin.peterson | 2008-05-22 02:57:02 +0200 (Thu, 22 May 2008) | 2 lines
use more specific asserts in test_opcode
........
r63531 | benjamin.peterson | 2008-05-22 03:02:23 +0200 (Thu, 22 May 2008) | 2 lines
remove redundant invocation of json doctests
........
r63540 | benjamin.peterson | 2008-05-23 01:09:26 +0200 (Fri, 23 May 2008) | 3 lines
fix test_pydoc so it works on make installed Python installations
Also let it pass when invoked directly
........
r63614 | georg.brandl | 2008-05-25 10:07:37 +0200 (Sun, 25 May 2008) | 2 lines
#2959: allow multiple close() calls for GzipFile.
........
2008-05-25 15:19:30 -03:00
|
|
|
Extract a member from the archive to the current working directory; *member*
|
2016-06-24 06:56:50 -03:00
|
|
|
must be its full name or a :class:`ZipInfo` object. Its file information is
|
Merged revisions 63412,63445-63447,63449-63450,63452,63454,63459,63463,63465,63470,63483-63484,63496-63497,63499-63501,63530-63531,63540,63614 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63412 | georg.brandl | 2008-05-17 19:57:01 +0200 (Sat, 17 May 2008) | 2 lines
#961805: fix Edit.text_modified().
........
r63445 | georg.brandl | 2008-05-18 10:52:59 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #180 by Michael Schneider: add examples to the socketserver documentation.
........
r63446 | georg.brandl | 2008-05-18 11:12:20 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #134, #171, #137: unit tests for the three HTTPServer modules.
........
r63447 | georg.brandl | 2008-05-18 12:39:26 +0200 (Sun, 18 May 2008) | 3 lines
Take namedtuple item names only from ascii_letters (this blew up on OSX),
and make sure there are no duplicate names.
........
r63449 | georg.brandl | 2008-05-18 13:46:51 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #217: add support for compiling Python with coverage checking enabled.
........
r63450 | georg.brandl | 2008-05-18 13:52:36 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #257: test distutils' build_ext command, written by Josip Dzolonga.
........
r63452 | georg.brandl | 2008-05-18 15:34:06 +0200 (Sun, 18 May 2008) | 2 lines
Add GHOP students.
........
r63454 | georg.brandl | 2008-05-18 18:32:48 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #121: improve test_pydoc, by Benjamin Peterson.
........
r63459 | benjamin.peterson | 2008-05-18 22:48:07 +0200 (Sun, 18 May 2008) | 2 lines
bring test_pydoc up to my high standards (now that I have them)
........
r63463 | georg.brandl | 2008-05-18 23:10:19 +0200 (Sun, 18 May 2008) | 2 lines
Fix test_pyclbr after another platform-dependent function was added to urllib.
........
r63465 | benjamin.peterson | 2008-05-19 01:07:07 +0200 (Mon, 19 May 2008) | 2 lines
change some imports in tests so they will not be skipped in 3.0
........
r63470 | georg.brandl | 2008-05-19 18:47:25 +0200 (Mon, 19 May 2008) | 2 lines
test_httpservers has unpredictable refcount behavior.
........
r63483 | georg.brandl | 2008-05-20 08:15:36 +0200 (Tue, 20 May 2008) | 2 lines
Activate two more test cases in test_httpservers.
........
r63484 | georg.brandl | 2008-05-20 08:47:31 +0200 (Tue, 20 May 2008) | 2 lines
Argh, this is the *actual* test that works under Windows.
........
r63496 | georg.brandl | 2008-05-20 10:07:36 +0200 (Tue, 20 May 2008) | 2 lines
Improve diffing logic and output for test_pydoc.
........
r63497 | georg.brandl | 2008-05-20 10:10:03 +0200 (Tue, 20 May 2008) | 2 lines
Use inspect.getabsfile() to get the documented module's filename.
........
r63499 | georg.brandl | 2008-05-20 10:25:48 +0200 (Tue, 20 May 2008) | 3 lines
Patch #1775025: allow opening zipfile members via ZipInfo instances.
Patch by Graham Horler.
........
r63500 | georg.brandl | 2008-05-20 10:40:43 +0200 (Tue, 20 May 2008) | 2 lines
#2592: delegate nb_index and the floor/truediv slots in weakref.proxy.
........
r63501 | georg.brandl | 2008-05-20 10:48:34 +0200 (Tue, 20 May 2008) | 2 lines
#615772: raise a more explicit error from Tkinter.Misc.__contains__.
........
r63530 | benjamin.peterson | 2008-05-22 02:57:02 +0200 (Thu, 22 May 2008) | 2 lines
use more specific asserts in test_opcode
........
r63531 | benjamin.peterson | 2008-05-22 03:02:23 +0200 (Thu, 22 May 2008) | 2 lines
remove redundant invocation of json doctests
........
r63540 | benjamin.peterson | 2008-05-23 01:09:26 +0200 (Fri, 23 May 2008) | 3 lines
fix test_pydoc so it works on make installed Python installations
Also let it pass when invoked directly
........
r63614 | georg.brandl | 2008-05-25 10:07:37 +0200 (Sun, 25 May 2008) | 2 lines
#2959: allow multiple close() calls for GzipFile.
........
2008-05-25 15:19:30 -03:00
|
|
|
extracted as accurately as possible. *path* specifies a different directory
|
|
|
|
to extract to. *member* can be a filename or a :class:`ZipInfo` object.
|
|
|
|
*pwd* is the password used for encrypted files.
|
Merged revisions 59822-59841 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59822 | georg.brandl | 2008-01-07 17:43:47 +0100 (Mon, 07 Jan 2008) | 2 lines
Restore "somenamedtuple" as the "class" for named tuple attrs.
........
r59824 | georg.brandl | 2008-01-07 18:09:35 +0100 (Mon, 07 Jan 2008) | 2 lines
Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
........
r59827 | georg.brandl | 2008-01-07 18:25:53 +0100 (Mon, 07 Jan 2008) | 2 lines
patch #1668: clarify envvar docs; rename THREADDEBUG to PYTHONTHREADDEBUG.
........
r59830 | georg.brandl | 2008-01-07 19:16:36 +0100 (Mon, 07 Jan 2008) | 2 lines
Make Python compile with --disable-unicode.
........
r59831 | georg.brandl | 2008-01-07 19:23:27 +0100 (Mon, 07 Jan 2008) | 2 lines
Restructure urllib doc structure.
........
r59833 | georg.brandl | 2008-01-07 19:41:34 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix #define ordering.
........
r59834 | georg.brandl | 2008-01-07 19:47:44 +0100 (Mon, 07 Jan 2008) | 2 lines
#467924, patch by Alan McIntyre: Add ZipFile.extract and ZipFile.extractall.
........
r59835 | raymond.hettinger | 2008-01-07 19:52:19 +0100 (Mon, 07 Jan 2008) | 1 line
Fix inconsistent title levels -- it made the whole doc build crash horribly.
........
r59836 | georg.brandl | 2008-01-07 19:57:03 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix two further doc build warnings.
........
r59837 | georg.brandl | 2008-01-07 20:17:10 +0100 (Mon, 07 Jan 2008) | 2 lines
Clarify metaclass docs and add example.
........
r59838 | vinay.sajip | 2008-01-07 20:40:10 +0100 (Mon, 07 Jan 2008) | 1 line
Added section about adding contextual information to log output.
........
r59839 | christian.heimes | 2008-01-07 20:58:41 +0100 (Mon, 07 Jan 2008) | 1 line
Fixed indention problem that caused the second TIPC test to run on systems without TIPC
........
r59840 | raymond.hettinger | 2008-01-07 21:07:38 +0100 (Mon, 07 Jan 2008) | 1 line
Cleanup named tuple subclassing example.
........
2008-01-07 17:14:23 -04:00
|
|
|
|
2015-04-13 18:40:49 -03:00
|
|
|
Returns the normalized path created (a directory or new file).
|
|
|
|
|
2013-02-01 15:22:43 -04:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
If a member filename is an absolute path, a drive/UNC sharepoint and
|
|
|
|
leading (back)slashes will be stripped, e.g.: ``///foo/bar`` becomes
|
2013-02-02 07:27:30 -04:00
|
|
|
``foo/bar`` on Unix, and ``C:\foo\bar`` becomes ``foo\bar`` on Windows.
|
2013-02-01 15:22:43 -04:00
|
|
|
And all ``".."`` components in a member filename will be removed, e.g.:
|
|
|
|
``../../foo../../ba..r`` becomes ``foo../ba..r``. On Windows illegal
|
|
|
|
characters (``:``, ``<``, ``>``, ``|``, ``"``, ``?``, and ``*``)
|
|
|
|
replaced by underscore (``_``).
|
|
|
|
|
2016-09-10 15:28:07 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
Calling :meth:`extract` on a closed ZipFile will raise a
|
|
|
|
:exc:`ValueError`. Previously, a :exc:`RuntimeError` was raised.
|
|
|
|
|
2017-03-08 08:37:51 -04:00
|
|
|
.. versionchanged:: 3.6.2
|
|
|
|
The *path* parameter accepts a :term:`path-like object`.
|
|
|
|
|
Merged revisions 59822-59841 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59822 | georg.brandl | 2008-01-07 17:43:47 +0100 (Mon, 07 Jan 2008) | 2 lines
Restore "somenamedtuple" as the "class" for named tuple attrs.
........
r59824 | georg.brandl | 2008-01-07 18:09:35 +0100 (Mon, 07 Jan 2008) | 2 lines
Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
........
r59827 | georg.brandl | 2008-01-07 18:25:53 +0100 (Mon, 07 Jan 2008) | 2 lines
patch #1668: clarify envvar docs; rename THREADDEBUG to PYTHONTHREADDEBUG.
........
r59830 | georg.brandl | 2008-01-07 19:16:36 +0100 (Mon, 07 Jan 2008) | 2 lines
Make Python compile with --disable-unicode.
........
r59831 | georg.brandl | 2008-01-07 19:23:27 +0100 (Mon, 07 Jan 2008) | 2 lines
Restructure urllib doc structure.
........
r59833 | georg.brandl | 2008-01-07 19:41:34 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix #define ordering.
........
r59834 | georg.brandl | 2008-01-07 19:47:44 +0100 (Mon, 07 Jan 2008) | 2 lines
#467924, patch by Alan McIntyre: Add ZipFile.extract and ZipFile.extractall.
........
r59835 | raymond.hettinger | 2008-01-07 19:52:19 +0100 (Mon, 07 Jan 2008) | 1 line
Fix inconsistent title levels -- it made the whole doc build crash horribly.
........
r59836 | georg.brandl | 2008-01-07 19:57:03 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix two further doc build warnings.
........
r59837 | georg.brandl | 2008-01-07 20:17:10 +0100 (Mon, 07 Jan 2008) | 2 lines
Clarify metaclass docs and add example.
........
r59838 | vinay.sajip | 2008-01-07 20:40:10 +0100 (Mon, 07 Jan 2008) | 1 line
Added section about adding contextual information to log output.
........
r59839 | christian.heimes | 2008-01-07 20:58:41 +0100 (Mon, 07 Jan 2008) | 1 line
Fixed indention problem that caused the second TIPC test to run on systems without TIPC
........
r59840 | raymond.hettinger | 2008-01-07 21:07:38 +0100 (Mon, 07 Jan 2008) | 1 line
Cleanup named tuple subclassing example.
........
2008-01-07 17:14:23 -04:00
|
|
|
|
2009-09-16 12:58:14 -03:00
|
|
|
.. method:: ZipFile.extractall(path=None, members=None, pwd=None)
|
Merged revisions 59822-59841 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59822 | georg.brandl | 2008-01-07 17:43:47 +0100 (Mon, 07 Jan 2008) | 2 lines
Restore "somenamedtuple" as the "class" for named tuple attrs.
........
r59824 | georg.brandl | 2008-01-07 18:09:35 +0100 (Mon, 07 Jan 2008) | 2 lines
Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
........
r59827 | georg.brandl | 2008-01-07 18:25:53 +0100 (Mon, 07 Jan 2008) | 2 lines
patch #1668: clarify envvar docs; rename THREADDEBUG to PYTHONTHREADDEBUG.
........
r59830 | georg.brandl | 2008-01-07 19:16:36 +0100 (Mon, 07 Jan 2008) | 2 lines
Make Python compile with --disable-unicode.
........
r59831 | georg.brandl | 2008-01-07 19:23:27 +0100 (Mon, 07 Jan 2008) | 2 lines
Restructure urllib doc structure.
........
r59833 | georg.brandl | 2008-01-07 19:41:34 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix #define ordering.
........
r59834 | georg.brandl | 2008-01-07 19:47:44 +0100 (Mon, 07 Jan 2008) | 2 lines
#467924, patch by Alan McIntyre: Add ZipFile.extract and ZipFile.extractall.
........
r59835 | raymond.hettinger | 2008-01-07 19:52:19 +0100 (Mon, 07 Jan 2008) | 1 line
Fix inconsistent title levels -- it made the whole doc build crash horribly.
........
r59836 | georg.brandl | 2008-01-07 19:57:03 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix two further doc build warnings.
........
r59837 | georg.brandl | 2008-01-07 20:17:10 +0100 (Mon, 07 Jan 2008) | 2 lines
Clarify metaclass docs and add example.
........
r59838 | vinay.sajip | 2008-01-07 20:40:10 +0100 (Mon, 07 Jan 2008) | 1 line
Added section about adding contextual information to log output.
........
r59839 | christian.heimes | 2008-01-07 20:58:41 +0100 (Mon, 07 Jan 2008) | 1 line
Fixed indention problem that caused the second TIPC test to run on systems without TIPC
........
r59840 | raymond.hettinger | 2008-01-07 21:07:38 +0100 (Mon, 07 Jan 2008) | 1 line
Cleanup named tuple subclassing example.
........
2008-01-07 17:14:23 -04:00
|
|
|
|
2009-01-03 17:18:54 -04:00
|
|
|
Extract all members from the archive to the current working directory. *path*
|
Merged revisions 59822-59841 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59822 | georg.brandl | 2008-01-07 17:43:47 +0100 (Mon, 07 Jan 2008) | 2 lines
Restore "somenamedtuple" as the "class" for named tuple attrs.
........
r59824 | georg.brandl | 2008-01-07 18:09:35 +0100 (Mon, 07 Jan 2008) | 2 lines
Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
........
r59827 | georg.brandl | 2008-01-07 18:25:53 +0100 (Mon, 07 Jan 2008) | 2 lines
patch #1668: clarify envvar docs; rename THREADDEBUG to PYTHONTHREADDEBUG.
........
r59830 | georg.brandl | 2008-01-07 19:16:36 +0100 (Mon, 07 Jan 2008) | 2 lines
Make Python compile with --disable-unicode.
........
r59831 | georg.brandl | 2008-01-07 19:23:27 +0100 (Mon, 07 Jan 2008) | 2 lines
Restructure urllib doc structure.
........
r59833 | georg.brandl | 2008-01-07 19:41:34 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix #define ordering.
........
r59834 | georg.brandl | 2008-01-07 19:47:44 +0100 (Mon, 07 Jan 2008) | 2 lines
#467924, patch by Alan McIntyre: Add ZipFile.extract and ZipFile.extractall.
........
r59835 | raymond.hettinger | 2008-01-07 19:52:19 +0100 (Mon, 07 Jan 2008) | 1 line
Fix inconsistent title levels -- it made the whole doc build crash horribly.
........
r59836 | georg.brandl | 2008-01-07 19:57:03 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix two further doc build warnings.
........
r59837 | georg.brandl | 2008-01-07 20:17:10 +0100 (Mon, 07 Jan 2008) | 2 lines
Clarify metaclass docs and add example.
........
r59838 | vinay.sajip | 2008-01-07 20:40:10 +0100 (Mon, 07 Jan 2008) | 1 line
Added section about adding contextual information to log output.
........
r59839 | christian.heimes | 2008-01-07 20:58:41 +0100 (Mon, 07 Jan 2008) | 1 line
Fixed indention problem that caused the second TIPC test to run on systems without TIPC
........
r59840 | raymond.hettinger | 2008-01-07 21:07:38 +0100 (Mon, 07 Jan 2008) | 1 line
Cleanup named tuple subclassing example.
........
2008-01-07 17:14:23 -04:00
|
|
|
specifies a different directory to extract to. *members* is optional and must
|
|
|
|
be a subset of the list returned by :meth:`namelist`. *pwd* is the password
|
|
|
|
used for encrypted files.
|
|
|
|
|
2013-02-08 02:15:04 -04:00
|
|
|
.. warning::
|
Merged revisions 75149,75260-75263,75265-75267,75292,75300,75376,75405,75429-75433,75437,75445,75501,75551,75572,75589-75591,75657,75742,75868,75952-75957,76057,76105,76139,76143,76162,76223 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r75149 | gregory.p.smith | 2009-09-29 16:56:31 -0500 (Tue, 29 Sep 2009) | 3 lines
Mention issue6972 in extractall docs about overwriting things outside of
the supplied path.
........
r75260 | andrew.kuchling | 2009-10-05 16:24:20 -0500 (Mon, 05 Oct 2009) | 1 line
Wording fix
........
r75261 | andrew.kuchling | 2009-10-05 16:24:35 -0500 (Mon, 05 Oct 2009) | 1 line
Fix narkup
........
r75262 | andrew.kuchling | 2009-10-05 16:25:03 -0500 (Mon, 05 Oct 2009) | 1 line
Document 'skip' parameter to constructor
........
r75263 | andrew.kuchling | 2009-10-05 16:25:35 -0500 (Mon, 05 Oct 2009) | 1 line
Note side benefit of socket.create_connection()
........
r75265 | andrew.kuchling | 2009-10-05 17:31:11 -0500 (Mon, 05 Oct 2009) | 1 line
Reword sentence
........
r75266 | andrew.kuchling | 2009-10-05 17:32:48 -0500 (Mon, 05 Oct 2009) | 1 line
Use standard comma punctuation; reword some sentences in the docs
........
r75267 | andrew.kuchling | 2009-10-05 17:42:56 -0500 (Mon, 05 Oct 2009) | 1 line
Backport r73983: Document the thousands separator.
........
r75292 | benjamin.peterson | 2009-10-08 22:11:36 -0500 (Thu, 08 Oct 2009) | 1 line
death to old CVS keyword
........
r75300 | benjamin.peterson | 2009-10-09 16:48:14 -0500 (Fri, 09 Oct 2009) | 1 line
fix some coding style
........
r75376 | benjamin.peterson | 2009-10-11 20:26:07 -0500 (Sun, 11 Oct 2009) | 1 line
platform we don't care about
........
r75405 | neil.schemenauer | 2009-10-14 12:17:14 -0500 (Wed, 14 Oct 2009) | 4 lines
Issue #1754094: Improve the stack depth calculation in the compiler.
There should be no other effect than a small decrease in memory use.
Patch by Christopher Tur Lesniewski-Laas.
........
r75429 | benjamin.peterson | 2009-10-14 20:47:28 -0500 (Wed, 14 Oct 2009) | 1 line
pep8ify if blocks
........
r75430 | benjamin.peterson | 2009-10-14 20:49:37 -0500 (Wed, 14 Oct 2009) | 1 line
use floor division and add a test that exercises the tabsize codepath
........
r75431 | benjamin.peterson | 2009-10-14 20:56:25 -0500 (Wed, 14 Oct 2009) | 1 line
change test to what I intended
........
r75432 | benjamin.peterson | 2009-10-14 22:05:39 -0500 (Wed, 14 Oct 2009) | 1 line
some cleanups
........
r75433 | benjamin.peterson | 2009-10-14 22:06:55 -0500 (Wed, 14 Oct 2009) | 1 line
make inspect.isabstract() always return a boolean; add a test for it, too #7069
........
r75437 | benjamin.peterson | 2009-10-15 10:44:46 -0500 (Thu, 15 Oct 2009) | 1 line
only clear a module's __dict__ if the module is the only one with a reference to it #7140
........
r75445 | vinay.sajip | 2009-10-16 09:06:44 -0500 (Fri, 16 Oct 2009) | 1 line
Issue #7120: logging: Removed import of multiprocessing which is causing crash in GAE.
........
r75501 | antoine.pitrou | 2009-10-18 13:37:11 -0500 (Sun, 18 Oct 2009) | 3 lines
Add a comment about unreachable code, and fix a typo
........
r75551 | benjamin.peterson | 2009-10-19 22:14:10 -0500 (Mon, 19 Oct 2009) | 1 line
use property api
........
r75572 | benjamin.peterson | 2009-10-20 16:55:17 -0500 (Tue, 20 Oct 2009) | 1 line
clarify buffer arg #7178
........
r75589 | benjamin.peterson | 2009-10-21 21:26:47 -0500 (Wed, 21 Oct 2009) | 1 line
whitespace
........
r75590 | benjamin.peterson | 2009-10-21 21:36:47 -0500 (Wed, 21 Oct 2009) | 1 line
rewrite to be nice to other implementations
........
r75591 | benjamin.peterson | 2009-10-21 21:50:38 -0500 (Wed, 21 Oct 2009) | 4 lines
rewrite for style, clarify, and comments
Also, use the hasattr() like scheme of allowing BaseException exceptions through.
........
r75657 | antoine.pitrou | 2009-10-24 07:41:27 -0500 (Sat, 24 Oct 2009) | 3 lines
Fix compilation error in debug mode.
........
r75742 | benjamin.peterson | 2009-10-26 17:51:16 -0500 (Mon, 26 Oct 2009) | 1 line
use 'is' instead of id()
........
r75868 | benjamin.peterson | 2009-10-27 15:59:18 -0500 (Tue, 27 Oct 2009) | 1 line
test expect base classes
........
r75952 | georg.brandl | 2009-10-29 15:38:32 -0500 (Thu, 29 Oct 2009) | 1 line
Use the correct function name in docstring.
........
r75953 | georg.brandl | 2009-10-29 15:39:50 -0500 (Thu, 29 Oct 2009) | 1 line
Remove mention of the old -X command line switch.
........
r75954 | georg.brandl | 2009-10-29 15:53:00 -0500 (Thu, 29 Oct 2009) | 1 line
Use constants instead of magic integers for test result. Do not re-run with --verbose3 for environment changing tests.
........
r75955 | georg.brandl | 2009-10-29 15:54:03 -0500 (Thu, 29 Oct 2009) | 1 line
Use a single style for all the docstrings in the math module.
........
r75956 | georg.brandl | 2009-10-29 16:16:34 -0500 (Thu, 29 Oct 2009) | 1 line
I do not think the "railroad" program mentioned is still available.
........
r75957 | georg.brandl | 2009-10-29 16:44:56 -0500 (Thu, 29 Oct 2009) | 1 line
Fix constant name.
........
r76057 | benjamin.peterson | 2009-11-02 09:06:45 -0600 (Mon, 02 Nov 2009) | 1 line
prevent a rather unlikely segfault
........
r76105 | georg.brandl | 2009-11-04 01:38:12 -0600 (Wed, 04 Nov 2009) | 1 line
#7259: show correct equivalent for operator.i* operations in docstring; fix minor issues in operator docs.
........
r76139 | benjamin.peterson | 2009-11-06 19:04:38 -0600 (Fri, 06 Nov 2009) | 1 line
spelling
........
r76143 | georg.brandl | 2009-11-07 02:26:07 -0600 (Sat, 07 Nov 2009) | 1 line
#7271: fix typo.
........
r76162 | benjamin.peterson | 2009-11-08 22:10:53 -0600 (Sun, 08 Nov 2009) | 1 line
discuss how to use -p
........
r76223 | georg.brandl | 2009-11-12 02:29:46 -0600 (Thu, 12 Nov 2009) | 1 line
Give the profile module a module directive.
........
2009-11-12 22:25:08 -04:00
|
|
|
|
2013-02-08 02:15:04 -04:00
|
|
|
Never extract archives from untrusted sources without prior inspection.
|
|
|
|
It is possible that files are created outside of *path*, e.g. members
|
|
|
|
that have absolute filenames starting with ``"/"`` or filenames with two
|
2013-02-08 02:17:21 -04:00
|
|
|
dots ``".."``. This module attempts to prevent that.
|
2013-02-01 15:22:43 -04:00
|
|
|
See :meth:`extract` note.
|
Merged revisions 75149,75260-75263,75265-75267,75292,75300,75376,75405,75429-75433,75437,75445,75501,75551,75572,75589-75591,75657,75742,75868,75952-75957,76057,76105,76139,76143,76162,76223 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r75149 | gregory.p.smith | 2009-09-29 16:56:31 -0500 (Tue, 29 Sep 2009) | 3 lines
Mention issue6972 in extractall docs about overwriting things outside of
the supplied path.
........
r75260 | andrew.kuchling | 2009-10-05 16:24:20 -0500 (Mon, 05 Oct 2009) | 1 line
Wording fix
........
r75261 | andrew.kuchling | 2009-10-05 16:24:35 -0500 (Mon, 05 Oct 2009) | 1 line
Fix narkup
........
r75262 | andrew.kuchling | 2009-10-05 16:25:03 -0500 (Mon, 05 Oct 2009) | 1 line
Document 'skip' parameter to constructor
........
r75263 | andrew.kuchling | 2009-10-05 16:25:35 -0500 (Mon, 05 Oct 2009) | 1 line
Note side benefit of socket.create_connection()
........
r75265 | andrew.kuchling | 2009-10-05 17:31:11 -0500 (Mon, 05 Oct 2009) | 1 line
Reword sentence
........
r75266 | andrew.kuchling | 2009-10-05 17:32:48 -0500 (Mon, 05 Oct 2009) | 1 line
Use standard comma punctuation; reword some sentences in the docs
........
r75267 | andrew.kuchling | 2009-10-05 17:42:56 -0500 (Mon, 05 Oct 2009) | 1 line
Backport r73983: Document the thousands separator.
........
r75292 | benjamin.peterson | 2009-10-08 22:11:36 -0500 (Thu, 08 Oct 2009) | 1 line
death to old CVS keyword
........
r75300 | benjamin.peterson | 2009-10-09 16:48:14 -0500 (Fri, 09 Oct 2009) | 1 line
fix some coding style
........
r75376 | benjamin.peterson | 2009-10-11 20:26:07 -0500 (Sun, 11 Oct 2009) | 1 line
platform we don't care about
........
r75405 | neil.schemenauer | 2009-10-14 12:17:14 -0500 (Wed, 14 Oct 2009) | 4 lines
Issue #1754094: Improve the stack depth calculation in the compiler.
There should be no other effect than a small decrease in memory use.
Patch by Christopher Tur Lesniewski-Laas.
........
r75429 | benjamin.peterson | 2009-10-14 20:47:28 -0500 (Wed, 14 Oct 2009) | 1 line
pep8ify if blocks
........
r75430 | benjamin.peterson | 2009-10-14 20:49:37 -0500 (Wed, 14 Oct 2009) | 1 line
use floor division and add a test that exercises the tabsize codepath
........
r75431 | benjamin.peterson | 2009-10-14 20:56:25 -0500 (Wed, 14 Oct 2009) | 1 line
change test to what I intended
........
r75432 | benjamin.peterson | 2009-10-14 22:05:39 -0500 (Wed, 14 Oct 2009) | 1 line
some cleanups
........
r75433 | benjamin.peterson | 2009-10-14 22:06:55 -0500 (Wed, 14 Oct 2009) | 1 line
make inspect.isabstract() always return a boolean; add a test for it, too #7069
........
r75437 | benjamin.peterson | 2009-10-15 10:44:46 -0500 (Thu, 15 Oct 2009) | 1 line
only clear a module's __dict__ if the module is the only one with a reference to it #7140
........
r75445 | vinay.sajip | 2009-10-16 09:06:44 -0500 (Fri, 16 Oct 2009) | 1 line
Issue #7120: logging: Removed import of multiprocessing which is causing crash in GAE.
........
r75501 | antoine.pitrou | 2009-10-18 13:37:11 -0500 (Sun, 18 Oct 2009) | 3 lines
Add a comment about unreachable code, and fix a typo
........
r75551 | benjamin.peterson | 2009-10-19 22:14:10 -0500 (Mon, 19 Oct 2009) | 1 line
use property api
........
r75572 | benjamin.peterson | 2009-10-20 16:55:17 -0500 (Tue, 20 Oct 2009) | 1 line
clarify buffer arg #7178
........
r75589 | benjamin.peterson | 2009-10-21 21:26:47 -0500 (Wed, 21 Oct 2009) | 1 line
whitespace
........
r75590 | benjamin.peterson | 2009-10-21 21:36:47 -0500 (Wed, 21 Oct 2009) | 1 line
rewrite to be nice to other implementations
........
r75591 | benjamin.peterson | 2009-10-21 21:50:38 -0500 (Wed, 21 Oct 2009) | 4 lines
rewrite for style, clarify, and comments
Also, use the hasattr() like scheme of allowing BaseException exceptions through.
........
r75657 | antoine.pitrou | 2009-10-24 07:41:27 -0500 (Sat, 24 Oct 2009) | 3 lines
Fix compilation error in debug mode.
........
r75742 | benjamin.peterson | 2009-10-26 17:51:16 -0500 (Mon, 26 Oct 2009) | 1 line
use 'is' instead of id()
........
r75868 | benjamin.peterson | 2009-10-27 15:59:18 -0500 (Tue, 27 Oct 2009) | 1 line
test expect base classes
........
r75952 | georg.brandl | 2009-10-29 15:38:32 -0500 (Thu, 29 Oct 2009) | 1 line
Use the correct function name in docstring.
........
r75953 | georg.brandl | 2009-10-29 15:39:50 -0500 (Thu, 29 Oct 2009) | 1 line
Remove mention of the old -X command line switch.
........
r75954 | georg.brandl | 2009-10-29 15:53:00 -0500 (Thu, 29 Oct 2009) | 1 line
Use constants instead of magic integers for test result. Do not re-run with --verbose3 for environment changing tests.
........
r75955 | georg.brandl | 2009-10-29 15:54:03 -0500 (Thu, 29 Oct 2009) | 1 line
Use a single style for all the docstrings in the math module.
........
r75956 | georg.brandl | 2009-10-29 16:16:34 -0500 (Thu, 29 Oct 2009) | 1 line
I do not think the "railroad" program mentioned is still available.
........
r75957 | georg.brandl | 2009-10-29 16:44:56 -0500 (Thu, 29 Oct 2009) | 1 line
Fix constant name.
........
r76057 | benjamin.peterson | 2009-11-02 09:06:45 -0600 (Mon, 02 Nov 2009) | 1 line
prevent a rather unlikely segfault
........
r76105 | georg.brandl | 2009-11-04 01:38:12 -0600 (Wed, 04 Nov 2009) | 1 line
#7259: show correct equivalent for operator.i* operations in docstring; fix minor issues in operator docs.
........
r76139 | benjamin.peterson | 2009-11-06 19:04:38 -0600 (Fri, 06 Nov 2009) | 1 line
spelling
........
r76143 | georg.brandl | 2009-11-07 02:26:07 -0600 (Sat, 07 Nov 2009) | 1 line
#7271: fix typo.
........
r76162 | benjamin.peterson | 2009-11-08 22:10:53 -0600 (Sun, 08 Nov 2009) | 1 line
discuss how to use -p
........
r76223 | georg.brandl | 2009-11-12 02:29:46 -0600 (Thu, 12 Nov 2009) | 1 line
Give the profile module a module directive.
........
2009-11-12 22:25:08 -04:00
|
|
|
|
2016-09-10 15:28:07 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
Calling :meth:`extractall` on a closed ZipFile will raise a
|
|
|
|
:exc:`ValueError`. Previously, a :exc:`RuntimeError` was raised.
|
|
|
|
|
2017-03-08 08:37:51 -04:00
|
|
|
.. versionchanged:: 3.6.2
|
|
|
|
The *path* parameter accepts a :term:`path-like object`.
|
|
|
|
|
Merged revisions 59822-59841 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59822 | georg.brandl | 2008-01-07 17:43:47 +0100 (Mon, 07 Jan 2008) | 2 lines
Restore "somenamedtuple" as the "class" for named tuple attrs.
........
r59824 | georg.brandl | 2008-01-07 18:09:35 +0100 (Mon, 07 Jan 2008) | 2 lines
Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
........
r59827 | georg.brandl | 2008-01-07 18:25:53 +0100 (Mon, 07 Jan 2008) | 2 lines
patch #1668: clarify envvar docs; rename THREADDEBUG to PYTHONTHREADDEBUG.
........
r59830 | georg.brandl | 2008-01-07 19:16:36 +0100 (Mon, 07 Jan 2008) | 2 lines
Make Python compile with --disable-unicode.
........
r59831 | georg.brandl | 2008-01-07 19:23:27 +0100 (Mon, 07 Jan 2008) | 2 lines
Restructure urllib doc structure.
........
r59833 | georg.brandl | 2008-01-07 19:41:34 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix #define ordering.
........
r59834 | georg.brandl | 2008-01-07 19:47:44 +0100 (Mon, 07 Jan 2008) | 2 lines
#467924, patch by Alan McIntyre: Add ZipFile.extract and ZipFile.extractall.
........
r59835 | raymond.hettinger | 2008-01-07 19:52:19 +0100 (Mon, 07 Jan 2008) | 1 line
Fix inconsistent title levels -- it made the whole doc build crash horribly.
........
r59836 | georg.brandl | 2008-01-07 19:57:03 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix two further doc build warnings.
........
r59837 | georg.brandl | 2008-01-07 20:17:10 +0100 (Mon, 07 Jan 2008) | 2 lines
Clarify metaclass docs and add example.
........
r59838 | vinay.sajip | 2008-01-07 20:40:10 +0100 (Mon, 07 Jan 2008) | 1 line
Added section about adding contextual information to log output.
........
r59839 | christian.heimes | 2008-01-07 20:58:41 +0100 (Mon, 07 Jan 2008) | 1 line
Fixed indention problem that caused the second TIPC test to run on systems without TIPC
........
r59840 | raymond.hettinger | 2008-01-07 21:07:38 +0100 (Mon, 07 Jan 2008) | 1 line
Cleanup named tuple subclassing example.
........
2008-01-07 17:14:23 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. method:: ZipFile.printdir()
|
|
|
|
|
|
|
|
Print a table of contents for the archive to ``sys.stdout``.
|
|
|
|
|
|
|
|
|
|
|
|
.. method:: ZipFile.setpassword(pwd)
|
|
|
|
|
|
|
|
Set *pwd* as default password to extract encrypted files.
|
|
|
|
|
|
|
|
|
2009-09-16 12:58:14 -03:00
|
|
|
.. method:: ZipFile.read(name, pwd=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
Merged revisions 63412,63445-63447,63449-63450,63452,63454,63459,63463,63465,63470,63483-63484,63496-63497,63499-63501,63530-63531,63540,63614 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63412 | georg.brandl | 2008-05-17 19:57:01 +0200 (Sat, 17 May 2008) | 2 lines
#961805: fix Edit.text_modified().
........
r63445 | georg.brandl | 2008-05-18 10:52:59 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #180 by Michael Schneider: add examples to the socketserver documentation.
........
r63446 | georg.brandl | 2008-05-18 11:12:20 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #134, #171, #137: unit tests for the three HTTPServer modules.
........
r63447 | georg.brandl | 2008-05-18 12:39:26 +0200 (Sun, 18 May 2008) | 3 lines
Take namedtuple item names only from ascii_letters (this blew up on OSX),
and make sure there are no duplicate names.
........
r63449 | georg.brandl | 2008-05-18 13:46:51 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #217: add support for compiling Python with coverage checking enabled.
........
r63450 | georg.brandl | 2008-05-18 13:52:36 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #257: test distutils' build_ext command, written by Josip Dzolonga.
........
r63452 | georg.brandl | 2008-05-18 15:34:06 +0200 (Sun, 18 May 2008) | 2 lines
Add GHOP students.
........
r63454 | georg.brandl | 2008-05-18 18:32:48 +0200 (Sun, 18 May 2008) | 2 lines
GHOP #121: improve test_pydoc, by Benjamin Peterson.
........
r63459 | benjamin.peterson | 2008-05-18 22:48:07 +0200 (Sun, 18 May 2008) | 2 lines
bring test_pydoc up to my high standards (now that I have them)
........
r63463 | georg.brandl | 2008-05-18 23:10:19 +0200 (Sun, 18 May 2008) | 2 lines
Fix test_pyclbr after another platform-dependent function was added to urllib.
........
r63465 | benjamin.peterson | 2008-05-19 01:07:07 +0200 (Mon, 19 May 2008) | 2 lines
change some imports in tests so they will not be skipped in 3.0
........
r63470 | georg.brandl | 2008-05-19 18:47:25 +0200 (Mon, 19 May 2008) | 2 lines
test_httpservers has unpredictable refcount behavior.
........
r63483 | georg.brandl | 2008-05-20 08:15:36 +0200 (Tue, 20 May 2008) | 2 lines
Activate two more test cases in test_httpservers.
........
r63484 | georg.brandl | 2008-05-20 08:47:31 +0200 (Tue, 20 May 2008) | 2 lines
Argh, this is the *actual* test that works under Windows.
........
r63496 | georg.brandl | 2008-05-20 10:07:36 +0200 (Tue, 20 May 2008) | 2 lines
Improve diffing logic and output for test_pydoc.
........
r63497 | georg.brandl | 2008-05-20 10:10:03 +0200 (Tue, 20 May 2008) | 2 lines
Use inspect.getabsfile() to get the documented module's filename.
........
r63499 | georg.brandl | 2008-05-20 10:25:48 +0200 (Tue, 20 May 2008) | 3 lines
Patch #1775025: allow opening zipfile members via ZipInfo instances.
Patch by Graham Horler.
........
r63500 | georg.brandl | 2008-05-20 10:40:43 +0200 (Tue, 20 May 2008) | 2 lines
#2592: delegate nb_index and the floor/truediv slots in weakref.proxy.
........
r63501 | georg.brandl | 2008-05-20 10:48:34 +0200 (Tue, 20 May 2008) | 2 lines
#615772: raise a more explicit error from Tkinter.Misc.__contains__.
........
r63530 | benjamin.peterson | 2008-05-22 02:57:02 +0200 (Thu, 22 May 2008) | 2 lines
use more specific asserts in test_opcode
........
r63531 | benjamin.peterson | 2008-05-22 03:02:23 +0200 (Thu, 22 May 2008) | 2 lines
remove redundant invocation of json doctests
........
r63540 | benjamin.peterson | 2008-05-23 01:09:26 +0200 (Fri, 23 May 2008) | 3 lines
fix test_pydoc so it works on make installed Python installations
Also let it pass when invoked directly
........
r63614 | georg.brandl | 2008-05-25 10:07:37 +0200 (Sun, 25 May 2008) | 2 lines
#2959: allow multiple close() calls for GzipFile.
........
2008-05-25 15:19:30 -03:00
|
|
|
Return the bytes of the file *name* in the archive. *name* is the name of the
|
|
|
|
file in the archive, or a :class:`ZipInfo` object. The archive must be open for
|
|
|
|
read or append. *pwd* is the password used for encrypted files and, if specified,
|
|
|
|
it will override the default password set with :meth:`setpassword`. Calling
|
2015-04-14 14:02:20 -03:00
|
|
|
:meth:`read` on a ZipFile that uses a compression method other than
|
2015-04-14 14:04:30 -03:00
|
|
|
:const:`ZIP_STORED`, :const:`ZIP_DEFLATED`, :const:`ZIP_BZIP2` or
|
2015-04-14 14:02:20 -03:00
|
|
|
:const:`ZIP_LZMA` will raise a :exc:`NotImplementedError`. An error will also
|
|
|
|
be raised if the corresponding compression module is not available.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-09-10 15:28:07 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
Calling :meth:`read` on a closed ZipFile will raise a :exc:`ValueError`.
|
|
|
|
Previously, a :exc:`RuntimeError` was raised.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. method:: ZipFile.testzip()
|
|
|
|
|
|
|
|
Read all the files in the archive and check their CRC's and file headers.
|
2016-09-10 15:28:07 -03:00
|
|
|
Return the name of the first bad file, or else return ``None``.
|
|
|
|
|
|
|
|
.. versionchanged:: 3.6
|
2018-10-27 17:06:46 -03:00
|
|
|
Calling :meth:`testzip` on a closed ZipFile will raise a
|
2016-09-10 15:28:07 -03:00
|
|
|
:exc:`ValueError`. Previously, a :exc:`RuntimeError` was raised.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
2018-01-30 01:54:07 -04:00
|
|
|
.. method:: ZipFile.write(filename, arcname=None, compress_type=None, \
|
|
|
|
compresslevel=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
Write the file named *filename* to the archive, giving it the archive name
|
|
|
|
*arcname* (by default, this will be the same as *filename*, but without a drive
|
|
|
|
letter and with leading path separators removed). If given, *compress_type*
|
|
|
|
overrides the value given for the *compression* parameter to the constructor for
|
2018-01-30 01:54:07 -04:00
|
|
|
the new entry. Similarly, *compresslevel* will override the constructor if
|
|
|
|
given.
|
2016-09-10 15:28:07 -03:00
|
|
|
The archive must be open with mode ``'w'``, ``'x'`` or ``'a'``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
There is no official file name encoding for ZIP files. If you have unicode file
|
Merged revisions 57620-57771 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r57771 | thomas.wouters | 2007-08-30 23:54:39 +0200 (Thu, 30 Aug 2007) | 5 lines
Don't lie in __all__ attributes when SSL is not available: only add the SSL
classes when they are actually created.
........
r57620 | walter.doerwald | 2007-08-28 18:38:26 +0200 (Tue, 28 Aug 2007) | 5 lines
Fix title endtag in HTMLCalender.formatyearpage(). Fix documentation for
HTMLCalender.formatyearpage() (there's no themonth parameter).
This fixes issue1046.
........
r57622 | georg.brandl | 2007-08-28 20:54:44 +0200 (Tue, 28 Aug 2007) | 2 lines
Add a crasher for the thread-unsafety of file objects.
........
r57626 | skip.montanaro | 2007-08-29 01:22:52 +0200 (Wed, 29 Aug 2007) | 1 line
fixes 813986
........
r57628 | walter.doerwald | 2007-08-29 01:35:33 +0200 (Wed, 29 Aug 2007) | 2 lines
Fix test output.
........
r57631 | skip.montanaro | 2007-08-29 03:24:11 +0200 (Wed, 29 Aug 2007) | 2 lines
Install pygettext (once the scriptsinstall target is working again).
........
r57633 | skip.montanaro | 2007-08-29 03:33:45 +0200 (Wed, 29 Aug 2007) | 2 lines
Recent items.
........
r57650 | neal.norwitz | 2007-08-29 08:15:33 +0200 (Wed, 29 Aug 2007) | 1 line
Add Bill as a developer
........
r57651 | facundo.batista | 2007-08-29 12:28:28 +0200 (Wed, 29 Aug 2007) | 5 lines
Ignore test failures caused by 'resource temporarily unavailable'
exceptions raised during FailingServerTestCase tests.
[GSoC - Alan McIntyre]
........
r57680 | bill.janssen | 2007-08-30 00:35:05 +0200 (Thu, 30 Aug 2007) | 17 lines
This contains a number of things:
1) Improve the documentation of the SSL module, with a fuller
explanation of certificate usage, another reference, proper
formatting of this and that.
2) Fix Windows bug in ssl.py, and general bug in sslsocket.close().
Remove some unused code from ssl.py. Allow accept() to be called on
sslsocket sockets.
3) Use try-except-else in import of ssl in socket.py. Deprecate use of
socket.ssl().
4) Remove use of socket.ssl() in every library module, except for
test_socket_ssl.py and test_ssl.py.
........
r57714 | georg.brandl | 2007-08-30 12:09:42 +0200 (Thu, 30 Aug 2007) | 2 lines
Stronger urge to convert filenames to str before using them as argument to ZipFile.write().
........
r57716 | georg.brandl | 2007-08-30 12:38:56 +0200 (Thu, 30 Aug 2007) | 2 lines
Patch #1680959: add test suite for pipes module.
........
r57717 | georg.brandl | 2007-08-30 14:32:23 +0200 (Thu, 30 Aug 2007) | 3 lines
* Skip test_pipes on non-POSIX.
* Don't raise TestSkipped within a test function.
........
r57723 | mark.summerfield | 2007-08-30 17:03:03 +0200 (Thu, 30 Aug 2007) | 3 lines
Added more cross-references.
........
r57726 | walter.doerwald | 2007-08-30 17:30:09 +0200 (Thu, 30 Aug 2007) | 2 lines
Rewrap line.
........
r57727 | walter.doerwald | 2007-08-30 17:34:55 +0200 (Thu, 30 Aug 2007) | 2 lines
Set startinpos before calling the error handler.
........
r57730 | bill.janssen | 2007-08-30 19:07:28 +0200 (Thu, 30 Aug 2007) | 3 lines
Added docstrings to methods and functions.
........
r57743 | bill.janssen | 2007-08-30 20:08:06 +0200 (Thu, 30 Aug 2007) | 1 line
added note on new ssl module and deprecation of socket.ssl
........
r57747 | martin.v.loewis | 2007-08-30 20:14:01 +0200 (Thu, 30 Aug 2007) | 1 line
Fix popen usage.
........
r57748 | martin.v.loewis | 2007-08-30 20:15:22 +0200 (Thu, 30 Aug 2007) | 1 line
Fix typo.
........
r57750 | martin.v.loewis | 2007-08-30 20:25:47 +0200 (Thu, 30 Aug 2007) | 1 line
Bug #1746880: Correctly install DLLs into system32 folder on Win64.
........
r57760 | martin.v.loewis | 2007-08-30 21:04:09 +0200 (Thu, 30 Aug 2007) | 1 line
Bug #1709599: Run test_1565150 only if the file system is NTFS.
........
r57762 | martin.v.loewis | 2007-08-30 22:10:57 +0200 (Thu, 30 Aug 2007) | 2 lines
Bump autoconf minimum version to 2.61.
........
r57764 | lars.gustaebel | 2007-08-30 22:24:31 +0200 (Thu, 30 Aug 2007) | 2 lines
Warn about possible risks when extracting untrusted archives.
........
r57769 | thomas.wouters | 2007-08-30 23:01:17 +0200 (Thu, 30 Aug 2007) | 7 lines
Somewhat-preliminary slice-object and extended slicing support for ctypes.
The exact behaviour of omitted and negative indices for the Pointer type may
need a closer look (especially as it's subtly different from simple slices)
but there's time yet before 2.6, and not enough before 3.0a1 :-)
........
2007-08-30 19:15:33 -03:00
|
|
|
names, you must convert them to byte strings in your desired encoding before
|
2007-08-15 11:28:22 -03:00
|
|
|
passing them to :meth:`write`. WinZip interprets all file names as encoded in
|
|
|
|
CP437, also known as DOS Latin.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
Archive names should be relative to the archive root, that is, they should not
|
|
|
|
start with a path separator.
|
|
|
|
|
|
|
|
.. note::
|
|
|
|
|
|
|
|
If ``arcname`` (or ``filename``, if ``arcname`` is not given) contains a null
|
|
|
|
byte, the name of the file in the archive will be truncated at the null byte.
|
|
|
|
|
2016-09-10 15:28:07 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
Calling :meth:`write` on a ZipFile created with mode ``'r'`` or
|
|
|
|
a closed ZipFile will raise a :exc:`ValueError`. Previously,
|
|
|
|
a :exc:`RuntimeError` was raised.
|
|
|
|
|
|
|
|
|
2018-01-30 01:54:07 -04:00
|
|
|
.. method:: ZipFile.writestr(zinfo_or_arcname, data, compress_type=None, \
|
|
|
|
compresslevel=None)
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2016-06-14 21:24:34 -03:00
|
|
|
Write the string *data* to the archive; *zinfo_or_arcname* is either the file
|
2007-08-15 11:28:22 -03:00
|
|
|
name it will be given in the archive, or a :class:`ZipInfo` instance. If it's
|
|
|
|
an instance, at least the filename, date, and time must be given. If it's a
|
2015-03-25 05:09:41 -03:00
|
|
|
name, the date and time is set to the current date and time.
|
2016-09-10 15:28:07 -03:00
|
|
|
The archive must be opened with mode ``'w'``, ``'x'`` or ``'a'``.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-02-07 16:24:02 -04:00
|
|
|
If given, *compress_type* overrides the value given for the *compression*
|
|
|
|
parameter to the constructor for the new entry, or in the *zinfo_or_arcname*
|
2018-01-30 01:54:07 -04:00
|
|
|
(if that is a :class:`ZipInfo` instance). Similarly, *compresslevel* will
|
|
|
|
override the constructor if given.
|
2010-02-07 16:24:02 -04:00
|
|
|
|
Merged revisions 59822-59841 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59822 | georg.brandl | 2008-01-07 17:43:47 +0100 (Mon, 07 Jan 2008) | 2 lines
Restore "somenamedtuple" as the "class" for named tuple attrs.
........
r59824 | georg.brandl | 2008-01-07 18:09:35 +0100 (Mon, 07 Jan 2008) | 2 lines
Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
........
r59827 | georg.brandl | 2008-01-07 18:25:53 +0100 (Mon, 07 Jan 2008) | 2 lines
patch #1668: clarify envvar docs; rename THREADDEBUG to PYTHONTHREADDEBUG.
........
r59830 | georg.brandl | 2008-01-07 19:16:36 +0100 (Mon, 07 Jan 2008) | 2 lines
Make Python compile with --disable-unicode.
........
r59831 | georg.brandl | 2008-01-07 19:23:27 +0100 (Mon, 07 Jan 2008) | 2 lines
Restructure urllib doc structure.
........
r59833 | georg.brandl | 2008-01-07 19:41:34 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix #define ordering.
........
r59834 | georg.brandl | 2008-01-07 19:47:44 +0100 (Mon, 07 Jan 2008) | 2 lines
#467924, patch by Alan McIntyre: Add ZipFile.extract and ZipFile.extractall.
........
r59835 | raymond.hettinger | 2008-01-07 19:52:19 +0100 (Mon, 07 Jan 2008) | 1 line
Fix inconsistent title levels -- it made the whole doc build crash horribly.
........
r59836 | georg.brandl | 2008-01-07 19:57:03 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix two further doc build warnings.
........
r59837 | georg.brandl | 2008-01-07 20:17:10 +0100 (Mon, 07 Jan 2008) | 2 lines
Clarify metaclass docs and add example.
........
r59838 | vinay.sajip | 2008-01-07 20:40:10 +0100 (Mon, 07 Jan 2008) | 1 line
Added section about adding contextual information to log output.
........
r59839 | christian.heimes | 2008-01-07 20:58:41 +0100 (Mon, 07 Jan 2008) | 1 line
Fixed indention problem that caused the second TIPC test to run on systems without TIPC
........
r59840 | raymond.hettinger | 2008-01-07 21:07:38 +0100 (Mon, 07 Jan 2008) | 1 line
Cleanup named tuple subclassing example.
........
2008-01-07 17:14:23 -04:00
|
|
|
.. note::
|
|
|
|
|
2010-12-26 13:53:27 -04:00
|
|
|
When passing a :class:`ZipInfo` instance as the *zinfo_or_arcname* parameter,
|
2009-01-03 17:18:54 -04:00
|
|
|
the compression method used will be that specified in the *compress_type*
|
|
|
|
member of the given :class:`ZipInfo` instance. By default, the
|
Merged revisions 59822-59841 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r59822 | georg.brandl | 2008-01-07 17:43:47 +0100 (Mon, 07 Jan 2008) | 2 lines
Restore "somenamedtuple" as the "class" for named tuple attrs.
........
r59824 | georg.brandl | 2008-01-07 18:09:35 +0100 (Mon, 07 Jan 2008) | 2 lines
Patch #602345 by Neal Norwitz and me: add -B option and PYTHONDONTWRITEBYTECODE envvar to skip writing bytecode.
........
r59827 | georg.brandl | 2008-01-07 18:25:53 +0100 (Mon, 07 Jan 2008) | 2 lines
patch #1668: clarify envvar docs; rename THREADDEBUG to PYTHONTHREADDEBUG.
........
r59830 | georg.brandl | 2008-01-07 19:16:36 +0100 (Mon, 07 Jan 2008) | 2 lines
Make Python compile with --disable-unicode.
........
r59831 | georg.brandl | 2008-01-07 19:23:27 +0100 (Mon, 07 Jan 2008) | 2 lines
Restructure urllib doc structure.
........
r59833 | georg.brandl | 2008-01-07 19:41:34 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix #define ordering.
........
r59834 | georg.brandl | 2008-01-07 19:47:44 +0100 (Mon, 07 Jan 2008) | 2 lines
#467924, patch by Alan McIntyre: Add ZipFile.extract and ZipFile.extractall.
........
r59835 | raymond.hettinger | 2008-01-07 19:52:19 +0100 (Mon, 07 Jan 2008) | 1 line
Fix inconsistent title levels -- it made the whole doc build crash horribly.
........
r59836 | georg.brandl | 2008-01-07 19:57:03 +0100 (Mon, 07 Jan 2008) | 2 lines
Fix two further doc build warnings.
........
r59837 | georg.brandl | 2008-01-07 20:17:10 +0100 (Mon, 07 Jan 2008) | 2 lines
Clarify metaclass docs and add example.
........
r59838 | vinay.sajip | 2008-01-07 20:40:10 +0100 (Mon, 07 Jan 2008) | 1 line
Added section about adding contextual information to log output.
........
r59839 | christian.heimes | 2008-01-07 20:58:41 +0100 (Mon, 07 Jan 2008) | 1 line
Fixed indention problem that caused the second TIPC test to run on systems without TIPC
........
r59840 | raymond.hettinger | 2008-01-07 21:07:38 +0100 (Mon, 07 Jan 2008) | 1 line
Cleanup named tuple subclassing example.
........
2008-01-07 17:14:23 -04:00
|
|
|
:class:`ZipInfo` constructor sets this member to :const:`ZIP_STORED`.
|
|
|
|
|
2010-03-21 04:16:43 -03:00
|
|
|
.. versionchanged:: 3.2
|
2012-10-06 12:02:05 -03:00
|
|
|
The *compress_type* argument.
|
2010-02-07 16:24:02 -04:00
|
|
|
|
2016-09-10 15:28:07 -03:00
|
|
|
.. versionchanged:: 3.6
|
|
|
|
Calling :meth:`writestr` on a ZipFile created with mode ``'r'`` or
|
|
|
|
a closed ZipFile will raise a :exc:`ValueError`. Previously,
|
|
|
|
a :exc:`RuntimeError` was raised.
|
|
|
|
|
|
|
|
|
2008-07-03 11:13:42 -03:00
|
|
|
The following data attributes are also available:
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2017-03-08 08:37:51 -04:00
|
|
|
.. attribute:: ZipFile.filename
|
|
|
|
|
|
|
|
Name of the ZIP file.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. attribute:: ZipFile.debug
|
|
|
|
|
|
|
|
The level of debug output to use. This may be set from ``0`` (the default, no
|
|
|
|
output) to ``3`` (the most output). Debugging information is written to
|
|
|
|
``sys.stdout``.
|
|
|
|
|
2008-07-03 11:13:42 -03:00
|
|
|
.. attribute:: ZipFile.comment
|
|
|
|
|
2009-01-03 17:18:54 -04:00
|
|
|
The comment text associated with the ZIP file. If assigning a comment to a
|
2015-03-25 05:09:41 -03:00
|
|
|
:class:`ZipFile` instance created with mode ``'w'``, ``'x'`` or ``'a'``,
|
|
|
|
this should be a
|
2009-01-03 17:18:54 -04:00
|
|
|
string no longer than 65535 bytes. Comments longer than this will be
|
2012-10-06 12:02:05 -03:00
|
|
|
truncated in the written archive when :meth:`close` is called.
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2010-12-04 06:26:46 -04:00
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
.. _pyzipfile-objects:
|
|
|
|
|
|
|
|
PyZipFile Objects
|
|
|
|
-----------------
|
|
|
|
|
|
|
|
The :class:`PyZipFile` constructor takes the same parameters as the
|
2010-12-04 06:26:46 -04:00
|
|
|
:class:`ZipFile` constructor, and one additional parameter, *optimize*.
|
|
|
|
|
2013-11-23 09:55:38 -04:00
|
|
|
.. class:: PyZipFile(file, mode='r', compression=ZIP_STORED, allowZip64=True, \
|
2010-12-04 06:26:46 -04:00
|
|
|
optimize=-1)
|
|
|
|
|
|
|
|
.. versionadded:: 3.2
|
|
|
|
The *optimize* parameter.
|
|
|
|
|
2013-11-23 09:55:38 -04:00
|
|
|
.. versionchanged:: 3.4
|
|
|
|
ZIP64 extensions are enabled by default.
|
|
|
|
|
2010-12-04 06:26:46 -04:00
|
|
|
Instances have one method in addition to those of :class:`ZipFile` objects:
|
|
|
|
|
2013-10-20 22:59:23 -03:00
|
|
|
.. method:: PyZipFile.writepy(pathname, basename='', filterfunc=None)
|
|
|
|
|
2010-12-04 06:26:46 -04:00
|
|
|
Search for files :file:`\*.py` and add the corresponding file to the
|
|
|
|
archive.
|
|
|
|
|
|
|
|
If the *optimize* parameter to :class:`PyZipFile` was not given or ``-1``,
|
2015-04-13 15:21:02 -03:00
|
|
|
the corresponding file is a :file:`\*.pyc` file, compiling if necessary.
|
2010-12-04 06:26:46 -04:00
|
|
|
|
|
|
|
If the *optimize* parameter to :class:`PyZipFile` was ``0``, ``1`` or
|
|
|
|
``2``, only files with that optimization level (see :func:`compile`) are
|
|
|
|
added to the archive, compiling if necessary.
|
|
|
|
|
2014-03-16 01:13:56 -03:00
|
|
|
If *pathname* is a file, the filename must end with :file:`.py`, and
|
2017-03-11 01:02:52 -04:00
|
|
|
just the (corresponding :file:`\*.pyc`) file is added at the top level
|
2014-03-16 01:13:56 -03:00
|
|
|
(no path information). If *pathname* is a file that does not end with
|
2010-12-04 06:26:46 -04:00
|
|
|
:file:`.py`, a :exc:`RuntimeError` will be raised. If it is a directory,
|
|
|
|
and the directory is not a package directory, then all the files
|
2017-03-11 01:02:52 -04:00
|
|
|
:file:`\*.pyc` are added at the top level. If the directory is a
|
|
|
|
package directory, then all :file:`\*.pyc` are added under the package
|
2010-12-04 06:26:46 -04:00
|
|
|
name as a file path, and if any subdirectories are package directories,
|
2018-01-31 06:17:10 -04:00
|
|
|
all of these are added recursively in sorted order.
|
2014-03-16 01:13:56 -03:00
|
|
|
|
|
|
|
*basename* is intended for internal use only.
|
|
|
|
|
|
|
|
*filterfunc*, if given, must be a function taking a single string
|
|
|
|
argument. It will be passed each path (including each individual full
|
|
|
|
file path) before it is added to the archive. If *filterfunc* returns a
|
|
|
|
false value, the path will not be added, and if it is a directory its
|
|
|
|
contents will be ignored. For example, if our test files are all either
|
|
|
|
in ``test`` directories or start with the string ``test_``, we can use a
|
|
|
|
*filterfunc* to exclude them::
|
|
|
|
|
|
|
|
>>> zf = PyZipFile('myprog.zip')
|
|
|
|
>>> def notests(s):
|
|
|
|
... fn = os.path.basename(s)
|
|
|
|
... return (not (fn == 'test' or fn.startswith('test_')))
|
|
|
|
>>> zf.writepy('myprog', filterfunc=notests)
|
|
|
|
|
2013-10-20 22:59:23 -03:00
|
|
|
The :meth:`writepy` method makes archives with file names like
|
2010-12-04 06:26:46 -04:00
|
|
|
this::
|
|
|
|
|
|
|
|
string.pyc # Top level name
|
|
|
|
test/__init__.pyc # Package directory
|
|
|
|
test/testall.pyc # Module test.testall
|
|
|
|
test/bogus/__init__.pyc # Subpackage directory
|
|
|
|
test/bogus/myfile.pyc # Submodule test.bogus.myfile
|
2007-08-15 11:28:22 -03:00
|
|
|
|
2013-10-21 03:29:29 -03:00
|
|
|
.. versionadded:: 3.4
|
|
|
|
The *filterfunc* parameter.
|
|
|
|
|
2017-03-08 08:37:51 -04:00
|
|
|
.. versionchanged:: 3.6.2
|
|
|
|
The *pathname* parameter accepts a :term:`path-like object`.
|
|
|
|
|
2018-01-31 06:17:10 -04:00
|
|
|
.. versionchanged:: 3.7
|
|
|
|
Recursion sorts directory entries.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. _zipinfo-objects:
|
|
|
|
|
|
|
|
ZipInfo Objects
|
|
|
|
---------------
|
|
|
|
|
2012-10-06 12:02:05 -03:00
|
|
|
Instances of the :class:`ZipInfo` class are returned by the :meth:`.getinfo` and
|
|
|
|
:meth:`.infolist` methods of :class:`ZipFile` objects. Each object stores
|
2007-08-15 11:28:22 -03:00
|
|
|
information about a single member of the ZIP archive.
|
|
|
|
|
2016-02-07 18:02:25 -04:00
|
|
|
There is one classmethod to make a :class:`ZipInfo` instance for a filesystem
|
|
|
|
file:
|
|
|
|
|
|
|
|
.. classmethod:: ZipInfo.from_file(filename, arcname=None)
|
|
|
|
|
|
|
|
Construct a :class:`ZipInfo` instance for a file on the filesystem, in
|
|
|
|
preparation for adding it to a zip file.
|
|
|
|
|
|
|
|
*filename* should be the path to a file or directory on the filesystem.
|
|
|
|
|
|
|
|
If *arcname* is specified, it is used as the name within the archive.
|
|
|
|
If *arcname* is not specified, the name will be the same as *filename*, but
|
|
|
|
with any drive letter and leading path separators removed.
|
|
|
|
|
|
|
|
.. versionadded:: 3.6
|
|
|
|
|
2017-03-08 08:37:51 -04:00
|
|
|
.. versionchanged:: 3.6.2
|
|
|
|
The *filename* parameter accepts a :term:`path-like object`.
|
|
|
|
|
|
|
|
|
2016-05-15 06:27:16 -03:00
|
|
|
Instances have the following methods and attributes:
|
|
|
|
|
|
|
|
.. method:: ZipInfo.is_dir()
|
|
|
|
|
2016-10-19 12:36:51 -03:00
|
|
|
Return ``True`` if this archive member is a directory.
|
2016-05-15 06:27:16 -03:00
|
|
|
|
|
|
|
This uses the entry's name: directories should always end with ``/``.
|
|
|
|
|
|
|
|
.. versionadded:: 3.6
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.filename
|
|
|
|
|
|
|
|
Name of the file in the archive.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.date_time
|
|
|
|
|
|
|
|
The time and date of the last modification to the archive member. This is a
|
|
|
|
tuple of six values:
|
|
|
|
|
|
|
|
+-------+--------------------------+
|
|
|
|
| Index | Value |
|
|
|
|
+=======+==========================+
|
2011-10-19 14:46:00 -03:00
|
|
|
| ``0`` | Year (>= 1980) |
|
2007-08-15 11:28:22 -03:00
|
|
|
+-------+--------------------------+
|
|
|
|
| ``1`` | Month (one-based) |
|
|
|
|
+-------+--------------------------+
|
|
|
|
| ``2`` | Day of month (one-based) |
|
|
|
|
+-------+--------------------------+
|
|
|
|
| ``3`` | Hours (zero-based) |
|
|
|
|
+-------+--------------------------+
|
|
|
|
| ``4`` | Minutes (zero-based) |
|
|
|
|
+-------+--------------------------+
|
|
|
|
| ``5`` | Seconds (zero-based) |
|
|
|
|
+-------+--------------------------+
|
|
|
|
|
2011-10-19 14:46:00 -03:00
|
|
|
.. note::
|
|
|
|
|
|
|
|
The ZIP file format does not support timestamps before 1980.
|
|
|
|
|
2007-08-15 11:28:22 -03:00
|
|
|
|
|
|
|
.. attribute:: ZipInfo.compress_type
|
|
|
|
|
|
|
|
Type of compression for the archive member.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.comment
|
|
|
|
|
|
|
|
Comment for the individual archive member.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.extra
|
|
|
|
|
2016-02-26 14:37:12 -04:00
|
|
|
Expansion field data. The `PKZIP Application Note`_ contains
|
2007-08-15 11:28:22 -03:00
|
|
|
some comments on the internal structure of the data contained in this string.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.create_system
|
|
|
|
|
|
|
|
System which created ZIP archive.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.create_version
|
|
|
|
|
|
|
|
PKZIP version which created ZIP archive.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.extract_version
|
|
|
|
|
|
|
|
PKZIP version needed to extract archive.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.reserved
|
|
|
|
|
|
|
|
Must be zero.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.flag_bits
|
|
|
|
|
|
|
|
ZIP flag bits.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.volume
|
|
|
|
|
|
|
|
Volume number of file header.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.internal_attr
|
|
|
|
|
|
|
|
Internal attributes.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.external_attr
|
|
|
|
|
|
|
|
External file attributes.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.header_offset
|
|
|
|
|
|
|
|
Byte offset to the file header.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.CRC
|
|
|
|
|
|
|
|
CRC-32 of the uncompressed file.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.compress_size
|
|
|
|
|
|
|
|
Size of the compressed data.
|
|
|
|
|
|
|
|
|
|
|
|
.. attribute:: ZipInfo.file_size
|
|
|
|
|
|
|
|
Size of the uncompressed file.
|
2016-02-07 18:02:25 -04:00
|
|
|
|
|
|
|
|
2016-11-02 07:06:15 -03:00
|
|
|
.. _zipfile-commandline:
|
|
|
|
.. program:: zipfile
|
|
|
|
|
|
|
|
Command-Line Interface
|
|
|
|
----------------------
|
|
|
|
|
|
|
|
The :mod:`zipfile` module provides a simple command-line interface to interact
|
|
|
|
with ZIP archives.
|
|
|
|
|
|
|
|
If you want to create a new ZIP archive, specify its name after the :option:`-c`
|
|
|
|
option and then list the filename(s) that should be included:
|
|
|
|
|
|
|
|
.. code-block:: shell-session
|
|
|
|
|
|
|
|
$ python -m zipfile -c monty.zip spam.txt eggs.txt
|
|
|
|
|
|
|
|
Passing a directory is also acceptable:
|
|
|
|
|
|
|
|
.. code-block:: shell-session
|
|
|
|
|
|
|
|
$ python -m zipfile -c monty.zip life-of-brian_1979/
|
|
|
|
|
|
|
|
If you want to extract a ZIP archive into the specified directory, use
|
|
|
|
the :option:`-e` option:
|
|
|
|
|
|
|
|
.. code-block:: shell-session
|
|
|
|
|
|
|
|
$ python -m zipfile -e monty.zip target-dir/
|
|
|
|
|
|
|
|
For a list of the files in a ZIP archive, use the :option:`-l` option:
|
|
|
|
|
|
|
|
.. code-block:: shell-session
|
|
|
|
|
|
|
|
$ python -m zipfile -l monty.zip
|
|
|
|
|
|
|
|
|
|
|
|
Command-line options
|
|
|
|
~~~~~~~~~~~~~~~~~~~~
|
|
|
|
|
|
|
|
.. cmdoption:: -l <zipfile>
|
2016-11-02 07:13:48 -03:00
|
|
|
--list <zipfile>
|
2016-11-02 07:06:15 -03:00
|
|
|
|
|
|
|
List files in a zipfile.
|
|
|
|
|
|
|
|
.. cmdoption:: -c <zipfile> <source1> ... <sourceN>
|
2016-11-02 07:13:48 -03:00
|
|
|
--create <zipfile> <source1> ... <sourceN>
|
2016-11-02 07:06:15 -03:00
|
|
|
|
|
|
|
Create zipfile from source files.
|
|
|
|
|
|
|
|
.. cmdoption:: -e <zipfile> <output_dir>
|
2016-11-02 07:13:48 -03:00
|
|
|
--extract <zipfile> <output_dir>
|
2016-11-02 07:06:15 -03:00
|
|
|
|
|
|
|
Extract zipfile into target directory.
|
|
|
|
|
|
|
|
.. cmdoption:: -t <zipfile>
|
2016-11-02 07:13:48 -03:00
|
|
|
--test <zipfile>
|
2016-11-02 07:06:15 -03:00
|
|
|
|
|
|
|
Test whether the zipfile is valid or not.
|
|
|
|
|
|
|
|
|
2016-02-26 14:37:12 -04:00
|
|
|
.. _PKZIP Application Note: https://pkware.cachefly.net/webdocs/casestudies/APPNOTE.TXT
|