##// END OF EJS Templates
Fix up argparse (update bundled version) so IPython starts whether or not argparse is installed system-wide.
Thomas Kluyver -
Show More
@@ -10,3 +10,4 b' try:'
10 10 from argparse import *
11 11 except ImportError:
12 12 from _argparse import *
13 from _argparse import SUPPRESS
@@ -1,4 +1,18 b''
1 # Author: Steven J. Bethard <steven.bethard@gmail.com>.
1 # -*- coding: utf-8 -*-
2
3 # Copyright Β© 2006-2009 Steven J. Bethard <steven.bethard@gmail.com>.
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License"); you may not
6 # use this file except in compliance with the License. You may obtain a copy
7 # of the License at
8 #
9 # http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
13 # WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
14 # License for the specific language governing permissions and limitations
15 # under the License.
2 16
3 17 """Command-line parsing library
4 18
@@ -83,10 +97,40 b' import textwrap as _textwrap'
83 97
84 98 from gettext import gettext as _
85 99
100 try:
101 _set = set
102 except NameError:
103 from sets import Set as _set
104
105 try:
106 _basestring = basestring
107 except NameError:
108 _basestring = str
109
110 try:
111 _sorted = sorted
112 except NameError:
113
114 def _sorted(iterable, reverse=False):
115 result = list(iterable)
116 result.sort()
117 if reverse:
118 result.reverse()
119 return result
120
86 121
87 122 def _callable(obj):
88 123 return hasattr(obj, '__call__') or hasattr(obj, '__bases__')
89 124
125 # silence Python 2.6 buggy warnings about Exception.message
126 if _sys.version_info[:2] == (2, 6):
127 import warnings
128 warnings.filterwarnings(
129 action='ignore',
130 message='BaseException.message has been deprecated as of Python 2.6',
131 category=DeprecationWarning,
132 module='argparse')
133
90 134
91 135 SUPPRESS = '==SUPPRESS=='
92 136
@@ -119,7 +163,7 b' class _AttributeHolder(object):'
119 163 return '%s(%s)' % (type_name, ', '.join(arg_strings))
120 164
121 165 def _get_kwargs(self):
122 return sorted(self.__dict__.items())
166 return _sorted(self.__dict__.items())
123 167
124 168 def _get_args(self):
125 169 return []
@@ -372,7 +416,7 b' class HelpFormatter(object):'
372 416
373 417 def _format_actions_usage(self, actions, groups):
374 418 # find group indices and identify actions in groups
375 group_actions = set()
419 group_actions = _set()
376 420 inserts = {}
377 421 for group in groups:
378 422 try:
@@ -442,7 +486,7 b' class HelpFormatter(object):'
442 486 parts.append(part)
443 487
444 488 # insert things at the necessary indices
445 for i in sorted(inserts, reverse=True):
489 for i in _sorted(inserts, reverse=True):
446 490 parts[i:i] = [inserts[i]]
447 491
448 492 # join all the action items with spaces
@@ -987,7 +1031,7 b' class _VersionAction(Action):'
987 1031 version=None,
988 1032 dest=SUPPRESS,
989 1033 default=SUPPRESS,
990 help="show program's version number and exit"):
1034 help=None):
991 1035 super(_VersionAction, self).__init__(
992 1036 option_strings=option_strings,
993 1037 dest=dest,
@@ -1131,8 +1175,6 b' class Namespace(_AttributeHolder):'
1131 1175 for name in kwargs:
1132 1176 setattr(self, name, kwargs[name])
1133 1177
1134 __hash__ = None
1135
1136 1178 def __eq__(self, other):
1137 1179 return vars(self) == vars(other)
1138 1180
@@ -1674,7 +1716,7 b' class ArgumentParser(_AttributeHolder, _ActionsContainer):'
1674 1716 if not hasattr(namespace, action.dest):
1675 1717 if action.default is not SUPPRESS:
1676 1718 default = action.default
1677 if isinstance(action.default, basestring):
1719 if isinstance(action.default, _basestring):
1678 1720 default = self._get_value(action, default)
1679 1721 setattr(namespace, action.dest, default)
1680 1722
@@ -1734,8 +1776,8 b' class ArgumentParser(_AttributeHolder, _ActionsContainer):'
1734 1776 arg_strings_pattern = ''.join(arg_string_pattern_parts)
1735 1777
1736 1778 # converts arg strings to the appropriate and then takes the action
1737 seen_actions = set()
1738 seen_non_default_actions = set()
1779 seen_actions = _set()
1780 seen_non_default_actions = _set()
1739 1781
1740 1782 def take_action(action, argument_strings, option_string=None):
1741 1783 seen_actions.add(action)
@@ -2148,7 +2190,7 b' class ArgumentParser(_AttributeHolder, _ActionsContainer):'
2148 2190 value = action.const
2149 2191 else:
2150 2192 value = action.default
2151 if isinstance(value, basestring):
2193 if isinstance(value, _basestring):
2152 2194 value = self._get_value(action, value)
2153 2195 self._check_value(action, value)
2154 2196
General Comments 0
You need to be logged in to leave comments. Login now