prefilter

Module: prefilter

Inheritance diagram for IPython.prefilter:

Classes and functions for prefiltering (transforming) a line of user input. This module is responsible, primarily, for breaking the line up into useful pieces and triggering the appropriate handlers in iplib to do the actual transforming work.

Class

LineInfo

class IPython.prefilter.LineInfo(line, continue_prompt)

Bases: object

A single line of input and associated info.

Includes the following as properties:

line
The original, raw line
continue_prompt
Is this line a continuation in a sequence of multiline input?
pre
The initial esc character or whitespace.
preChar
The escape character(s) in pre or the empty string if there isn’t one. Note that ‘!!’ is a possible value for preChar. Otherwise it will always be a single character.
preWhitespace
The leading whitespace from pre if it exists. If there is a preChar, this is just ‘’.
iFun
The ‘function part’, which is basically the maximal initial sequence of valid python identifiers and the ‘.’ character. This is what is checked for alias and magic transformations, used for auto-calling, etc.
theRest
Everything else on the line.
__init__(line, continue_prompt)
ofind(ip)

Do a full, attribute-walking lookup of the iFun in the various namespaces for the given IPython InteractiveShell instance.

Return a dict with keys: found,obj,ospace,ismagic

Note: can cause state changes because of calling getattr, but should only be run if autocall is on and if the line hasn’t matched any other, less dangerous handlers.

Does cache the results of the call, so can be called multiple times without worrying about further damaging state.

Functions

IPython.prefilter.checkAlias(l_info, ip)
Check if the initital identifier on the line is an alias.
IPython.prefilter.checkAssignment(l_info, ip)

Check to see if user is assigning to a var for the first time, in which case we want to avoid any sort of automagic / autocall games.

This allows users to assign to either alias or magic names true python variables (the magic/alias systems always take second seat to true python code). E.g. ls=’hi’, or ls,that=1,2

IPython.prefilter.checkAutocall(l_info, ip)
Check if the initial word/function is callable and autocall is on.
IPython.prefilter.checkAutomagic(l_info, ip)
If the iFun is magic, and automagic is on, run it. Note: normal, non-auto magic would already have been triggered via ‘%’ in check_esc_chars. This just checks for automagic. Also, before triggering the magic handler, make sure that there is nothing in the user namespace which could shadow it.
IPython.prefilter.checkEmacs(l_info, ip)
Emacs ipython-mode tags certain input lines.
IPython.prefilter.checkEscChars(l_info, ip)
Check for escape character and return either a handler to handle it, or None if there is no escape char.
IPython.prefilter.checkIPyAutocall(l_info, ip)
Instances of IPyAutocall in user_ns get autocalled immediately
IPython.prefilter.checkMultiLineMagic(l_info, ip)
Allow ! and !! in multi-line statements if multi_line_specials is on
IPython.prefilter.checkPythonOps(l_info, ip)
If the ‘rest’ of the line begins with a function call or pretty much any python operator, we should simply execute the line (regardless of whether or not there’s a possible autocall expansion). This avoids spurious (and very confusing) geattr() accesses.
IPython.prefilter.checkShellEscape(l_info, ip)
IPython.prefilter.isShadowed(identifier, ip)
Is the given identifier defined in one of the namespaces which shadow the alias and magic namespaces? Note that an identifier is different than iFun, because it can not contain a ‘.’ character.
IPython.prefilter.prefilter(line_info, ip)
Call one of the passed-in InteractiveShell’s handler preprocessors, depending on the form of the line. Return the results, which must be a value, even if it’s a blank (‘’).
IPython.prefilter.splitUserInput(line, pattern=None)

Split user input into pre-char/whitespace, function part and rest.

Mostly internal to this module, but also used by iplib.expand_aliases, which passes in a shell pattern.