Show More
@@ -9,6 +9,7 import abc | |||||
9 | import functools |
|
9 | import functools | |
10 | import re |
|
10 | import re | |
11 | import tokenize |
|
11 | import tokenize | |
|
12 | import warnings | |||
12 | from tokenize import untokenize, TokenError |
|
13 | from tokenize import untokenize, TokenError | |
13 | from io import StringIO |
|
14 | from io import StringIO | |
14 |
|
15 | |||
@@ -42,7 +43,16 ESC_SEQUENCES = [ESC_SHELL, ESC_SH_CAP, ESC_HELP ,\ | |||||
42 |
|
43 | |||
43 | class InputTransformer(metaclass=abc.ABCMeta): |
|
44 | class InputTransformer(metaclass=abc.ABCMeta): | |
44 | """Abstract base class for line-based input transformers.""" |
|
45 | """Abstract base class for line-based input transformers.""" | |
45 |
|
46 | |||
|
47 | def __init__(self): | |||
|
48 | warnings.warn( | |||
|
49 | "`InputTransformer` has been deprecated since IPython 7.0" | |||
|
50 | " and emit a warnig since IPython 8.31, it" | |||
|
51 | " will be removed in the future", | |||
|
52 | DeprecationWarning, | |||
|
53 | stacklevel=2, | |||
|
54 | ) | |||
|
55 | ||||
46 | @abc.abstractmethod |
|
56 | @abc.abstractmethod | |
47 | def push(self, line): |
|
57 | def push(self, line): | |
48 | """Send a line of input to the transformer, returning the transformed |
|
58 | """Send a line of input to the transformer, returning the transformed | |
@@ -78,6 +88,14 class InputTransformer(metaclass=abc.ABCMeta): | |||||
78 | class StatelessInputTransformer(InputTransformer): |
|
88 | class StatelessInputTransformer(InputTransformer): | |
79 | """Wrapper for a stateless input transformer implemented as a function.""" |
|
89 | """Wrapper for a stateless input transformer implemented as a function.""" | |
80 | def __init__(self, func): |
|
90 | def __init__(self, func): | |
|
91 | super().__init__() | |||
|
92 | warnings.warn( | |||
|
93 | "`StatelessInputTransformer` has been deprecated since IPython 7.0" | |||
|
94 | " and emit a warnig since IPython 8.31, it" | |||
|
95 | " will be removed in the future", | |||
|
96 | DeprecationWarning, | |||
|
97 | stacklevel=2, | |||
|
98 | ) | |||
81 | self.func = func |
|
99 | self.func = func | |
82 |
|
100 | |||
83 | def __repr__(self): |
|
101 | def __repr__(self): | |
@@ -96,6 +114,14 class CoroutineInputTransformer(InputTransformer): | |||||
96 | """Wrapper for an input transformer implemented as a coroutine.""" |
|
114 | """Wrapper for an input transformer implemented as a coroutine.""" | |
97 | def __init__(self, coro, **kwargs): |
|
115 | def __init__(self, coro, **kwargs): | |
98 | # Prime it |
|
116 | # Prime it | |
|
117 | super().__init__() | |||
|
118 | warnings.warn( | |||
|
119 | "`CoroutineInputTransformer` has been deprecated since IPython 7.0" | |||
|
120 | " and emit a warnig since IPython 8.31, it" | |||
|
121 | " will be removed in the future", | |||
|
122 | DeprecationWarning, | |||
|
123 | stacklevel=2, | |||
|
124 | ) | |||
99 | self.coro = coro(**kwargs) |
|
125 | self.coro = coro(**kwargs) | |
100 | next(self.coro) |
|
126 | next(self.coro) | |
101 |
|
127 | |||
@@ -122,6 +148,13 class TokenInputTransformer(InputTransformer): | |||||
122 | return an iterable which can be passed to tokenize.untokenize(). |
|
148 | return an iterable which can be passed to tokenize.untokenize(). | |
123 | """ |
|
149 | """ | |
124 | def __init__(self, func): |
|
150 | def __init__(self, func): | |
|
151 | warnings.warn( | |||
|
152 | "`CoroutineInputTransformer` has been deprecated since IPython 7.0" | |||
|
153 | " and emit a warnig since IPython 8.31, it" | |||
|
154 | " will be removed in the future", | |||
|
155 | DeprecationWarning, | |||
|
156 | stacklevel=2, | |||
|
157 | ) | |||
125 | self.func = func |
|
158 | self.func = func | |
126 | self.buf = [] |
|
159 | self.buf = [] | |
127 | self.reset_tokenizer() |
|
160 | self.reset_tokenizer() | |
@@ -167,7 +200,7 class TokenInputTransformer(InputTransformer): | |||||
167 |
|
200 | |||
168 | class assemble_python_lines(TokenInputTransformer): |
|
201 | class assemble_python_lines(TokenInputTransformer): | |
169 | def __init__(self): |
|
202 | def __init__(self): | |
170 |
super( |
|
203 | super().__init__(None) | |
171 |
|
204 | |||
172 | def output(self, tokens): |
|
205 | def output(self, tokens): | |
173 | return self.reset() |
|
206 | return self.reset() |
@@ -13,7 +13,7 interactive interface. Using them carelessly can easily break IPython! | |||||
13 | String based transformations |
|
13 | String based transformations | |
14 | ============================ |
|
14 | ============================ | |
15 |
|
15 | |||
16 | .. currentmodule:: IPython.core.inputtransforms |
|
16 | .. currentmodule:: IPython.core.inputtransformers2 | |
17 |
|
17 | |||
18 | When the user enters code, it is first processed as a string. By the |
|
18 | When the user enters code, it is first processed as a string. By the | |
19 | end of this stage, it must be valid Python syntax. |
|
19 | end of this stage, it must be valid Python syntax. |
General Comments 0
You need to be logged in to leave comments.
Login now