summaryrefslogtreecommitdiffstats
path: root/Lib/zipfile.py
diff options
context:
space:
mode:
authorMartin v. Löwis <martin@v.loewis.de>2007-02-13 10:10:39 (GMT)
committerMartin v. Löwis <martin@v.loewis.de>2007-02-13 10:10:39 (GMT)
commit84f6de9d7e4a65089531699f1c6efc4e15d13dd2 (patch)
treef93cdaeb3b4d3ba7f5f0d41403f27da7800d7224 /Lib/zipfile.py
parentc6d626ed9f49daf84e72c817bce274a3547325ad (diff)
downloadcpython-84f6de9d7e4a65089531699f1c6efc4e15d13dd2.zip
cpython-84f6de9d7e4a65089531699f1c6efc4e15d13dd2.tar.gz
cpython-84f6de9d7e4a65089531699f1c6efc4e15d13dd2.tar.bz2
Patch #1517891: Make 'a' create the file if it doesn't exist.
Fixes #1514451.
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r--Lib/zipfile.py9
1 files changed, 8 insertions, 1 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 93a0b75..6e59242 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -396,7 +396,14 @@ class ZipFile:
self._filePassed = 0
self.filename = file
modeDict = {'r' : 'rb', 'w': 'wb', 'a' : 'r+b'}
- self.fp = open(file, modeDict[mode])
+ try:
+ self.fp = open(file, modeDict[mode])
+ except IOError:
+ if mode == 'a':
+ mode = key = 'w'
+ self.fp = open(file, modeDict[mode])
+ else:
+ raise
else:
self._filePassed = 1
self.fp = file