# HG changeset patch # User catherine@Elli.myhome.westell.com # Date 1226198027 18000 # Node ID c28ae4f75c153493f21baa1640d2714f68bf6be8 # Parent 31674148b13c132bf484b96ed79eebd58b00fcf7 incorporated changes from branch at work diff -r 31674148b13c -r c28ae4f75c15 cmd2.py --- a/cmd2.py Sat Nov 08 17:10:20 2008 -0500 +++ b/cmd2.py Sat Nov 08 21:33:47 2008 -0500 @@ -203,6 +203,8 @@ result = "\n".join('%s: %s' % (sc[0], sc[1]) for sc in self.shortcuts.items()) self.stdout.write("Single-key shortcuts for other commands:\n%s\n" % (result)) + commentRemover = (pyparsing.SkipTo(pyparsing.StringEnd()))('fullStatement') + commentRemover.suppress(pyparsing.pythonStyleComment) specialTerminators = {'/*': pyparsing.Literal('*/')('terminator') } terminatorPattern = ((pyparsing.Literal(';') ^ pyparsing.Literal('\n\n')) ^ (pyparsing.Literal('\nEOF') + pyparsing.lineEnd))('terminator') @@ -243,19 +245,16 @@ ''' if isinstance(s, pyparsing.ParseResults): return s - result = (pyparsing.SkipTo(pyparsing.StringEnd()))('fullStatement').parseString(s) + result = self.commentRemover.parseString(s) command = s.split()[0] if self.caseInsensitive: command = command.lower() - '''if command in self.noSpecialParse: - result['statement'] = result['upToIncluding'] = result['unterminated'] = result.fullStatement + if command in self.noSpecialParse: result['command'] = command - result['args'] = ' '.join(result.fullStatement.split()[1:]) - return result''' - for (shortcut, fullCommand) in self.shortcuts.items(): - if s.startswith(shortcut): - s = s.replace(shortcut, fullCommand + ' ', 1) - break + result['statement'] = result.fullStatement + return result + if s[0] in self.shortcuts: + s = self.shortcuts[s[0]] + ' ' + s[1:] result['statement'] = s result['parseable'] = s terminator = self.specialTerminators.get(command) or self.terminatorPattern @@ -349,7 +348,10 @@ if statekeeper: if statement.output and not statement.outputTo: self.stdout.seek(0) - writeToPasteBuffer(self.stdout.read()) + try: + writeToPasteBuffer(self.stdout.read()) + except Exception, e: + print str(e) elif statement.pipe: for result in redirect.communicate(): statekeeper.stdout.write(result or '')