Commit Graph

44 Commits

Author SHA1 Message Date
Martin v. Löwis 3eb7648986 Patch #1121142: Implement ZipFile.open. 2007-03-06 10:41:24 +00:00
Martin v. Löwis 84f6de9d7e Patch #1517891: Make 'a' create the file if it doesn't exist.
Fixes #1514451.
2007-02-13 10:10:39 +00:00
Martin v. Löwis c6d626ed9f Patch #698833: Support file decryption in zipfile. 2007-02-13 09:49:38 +00:00
Tim Peters f79c32dbfb ZipFile.close(): Kill the other struct.pack deprecation
warning on Windows.

Afraid I can't detect a pattern to when the pack formats decide
to use a signed or unsigned format code -- appears nearly
arbitrary to my eyes.  So I left all the pack formats alone and
changed the special-case data values instead.
2006-07-31 02:53:03 +00:00
Tim Peters 352bf0d7ee ZipFile.close(): Killed one of the struct.pack deprecation
warnings on Win32.

Also added an XXX about the line:

                pos3 = self.fp.tell()

`pos3` is never referenced, and I have no idea what the code
intended to do instead.
2006-07-31 02:40:23 +00:00
Tim Peters a608bb228c Whitespace normalization. 2006-06-15 18:06:29 +00:00
Ronald Oussoren 143cefb846 Patch #1446489 (zipfile: support for ZIP64) 2006-06-15 08:14:18 +00:00
Georg Brandl 8f7c54eaa5 Bug #1413790: zipfile now sanitizes absolute archive names that are
not allowed by the specs.
2006-02-20 08:40:38 +00:00
Martin v. Löwis 0075690ced Patch #1412872: zipfile: use correct system type on unixy systems. 2006-02-05 17:09:41 +00:00
Raymond Hettinger 2ca7c190b6 Remove dependency on order of mode flags 2005-02-16 09:27:49 +00:00
Raymond Hettinger 8a92dd5866 Don't choke on modes like rb or wb. 2004-11-06 00:31:51 +00:00
Brett Cannon ff450f7512 Make struct formats for specifying file size to be unsigned instead of signed
(ZIP file spec. says in section K, "General notes" in point 1 that unless
specified otherwise values are unsigned and they are not specified as signed in
the spec).

Closes bug #679953.  Thanks Jimmy Burgett.
2004-07-10 19:09:20 +00:00
Andrew M. Kuchling 55430213c5 [Bug #835415] AIX can return modes that are >65536, which causes an OverflowError. Fix from Albert Chin 2004-07-10 15:40:29 +00:00
Raymond Hettinger c0fac96c29 SF patch #756996: Bare except in ZipFile.testzip()
(Contributed by Steven Taschuk)

Replaces a bare except that caused all errors to be mis-reported as
archive errors.

Added a related NEWS item.
2003-06-27 22:25:03 +00:00
Greg Ward 9b15878369 Remove debug print on filename with NUL byte. 2003-06-18 00:54:28 +00:00
Greg Ward 8e36d28f3c SF patch #755987 (Jim Ahlstrom):
This is a patch for Bug 755031: If a null byte appears in
a file name, Python zipfile.py retains it, but InfoZip
terminates the name. Null bytes in file names are used
as a trick by viruses. I tested WinZip, and it also
truncates the file name at the null byte.

The patch also fixes a buglet: If a zipfile incorrectly
uses a directory separator other than '/', there was an
invalid complaint that the central directory name does
not match the file header name.

I also removed my name from the top of the file. It was
there for legal reasons which I believe no longer apply.
Many people have worked on this file besides me.
2003-06-18 00:53:06 +00:00
Martin v. Löwis 0c6774d92b Patch #661719: Expose compilation errors as exceptions on request. 2003-01-15 11:51:06 +00:00
Just van Rossum b083cb3901 Patch #651621, approved by MvL.
This patch allows ZipFile.writestr() to be called with
an archive file name instead of a ZipInfo instance:

z = ZipFile("myarchive.zip", "w")
z.writestr("foo/baz/file.ext", data)
z.close()

I found the old writestr() method very inconvenient
for simple (but common) things.

If called with a file name instead of a ZipInfo
instance, the date_time is set to the current date/time,
which makes sense to me for anonymous data.
2002-12-12 12:23:32 +00:00
Martin v. Löwis 6f6873baa1 Patch #611760: read archives with comments. 2002-10-13 13:54:50 +00:00
Guido van Rossum 1ae4c3d0d8 Avoid warnings about <<. external_attr is now an unsigned long. 2002-08-12 15:15:51 +00:00
Walter Dörwald 65230a2de7 Remove uses of the string and types modules:
x in string.whitespace => x.isspace()
type(x) in types.StringTypes => isinstance(x, basestring)
isinstance(x, types.StringTypes) => isinstance(x, basestring)
type(x) is types.StringType => isinstance(x, str)
type(x) == types.StringType => isinstance(x, str)
string.split(x, ...) => x.split(...)
string.join(x, y) => y.join(x)
string.zfill(x, ...) => x.zfill(...)
string.count(x, ...) => x.count(...)
hasattr(types, "UnicodeType") => try: unicode except NameError:
type(x) != types.TupleTuple => not isinstance(x, tuple)
isinstance(x, types.TupleType) => isinstance(x, tuple)
type(x) is types.IntType => isinstance(x, int)

Do not mention the string module in the rlcompleter docstring.

This partially applies SF patch http://www.python.org/sf/562373
(with basestring instead of string). (It excludes the changes to
unittest.py and does not change the os.stat stuff.)
2002-06-03 15:58:32 +00:00
Raymond Hettinger 32200aeac6 Replaced obsolete stat module constants with equivalent attributes 2002-06-01 19:51:15 +00:00
Raymond Hettinger 54f0222547 SF 563203. Replaced 'has_key()' with 'in'. 2002-06-01 14:18:47 +00:00
Guido van Rossum 8ca162f417 Partial introduction of bools where appropriate. 2002-04-07 06:36:23 +00:00
Tim Peters 3caca2326e SF bug #488514: -Qnew needs work
Big Hammer to implement -Qnew as PEP 238 says it should work (a global
option affecting all instances of "/").

pydebug.h, main.c, pythonrun.c:  define a private _Py_QnewFlag flag, true
iff -Qnew is passed on the command line.  This should go away (as the
comments say) when true division becomes The Rule.  This is
deliberately not exposed to runtime inspection or modification:  it's
a one-way one-shot switch to pretend you're using Python 3.

ceval.c:  when _Py_QnewFlag is set, treat BINARY_DIVIDE as
BINARY_TRUE_DIVIDE.

test_{descr, generators, zipfile}.py:  fiddle so these pass under
-Qnew too.  This was just a matter of s!/!//! in test_generators and
test_zipfile.  test_descr was trickier, as testbinop() is passed
assumptions that "/" is the same as calling a "__div__" method; put
a temporary hack there to call "__truediv__" instead when the method
name is "__div__" and 1/2 evaluates to 0.5.

Three standard tests still fail under -Qnew (on Windows; somebody
please try the Linux tests with -Qnew too!  Linux runs a whole bunch
of tests Windows doesn't):
    test_augassign
    test_class
    test_coercion
I can't stay awake longer to stare at this (be my guest).  Offhand
cures weren't obvious, nor was it even obvious that cures are possible
without major hackery.

Question:  when -Qnew is in effect, should calls to __div__ magically
change into calls to __truediv__?  See "major hackery" at tail end of
last paragraph <wink>.
2001-12-06 06:23:26 +00:00
Tim Peters d15f8bbe32 SF bug 486480: zipfile __del__ is broken
ZipFile.__del__():  call ZipFile.close(), like its docstring says it does.
ZipFile.close():  allow calling more than once (as all file-like objects
in Python should support).
2001-11-28 23:16:40 +00:00
Guido van Rossum dbb718fa87 Make these modules work when Python is compiled without Unicode support. 2001-09-21 19:22:34 +00:00
Tim Peters b64bec3ec0 Whitespace normalization. 2001-09-18 02:26:39 +00:00
Finn Bock 03a3bb812a [ #458701 ] Patch to zipfile.py for Java
Patch by Jim Ahlstrom which lets java's zipfile classes read zipfiles
create by zipfile.py.
2001-09-05 18:40:33 +00:00
Fred Drake a58947f600 Make sure path names inserted into ZIP files are normalized to use "/" as
the directory separator, as required by the format specification.

This closes SF bug #440693.
2001-07-19 19:44:25 +00:00
Fred Drake 7e473800c3 Fix one bare except: clause. 2001-05-11 19:52:57 +00:00
Guido van Rossum f85af612f8 Mark Favas points out that there's an 'self.fp.flush()' call in the
ZipFile.close() method that should be part of the preceding 'if'
block.  On some platforms (Mark noticed this on FreeBSD 4.2) doing a
flush() on a file open for reading is not allowed.
2001-04-14 16:45:14 +00:00
Guido van Rossum 9c673f35d2 Try an except: after an import into "except ImportError".
This came out of SF bug #411881.

Note that there's another unqualified except: still.
2001-04-10 15:37:12 +00:00
Tim Peters 7d3bad66e4 Sf bug [ #412214 ] ZipFile constructor leaves files open.
This applies the patch Fred Drake created to fix it.
I'm checking it in since I had to apply the patch anyway in order
to test its behavior on Windows.
2001-04-04 18:56:49 +00:00
Tim Peters a19a168ccc Whitespace normalization. 2001-03-29 04:36:09 +00:00
Fred Drake 3d9091ece1 Itamar Shtull-Trauring <itamar@maxnm.com>:
Add support to zipfile to support opening an archive represented by an
open file rather than a file name.
2001-03-26 15:49:24 +00:00
Skip Montanaro 40fc16059f final round of __all__ lists (I hope) - skipped urllib2 because Moshe may be
giving it a slight facelift
2001-03-01 04:27:19 +00:00
Fred Drake 3e038e5e25 Define lots of constants for indexes into the structures for the file
header and central directory structures, and use them as appropriate.
The point being to make it easier to tell what is getting pulled out
where; magic numbers are evil!

Change the computation of the ZipInfo.file_offset field to use the
length of the relevant "extra" field -- there are two different ones,
and the wrong one had been used.  ;-(

This closes SF tracker patch #403276, but more verbosely than the
proposed patch.
2001-02-28 17:56:26 +00:00
Fred Drake 90eac285c8 Fix SF tracker bug #403871: AttributeError in ZipFile.__del__() when
there was an IOError opening the underlying file in ZipFile.__init__().
2001-02-28 05:29:34 +00:00
Tim Peters e119006e7d Whitespace normalization. Top level of Lib now fixed-point for reindent.py! 2001-01-15 03:34:38 +00:00
Fred Drake 484d735f1e Delay import of py_compile until needed, since is is only used by the
PyZipFile class.

End sentences in docstrings with periods.

Reformat docstrings to be more similar to those of other modules.
2000-10-02 21:14:52 +00:00
Fred Drake 5db246d1fa Always use the same name for the exception defined in this module!
Error reported via email by Pete Shinners <pete@visionart.com>.

Fixed some indentation inconsistencies.
2000-09-29 20:44:48 +00:00
Fred Drake 414ca6666c James C. Ahlstron <jim@interet.com>:
Thanks to Hubert Hoegl <hubert.hoegl@dlr.de> for finding this bug.
2000-06-13 18:49:53 +00:00
Guido van Rossum 32abe6f7d0 Zip file handling module, by Jim Ahlstrom. 2000-03-31 17:30:02 +00:00