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

Method cmdloop

tools/python-3.11.9-amd64/Lib/cmd.py:98–147  ·  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

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

Callers 3

pstats.pyFile · 0.80
_cmdloopMethod · 0.80
do_commandsMethod · 0.80

Calls 12

preloopMethod · 0.95
precmdMethod · 0.95
onecmdMethod · 0.95
postcmdMethod · 0.95
postloopMethod · 0.95
strFunction · 0.85
inputFunction · 0.85
writeMethod · 0.45
popMethod · 0.45
flushMethod · 0.45
readlineMethod · 0.45
rstripMethod · 0.45

Tested by

no test coverage detected