# Module: `core.inputtransformer`

Input transformer classes to support IPython special syntax.

This includes the machinery to recognise and transform `%magic` commands, `!system` commands, `help?` querying, prompt stripping, and so forth.

## 5 Classes

class `IPython.core.inputtransformer.``InputTransformer`

  Bases: `abc._NewBase`

  Abstract base class for line-based input transformers.

  `push`(line)

    Send a line of input to the transformer, returning the transformed input or None if the transformer is waiting for more input.

    Must be overridden by subclasses.

    Implementations may raise `SyntaxError` if the input is invalid. No other exceptions may be raised.

  `reset`()

    Return, transformed any lines that the transformer has accumulated, and reset its internal state.

    Must be overridden by subclasses.

  classmethod `wrap`(func)

    Can be used by subclasses as a decorator, to return a factory that will allow instantiation with the decorated object.

class `IPython.core.inputtransformer.``StatelessInputTransformer`(func)

  Bases: `IPython.core.inputtransformer.InputTransformer`

  Wrapper for a stateless input transformer implemented as a function.

  `__init__`(func)
  `push`(line)

    Send a line of input to the transformer, returning the transformed input.

  `reset`()

    No-op - exists for compatibility.

class `IPython.core.inputtransformer.``CoroutineInputTransformer`(coro, **kwargs)

  Bases: `IPython.core.inputtransformer.InputTransformer`

  Wrapper for an input transformer implemented as a coroutine.

  `__init__`(coro, **kwargs)
  `push`(line)

    Send a line of input to the transformer, returning the transformed input or None if the transformer is waiting for more input.

  `reset`()

    Return, transformed any lines that the transformer has accumulated, and reset its internal state.

class `IPython.core.inputtransformer.``TokenInputTransformer`(func)

  Bases: `IPython.core.inputtransformer.InputTransformer`

  Wrapper for a token-based input transformer.

  func should accept a list of tokens (5-tuples, see tokenize docs), and return an iterable which can be passed to tokenize.untokenize().

  `__init__`(func)

class `IPython.core.inputtransformer.``assemble_python_lines`

  Bases: `IPython.core.inputtransformer.TokenInputTransformer`

  `__init__`()

## 12 Functions

`IPython.core.inputtransformer.``assemble_logical_lines`(**kwargs)

  Join lines following explicit line continuations ()

`IPython.core.inputtransformer.``escaped_commands`(**kwargs)

  Transform escaped commands - %magic, !system, ?help + various autocalls.

`IPython.core.inputtransformer.``has_comment`(src)

  Indicate whether an input line has (i.e. ends in, or is) a comment.

  This uses tokenize, so it can distinguish comments from # inside strings.

  Parameters: | src (string) – A single line input string.
  Returns: | comment – True if source has a comment.
  Return type: | bool

`IPython.core.inputtransformer.``ends_in_comment_or_string`(src)

  Indicates whether or not an input line ends in a comment or within a multiline string.

  Parameters: | src (string) – A single line input string.
  Returns: | comment – True if source ends in a comment or multiline string.
  Return type: | bool

`IPython.core.inputtransformer.``help_end`(**kwargs)

  Translate lines with ?/?? at the end

`IPython.core.inputtransformer.``cellmagic`(**kwargs)

  Captures & transforms cell magics.

  After a cell magic is started, this stores up any lines it gets until it is reset (sent None).

`IPython.core.inputtransformer.``classic_prompt`(**kwargs)

  Strip the >>>/... prompts of the Python interactive shell.

`IPython.core.inputtransformer.``ipy_prompt`(**kwargs)

  Strip IPython’s In [1]:/...: prompts.

`IPython.core.inputtransformer.``leading_indent`(**kwargs)

  Remove leading indentation.

  If the first line starts with a spaces or tabs, the same whitespace will be removed from each following line until it is reset.

`IPython.core.inputtransformer.``strip_encoding_cookie`(**kwargs)

  Remove encoding comment if found in first two lines

  If the first or second line has the `# coding: utf-8` comment, it will be removed.

`IPython.core.inputtransformer.``assign_from_system`(**kwargs)

  Transform assignment from system commands (e.g. files = !ls)

`IPython.core.inputtransformer.``assign_from_magic`(**kwargs)

  Transform assignment from magic commands (e.g. a = %who_ls)