MCPcopy Index your code
hub / github.com/ipython/ipython / __call__

Method __call__

IPython/core/inputtransformer2.py:115–172  ·  view source on GitHub ↗
(self, lines)

Source from the content-addressed store, hash-verified

113 return [self.prompt_re.sub('', l, count=1) for l in lines]
114
115 def __call__(self, lines):
116 if not lines:
117 return lines
118
119 if self.doctest:
120 triple_mask = self._triple_quote_mask(lines)
121
122 # Detect doctest prompts only outside triple-quoted strings.
123 has_doctest_outside = any(
124 (not in_triple) and self._doctest_initial_re.match(l)
125 for l, in_triple in zip(lines, triple_mask)
126 )
127 if not has_doctest_outside:
128 return lines
129
130 out_lines: List[str] = []
131 stripped_mask: List[bool] = []
132
133 for l, in_triple in zip(lines, triple_mask):
134 if in_triple:
135 out_lines.append(l)
136 stripped_mask.append(False)
137 continue
138
139 if self._doctest_ps1_re.match(l):
140 new_l = self._doctest_ps1_re.sub('', l, count=1)
141 elif self._doctest_ps2_re.match(l):
142 new_l = self._doctest_ps2_re.sub('', l, count=1)
143 else:
144 new_l = l
145 out_lines.append(new_l)
146 stripped_mask.append(new_l != l)
147
148 # Dedent only the non-triple-quoted segments where stripping occurred.
149 dedented: List[str] = []
150 i = 0
151 while i < len(out_lines):
152 j = i
153 in_triple = triple_mask[i]
154 while j < len(out_lines) and triple_mask[j] == in_triple:
155 j += 1
156
157 segment = out_lines[i:j]
158 seg_stripped = any(stripped_mask[i:j])
159
160 if (not in_triple) and seg_stripped:
161 dedented.extend(dedent(''.join(segment)).splitlines(keepends=True))
162 else:
163 dedented.extend(segment)
164
165 i = j
166
167 return dedented
168
169 if self.initial_re.match(lines[0]) or \
170 (len(lines) > 1 and self.prompt_re.match(lines[1])):
171 return self._strip(lines)
172 return lines

Callers

nothing calls this directly

Calls 4

_triple_quote_maskMethod · 0.95
_stripMethod · 0.95
dedentFunction · 0.85
matchMethod · 0.80

Tested by

no test coverage detected