summaryrefslogtreecommitdiffstats
path: root/Lib/zipfile.py
diff options
context:
space:
mode:
authorEzio Melotti <ezio.melotti@gmail.com>2012-11-18 11:20:36 (GMT)
committerEzio Melotti <ezio.melotti@gmail.com>2012-11-18 11:20:36 (GMT)
commit6a5fc4c443fb7190f3f68ed1eaa799b71fa36124 (patch)
tree750a39715372ea241831a0e19d5be4a4a6fe3bd6 /Lib/zipfile.py
parenta69be2803b25c226a439152ec680d7ee6f5e57f6 (diff)
downloadcpython-6a5fc4c443fb7190f3f68ed1eaa799b71fa36124.zip
cpython-6a5fc4c443fb7190f3f68ed1eaa799b71fa36124.tar.gz
cpython-6a5fc4c443fb7190f3f68ed1eaa799b71fa36124.tar.bz2
#14313: zipfile now raises NotImplementedError when the compression type is unknown.
Diffstat (limited to 'Lib/zipfile.py')
-rw-r--r--Lib/zipfile.py28
1 files changed, 28 insertions, 0 deletions
diff --git a/Lib/zipfile.py b/Lib/zipfile.py
index 2da70b5..5b3f6f9 100644
--- a/Lib/zipfile.py
+++ b/Lib/zipfile.py
@@ -461,6 +461,28 @@ class _ZipDecrypter:
self._UpdateKeys(c)
return c
+
+compressor_names = {
+ 0: 'store',
+ 1: 'shrink',
+ 2: 'reduce',
+ 3: 'reduce',
+ 4: 'reduce',
+ 5: 'reduce',
+ 6: 'implode',
+ 7: 'tokenize',
+ 8: 'deflate',
+ 9: 'deflate64',
+ 10: 'implode',
+ 12: 'bzip2',
+ 14: 'lzma',
+ 18: 'terse',
+ 19: 'lz77',
+ 97: 'wavpack',
+ 98: 'ppmd',
+}
+
+
class ZipExtFile(io.BufferedIOBase):
"""File-like object for reading an archive member.
Is returned by ZipFile.open().
@@ -487,6 +509,12 @@ class ZipExtFile(io.BufferedIOBase):
if self._compress_type == ZIP_DEFLATED:
self._decompressor = zlib.decompressobj(-15)
+ elif self._compress_type != ZIP_STORED:
+ descr = compressor_names.get(self._compress_type)
+ if descr:
+ raise NotImplementedError("compression type %d (%s)" % (self._compress_type, descr))
+ else:
+ raise NotImplementedError("compression type %d" % (self._compress_type,))
self._unconsumed = b''
self._readbuffer = b''