class_docstr: An embedded IPython instance to run inside Sphinx
docstr: Process data block for INPUT token.
docstr_tok: ["Process","data","block","for","INPUT","token","."]
code: def process_input(self, data, input_prompt, lineno):
      """
      Process data block for INPUT token.
  
      """
      decorator, input, rest = data
      image_file = None
      image_directive = None
  
      is_verbatim = decorator == "@verbatim" or self.is_verbatim
      is_doctest = (
          decorator is not None and decorator.startswith("@doctest")
      ) or self.is_doctest
      is_suppress = decorator == "@suppress" or self.is_suppress
      is_okexcept = decorator == "@okexcept" or self.is_okexcept
      is_okwarning = decorator == "@okwarning" or self.is_okwarning
      is_savefig = decorator is not None and decorator.startswith(
          "@savefig"
      )
  
      input_lines = input.split("\n")
      if len(input_lines) > 1:
          if input_lines[-1] != "":
              input_lines.append("")  # make sure there's a blank line
              # so splitter buffer gets reset
  
      continuation = "   %s:" % "".join(["."] * (len(str(lineno)) + 2))
  
      if is_savefig:
          image_file, image_directive = self.process_image(decorator)
  
      ret = []
      is_semicolon = False
  
      # Hold the execution count, if requested to do so.
      if is_suppress and self.hold_count:
          store_history = False
      else:
          store_history = True
  
      # Note: catch_warnings is not thread safe
      with warnings.catch_warnings(record=True) as ws:
          if input_lines[0].endswith(";"):
              is_semicolon = True
          # for i, line in enumerate(input_lines):
  
          # process the first input line
          if is_verbatim:
              self.process_input_lines([""])
              self.IP.execution_count += 1  # increment it anyway
          else:
              # only submit the line in non-verbatim mode
              self.process_input_lines(
                  input_lines, store_history=store_history
              )
  
      if not is_suppress:
          for i, line in enumerate(input_lines):
              if i == 0:
                  formatted_line = "%s %s" % (input_prompt, line)
              else:
                  formatted_line = "%s %s" % (continuation, line)
              ret.append(formatted_line)
  
      if not is_suppress and len(rest.strip()) and is_verbatim:
          # The "rest" is the standard output of the input. This needs to be
          # added when in verbatim mode. If there is no "rest", then we don't
          # add it, as the new line will be added by the processed output.
          ret.append(rest)
  
      # Fetch the processed output. (This is not the submitted output.)
      self.cout.seek(0)
      processed_output = self.cout.read()
      if not is_suppress and not is_semicolon:
          #
          # In IPythonDirective.run, the elements of `ret` are eventually
          # combined such that '' entries correspond to newlines. So if
          # `processed_output` is equal to '', then the adding it to `ret`
          # ensures that there is a blank line between consecutive inputs
          # that have no outputs, as in:
          #
          #    In [1]: x = 4
          #
          #    In [2]: x = 5
          #
          # When there is processed output, it has a '\n' at the tail end. So
          # adding the output to `ret` will provide the necessary spacing
          # between consecutive input/output blocks, as in:
          #
          #   In [1]: x
          #   Out[1]: 5
          #
          #   In [2]: x
          #   Out[2]: 5
          #
          # When there is stdout from the input, it also has a '\n' at the
          # tail end, and so this ensures proper spacing as well. E.g.:
          #
          #   In [1]: print x
          #   5
          #
          #   In [2]: x = 5
          #
          # When in verbatim mode, `processed_output` is empty (because
          # nothing was passed to IP. Sometimes the submitted code block has
          # an Out[] portion and sometimes it does not. When it does not, we
          # need to ensure proper spacing, so we have to add '' to `ret`.
          # However, if there is an Out[] in the submitted code, then we do
          # not want to add a newline as `process_output` has stuff to add.
          # The difficulty is that `process_input` doesn't know if
          # `process_output` will be called---so it doesn't know if there is
          # Out[] in the code block. The requires that we include a hack in
          # `process_block`. See the comments there.
          #
          ret.append(processed_output)
      elif is_semicolon:
          # Make sure there is a newline after the semicolon.
          ret.append("")
  
      # context information
      filename = "Unknown"
      lineno = 0
      if self.directive.state:
          filename = self.directive.state.document.current_source
          lineno = self.directive.state.document.current_line
  
      # Use sphinx logger for warnings
      logger = logging.getLogger(__name__)
  
      # output any exceptions raised during execution to stdout
      # unless :okexcept: has been specified.
      if not is_okexcept and (
          ("Traceback" in processed_output)
          or ("SyntaxError" in processed_output)
      ):
          s = "\n>>>" + ("-" * 73) + "\n"
          s += "Exception in %s at block ending on line %s\n" % (
              filename,
              lineno,
          )
          s += "Specify :okexcept: as an option in the ipython:: block to suppress this message\n"
          s += processed_output + "\n"
          s += "<<<" + ("-" * 73)
          logger.warning(s)
          if self.warning_is_error:
              raise RuntimeError(
                  "Unexpected exception in `{}` line {}".format(
                      filename, lineno
                  )
              )
  
      # output any warning raised during execution to stdout
      # unless :okwarning: has been specified.
      if not is_okwarning:
          for w in ws:
              s = "\n>>>" + ("-" * 73) + "\n"
              s += "Warning in %s at block ending on line %s\n" % (
                  filename,
                  lineno,
              )
              s += "Specify :okwarning: as an option in the ipython:: block to suppress this message\n"
              s += ("-" * 76) + "\n"
              s += warnings.formatwarning(
                  w.message, w.category, w.filename, w.lineno, w.line
              )
              s += "<<<" + ("-" * 73)
              logger.warning(s)
              if self.warning_is_error:
                  raise RuntimeError(
                      "Unexpected warning in `{}` line {}".format(
                          filename, lineno
                      )
                  )
  
      self.clear_cout()
      return (
          ret,
          input_lines,
          processed_output,
          is_doctest,
          decorator,
          image_file,
          image_directive,
      )
  
imports: import atexit
  import errno
  import os
  import pathlib
  import re
  import sys
  import tempfile
  import ast
  import warnings
  import shutil
  from io import StringIO
  from docutils.parsers.rst import directives
  from docutils.parsers.rst import Directive
  from sphinx.util import logging
  from traitlets.config import Config
  from IPython import InteractiveShell
  from IPython.core.profiledir import ProfileDir
label_desc: Use image node_id 7 for calling the EmbeddedSphinxShell obj's underlying member method code with example usage: obj.process_input(data, input_prompt, lineno) and returns: ret,  input_lines,  processed_output,  is_doctest,  decorator,  image_file,  image_directive