2222 zlib = None
2323 crc32 = binascii .crc32
2424
25- __all__ = ["BadZipfile " , "error " , "ZIP_STORED " , "ZIP_DEFLATED " , "is_zipfile " ,
26- "ZipInfo" , "ZipFile" , "PyZipFile" , "LargeZipFile" ]
25+ __all__ = ["BadZipFile " , "BadZipfile " , "error " , "ZIP_STORED " , "ZIP_DEFLATED " ,
26+ "is_zipfile" , " ZipInfo" , "ZipFile" , "PyZipFile" , "LargeZipFile" ]
2727
28- class BadZipfile (Exception ):
28+ class BadZipFile (Exception ):
2929 pass
3030
3131
@@ -35,7 +35,8 @@ class LargeZipFile(Exception):
3535 and those extensions are disabled.
3636 """
3737
38- error = BadZipfile # The exception raised by this module
38+ error = BadZipfile = BadZipFile # Pre-3.2 compatibility names
39+
3940
4041ZIP64_LIMIT = (1 << 31 ) - 1
4142ZIP_FILECOUNT_LIMIT = 1 << 16
@@ -180,7 +181,7 @@ def _EndRecData64(fpin, offset, endrec):
180181 return endrec
181182
182183 if diskno != 0 or disks != 1 :
183- raise BadZipfile ("zipfiles that span multiple disks are not supported" )
184+ raise BadZipZile ("zipfiles that span multiple disks are not supported" )
184185
185186 # Assume no 'zip64 extensible data'
186187 fpin .seek (offset - sizeEndCentDir64Locator - sizeEndCentDir64 , 2 )
@@ -592,7 +593,7 @@ def _update_crc(self, newdata, eof):
592593 self ._running_crc = crc32 (newdata , self ._running_crc ) & 0xffffffff
593594 # Check the CRC if we're at the end of the file
594595 if eof and self ._running_crc != self ._expected_crc :
595- raise BadZipfile ("Bad CRC-32 for file %r" % self .name )
596+ raise BadZipFile ("Bad CRC-32 for file %r" % self .name )
596597
597598 def read1 (self , n ):
598599 """Read up to n bytes with at most one read() system call."""
@@ -720,7 +721,7 @@ def __init__(self, file, mode="r", compression=ZIP_STORED, allowZip64=False):
720721 self ._RealGetContents ()
721722 # seek to start of directory and overwrite
722723 self .fp .seek (self .start_dir , 0 )
723- except BadZipfile :
724+ except BadZipFile :
724725 # file is not a zip file, just append
725726 self .fp .seek (0 , 2 )
726727
@@ -744,7 +745,7 @@ def _GetContents(self):
744745 is bad."""
745746 try :
746747 self ._RealGetContents ()
747- except BadZipfile :
748+ except BadZipFile :
748749 if not self ._filePassed :
749750 self .fp .close ()
750751 self .fp = None
@@ -756,9 +757,9 @@ def _RealGetContents(self):
756757 try :
757758 endrec = _EndRecData (fp )
758759 except IOError :
759- raise BadZipfile ("File is not a zip file" )
760+ raise BadZipFile ("File is not a zip file" )
760761 if not endrec :
761- raise BadZipfile ("File is not a zip file" )
762+ raise BadZipFile ("File is not a zip file" )
762763 if self .debug > 1 :
763764 print (endrec )
764765 size_cd = endrec [_ECD_SIZE ] # bytes in central directory
@@ -783,7 +784,7 @@ def _RealGetContents(self):
783784 while total < size_cd :
784785 centdir = fp .read (sizeCentralDir )
785786 if centdir [0 :4 ] != stringCentralDir :
786- raise BadZipfile ("Bad magic number for central directory" )
787+ raise BadZipFile ("Bad magic number for central directory" )
787788 centdir = struct .unpack (structCentralDir , centdir )
788789 if self .debug > 2 :
789790 print (centdir )
@@ -854,7 +855,7 @@ def testzip(self):
854855 f = self .open (zinfo .filename , "r" )
855856 while f .read (chunk_size ): # Check CRC-32
856857 pass
857- except BadZipfile :
858+ except BadZipFile :
858859 return zinfo .filename
859860
860861 def getinfo (self , name ):
@@ -903,15 +904,15 @@ def open(self, name, mode="r", pwd=None):
903904 # Skip the file header:
904905 fheader = zef_file .read (sizeFileHeader )
905906 if fheader [0 :4 ] != stringFileHeader :
906- raise BadZipfile ("Bad magic number for file header" )
907+ raise BadZipFile ("Bad magic number for file header" )
907908
908909 fheader = struct .unpack (structFileHeader , fheader )
909910 fname = zef_file .read (fheader [_FH_FILENAME_LENGTH ])
910911 if fheader [_FH_EXTRA_FIELD_LENGTH ]:
911912 zef_file .read (fheader [_FH_EXTRA_FIELD_LENGTH ])
912913
913914 if fname != zinfo .orig_filename .encode ("utf-8" ):
914- raise BadZipfile (
915+ raise BadZipFile (
915916 'File name in directory %r and header %r differ.'
916917 % (zinfo .orig_filename , fname ))
917918
0 commit comments