class_docstr: Magics related to code management (loading, saving, editing, ...).
docstr: Save a set of lines or a macro to a given filename.
  
  Usage:\
    %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
  
  Options:
  
    -r: use 'raw' input.  By default, the 'processed' history is used,
    so that magics are loaded in their transformed version to valid
    Python.  If this option is given, the raw input as typed as the
    command line is used instead.
    
    -f: force overwrite.  If file exists, %save will prompt for overwrite
    unless -f is given.
  
    -a: append to the file instead of overwriting it.
  
  This function uses the same syntax as %history for input ranges,
  then saves the lines to the filename you specify.
  
  It adds a '.py' extension to the file if you don't do so yourself, and
  it asks for confirmation before overwriting existing files.
  
  If `-r` option is used, the default extension is `.ipy`.
code: def save(self, parameter_s=""):
      """Save a set of lines or a macro to a given filename.
  
          Usage:\\
            %save [options] filename n1-n2 n3-n4 ... n5 .. n6 ...
  
          Options:
  
            -r: use 'raw' input.  By default, the 'processed' history is used,
            so that magics are loaded in their transformed version to valid
            Python.  If this option is given, the raw input as typed as the
            command line is used instead.
            
            -f: force overwrite.  If file exists, %save will prompt for overwrite
            unless -f is given.
  
            -a: append to the file instead of overwriting it.
  
          This function uses the same syntax as %history for input ranges,
          then saves the lines to the filename you specify.
  
          It adds a '.py' extension to the file if you don't do so yourself, and
          it asks for confirmation before overwriting existing files.
  
          If `-r` option is used, the default extension is `.ipy`.
          """
  
      opts, args = self.parse_options(parameter_s, "fra", mode="list")
      if not args:
          raise UsageError("Missing filename.")
      raw = "r" in opts
      force = "f" in opts
      append = "a" in opts
      mode = "a" if append else "w"
      ext = ".ipy" if raw else ".py"
      fname, codefrom = args[0], " ".join(args[1:])
      if not fname.endswith((".py", ".ipy")):
          fname += ext
      file_exists = os.path.isfile(fname)
      if file_exists and not force and not append:
          try:
              overwrite = self.shell.ask_yes_no(
                  "File `%s` exists. Overwrite (y/[N])? " % fname,
                  default="n",
              )
          except StdinNotImplementedError:
              print(
                  "File `%s` exists. Use `%%save -f %s` to force overwrite"
                  % (fname, parameter_s)
              )
              return
          if not overwrite:
              print("Operation cancelled.")
              return
      try:
          cmds = self.shell.find_user_code(codefrom, raw)
      except (TypeError, ValueError) as e:
          print(e.args[0])
          return
      out = py3compat.cast_unicode(cmds)
      with io.open(fname, mode, encoding="utf-8") as f:
          if not file_exists or not append:
              f.write("# coding: utf-8\n")
          f.write(out)
          # make sure we end on a newline
          if not out.endswith("\n"):
              f.write("\n")
      print("The following commands were written to file `%s`:" % fname)
      print(cmds)
  
imports: from __future__ import print_function
  from __future__ import absolute_import
  import inspect
  import io
  import os
  import re
  import sys
  import ast
  from itertools import chain
  from IPython.core.error import TryNext, StdinNotImplementedError, UsageError
  from IPython.core.macro import Macro
  from IPython.core.magic import Magics, magics_class, line_magic
  from IPython.core.oinspect import find_file, find_source_lines
  from IPython.testing.skipdoctest import skip_doctest
  from IPython.utils import py3compat
  from IPython.utils.py3compat import string_types
  from IPython.utils.contexts import preserve_keys
  from IPython.utils.path import get_py_filename
  from warnings import warn
  from logging import error
  from IPython.utils.text import get_text_list
label_desc: Use image node_id 2 for calling the CodeMagics obj's underlying member method code with example usage: obj.save(parameter_s) without return types