Mercurial > python-cmd2
comparison cmd2.py @ 204:5d22be6d2f88 0.4.7
v1.6.0
author | catherine@dellzilla |
---|---|
date | Mon, 02 Mar 2009 16:22:38 -0500 |
parents | 68a609fc516b |
children | 00eaec841567 |
comparison
equal
deleted
inserted
replaced
203:68a609fc516b | 204:5d22be6d2f88 |
---|---|
25 flagReader.py options are still supported for backward compatibility | 25 flagReader.py options are still supported for backward compatibility |
26 """ | 26 """ |
27 import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest | 27 import cmd, re, os, sys, optparse, subprocess, tempfile, pyparsing, doctest |
28 import unittest, string, datetime | 28 import unittest, string, datetime |
29 from optparse import make_option | 29 from optparse import make_option |
30 __version__ = '0.4.6' | 30 __version__ = '0.4.7' |
31 | 31 |
32 class OptionParser(optparse.OptionParser): | 32 class OptionParser(optparse.OptionParser): |
33 def exit(self, status=0, msg=None): | 33 def exit(self, status=0, msg=None): |
34 self.values._exit = True | 34 self.values._exit = True |
35 if msg: | 35 if msg: |
197 exc.loc = loc | 197 exc.loc = loc |
198 exc.pstr = instring | 198 exc.pstr = instring |
199 raise exc | 199 raise exc |
200 | 200 |
201 def replace_with_file_contents(fname): | 201 def replace_with_file_contents(fname): |
202 import pdb; pdb.set_trace() | |
202 if fname: | 203 if fname: |
203 try: | 204 try: |
204 result = open(os.path.expanduser(fname[0])).read() | 205 result = open(os.path.expanduser(fname[0])).read() |
205 except IOError: | 206 except IOError: |
206 result = '< %s' % fname[0] # wasn't a file after all | 207 result = '< %s' % fname[0] # wasn't a file after all |
466 ) | 467 ) |
467 self.parser.ignore(pyparsing.quotedString).ignore(self.commentGrammars).ignore(self.commentInProgress) | 468 self.parser.ignore(pyparsing.quotedString).ignore(self.commentGrammars).ignore(self.commentInProgress) |
468 | 469 |
469 inputMark = pyparsing.Literal('<') | 470 inputMark = pyparsing.Literal('<') |
470 inputMark.setParseAction(lambda x: '') | 471 inputMark.setParseAction(lambda x: '') |
471 inputFrom = pyparsing.Word(self.legalChars + '/\\')('inputFrom') | 472 fileName = pyparsing.Word(self.legalChars + '/\\') |
473 inputFrom = fileName('inputFrom') | |
472 inputFrom.setParseAction(replace_with_file_contents) | 474 inputFrom.setParseAction(replace_with_file_contents) |
473 self.inputParser = inputMark + pyparsing.Optional(inputFrom) | 475 # a not-entirely-satisfactory way of distinguishing < as in "import from" from < |
476 # as in "lesser than" | |
477 self.inputParser = inputMark + pyparsing.Optional(inputFrom) + pyparsing.Optional('>') + \ | |
478 pyparsing.Optional(fileName) + (pyparsing.stringEnd | '|') | |
474 self.inputParser.ignore(pyparsing.quotedString).ignore(self.commentGrammars).ignore(self.commentInProgress) | 479 self.inputParser.ignore(pyparsing.quotedString).ignore(self.commentGrammars).ignore(self.commentInProgress) |
475 | 480 |
476 def parsed(self, raw, **kwargs): | 481 def parsed(self, raw, **kwargs): |
477 if isinstance(raw, ParsedString): | 482 if isinstance(raw, ParsedString): |
478 p = raw | 483 p = raw |