'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
    else:
        zef_file = open(self.filename, 'rb')
    if isinstance(name, ZipInfo):
        zinfo = name
    else:
        zinfo = self.getinfo(name)
    zef_file.seek(zinfo.header_offset, 0)
    fheader = zef_file.read(sizeFileHeader)
    if (fheader[0:4] != stringFileHeader):
        raise BadZipfile, 'Bad    magic    number    for    file    header'
    fheader = struct.unpack(structFileHeader, fheader)
    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)
    if (zd is None):
        zef = ZipExtFile(zef_file, zinfo)
    else:
        zef = ZipExtFile(zef_file, zinfo, zd)
    if ('U' in mode):
        zef.set_univ_newlines(True)
    return zef
