From bbfad2e260d30c76c09946c37191ae0882b3daf5 Mon Sep 17 00:00:00 2001 From: Seblu <sebastien.luttringer@smartjog.com> Date: Mon, 11 Jul 2011 18:34:49 +0200 Subject: [PATCH] Revert "Update argparse to python 2.7.2" This reverts commit dd0421255493c2e686c7c64156b1c38164e3cdc1. This cause call to python2.7 unsupported ordereddict --- installsystems/argparse.py | 32 +++++++++++--------------------- 1 file changed, 11 insertions(+), 21 deletions(-) diff --git a/installsystems/argparse.py b/installsystems/argparse.py index a9129de..9837432 100644 --- a/installsystems/argparse.py +++ b/installsystems/argparse.py @@ -82,7 +82,6 @@ __all__ = [ ] -import collections as _collections import copy as _copy import os as _os import re as _re @@ -1038,7 +1037,7 @@ class _SubParsersAction(Action): self._prog_prefix = prog self._parser_class = parser_class - self._name_parser_map = _collections.OrderedDict() + self._name_parser_map = {} self._choices_actions = [] super(_SubParsersAction, self).__init__( @@ -1081,7 +1080,7 @@ class _SubParsersAction(Action): parser = self._name_parser_map[parser_name] except KeyError: tup = parser_name, ', '.join(self._name_parser_map) - msg = _('unknown parser %r (choices: %s)') % tup + msg = _('unknown parser %r (choices: %s)' % tup) raise ArgumentError(self, msg) # parse all the remaining options into the namespace @@ -1110,7 +1109,7 @@ class FileType(object): the builtin open() function. """ - def __init__(self, mode='r', bufsize=-1): + def __init__(self, mode='r', bufsize=None): self._mode = mode self._bufsize = bufsize @@ -1122,19 +1121,18 @@ class FileType(object): elif 'w' in self._mode: return _sys.stdout else: - msg = _('argument "-" with mode %r') % self._mode + msg = _('argument "-" with mode %r' % self._mode) raise ValueError(msg) # all other arguments are used as file names - try: + if self._bufsize: return open(string, self._mode, self._bufsize) - except IOError as e: - message = _("can't open '%s': %s") - raise ArgumentTypeError(message % (string, e)) + else: + return open(string, self._mode) def __repr__(self): - args = self._mode, self._bufsize - args_str = ', '.join(repr(arg) for arg in args if arg != -1) + args = [self._mode, self._bufsize] + args_str = ', '.join([repr(arg) for arg in args if arg is not None]) return '%s(%s)' % (type(self).__name__, args_str) # =========================== @@ -1277,20 +1275,13 @@ class _ActionsContainer(object): # create the action object, and add it to the parser action_class = self._pop_action_class(kwargs) if not _callable(action_class): - raise ValueError('unknown action "%s"' % (action_class,)) + raise ValueError('unknown action "%s"' % action_class) action = action_class(**kwargs) # raise an error if the action type is not callable type_func = self._registry_get('type', action.type, action.type) if not _callable(type_func): - raise ValueError('%r is not callable' % (type_func,)) - - # raise an error if the metavar does not match the type - if hasattr(self, "_get_formatter"): - try: - self._get_formatter()._format_args(action, None) - except TypeError: - raise ValueError("length of metavar tuple does not match nargs") + raise ValueError('%r is not callable' % type_func) return self._add_action(action) @@ -1490,7 +1481,6 @@ class _ArgumentGroup(_ActionsContainer): self._defaults = container._defaults self._has_negative_number_optionals = \ container._has_negative_number_optionals - self._mutually_exclusive_groups = container._mutually_exclusive_groups def _add_action(self, action): action = super(_ArgumentGroup, self)._add_action(action) -- GitLab