def folder_path(preferred_mode, check_other_mode, key):
other_mode = '<STR_LIT>' if preferred_mode == '<STR_LIT:user>' else '<STR_LIT:user>'<EOL>path, exception = dirs_src[preferred_mode][key]<EOL>if not exception:<EOL><INDENT>return path<EOL><DEDENT>logger.info("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>"<EOL>% (key, path, type(exception).__name__))<EOL>if preferred_mode == '<STR_LIT:user>' and key == '<STR_LIT>':<EOL><INDENT>user_profile, exception = dirs_src['<STR_LIT:user>']['<STR_LIT>']<EOL>if not exception:<EOL><INDENT>path = join(user_profile, '<STR_LIT>')<EOL>if os.access(path, os.W_OK):<EOL><INDENT>logger.info("<STR_LIT>" % (path))<EOL>return path<EOL><DEDENT><DEDENT><DEDENT>path, exception = dirs_src[other_mode][key]<EOL>if exception:<EOL><INDENT>if check_other_mode:<EOL><INDENT>logger.info("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (path,<EOL>type(exception).__name__))<EOL><DEDENT>else:<EOL><INDENT>logger.info("<STR_LIT>"<EOL>"<STR_LIT>"<EOL>"<STR_LIT>" % (path, type(exception).__name__))<EOL><DEDENT>return None<EOL><DEDENT>if not check_other_mode:<EOL><INDENT>logger.info("<STR_LIT>"<EOL>"<STR_LIT>" % (path))<EOL>return None<EOL><DEDENT>return path<EOL>
This function implements all heuristics and workarounds for messed up
        KNOWNFOLDERID registry values. It's also verbose (OutputDebugStringW)
        about whether fallbacks worked or whether they would have worked if
        check_other_mode had been allowed.