<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def temporary_dir(root_dir=None, cleanup=True, suffix='', permissions=None, prefix=tempfile.template):
 """ A with-context that creates a temporary directory. :API: public You may specify the following keyword args: :param string root_dir: The parent directory to create the temporary directory. :param bool cleanup: Whether or not to clean up the temporary directory. :param int permissions: If provided, sets the directory permissions to this mode. """

  path = tempfile.mkdtemp(dir=root_dir, suffix=suffix, prefix=prefix)

  try:
    if permissions is not None:
      os.chmod(path, permissions)
    yield path
  finally:
    if cleanup:
      shutil.rmtree(path, ignore_errors=True)