MCPcopy Index your code
hub / github.com/python/cpython / complete

Method complete

Lib/cmd.py:261–289  ·  view source on GitHub ↗

Return the next possible completion for 'text'. If a command has not been entered, then complete against command list. Otherwise try to call complete_ to get list of completions.

(self, text, state)

Source from the content-addressed store, hash-verified

259 return [a[3:] for a in self.get_names() if a.startswith(dotext)]
260
261 def complete(self, text, state):
262 """Return the next possible completion for 'text'.
263
264 If a command has not been entered, then complete against command list.
265 Otherwise try to call complete_<command> to get list of completions.
266 """
267 if state == 0:
268 import readline
269 origline = readline.get_line_buffer()
270 line = origline.lstrip()
271 stripped = len(origline) - len(line)
272 begidx = readline.get_begidx() - stripped
273 endidx = readline.get_endidx() - stripped
274 if begidx>0:
275 cmd, args, foo = self.parseline(line)
276 if not cmd:
277 compfunc = self.completedefault
278 else:
279 try:
280 compfunc = getattr(self, 'complete_' + cmd)
281 except AttributeError:
282 compfunc = self.completedefault
283 else:
284 compfunc = self.completenames
285 self.completion_matches = compfunc(text, line, begidx, endidx)
286 try:
287 return self.completion_matches[state]
288 except IndexError:
289 return None
290
291 def get_names(self):
292 # This method used to pull in base class attributes

Callers

nothing calls this directly

Calls 5

parselineMethod · 0.95
get_line_bufferMethod · 0.80
get_begidxMethod · 0.80
get_endidxMethod · 0.80
lstripMethod · 0.45

Tested by

no test coverage detected