def is_pathname_valid(pathname):
try:<EOL><INDENT>if not isinstance(pathname, str) or not pathname:<EOL><INDENT>return False<EOL><DEDENT>_, pathname = os.path.splitdrive(pathname)<EOL>root_dirname = os.environ.get('<STR_LIT>', '<STR_LIT>')if sys.platform == '<STR_LIT:win32>' else os.path.sep<EOL>assert os.path.isdir(root_dirname)<EOL>root_dirname = root_dirname.rstrip(os.path.sep) + os.path.sep<EOL>for pathname_part in pathname.split(os.path.sep):<EOL><INDENT>try:<EOL><INDENT>os.lstat(root_dirname + pathname_part)<EOL><DEDENT>except OSError as exc:<EOL><INDENT>if hasattr(exc, '<STR_LIT>'):<EOL><INDENT>if exc.winerror == ERROR_INVALID_NAME:<EOL><INDENT>return False<EOL><DEDENT><DEDENT>elif exc.errno in {errno.ENAMETOOLONG, errno.ERANGE}:<EOL><INDENT>return False<EOL><DEDENT><DEDENT><DEDENT><DEDENT>except (ValueError, TypeError):<EOL><INDENT>return False<EOL><DEDENT>else:<EOL><INDENT>return True<EOL><DEDENT>
`True` if the passed pathname is a valid pathname for the current OS;
`False` otherwise.