Mercurial > xib
annotate argparse_modified.py @ 108:dff9746aa508
XMPP room deletion (and server shut down) handling
Signed-off-by: Charly COSTE <changaco@changaco.net>
author | Charly COSTE <changaco@changaco.net> |
---|---|
date | Sun, 22 Nov 2009 11:39:33 +0100 |
parents | 60cc60f0058d |
children | 99f3dee1fad7 |
rev | line source |
---|---|
104
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
1 #!/usr/bin/env python |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
2 # -*- coding: utf-8 -*- |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
3 |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
4 # This program is free software: you can redistribute it and/or modify |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
5 # it under the terms of the GNU General Public License as published by |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
6 # the Free Software Foundation, either version 3 of the License, or |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
7 # (at your option) any later version. |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
8 # |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
9 # This program is distributed in the hope that it will be useful, |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
12 # GNU General Public License for more details. |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
13 # |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
14 # You should have received a copy of the GNU General Public License |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
15 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
16 |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
17 from argparse import ArgumentParser as OriginalArgumentParser |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
18 |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
19 class ParseException(Exception): pass |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
20 |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
21 class ArgumentParser(OriginalArgumentParser): |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
22 |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
23 def _print_message(self, message, file=None): |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
24 if not hasattr(self, 'ret'): |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
25 self.ret = '' |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
26 self.ret += message |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
27 |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
28 def exit(self, status=0, message=''): |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
29 if hasattr(self, 'ret') and isinstance(self.ret, basestring): |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
30 raise ParseException(status, self.ret+message) |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
31 else: |
60cc60f0058d
Oops, forgot to add this file in the new command system commit
Charly COSTE <changaco@changaco.net>
parents:
diff
changeset
|
32 raise ParseException(status, message) |