<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def safe_open(filename, *args, **kwargs):
 """Safely open a file. ``safe_open`` ensures that the directory components leading up the specified file have been created first. """

  safe_mkdir(os.path.dirname(filename))
  return open(filename, *args, **kwargs)