def is_writable(dir):
if not os.path.isdir(dir):<EOL><INDENT>return False<EOL><DEDENT>prefix = '<STR_LIT>' % (socket.gethostname(),os.getpid())<EOL>try:<EOL><INDENT>tmp = tempfile.TemporaryFile(prefix=prefix,dir=dir)<EOL><DEDENT>except OSError:<EOL><INDENT>return False<EOL><DEDENT>tmp.close()<EOL>return True<EOL>
Determine whether a given directory is writable in a portable manner.

    Parameters
    ----------
    dir : str
        A string represeting a path to a directory on the filesystem.

    Returns
    -------
    res : bool
        True or False.