comparison argparse_modified.py @ 124:99f3dee1fad7

code cleaning Signed-off-by: Charly COSTE <changaco@changaco.net>
author Charly COSTE <changaco@changaco.net>
date Wed, 13 Jan 2010 23:08:44 +0100
parents 60cc60f0058d
children
comparison
equal deleted inserted replaced
123:75a03f10a863 124:99f3dee1fad7
14 # You should have received a copy of the GNU General Public License 14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. 15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16 16
17 from argparse import ArgumentParser as OriginalArgumentParser 17 from argparse import ArgumentParser as OriginalArgumentParser
18 18
19 class ParseException(Exception): pass
20
21 class ArgumentParser(OriginalArgumentParser): 19 class ArgumentParser(OriginalArgumentParser):
20
21 class ParseException(Exception): pass
22 22
23 def _print_message(self, message, file=None): 23 def _print_message(self, message, file=None):
24 if not hasattr(self, 'ret'): 24 if not hasattr(self, 'ret'):
25 self.ret = '' 25 self.ret = ''
26 self.ret += message 26 self.ret += message
27 27
28 def exit(self, status=0, message=''): 28 def exit(self, status=0, message=''):
29 if hasattr(self, 'ret') and isinstance(self.ret, basestring): 29 if hasattr(self, 'ret') and isinstance(self.ret, basestring):
30 raise ParseException(status, self.ret+message) 30 raise self.ParseException(status, self.ret+message)
31 else: 31 else:
32 raise ParseException(status, message) 32 raise self.ParseException(status, message)