code: def write_file(path, data, binary=True):
      dir_path = os.path.dirname(path)
      if dir_path:
          ensure_dir(dir_path)
      tmp_path = path + ".tmp." + str(random.random())
      with open_file(tmp_path, "w" + ("b" if binary else "")) as f:
          if not isinstance(data, bytes) and binary:
              data = data.encode("UTF-8")
          f.write(data)
      replace_file(tmp_path, path)
  
imports: import codecs
  import errno
  import logging
  import os
  import random
  import shutil
  import six
  import stat
  import sys
  import library.python.func
  import library.python.strings
  import library.python.windows
label_desc: Use image node_id 23 for calling a global function with example usage: write_file(path, data, binary) without return types