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

Method cmdloop

Lib/cmd.py:101–158  ·  view source on GitHub ↗

Repeatedly issue a prompt, accept input, parse an initial prefix off the received input, and dispatch to action methods, passing them the remainder of the line as argument.

(self, intro=None)

Source from the content-addressed store, hash-verified

99 self.completekey = completekey
100
101 def cmdloop(self, intro=None):
102 """Repeatedly issue a prompt, accept input, parse an initial prefix
103 off the received input, and dispatch to action methods, passing them
104 the remainder of the line as argument.
105
106 """
107
108 self.preloop()
109 if self.use_rawinput and self.completekey:
110 try:
111 import readline
112 self.old_completer = readline.get_completer()
113 readline.set_completer(self.complete)
114 if readline.backend == "editline":
115 if self.completekey == 'tab':
116 # libedit uses "^I" instead of "tab"
117 command_string = "bind ^I rl_complete"
118 else:
119 command_string = f"bind {self.completekey} rl_complete"
120 else:
121 command_string = f"{self.completekey}: complete"
122 readline.parse_and_bind(command_string)
123 except ImportError:
124 pass
125 try:
126 if intro is not None:
127 self.intro = intro
128 if self.intro:
129 self.stdout.write(str(self.intro)+"\n")
130 stop = None
131 while not stop:
132 if self.cmdqueue:
133 line = self.cmdqueue.pop(0)
134 else:
135 if self.use_rawinput:
136 try:
137 line = input(self.prompt)
138 except EOFError:
139 line = 'EOF'
140 else:
141 self.stdout.write(self.prompt)
142 self.stdout.flush()
143 line = self.stdin.readline()
144 if not len(line):
145 line = 'EOF'
146 else:
147 line = line.rstrip('\r\n')
148 line = self.precmd(line)
149 stop = self.onecmd(line)
150 stop = self.postcmd(stop, line)
151 self.postloop()
152 finally:
153 if self.use_rawinput and self.completekey:
154 try:
155 import readline
156 readline.set_completer(self.old_completer)
157 except ImportError:
158 pass

Callers 7

pstats.pyFile · 0.45
do_testMethod · 0.45
test_cmdloopMethod · 0.45
test_cmd.pyFile · 0.45

Calls 15

preloopMethod · 0.95
precmdMethod · 0.95
onecmdMethod · 0.95
postcmdMethod · 0.95
postloopMethod · 0.95
strFunction · 0.85
inputFunction · 0.85
get_completerMethod · 0.80
set_completerMethod · 0.80
parse_and_bindMethod · 0.80
writeMethod · 0.45
popMethod · 0.45

Tested by 5

do_testMethod · 0.36
test_cmdloopMethod · 0.36