def unzip_file(source_file, dest_dir=None, mkdir=False):
<EOL>if dest_dir is None:<EOL><INDENT>dest_dir, fname = os.path.split(source_file)<EOL><DEDENT>elif not os.path.isdir(dest_dir):<EOL><INDENT>if mkdir:<EOL><INDENT>preparedir(dest_dir)<EOL><DEDENT>else:<EOL><INDENT>created = preparedir(dest_dir, False)<EOL>if not created:<EOL><INDENT>raise ValueError("<STR_LIT>" % dest_dir)<EOL><DEDENT><DEDENT><DEDENT>with zipfile.ZipFile(source_file) as zf:<EOL><INDENT>for member in zf.infolist():<EOL><INDENT>words = member.filename.split('<STR_LIT:\\>')<EOL>for word in words[:-<NUM_LIT:1>]:<EOL><INDENT>drive, word = os.path.splitdrive(word)<EOL>head, word = os.path.split(word)<EOL>if word in (os.curdir, os.pardir, '<STR_LIT>'):<EOL><INDENT>continue<EOL><DEDENT>dest_dir = os.path.join(dest_dir, word)<EOL><DEDENT>zf.extract(member, dest_dir)<EOL><DEDENT><DEDENT>
Unzip a compressed file.

    Args:
        source_file: Full path to a valid compressed file (e.g. c:/ladybug/testPts.zip)
        dest_dir: Target folder to extract to (e.g. c:/ladybug).
            Default is set to the same directory as the source file.
        mkdir: Set to True to create the directory if doesn't exist (Default: False)