Warning
This documentation is for an old version of IPython. You can find docs for newer versions here.
Prefiltering components.
Prefilters transform user input before it is exec’d by Python. These transforms are used to implement additional syntax such as !ls and %magic.
Authors:
Bases: exceptions.Exception
Bases: IPython.config.configurable.Configurable
Main prefilter component.
The IPython prefilter is run on all user input before it is run. The prefilter consumes lines of input and produces transformed lines of input.
The iplementation consists of two phases:
Over time, we plan on deprecating the checkers and handlers and doing everything in the transformers.
The transformers are instances of PrefilterTransformer and have a single method transform() that takes a line and returns a transformed line. The transformation can be accomplished using any tool, but our current ones use regular expressions for speed.
After all the transformers have been run, the line is fed to the checkers, which are instances of PrefilterChecker. The line is passed to the check() method, which either returns None or a PrefilterHandler instance. If None is returned, the other checkers are tried. If an PrefilterHandler instance is returned, the line is passed to the handle() method of the returned handler and no further checkers are tried.
Both transformers and checkers have a priority attribute, that determines the order in which they are called. Smaller priorities are tried first.
Both transformers and checkers also have enabled attribute, which is a boolean that determines if the instance is used.
Users or developers can change the priority or enabled attribute of transformers or checkers, but they must call the sort_checkers() or sort_transformers() method after changing the priority.
Return a list of checkers, sorted by priority.
Find a handler for the line_info by trying checkers.
Get a handler by its escape string.
Get a handler by its name.
Return a dict of all the handlers.
Create the default checkers.
Create the default handlers.
Create the default transformers.
Prefilter a single input line as text.
This method prefilters a single line of text by calling the transformers and then the checkers/handlers.
Prefilter a line that has been converted to a LineInfo object.
This implements the checker/handler part of the prefilter pipe.
Prefilter multiple input lines of text.
This is the main entry point for prefiltering multiple lines of input. This simply calls prefilter_line() for each line of input.
This covers cases where there are multiple lines in the user entry, which is the case when the user goes back to a multiline history entry and presses enter.
Register a checker instance.
Register a handler instance by name with esc_strings.
Register a transformer instance.
Sort the checkers by priority.
This must be called after the priority of a checker is changed. The register_checker() method calls this automatically.
Sort the transformers by priority.
This must be called after the priority of a transformer is changed. The register_transformer() method calls this automatically.
Calls the enabled transformers in order of increasing priority.
Return a list of checkers, sorted by priority.
Unregister a checker instance.
Unregister a handler instance by name with esc_strings.
Unregister a transformer instance.
Bases: IPython.config.configurable.Configurable
Transform a line of user input.
Transform a line, returning the new one.
Bases: IPython.config.configurable.Configurable
Inspect an input line and return a handler for that line.
Inspect line_info and return a handler instance or None.
Bases: IPython.core.prefilter.PrefilterChecker
Emacs ipython-mode tags certain input lines.
Bases: IPython.core.prefilter.PrefilterChecker
Instances of IPyAutocall in user_ns get autocalled immediately
Bases: IPython.core.prefilter.PrefilterChecker
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
Bases: IPython.core.prefilter.PrefilterChecker
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.
Bases: IPython.core.prefilter.PrefilterChecker
Check if the initital identifier on the line is an alias.
Bases: IPython.core.prefilter.PrefilterChecker
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.
Bases: IPython.core.prefilter.PrefilterChecker
Check if the initial word/function is callable and autocall is on.
Bases: IPython.config.configurable.Configurable
Handle normal input lines. Use as a template for handlers.
Bases: IPython.core.prefilter.PrefilterHandler
Handle alias input lines.
Bases: IPython.core.prefilter.PrefilterHandler
Execute magic functions.
Bases: IPython.core.prefilter.PrefilterHandler
Handle lines which can be auto-executed, quoting if requested.
Bases: IPython.core.prefilter.PrefilterHandler
Handle input lines marked by python-mode.