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.
This commit is contained in:
Fred Drake 2000-09-29 20:44:48 +00:00
parent a77254a724
commit 5db246d1fa

View file

@ -10,9 +10,9 @@ try:
except: except:
zlib = None zlib = None
class _BadZipfile(Exception): class BadZipfile(Exception):
pass pass
error = _BadZipfile # The exception raised by this module error = BadZipfile # The exception raised by this module
# constants for Zip file compression methods # constants for Zip file compression methods
ZIP_STORED = 0 ZIP_STORED = 0
@ -94,7 +94,7 @@ class ZipFile:
elif compression == ZIP_DEFLATED: elif compression == ZIP_DEFLATED:
if not zlib: if not zlib:
raise RuntimeError,\ raise RuntimeError,\
"Compression requires the (missing) zlib module" "Compression requires the (missing) zlib module"
else: else:
raise RuntimeError, "That compression method is not supported" raise RuntimeError, "That compression method is not supported"
self.debug = 0 # Level of printing: 0 through 3 self.debug = 0 # Level of printing: 0 through 3
@ -180,8 +180,8 @@ class ZipFile:
fname = fp.read(fheader[10]) fname = fp.read(fheader[10])
if fname != data.filename: if fname != data.filename:
raise RuntimeError, \ raise RuntimeError, \
'File name in Central Directory "%s" and File Header "%s" differ.' % ( 'File name in directory "%s" and header "%s" differ.' % (
data.filename, fname) data.filename, fname)
def namelist(self): def namelist(self):
"Return a list of file names in the archive" "Return a list of file names in the archive"
@ -219,7 +219,7 @@ class ZipFile:
raise RuntimeError, 'read() requires mode "r" or "a"' raise RuntimeError, 'read() requires mode "r" or "a"'
if not self.fp: if not self.fp:
raise RuntimeError, \ raise RuntimeError, \
"Attempt to read ZIP archive that was already closed" "Attempt to read ZIP archive that was already closed"
zinfo = self.getinfo(name) zinfo = self.getinfo(name)
filepos = self.fp.tell() filepos = self.fp.tell()
self.fp.seek(zinfo.file_offset, 0) self.fp.seek(zinfo.file_offset, 0)
@ -230,7 +230,7 @@ class ZipFile:
elif zinfo.compress_type == ZIP_DEFLATED: elif zinfo.compress_type == ZIP_DEFLATED:
if not zlib: if not zlib:
raise RuntimeError, \ raise RuntimeError, \
"De-compression requires the (missing) zlib module" "De-compression requires the (missing) zlib module"
# zlib compress/decompress code by Jeremy Hylton of CNRI # zlib compress/decompress code by Jeremy Hylton of CNRI
dc = zlib.decompressobj(-15) dc = zlib.decompressobj(-15)
bytes = dc.decompress(bytes) bytes = dc.decompress(bytes)
@ -240,7 +240,7 @@ class ZipFile:
bytes = bytes + ex bytes = bytes + ex
else: else:
raise BadZipfile, \ raise BadZipfile, \
"Unsupported compression method %d for file %s" % \ "Unsupported compression method %d for file %s" % \
(zinfo.compress_type, name) (zinfo.compress_type, name)
crc = binascii.crc32(bytes) crc = binascii.crc32(bytes)
if crc != zinfo.CRC: if crc != zinfo.CRC:
@ -256,13 +256,13 @@ class ZipFile:
raise RuntimeError, 'write() requires mode "w" or "a"' raise RuntimeError, 'write() requires mode "w" or "a"'
if not self.fp: if not self.fp:
raise RuntimeError, \ raise RuntimeError, \
"Attempt to write ZIP archive that was already closed" "Attempt to write ZIP archive that was already closed"
if zinfo.compress_type == ZIP_DEFLATED and not zlib: if zinfo.compress_type == ZIP_DEFLATED and not zlib:
raise RuntimeError, \ raise RuntimeError, \
"Compression requires the (missing) zlib module" "Compression requires the (missing) zlib module"
if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED): if zinfo.compress_type not in (ZIP_STORED, ZIP_DEFLATED):
raise RuntimeError, \ raise RuntimeError, \
"That compression method is not supported" "That compression method is not supported"
def write(self, filename, arcname=None, compress_type=None): def write(self, filename, arcname=None, compress_type=None):
'Put the bytes from filename into the archive under the name arcname.' 'Put the bytes from filename into the archive under the name arcname.'
@ -437,7 +437,7 @@ This method will compile the module.py into module.pyc if necessary."""
else: else:
if pathname[-3:] != ".py": if pathname[-3:] != ".py":
raise RuntimeError, \ raise RuntimeError, \
'Files added with writepy() must end with ".py"' 'Files added with writepy() must end with ".py"'
fname, arcname = self._get_codename(pathname[0:-3], basename) fname, arcname = self._get_codename(pathname[0:-3], basename)
if self.debug: if self.debug:
print "Adding file", arcname print "Adding file", arcname