Merged revisions 78600-78601 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r78600 | benjamin.peterson | 2010-03-02 16:58:01 -0600 (Tue, 02 Mar 2010) | 1 line remove code to avoid BaseException.message bug ........ r78601 | benjamin.peterson | 2010-03-02 17:02:02 -0600 (Tue, 02 Mar 2010) | 1 line remove cross-version compatibility code ........
This commit is contained in:
parent
7124a41da2
commit
16f2fd013d
|
@ -95,40 +95,10 @@ import textwrap as _textwrap
|
|||
|
||||
from gettext import gettext as _
|
||||
|
||||
try:
|
||||
_set = set
|
||||
except NameError:
|
||||
from sets import Set as _set
|
||||
|
||||
try:
|
||||
_basestring = basestring
|
||||
except NameError:
|
||||
_basestring = str
|
||||
|
||||
try:
|
||||
_sorted = sorted
|
||||
except NameError:
|
||||
|
||||
def _sorted(iterable, reverse=False):
|
||||
result = list(iterable)
|
||||
result.sort()
|
||||
if reverse:
|
||||
result.reverse()
|
||||
return result
|
||||
|
||||
|
||||
def _callable(obj):
|
||||
return hasattr(obj, '__call__') or hasattr(obj, '__bases__')
|
||||
|
||||
# silence Python 2.6 buggy warnings about Exception.message
|
||||
if _sys.version_info[:2] == (2, 6):
|
||||
import warnings
|
||||
warnings.filterwarnings(
|
||||
action='ignore',
|
||||
message='BaseException.message has been deprecated as of Python 2.6',
|
||||
category=DeprecationWarning,
|
||||
module='argparse')
|
||||
|
||||
|
||||
SUPPRESS = '==SUPPRESS=='
|
||||
|
||||
|
@ -161,7 +131,7 @@ class _AttributeHolder(object):
|
|||
return '%s(%s)' % (type_name, ', '.join(arg_strings))
|
||||
|
||||
def _get_kwargs(self):
|
||||
return _sorted(self.__dict__.items())
|
||||
return sorted(self.__dict__.items())
|
||||
|
||||
def _get_args(self):
|
||||
return []
|
||||
|
@ -414,7 +384,7 @@ class HelpFormatter(object):
|
|||
|
||||
def _format_actions_usage(self, actions, groups):
|
||||
# find group indices and identify actions in groups
|
||||
group_actions = _set()
|
||||
group_actions = set()
|
||||
inserts = {}
|
||||
for group in groups:
|
||||
try:
|
||||
|
@ -484,7 +454,7 @@ class HelpFormatter(object):
|
|||
parts.append(part)
|
||||
|
||||
# insert things at the necessary indices
|
||||
for i in _sorted(inserts, reverse=True):
|
||||
for i in sorted(inserts, reverse=True):
|
||||
parts[i:i] = [inserts[i]]
|
||||
|
||||
# join all the action items with spaces
|
||||
|
@ -1714,7 +1684,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||
if not hasattr(namespace, action.dest):
|
||||
if action.default is not SUPPRESS:
|
||||
default = action.default
|
||||
if isinstance(action.default, _basestring):
|
||||
if isinstance(action.default, str):
|
||||
default = self._get_value(action, default)
|
||||
setattr(namespace, action.dest, default)
|
||||
|
||||
|
@ -1774,8 +1744,8 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||
arg_strings_pattern = ''.join(arg_string_pattern_parts)
|
||||
|
||||
# converts arg strings to the appropriate and then takes the action
|
||||
seen_actions = _set()
|
||||
seen_non_default_actions = _set()
|
||||
seen_actions = set()
|
||||
seen_non_default_actions = set()
|
||||
|
||||
def take_action(action, argument_strings, option_string=None):
|
||||
seen_actions.add(action)
|
||||
|
@ -2188,7 +2158,7 @@ class ArgumentParser(_AttributeHolder, _ActionsContainer):
|
|||
value = action.const
|
||||
else:
|
||||
value = action.default
|
||||
if isinstance(value, _basestring):
|
||||
if isinstance(value, str):
|
||||
value = self._get_value(action, value)
|
||||
self._check_value(action, value)
|
||||
|
||||
|
|
|
@ -22,30 +22,10 @@ import unittest
|
|||
import warnings
|
||||
import argparse
|
||||
|
||||
from io import StringIO
|
||||
|
||||
from test import support
|
||||
|
||||
try:
|
||||
from StringIO import StringIO
|
||||
except ImportError:
|
||||
from io import StringIO
|
||||
|
||||
try:
|
||||
set
|
||||
except NameError:
|
||||
from sets import Set as set
|
||||
|
||||
try:
|
||||
sorted
|
||||
except NameError:
|
||||
|
||||
def sorted(iterable, reverse=False):
|
||||
result = list(iterable)
|
||||
result.sort()
|
||||
if reverse:
|
||||
result.reverse()
|
||||
return result
|
||||
|
||||
|
||||
class TestCase(unittest.TestCase):
|
||||
|
||||
def assertEqual(self, obj1, obj2):
|
||||
|
@ -4183,12 +4163,6 @@ class TestImportStar(TestCase):
|
|||
|
||||
def test_main():
|
||||
with warnings.catch_warnings():
|
||||
# silence Python 2.6 buggy warnings about Exception.message
|
||||
warnings.filterwarnings(
|
||||
action='ignore',
|
||||
message='BaseException.message has been deprecated as of'
|
||||
'Python 2.6',
|
||||
category=DeprecationWarning)
|
||||
# silence warnings about version argument - these are expected
|
||||
warnings.filterwarnings(
|
||||
action='ignore',
|
||||
|
|
Loading…
Reference in New Issue