Mercurial > python-cmd2
diff cmd2.py @ 80:1e4ba836539e
fixed unit tests
author | catherine@Elli.myhome.westell.com |
---|---|
date | Fri, 04 Jul 2008 07:13:57 -0400 |
parents | f583663c610f |
children | a3b0ef23146f |
line wrap: on
line diff
--- a/cmd2.py Fri Jul 04 07:08:21 2008 -0400 +++ b/cmd2.py Fri Jul 04 07:13:57 2008 -0400 @@ -175,11 +175,6 @@ def __init__(self, *args, **kwargs): cmd.Cmd.__init__(self, *args, **kwargs) self.history = History() - self.punctuationPattern = self.terminators ^ self.pipePattern ^ \ - self.redirectInPattern ^ \ - self.redirectOutPattern - self.punctuationPattern.ignore(pyparsing.sglQuotedString) - self.punctuationPattern.ignore(pyparsing.dblQuotedString) def do_shortcuts(self, args): """Lists single-key shortcuts available.""" @@ -197,7 +192,8 @@ + pyparsing.Optional(filenamePattern)('outputTo') redirectInPattern = pyparsing.Literal('<')('input') \ + pyparsing.Optional(filenamePattern)('inputFrom') - for p in (terminators, pipePattern, redirectInPattern, redirectOutPattern): + punctuationPattern = pipePattern ^ redirectInPattern ^ redirectOutPattern + for p in (terminators, pipePattern, redirectInPattern, redirectOutPattern, punctuationPattern): p.ignore(pyparsing.sglQuotedString) p.ignore(pyparsing.dblQuotedString) @@ -205,18 +201,18 @@ ''' >>> c = Cmd() >>> c.parsed('quotes "are > ignored" < inp.txt').asDict() - {'args': ' "are > ignored"', 'inputFrom': 'inp.txt', 'command': 'quotes', 'statement': 'quotes "are > ignored"', 'input': '<', 'fullStatement': 'quotes "are > ignored" < inp.txt'} + {'args': '"are > ignored"', 'inputFrom': 'inp.txt', 'command': 'quotes', 'statement': 'quotes "are > ignored"', 'input': '<', 'fullStatement': 'quotes "are > ignored" < inp.txt'} >>> c.parsed('very complex; < from.txt >> to.txt etc.').asDict() - {'args': ' complex', 'inputFrom': 'from.txt', 'command': 'very', 'terminator': ';', 'statement': 'very complex', 'input': '<', 'output': '>>', 'outputTo': 'to.txt', 'fullStatement': 'very complex; < from.txt >> to.txt etc.'} + {'args': 'complex;', 'inputFrom': 'from.txt', 'command': 'very', 'statement': 'very complex;', 'input': '<', 'output': '>>', 'outputTo': 'to.txt', 'fullStatement': 'very complex; < from.txt >> to.txt etc.'} >>> c.parsed('nothing to parse').asDict() - {'args': ' to parse', 'command': 'nothing', 'statement': 'nothing to parse', 'fullStatement': 'nothing to parse'} + {'args': 'to parse', 'command': 'nothing', 'statement': 'nothing to parse', 'fullStatement': 'nothing to parse'} >>> c.parsed('send it to | sort | wc').asDict() - {'args': ' it to', 'pipe': '|', 'pipeTo': ' sort | wc', 'command': 'send', 'statement': 'send it to', 'fullStatement': 'send it to | sort | wc'} + {'args': 'it to', 'pipe': '|', 'pipeTo': ' sort | wc', 'command': 'send', 'statement': 'send it to', 'fullStatement': 'send it to | sort | wc'} >>> r = c.parsed('got from < thisfile.txt plus blah blah') >>> r.asDict() - {'args': ' from', 'inputFrom': 'thisfile.txt', 'command': 'got', 'statement': 'got from', 'input': '<', 'fullStatement': 'got from < thisfile.txt plus blah blah'} + {'args': 'from', 'inputFrom': 'thisfile.txt', 'command': 'got', 'statement': 'got from', 'input': '<', 'fullStatement': 'got from < thisfile.txt plus blah blah'} >>> c.parsed(r).asDict() - {'args': ' from', 'inputFrom': 'thisfile.txt', 'command': 'got', 'statement': 'got from', 'input': '<', 'fullStatement': 'got from < thisfile.txt plus blah blah'} + {'args': 'from', 'inputFrom': 'thisfile.txt', 'command': 'got', 'statement': 'got from', 'input': '<', 'fullStatement': 'got from < thisfile.txt plus blah blah'} ''' if isinstance(s, pyparsing.ParseResults): return s