# HG changeset patch # User catherine@Elli.myhome.westell.com # Date 1215170037 14400 # Node ID 1e4ba836539e4d6591d2e4ce64ad82d59c6ea7c6 # Parent f583663c610f08627fef8946c8fdee912b5da6e3 fixed unit tests diff -r f583663c610f -r 1e4ba836539e cmd2.py --- 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