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.
A casting version of the boolean trait.
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.
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
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.
A boolean (True, False) trait.
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
An integer trait.
Longs that are unnecessary (<= sys.maxint) are cast to ints.
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
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.
A boolean (True, False) trait.
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
An integer trait.
Longs that are unnecessary (<= sys.maxint) are cast to ints.
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Bases: IPython.core.prefilter.PrefilterChecker
Emacs ipython-mode tags certain input lines.
A boolean (True, False) trait.
An integer trait.
Longs that are unnecessary (<= sys.maxint) are cast to ints.
Bases: IPython.core.prefilter.PrefilterChecker
An integer trait.
Longs that are unnecessary (<= sys.maxint) are cast to ints.
Bases: IPython.core.prefilter.PrefilterChecker
Instances of IPyAutocall in user_ns get autocalled immediately
An integer trait.
Longs that are unnecessary (<= sys.maxint) are cast to ints.
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
An integer trait.
Longs that are unnecessary (<= sys.maxint) are cast to ints.
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.
An integer trait.
Longs that are unnecessary (<= sys.maxint) are cast to ints.
Bases: IPython.core.prefilter.PrefilterChecker
Check if the initital identifier on the line is an alias.
An integer trait.
Longs that are unnecessary (<= sys.maxint) are cast to ints.
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.
An integer trait.
Longs that are unnecessary (<= sys.maxint) are cast to ints.
Bases: IPython.core.prefilter.PrefilterChecker
Check if the initial word/function is callable and autocall is on.
A casting compiled regular expression trait.
Accepts both strings and compiled regular expressions. The resulting attribute will be a compiled regular expression.
A casting compiled regular expression trait.
Accepts both strings and compiled regular expressions. The resulting attribute will be a compiled regular expression.
An integer trait.
Longs that are unnecessary (<= sys.maxint) are cast to ints.
Bases: IPython.config.configurable.Configurable
An instance of a Python list.
Handle normal input lines. Use as a template for handlers.
A trait for unicode strings.
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
A trait whose value must be an instance of a specified class.
The value can also be an instance of a subclass of the specified class.
Bases: IPython.core.prefilter.PrefilterHandler
Handle alias input lines.
A trait for unicode strings.
Bases: IPython.core.prefilter.PrefilterHandler
A trait for unicode strings.
Bases: IPython.core.prefilter.PrefilterHandler
An instance of a Python list.
Execute magic functions.
A trait for unicode strings.
Bases: IPython.core.prefilter.PrefilterHandler
An instance of a Python list.
Handle lines which can be auto-executed, quoting if requested.
A trait for unicode strings.
Bases: IPython.core.prefilter.PrefilterHandler
An instance of a Python list.
Handle input lines marked by python-mode.
A trait for unicode strings.