'Open the ZIP file with mode read "r", write "w" or append "a".'

def __init__(self, file, mode='r', compression=ZIP_STORED, allowZip64=False):

    if (mode not in ('r', 'w', 'a')):
        raise RuntimeError('ZipFile()    requires    mode    "r",    "w",    or    "a"')
    if (compression == ZIP_STORED):
        pass
    elif (compression == ZIP_DEFLATED):
        if (not zlib):
            raise RuntimeError, 'Compression    requires    the    (missing)    zlib    module'
    else:
        raise RuntimeError, 'That    compression    method    is    not    supported'
    self._allowZip64 = allowZip64
    self._didModify = False
    self.debug = 0
    self.NameToInfo = {}
    self.filelist = []
    self.compression = compression
    self.mode = key = mode.replace('b', '')[0]
    self.pwd = None
    self.comment = ''
    if isinstance(file, basestring):
        self._filePassed = 0
        self.filename = file
        modeDict = {'r': 'rb', 'w': 'wb', 'a': 'r+b'}
        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
        self.filename = getattr(file, 'name', None)
    if (key == 'r'):
        self._GetContents()
    elif (key == 'w'):
        pass
    elif (key == 'a'):
        try:
            self._RealGetContents()
            self.fp.seek(self.start_dir, 0)
        except BadZipfile:
            self.fp.seek(0, 2)
    else:
        if (not self._filePassed):
            self.fp.close()
            self.fp = None
        raise RuntimeError, 'Mode    must    be    "r",    "w"    or    "a"'
