MCPcopy Create free account
hub / github.com/RT-Thread/env-windows / Completer

Class Completer

tools/python-3.11.9-amd64/Lib/rlcompleter.py:41–200  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

39__all__ = ["Completer"]
40
41class Completer:
42 def __init__(self, namespace = None):
43 """Create a new completer for the command line.
44
45 Completer([namespace]) -> completer instance.
46
47 If unspecified, the default namespace where completions are performed
48 is __main__ (technically, __main__.__dict__). Namespaces should be
49 given as dictionaries.
50
51 Completer instances should be used as the completion mechanism of
52 readline via the set_completer() call:
53
54 readline.set_completer(Completer(my_namespace).complete)
55 """
56
57 if namespace and not isinstance(namespace, dict):
58 raise TypeError('namespace must be a dictionary')
59
60 # Don't bind to namespace quite yet, but flag whether the user wants a
61 # specific namespace or to use __main__.__dict__. This will allow us
62 # to bind to __main__.__dict__ at completion time, not now.
63 if namespace is None:
64 self.use_main_ns = 1
65 else:
66 self.use_main_ns = 0
67 self.namespace = namespace
68
69 def complete(self, text, state):
70 """Return the next possible completion for 'text'.
71
72 This is called successively with state == 0, 1, 2, ... until it
73 returns None. The completion should begin with 'text'.
74
75 """
76 if self.use_main_ns:
77 self.namespace = __main__.__dict__
78
79 if not text.strip():
80 if state == 0:
81 if _readline_available:
82 readline.insert_text('\t')
83 readline.redisplay()
84 return ''
85 else:
86 return '\t'
87 else:
88 return None
89
90 if state == 0:
91 if "." in text:
92 self.matches = self.attr_matches(text)
93 else:
94 self.matches = self.global_matches(text)
95 try:
96 return self.matches[state]
97 except IndexError:
98 return None

Callers 1

rlcompleter.pyFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected