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

Method precmd

Lib/pdb.py:1021–1057  ·  view source on GitHub ↗

Handle alias expansion and ';;' separator.

(self, line)

Source from the content-addressed store, hash-verified

1019 return ''.join(line_pieces)
1020
1021 def precmd(self, line):
1022 """Handle alias expansion and ';;' separator."""
1023 if not line.strip():
1024 return line
1025 args = line.split()
1026 while args[0] in self.aliases:
1027 line = self.aliases[args[0]]
1028 for idx in range(1, 10):
1029 if f'%{idx}' in line:
1030 if idx >= len(args):
1031 self.error(f"Not enough arguments for alias '{args[0]}'")
1032 # This is a no-op
1033 return "!"
1034 line = line.replace(f'%{idx}', args[idx])
1035 elif '%*' not in line:
1036 if idx < len(args):
1037 self.error(f"Too many arguments for alias '{args[0]}'")
1038 # This is a no-op
1039 return "!"
1040 break
1041
1042 line = line.replace("%*", ' '.join(args[1:]))
1043 args = line.split()
1044 # split into ';;' separated commands
1045 # unless it's an alias command
1046 if args[0] != 'alias':
1047 marker = line.find(';;')
1048 if marker >= 0:
1049 # queue up everything after marker
1050 next = line[marker+2:].lstrip()
1051 self.cmdqueue.insert(0, next)
1052 line = line[:marker].rstrip()
1053
1054 # Replace all the convenience variables
1055 line = self._replace_convenience_variables(line)
1056
1057 return line
1058
1059 def onecmd(self, line):
1060 """Interpret the argument as though it had been typed in response

Callers 1

cmdloopMethod · 0.45

Calls 10

errorMethod · 0.95
stripMethod · 0.45
splitMethod · 0.45
replaceMethod · 0.45
joinMethod · 0.45
findMethod · 0.45
lstripMethod · 0.45
insertMethod · 0.45
rstripMethod · 0.45

Tested by

no test coverage detected