Important

This documentation covers IPython versions 6.0 and higher. Beginning with version 6.0, IPython stopped supporting compatibility with Python versions lower than 3.3 including all versions of Python 2.7.

If you are looking for an IPython version compatible with Python 2.7, please use the IPython 5.x LTS release and refer to its documentation (LTS is the long term support release).

Module: core.inputtransformer

DEPRECATED: Input transformer classes to support IPython special syntax.

This module was deprecated in IPython 7.0, in favour of inputtransformer2.

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: object

Abstract base class for line-based input transformers.

abstract 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.

abstract 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: 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: 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: 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)
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.

class IPython.core.inputtransformer.assemble_python_lines

Bases: TokenInputTransformer

__init__()

11 Functions

IPython.core.inputtransformer.assemble_logical_lines()

Join lines following explicit line continuations ()

IPython.core.inputtransformer.escaped_commands(line)

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(line)

Translate lines with ?/?? at the end

IPython.core.inputtransformer.cellmagic(end_on_blank_line=False)

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()

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

IPython.core.inputtransformer.ipy_prompt()

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

IPython.core.inputtransformer.leading_indent()

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.assign_from_system(line)

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

IPython.core.inputtransformer.assign_from_magic(line)

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