def expanduser(path):
if '<STR_LIT>' not in path:<EOL><INDENT>return path<EOL><DEDENT>if os.name == "<STR_LIT>":<EOL><INDENT>if '<STR_LIT>' in os.environ:<EOL><INDENT>userhome = os.environ['<STR_LIT>']<EOL><DEDENT>elif '<STR_LIT>' in os.environ:<EOL><INDENT>userhome = os.environ['<STR_LIT>']<EOL><DEDENT>elif '<STR_LIT>' in os.environ:<EOL><INDENT>drive = os.environ.get('<STR_LIT>', '<STR_LIT>')<EOL>userhome = os.path.join(drive, os.environ['<STR_LIT>'])<EOL><DEDENT>else:<EOL><INDENT>return path<EOL><DEDENT><DEDENT>else:<EOL><INDENT>userhome = os.path.expanduser('<STR_LIT>')<EOL><DEDENT>def _expanduser(path):<EOL><INDENT>return EXPANDUSER_RE.sub(<EOL>lambda m: m.groups()[<NUM_LIT:0>] + userhome + m.groups()[<NUM_LIT:1>],<EOL>path)<EOL><DEDENT>return os.path.normpath(_expanduser(path))<EOL>
Expand '~' to home directory in the given string.

    Note that this function deliberately differs from the builtin
    os.path.expanduser() on Linux systems, which expands strings such as
    '~sclaus' to that user's homedir. This is problematic in rez because the
    string '~packagename' may inadvertently convert to a homedir, if a package
    happens to match a username.