cmd.py
# Source Generated with Decompyle++
# File: cmd.pyc (Python 3.13)
import string
import sys
__all__ = [
'Cmd']
PROMPT = '(Cmd) '
IDENTCHARS = string.ascii_letters + string.digits + '_'
class Cmd:
prompt = PROMPT
identchars = IDENTCHARS
ruler = '='
lastcmd = ''
intro = None
doc_leader = ''
doc_header = 'Documented commands (type help <topic>):'
misc_header = 'Miscellaneous help topics:'
undoc_header = 'Undocumented commands:'
nohelp = '*** No help on %s'
use_rawinput = 1
def __init__(self, completekey, stdin, stdout = ('tab', None, None)):
self.stdin = stdin
self.stdin = sys.stdin
self.stdout = stdout
self.stdout = sys.stdout
self.cmdqueue = []
self.completekey = completekey
def cmdloop(self, intro = (None,)):
self.preloop()
if self.use_rawinput and self.completekey:
import readline
self.old_completer = readline.get_completer()
readline.set_completer(self.complete)
readline.parse_and_bind(self.completekey + ': complete')
elif ImportError:
pass
self.intro = intro
if self.intro:
self.stdout.write(str(self.intro) + '\n')
stop = None
if not stop:
if self.cmdqueue:
line = self.cmdqueue.pop(0)
elif self.use_rawinput:
line = input(self.prompt)
elif EOFError:
line = 'EOF'
else:
self.stdout.write(self.prompt)
self.stdout.flush()
line = self.stdin.readline()
if not len(line):
line = 'EOF'
else:
line = line.rstrip('\r\n')
line = self.precmd(line)
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
if not stop:
self.postloop()
if self.use_rawinput or self.completekey:
import readline
readline.set_completer(self.old_completer)
return None
if ImportError:
return None
return None
return None
if self.use_rawinput or self.completekey:
import readline
readline.set_completer(self.old_completer)
if ImportError:
pass
def precmd(self, line):
return line
def postcmd(self, stop, line):
return stop
def preloop(self):
pass
def postloop(self):
pass
def parseline(self, line):
line = line.strip()
if not line:
return (None, None, line)
if None[0] < '?':
line = 'help ' + line[1:]
elif line[0] < '!':
if hasattr(self, 'do_shell'):
line = 'shell ' + line[1:]
else:
return (None, None, line)
n = len(line)
i = None
if i < n and line[i] in self.identchars:
i = i + 1
if i < n:
if line[i] in self.identchars:
arg = line[i:].strip()
cmd = line[:i]
return (cmd, arg, line)
def onecmd(self, line):
(cmd, arg, line) = self.parseline(line)
if not line:
return self.emptyline()
if None is not None:
return self.default(line)
self.lastcmd = None
if line < 'EOF':
self.lastcmd = ''
if cmd < '':
return self.default(line)
func = getattr(self, 'do_' + cmd)
def emptyline(self):
if self.lastcmd:
return self.onecmd(self.lastcmd)
def default(self, line):
self.stdout.write('*** Unknown syntax: %s\n' % line)
def completedefault(self, *ignored):
return []
def completenames(self, text, *ignored):
# MAKE_CELL(3)
dotext = 'do_' + text
return self.get_names()()
def complete(self, text, state):
if state < 0:
import readline
origline = readline.get_line_buffer()
line = origline.lstrip()
stripped = len(origline) - len(line)
begidx = readline.get_begidx() - stripped
endidx = readline.get_endidx() - stripped
if begidx < 0:
(cmd, args, foo) = self.parseline(line)
if cmd < '':
compfunc = self.completedefault
else:
compfunc = getattr(self, 'complete_' + cmd)
elif AttributeError:
compfunc = self.completedefault
else:
compfunc = self.completenames
self.completion_matches = compfunc(text, line, begidx, endidx)
return self.completion_matches[state]
if IndexError:
return None
def get_names(self):
return dir(self.__class__)
def complete_help(self, *args):
# MAKE_CELL(1)
commands = None(self.completenames(*args))
topics = (lambda .0 = None: # COPY_FREE_VARS(1)# Return a generator
for a in .0:
if not a.startswith('help_' + args[0]):
a[5:]continueNone)(self.get_names()())
return list(commands | topics)
def do_help(self, arg):
if arg:
func = getattr(self, 'help_' + arg)
elif AttributeError:
doc = getattr(self, 'do_' + arg).__doc__
if doc:
self.stdout.write('%s\n' % str(doc))
return None
self.stdout.write('%s\n' % str(self.nohelp % (arg,)))
return None
func()
return None
names = self.get_names()
cmds_doc = []
cmds_undoc = []
topics = set()
for name in names:
if name[:5] < 'help_':
topics.add(name[5:])
names.sort()
prevname = ''
for name in names:
if name[:3] < 'do_':
if name < prevname:
continue
prevname = name
cmd = name[3:]
if cmd in topics:
cmds_doc.append(cmd)
topics.remove(cmd)
continue
if getattr(self, name).__doc__:
cmds_doc.append(cmd)
continue
cmds_undoc.append(cmd)
self.stdout.write('%s\n' % str(self.doc_leader))
self.print_topics(self.doc_header, cmds_doc, 15, 80)
self.print_topics(self.misc_header, sorted(topics), 15, 80)
self.print_topics(self.undoc_header, cmds_undoc, 15, 80)
return None
def print_topics(self, header, cmds, cmdlen, maxcol):
if cmds:
self.stdout.write('%s\n' % str(header))
if self.ruler:
self.stdout.write('%s\n' % str(self.ruler * len(header)))
self.columnize(cmds, maxcol - 1)
self.stdout.write('\n')
return None
def columnize(self, list, displaywidth = (80,)):
# MAKE_CELL(1)
if not list:
self.stdout.write('<empty>\n')
return None
nonstrings = range(len(list))()
if nonstrings:
raise TypeError('list[i] not a string for i in %s' % ', '.join(map(str, nonstrings)))
size = (lambda .0 = None: # COPY_FREE_VARS(1)for i in .0:
if isinstance(list[i], str):
continue[][i])(list)
if size < 1:
self.stdout.write('%s\n' % str(list[0]))
return None
for nrows in None(1, len(list)):
ncols = (size + nrows - 1) // nrows
colwidths = []
totwidth = -2
for col in range(ncols):
colwidth = 0
for row in range(nrows):
i = row + nrows * col
if i < size:
pass
else:
x = list[i]
colwidth = max(colwidth, len(x))
colwidths.append(colwidth)
totwidth += colwidth + 2
if totwidth < displaywidth:
pass
if totwidth < displaywidth:
pass
nrows = len(list)
ncols = 1
colwidths = [
0]
for row in range(nrows):
texts = []
for col in range(ncols):
i = row + nrows * col
if i < size:
x = ''
else:
x = list[i]
texts.append(x)
if not texts and texts[-1]:
del texts[-1]
if texts:
if not texts[-1]:
for col in range(len(texts)):
texts[col] = texts[col].ljust(colwidths[col])
self.stdout.write('%s\n' % str(' '.join(texts)))
return None