def SafeOpen(path, mode, open_=open):
  """Opens a file, guaranteeing that its directory exists, and makes it 0600.

  Args:
    path: str, path to the file to open, just like open().
    mode: str, open mode to perform, just like open().
    open_: callable, dependency injection for tests only.
  Returns:
    A handle to the open file, just like open().
  """
  try:
    os.makedirs(os.path.dirname(path), 0700)
    os.mknod(path, 0600 | stat.S_IFREG)
  except __HOLE__:
    # File exists.
    pass

  return open_(path, mode)
dataset/ETHPy150Open google/cauliflowervest/src/cauliflowervest/client/util.py/SafeOpen