'Return file-like object for \'name\'.'

def open(self, name, mode='r', pwd=None):

    if (mode not in ('r', 'U', 'rU')):
        raise RuntimeError, 'open()    requires    mode    "r",    "U",    or    "rU"'
    if (not self.fp):
        raise RuntimeError, 'Attempt    to    read    ZIP    archive    that    was    already    closed'
    if self._filePassed:
        zef_file = self.fp
        should_close = False
    else:
        zef_file = open(self.filename, 'rb')
        should_close = True
    try:
        if isinstance(name, ZipInfo):
            zinfo = name
        else:
            zinfo = self.getinfo(name)
        zef_file.seek(zinfo.header_offset, 0)
        fheader = zef_file.read(sizeFileHeader)
        if (len(fheader) != sizeFileHeader):
            raise BadZipfile('Truncated    file    header')
        fheader = struct.unpack(structFileHeader, fheader)
        if (fheader[_FH_SIGNATURE] != stringFileHeader):
            raise BadZipfile('Bad    magic    number    for    file    header')
        fname = zef_file.read(fheader[_FH_FILENAME_LENGTH])
        if fheader[_FH_EXTRA_FIELD_LENGTH]:
            zef_file.read(fheader[_FH_EXTRA_FIELD_LENGTH])
        if (fname != zinfo.orig_filename):
            raise BadZipfile, ('File    name    in    directory    "%s"    and    header    "%s"    differ.' % (zinfo.orig_filename, fname))
        is_encrypted = (zinfo.flag_bits & 1)
        zd = None
        if is_encrypted:
            if (not pwd):
                pwd = self.pwd
            if (not pwd):
                raise RuntimeError, ('File    %s    is    encrypted,    password    required    for    extraction' % name)
            zd = _ZipDecrypter(pwd)
            bytes = zef_file.read(12)
            h = map(zd, bytes[0:12])
            if (zinfo.flag_bits & 8):
                check_byte = ((zinfo._raw_time >> 8) & 255)
            else:
                check_byte = ((zinfo.CRC >> 24) & 255)
            if (ord(h[11]) != check_byte):
                raise RuntimeError('Bad    password    for    file', name)
        return ZipExtFile(zef_file, mode, zinfo, zd, close_fileobj=should_close)
    except:
        if should_close:
            zef_file.close()
        raise
