def _unpack_zipfile(filename, extract_dir):
try:<EOL><INDENT>import zipfile<EOL><DEDENT>except ImportError:<EOL><INDENT>raise ReadError('<STR_LIT>')<EOL><DEDENT>if not zipfile.is_zipfile(filename):<EOL><INDENT>raise ReadError("<STR_LIT>" % filename)<EOL><DEDENT>zip = zipfile.ZipFile(filename)<EOL>try:<EOL><INDENT>for info in zip.infolist():<EOL><INDENT>name = info.filename<EOL>if name.startswith('<STR_LIT:/>') or '<STR_LIT:..>' in name:<EOL><INDENT>continue<EOL><DEDENT>target = os.path.join(extract_dir, *name.split('<STR_LIT:/>'))<EOL>if not target:<EOL><INDENT>continue<EOL><DEDENT>_ensure_directory(target)<EOL>if not name.endswith('<STR_LIT:/>'):<EOL><INDENT>data = zip.read(info.filename)<EOL>f = open(target, '<STR_LIT:wb>')<EOL>try:<EOL><INDENT>f.write(data)<EOL><DEDENT>finally:<EOL><INDENT>f.close()<EOL>del data<EOL><DEDENT><DEDENT><DEDENT><DEDENT>finally:<EOL><INDENT>zip.close()<EOL><DEDENT>
Unpack zip `filename` to `extract_dir`