<s> """<STR_LIT>""" <EOL> __version__ = '<STR_LIT>' <EOL> __all__ = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> import copy as _copy <EOL> import os as _os <EOL> import re as _re <EOL> import sys as _sys <EOL> import textwrap as _textwrap <EOL> from gettext import gettext as _ <EOL> try : <EOL> set <EOL> except NameError : <EOL> from sets import Set as set <EOL> try : <EOL> basestring <EOL> except NameError : <EOL> basestring = str <EOL> try : <EOL> sorted <EOL> except NameError : <EOL> def sorted ( iterable , reverse = False ) : <EOL> result = list ( iterable ) <EOL> result . sort ( ) <EOL> if reverse : <EOL> result . reverse ( ) <EOL> return result <EOL> def _callable ( obj ) : <EOL> return hasattr ( obj , '<STR_LIT>' ) or hasattr ( obj , '<STR_LIT>' ) <EOL> SUPPRESS = '<STR_LIT>' <EOL> OPTIONAL = '<STR_LIT:?>' <EOL> ZERO_OR_MORE = '<STR_LIT:*>' <EOL> ONE_OR_MORE = '<STR_LIT:+>' <EOL> PARSER = '<STR_LIT>' <EOL> REMAINDER = '<STR_LIT>' <EOL> _UNRECOGNIZED_ARGS_ATTR = '<STR_LIT>' <EOL> class _AttributeHolder ( object ) : <EOL> """<STR_LIT>""" <EOL> def __repr__ ( self ) : <EOL> type_name = type ( self ) . __name__ <EOL> arg_strings = [ ] <EOL> for arg in self . _get_args ( ) : <EOL> arg_strings . append ( repr ( arg ) ) <EOL> for name , value in self . _get_kwargs ( ) : <EOL> arg_strings . append ( '<STR_LIT>' % ( name , value ) ) <EOL> return '<STR_LIT>' % ( type_name , '<STR_LIT:U+002CU+0020>' . join ( arg_strings ) ) <EOL> def _get_kwargs ( self ) : <EOL> return sorted ( self . __dict__ . items ( ) ) <EOL> def _get_args ( self ) : <EOL> return [ ] <EOL> def _ensure_value ( namespace , name , value ) : <EOL> if getattr ( namespace , name , None ) is None : <EOL> setattr ( namespace , name , value ) <EOL> return getattr ( namespace , name ) <EOL> class HelpFormatter ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> prog , <EOL> indent_increment = <NUM_LIT:2> , <EOL> max_help_position = <NUM_LIT> , <EOL> width = None ) : <EOL> if width is None : <EOL> try : <EOL> width = int ( _os . environ [ '<STR_LIT>' ] ) <EOL> except ( KeyError , ValueError ) : <EOL> width = <NUM_LIT> <EOL> width -= <NUM_LIT:2> <EOL> self . _prog = prog <EOL> self . _indent_increment = indent_increment <EOL> self . _max_help_position = max_help_position <EOL> self . _width = width <EOL> self . _current_indent = <NUM_LIT:0> <EOL> self . _level = <NUM_LIT:0> <EOL> self . _action_max_length = <NUM_LIT:0> <EOL> self . _root_section = self . _Section ( self , None ) <EOL> self . _current_section = self . _root_section <EOL> self . _whitespace_matcher = _re . compile ( r'<STR_LIT>' ) <EOL> self . _long_break_matcher = _re . compile ( r'<STR_LIT>' ) <EOL> def _indent ( self ) : <EOL> self . _current_indent += self . _indent_increment <EOL> self . _level += <NUM_LIT:1> <EOL> def _dedent ( self ) : <EOL> self . _current_indent -= self . _indent_increment <EOL> assert self . _current_indent >= <NUM_LIT:0> , '<STR_LIT>' <EOL> self . _level -= <NUM_LIT:1> <EOL> class _Section ( object ) : <EOL> def __init__ ( self , formatter , parent , heading = None ) : <EOL> self . formatter = formatter <EOL> self . parent = parent <EOL> self . heading = heading <EOL> self . items = [ ] <EOL> def format_help ( self ) : <EOL> if self . parent is not None : <EOL> self . formatter . _indent ( ) <EOL> join = self . formatter . _join_parts <EOL> for func , args in self . items : <EOL> func ( * args ) <EOL> item_help = join ( [ func ( * args ) for func , args in self . items ] ) <EOL> if self . parent is not None : <EOL> self . formatter . _dedent ( ) <EOL> if not item_help : <EOL> return '<STR_LIT>' <EOL> if self . heading is not SUPPRESS and self . heading is not None : <EOL> current_indent = self . formatter . _current_indent <EOL> heading = '<STR_LIT>' % ( current_indent , '<STR_LIT>' , self . heading ) <EOL> else : <EOL> heading = '<STR_LIT>' <EOL> return join ( [ '<STR_LIT:\n>' , heading , item_help , '<STR_LIT:\n>' ] ) <EOL> def _add_item ( self , func , args ) : <EOL> self . _current_section . items . append ( ( func , args ) ) <EOL> def start_section ( self , heading ) : <EOL> self . _indent ( ) <EOL> section = self . _Section ( self , self . _current_section , heading ) <EOL> self . _add_item ( section . format_help , [ ] ) <EOL> self . _current_section = section <EOL> def end_section ( self ) : <EOL> self . _current_section = self . _current_section . parent <EOL> self . _dedent ( ) <EOL> def add_text ( self , text ) : <EOL> if text is not SUPPRESS and text is not None : <EOL> self . _add_item ( self . _format_text , [ text ] ) <EOL> def add_usage ( self , usage , actions , groups , prefix = None ) : <EOL> if usage is not SUPPRESS : <EOL> args = usage , actions , groups , prefix <EOL> self . _add_item ( self . _format_usage , args ) <EOL> def add_argument ( self , action ) : <EOL> if action . help is not SUPPRESS : <EOL> get_invocation = self . _format_action_invocation <EOL> invocations = [ get_invocation ( action ) ] <EOL> for subaction in self . _iter_indented_subactions ( action ) : <EOL> invocations . append ( get_invocation ( subaction ) ) <EOL> invocation_length = max ( [ len ( s ) for s in invocations ] ) <EOL> action_length = invocation_length + self . _current_indent <EOL> self . _action_max_length = max ( self . _action_max_length , <EOL> action_length ) <EOL> self . _add_item ( self . _format_action , [ action ] ) <EOL> def add_arguments ( self , actions ) : <EOL> for action in actions : <EOL> self . add_argument ( action ) <EOL> def format_help ( self ) : <EOL> help = self . _root_section . format_help ( ) <EOL> if help : <EOL> help = self . _long_break_matcher . sub ( '<STR_LIT>' , help ) <EOL> help = help . strip ( '<STR_LIT:\n>' ) + '<STR_LIT:\n>' <EOL> return help <EOL> def _join_parts ( self , part_strings ) : <EOL> return '<STR_LIT>' . join ( [ part <EOL> for part in part_strings <EOL> if part and part is not SUPPRESS ] ) <EOL> def _format_usage ( self , usage , actions , groups , prefix ) : <EOL> if prefix is None : <EOL> prefix = _ ( '<STR_LIT>' ) <EOL> if usage is not None : <EOL> usage = usage % dict ( prog = self . _prog ) <EOL> elif usage is None and not actions : <EOL> usage = '<STR_LIT>' % dict ( prog = self . _prog ) <EOL> elif usage is None : <EOL> prog = '<STR_LIT>' % dict ( prog = self . _prog ) <EOL> optionals = [ ] <EOL> positionals = [ ] <EOL> for action in actions : <EOL> if action . option_strings : <EOL> optionals . append ( action ) <EOL> else : <EOL> positionals . append ( action ) <EOL> format = self . _format_actions_usage <EOL> action_usage = format ( optionals + positionals , groups ) <EOL> usage = '<STR_LIT:U+0020>' . join ( [ s for s in [ prog , action_usage ] if s ] ) <EOL> text_width = self . _width - self . _current_indent <EOL> if len ( prefix ) + len ( usage ) > text_width : <EOL> part_regexp = r'<STR_LIT>' <EOL> opt_usage = format ( optionals , groups ) <EOL> pos_usage = format ( positionals , groups ) <EOL> opt_parts = _re . findall ( part_regexp , opt_usage ) <EOL> pos_parts = _re . findall ( part_regexp , pos_usage ) <EOL> assert '<STR_LIT:U+0020>' . join ( opt_parts ) == opt_usage <EOL> assert '<STR_LIT:U+0020>' . join ( pos_parts ) == pos_usage <EOL> def get_lines ( parts , indent , prefix = None ) : <EOL> lines = [ ] <EOL> line = [ ] <EOL> if prefix is not None : <EOL> line_len = len ( prefix ) - <NUM_LIT:1> <EOL> else : <EOL> line_len = len ( indent ) - <NUM_LIT:1> <EOL> for part in parts : <EOL> if line_len + <NUM_LIT:1> + len ( part ) > text_width : <EOL> lines . append ( indent + '<STR_LIT:U+0020>' . join ( line ) ) <EOL> line = [ ] <EOL> line_len = len ( indent ) - <NUM_LIT:1> <EOL> line . append ( part ) <EOL> line_len += len ( part ) + <NUM_LIT:1> <EOL> if line : <EOL> lines . append ( indent + '<STR_LIT:U+0020>' . join ( line ) ) <EOL> if prefix is not None : <EOL> lines [ <NUM_LIT:0> ] = lines [ <NUM_LIT:0> ] [ len ( indent ) : ] <EOL> return lines <EOL> if len ( prefix ) + len ( prog ) <= <NUM_LIT> * text_width : <EOL> indent = '<STR_LIT:U+0020>' * ( len ( prefix ) + len ( prog ) + <NUM_LIT:1> ) <EOL> if opt_parts : <EOL> lines = get_lines ( [ prog ] + opt_parts , indent , prefix ) <EOL> lines . extend ( get_lines ( pos_parts , indent ) ) <EOL> elif pos_parts : <EOL> lines = get_lines ( [ prog ] + pos_parts , indent , prefix ) <EOL> else : <EOL> lines = [ prog ] <EOL> else : <EOL> indent = '<STR_LIT:U+0020>' * len ( prefix ) <EOL> parts = opt_parts + pos_parts <EOL> lines = get_lines ( parts , indent ) <EOL> if len ( lines ) > <NUM_LIT:1> : <EOL> lines = [ ] <EOL> lines . extend ( get_lines ( opt_parts , indent ) ) <EOL> lines . extend ( get_lines ( pos_parts , indent ) ) <EOL> lines = [ prog ] + lines <EOL> usage = '<STR_LIT:\n>' . join ( lines ) <EOL> return '<STR_LIT>' % ( prefix , usage ) <EOL> def _format_actions_usage ( self , actions , groups ) : <EOL> group_actions = set ( ) <EOL> inserts = { } <EOL> for group in groups : <EOL> try : <EOL> start = actions . index ( group . _group_actions [ <NUM_LIT:0> ] ) <EOL> except ValueError : <EOL> continue <EOL> else : <EOL> end = start + len ( group . _group_actions ) <EOL> if actions [ start : end ] == group . _group_actions : <EOL> for action in group . _group_actions : <EOL> group_actions . add ( action ) <EOL> if not group . required : <EOL> if start in inserts : <EOL> inserts [ start ] += '<STR_LIT>' <EOL> else : <EOL> inserts [ start ] = '<STR_LIT:[>' <EOL> inserts [ end ] = '<STR_LIT:]>' <EOL> else : <EOL> if start in inserts : <EOL> inserts [ start ] += '<STR_LIT>' <EOL> else : <EOL> inserts [ start ] = '<STR_LIT:(>' <EOL> inserts [ end ] = '<STR_LIT:)>' <EOL> for i in range ( start + <NUM_LIT:1> , end ) : <EOL> inserts [ i ] = '<STR_LIT:|>' <EOL> parts = [ ] <EOL> for i , action in enumerate ( actions ) : <EOL> if action . help is SUPPRESS : <EOL> parts . append ( None ) <EOL> if inserts . get ( i ) == '<STR_LIT:|>' : <EOL> inserts . pop ( i ) <EOL> elif inserts . get ( i + <NUM_LIT:1> ) == '<STR_LIT:|>' : <EOL> inserts . pop ( i + <NUM_LIT:1> ) <EOL> elif not action . option_strings : <EOL> part = self . _format_args ( action , action . dest ) <EOL> if action in group_actions : <EOL> if part [ <NUM_LIT:0> ] == '<STR_LIT:[>' and part [ - <NUM_LIT:1> ] == '<STR_LIT:]>' : <EOL> part = part [ <NUM_LIT:1> : - <NUM_LIT:1> ] <EOL> parts . append ( part ) <EOL> else : <EOL> option_string = action . option_strings [ <NUM_LIT:0> ] <EOL> if action . nargs == <NUM_LIT:0> : <EOL> part = '<STR_LIT:%s>' % option_string <EOL> else : <EOL> default = action . dest . upper ( ) <EOL> args_string = self . _format_args ( action , default ) <EOL> part = '<STR_LIT>' % ( option_string , args_string ) <EOL> if not action . required and action not in group_actions : <EOL> part = '<STR_LIT>' % part <EOL> parts . append ( part ) <EOL> for i in sorted ( inserts , reverse = True ) : <EOL> parts [ i : i ] = [ inserts [ i ] ] <EOL> text = '<STR_LIT:U+0020>' . join ( [ item for item in parts if item is not None ] ) <EOL> open = r'<STR_LIT>' <EOL> close = r'<STR_LIT>' <EOL> text = _re . sub ( r'<STR_LIT>' % open , r'<STR_LIT>' , text ) <EOL> text = _re . sub ( r'<STR_LIT>' % close , r'<STR_LIT>' , text ) <EOL> text = _re . sub ( r'<STR_LIT>' % ( open , close ) , r'<STR_LIT>' , text ) <EOL> text = _re . sub ( r'<STR_LIT>' , r'<STR_LIT>' , text ) <EOL> text = text . strip ( ) <EOL> return text <EOL> def _format_text ( self , text ) : <EOL> if '<STR_LIT>' in text : <EOL> text = text % dict ( prog = self . _prog ) <EOL> text_width = self . _width - self . _current_indent <EOL> indent = '<STR_LIT:U+0020>' * self . _current_indent <EOL> return self . _fill_text ( text , text_width , indent ) + '<STR_LIT>' <EOL> def _format_action ( self , action ) : <EOL> help_position = min ( self . _action_max_length + <NUM_LIT:2> , <EOL> self . _max_help_position ) <EOL> help_width = self . _width - help_position <EOL> action_width = help_position - self . _current_indent - <NUM_LIT:2> <EOL> action_header = self . _format_action_invocation ( action ) <EOL> if not action . help : <EOL> tup = self . _current_indent , '<STR_LIT>' , action_header <EOL> action_header = '<STR_LIT>' % tup <EOL> elif len ( action_header ) <= action_width : <EOL> tup = self . _current_indent , '<STR_LIT>' , action_width , action_header <EOL> action_header = '<STR_LIT>' % tup <EOL> indent_first = <NUM_LIT:0> <EOL> else : <EOL> tup = self . _current_indent , '<STR_LIT>' , action_header <EOL> action_header = '<STR_LIT>' % tup <EOL> indent_first = help_position <EOL> parts = [ action_header ] <EOL> if action . help : <EOL> help_text = self . _expand_help ( action ) <EOL> help_lines = self . _split_lines ( help_text , help_width ) <EOL> parts . append ( '<STR_LIT>' % ( indent_first , '<STR_LIT>' , help_lines [ <NUM_LIT:0> ] ) ) <EOL> for line in help_lines [ <NUM_LIT:1> : ] : <EOL> parts . append ( '<STR_LIT>' % ( help_position , '<STR_LIT>' , line ) ) <EOL> elif not action_header . endswith ( '<STR_LIT:\n>' ) : <EOL> parts . append ( '<STR_LIT:\n>' ) <EOL> for subaction in self . _iter_indented_subactions ( action ) : <EOL> parts . append ( self . _format_action ( subaction ) ) <EOL> return self . _join_parts ( parts ) <EOL> def _format_action_invocation ( self , action ) : <EOL> if not action . option_strings : <EOL> metavar , = self . _metavar_formatter ( action , action . dest ) ( <NUM_LIT:1> ) <EOL> return metavar <EOL> else : <EOL> parts = [ ] <EOL> if action . nargs == <NUM_LIT:0> : <EOL> parts . extend ( action . option_strings ) <EOL> else : <EOL> default = action . dest . upper ( ) <EOL> args_string = self . _format_args ( action , default ) <EOL> for option_string in action . option_strings : <EOL> parts . append ( '<STR_LIT>' % ( option_string , args_string ) ) <EOL> return '<STR_LIT:U+002CU+0020>' . join ( parts ) <EOL> def _metavar_formatter ( self , action , default_metavar ) : <EOL> if action . metavar is not None : <EOL> result = action . metavar <EOL> elif action . choices is not None : <EOL> choice_strs = [ str ( choice ) for choice in action . choices ] <EOL> result = '<STR_LIT>' % '<STR_LIT:U+002C>' . join ( choice_strs ) <EOL> else : <EOL> result = default_metavar <EOL> def format ( tuple_size ) : <EOL> if isinstance ( result , tuple ) : <EOL> return result <EOL> else : <EOL> return ( result , ) * tuple_size <EOL> return format <EOL> def _format_args ( self , action , default_metavar ) : <EOL> get_metavar = self . _metavar_formatter ( action , default_metavar ) <EOL> if action . nargs is None : <EOL> result = '<STR_LIT:%s>' % get_metavar ( <NUM_LIT:1> ) <EOL> elif action . nargs == OPTIONAL : <EOL> result = '<STR_LIT>' % get_metavar ( <NUM_LIT:1> ) <EOL> elif action . nargs == ZERO_OR_MORE : <EOL> result = '<STR_LIT>' % get_metavar ( <NUM_LIT:2> ) <EOL> elif action . nargs == ONE_OR_MORE : <EOL> result = '<STR_LIT>' % get_metavar ( <NUM_LIT:2> ) <EOL> elif action . nargs == REMAINDER : <EOL> result = '<STR_LIT>' <EOL> elif action . nargs == PARSER : <EOL> result = '<STR_LIT>' % get_metavar ( <NUM_LIT:1> ) <EOL> else : <EOL> formats = [ '<STR_LIT:%s>' for _ in range ( action . nargs ) ] <EOL> result = '<STR_LIT:U+0020>' . join ( formats ) % get_metavar ( action . nargs ) <EOL> return result <EOL> def _expand_help ( self , action ) : <EOL> params = dict ( vars ( action ) , prog = self . _prog ) <EOL> for name in list ( params ) : <EOL> if params [ name ] is SUPPRESS : <EOL> del params [ name ] <EOL> for name in list ( params ) : <EOL> if hasattr ( params [ name ] , '<STR_LIT>' ) : <EOL> params [ name ] = params [ name ] . __name__ <EOL> if params . get ( '<STR_LIT>' ) is not None : <EOL> choices_str = '<STR_LIT:U+002CU+0020>' . join ( [ str ( c ) for c in params [ '<STR_LIT>' ] ] ) <EOL> params [ '<STR_LIT>' ] = choices_str <EOL> return self . _get_help_string ( action ) % params <EOL> def _iter_indented_subactions ( self , action ) : <EOL> try : <EOL> get_subactions = action . _get_subactions <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> self . _indent ( ) <EOL> for subaction in get_subactions ( ) : <EOL> yield subaction <EOL> self . _dedent ( ) <EOL> def _split_lines ( self , text , width ) : <EOL> text = self . _whitespace_matcher . sub ( '<STR_LIT:U+0020>' , text ) . strip ( ) <EOL> return _textwrap . wrap ( text , width ) <EOL> def _fill_text ( self , text , width , indent ) : <EOL> text = self . _whitespace_matcher . sub ( '<STR_LIT:U+0020>' , text ) . strip ( ) <EOL> return _textwrap . fill ( text , width , initial_indent = indent , <EOL> subsequent_indent = indent ) <EOL> def _get_help_string ( self , action ) : <EOL> return action . help <EOL> class RawDescriptionHelpFormatter ( HelpFormatter ) : <EOL> """<STR_LIT>""" <EOL> def _fill_text ( self , text , width , indent ) : <EOL> return '<STR_LIT>' . join ( [ indent + line for line in text . splitlines ( True ) ] ) <EOL> class RawTextHelpFormatter ( RawDescriptionHelpFormatter ) : <EOL> """<STR_LIT>""" <EOL> def _split_lines ( self , text , width ) : <EOL> return text . splitlines ( ) <EOL> class ArgumentDefaultsHelpFormatter ( HelpFormatter ) : <EOL> """<STR_LIT>""" <EOL> def _get_help_string ( self , action ) : <EOL> help = action . help <EOL> if '<STR_LIT>' not in action . help : <EOL> if action . default is not SUPPRESS : <EOL> defaulting_nargs = [ OPTIONAL , ZERO_OR_MORE ] <EOL> if action . option_strings or action . nargs in defaulting_nargs : <EOL> help += '<STR_LIT>' <EOL> return help <EOL> def _get_action_name ( argument ) : <EOL> if argument is None : <EOL> return None <EOL> elif argument . option_strings : <EOL> return '<STR_LIT:/>' . join ( argument . option_strings ) <EOL> elif argument . metavar not in ( None , SUPPRESS ) : <EOL> return argument . metavar <EOL> elif argument . dest not in ( None , SUPPRESS ) : <EOL> return argument . dest <EOL> else : <EOL> return None <EOL> class ArgumentError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , argument , message ) : <EOL> self . argument_name = _get_action_name ( argument ) <EOL> self . message = message <EOL> def __str__ ( self ) : <EOL> if self . argument_name is None : <EOL> format = '<STR_LIT>' <EOL> else : <EOL> format = '<STR_LIT>' <EOL> return format % dict ( message = self . message , <EOL> argument_name = self . argument_name ) <EOL> class ArgumentTypeError ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class Action ( _AttributeHolder ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> option_strings , <EOL> dest , <EOL> nargs = None , <EOL> const = None , <EOL> default = None , <EOL> type = None , <EOL> choices = None , <EOL> required = False , <EOL> help = None , <EOL> metavar = None ) : <EOL> self . option_strings = option_strings <EOL> self . dest = dest <EOL> self . nargs = nargs <EOL> self . const = const <EOL> self . default = default <EOL> self . type = type <EOL> self . choices = choices <EOL> self . required = required <EOL> self . help = help <EOL> self . metavar = metavar <EOL> def _get_kwargs ( self ) : <EOL> names = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:default>' , <EOL> '<STR_LIT:type>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> return [ ( name , getattr ( self , name ) ) for name in names ] <EOL> def __call__ ( self , parser , namespace , values , option_string = None ) : <EOL> raise NotImplementedError ( _ ( '<STR_LIT>' ) ) <EOL> class _StoreAction ( Action ) : <EOL> def __init__ ( self , <EOL> option_strings , <EOL> dest , <EOL> nargs = None , <EOL> const = None , <EOL> default = None , <EOL> type = None , <EOL> choices = None , <EOL> required = False , <EOL> help = None , <EOL> metavar = None ) : <EOL> if nargs == <NUM_LIT:0> : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if const is not None and nargs != OPTIONAL : <EOL> raise ValueError ( '<STR_LIT>' % OPTIONAL ) <EOL> super ( _StoreAction , self ) . __init__ ( <EOL> option_strings = option_strings , <EOL> dest = dest , <EOL> nargs = nargs , <EOL> const = const , <EOL> default = default , <EOL> type = type , <EOL> choices = choices , <EOL> required = required , <EOL> help = help , <EOL> metavar = metavar ) <EOL> def __call__ ( self , parser , namespace , values , option_string = None ) : <EOL> setattr ( namespace , self . dest , values ) <EOL> class _StoreConstAction ( Action ) : <EOL> def __init__ ( self , <EOL> option_strings , <EOL> dest , <EOL> const , <EOL> default = None , <EOL> required = False , <EOL> help = None , <EOL> metavar = None ) : <EOL> super ( _StoreConstAction , self ) . __init__ ( <EOL> option_strings = option_strings , <EOL> dest = dest , <EOL> nargs = <NUM_LIT:0> , <EOL> const = const , <EOL> default = default , <EOL> required = required , <EOL> help = help ) <EOL> def __call__ ( self , parser , namespace , values , option_string = None ) : <EOL> setattr ( namespace , self . dest , self . const ) <EOL> class _StoreTrueAction ( _StoreConstAction ) : <EOL> def __init__ ( self , <EOL> option_strings , <EOL> dest , <EOL> default = False , <EOL> required = False , <EOL> help = None ) : <EOL> super ( _StoreTrueAction , self ) . __init__ ( <EOL> option_strings = option_strings , <EOL> dest = dest , <EOL> const = True , <EOL> default = default , <EOL> required = required , <EOL> help = help ) <EOL> class _StoreFalseAction ( _StoreConstAction ) : <EOL> def __init__ ( self , <EOL> option_strings , <EOL> dest , <EOL> default = True , <EOL> required = False , <EOL> help = None ) : <EOL> super ( _StoreFalseAction , self ) . __init__ ( <EOL> option_strings = option_strings , <EOL> dest = dest , <EOL> const = False , <EOL> default = default , <EOL> required = required , <EOL> help = help ) <EOL> class _AppendAction ( Action ) : <EOL> def __init__ ( self , <EOL> option_strings , <EOL> dest , <EOL> nargs = None , <EOL> const = None , <EOL> default = None , <EOL> type = None , <EOL> choices = None , <EOL> required = False , <EOL> help = None , <EOL> metavar = None ) : <EOL> if nargs == <NUM_LIT:0> : <EOL> raise ValueError ( '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> if const is not None and nargs != OPTIONAL : <EOL> raise ValueError ( '<STR_LIT>' % OPTIONAL ) <EOL> super ( _AppendAction , self ) . __init__ ( <EOL> option_strings = option_strings , <EOL> dest = dest , <EOL> nargs = nargs , <EOL> const = const , <EOL> default = default , <EOL> type = type , <EOL> choices = choices , <EOL> required = required , <EOL> help = help , <EOL> metavar = metavar ) <EOL> def __call__ ( self , parser , namespace , values , option_string = None ) : <EOL> items = _copy . copy ( _ensure_value ( namespace , self . dest , [ ] ) ) <EOL> items . append ( values ) <EOL> setattr ( namespace , self . dest , items ) <EOL> class _AppendConstAction ( Action ) : <EOL> def __init__ ( self , <EOL> option_strings , <EOL> dest , <EOL> const , <EOL> default = None , <EOL> required = False , <EOL> help = None , <EOL> metavar = None ) : <EOL> super ( _AppendConstAction , self ) . __init__ ( <EOL> option_strings = option_strings , <EOL> dest = dest , <EOL> nargs = <NUM_LIT:0> , <EOL> const = const , <EOL> default = default , <EOL> required = required , <EOL> help = help , <EOL> metavar = metavar ) <EOL> def __call__ ( self , parser , namespace , values , option_string = None ) : <EOL> items = _copy . copy ( _ensure_value ( namespace , self . dest , [ ] ) ) <EOL> items . append ( self . const ) <EOL> setattr ( namespace , self . dest , items ) <EOL> class _CountAction ( Action ) : <EOL> def __init__ ( self , <EOL> option_strings , <EOL> dest , <EOL> default = None , <EOL> required = False , <EOL> help = None ) : <EOL> super ( _CountAction , self ) . __init__ ( <EOL> option_strings = option_strings , <EOL> dest = dest , <EOL> nargs = <NUM_LIT:0> , <EOL> default = default , <EOL> required = required , <EOL> help = help ) <EOL> def __call__ ( self , parser , namespace , values , option_string = None ) : <EOL> new_count = _ensure_value ( namespace , self . dest , <NUM_LIT:0> ) + <NUM_LIT:1> <EOL> setattr ( namespace , self . dest , new_count ) <EOL> class _HelpAction ( Action ) : <EOL> def __init__ ( self , <EOL> option_strings , <EOL> dest = SUPPRESS , <EOL> default = SUPPRESS , <EOL> help = None ) : <EOL> super ( _HelpAction , self ) . __init__ ( <EOL> option_strings = option_strings , <EOL> dest = dest , <EOL> default = default , <EOL> nargs = <NUM_LIT:0> , <EOL> help = help ) <EOL> def __call__ ( self , parser , namespace , values , option_string = None ) : <EOL> parser . print_help ( ) <EOL> parser . exit ( ) <EOL> class _VersionAction ( Action ) : <EOL> def __init__ ( self , <EOL> option_strings , <EOL> version = None , <EOL> dest = SUPPRESS , <EOL> default = SUPPRESS , <EOL> help = "<STR_LIT>" ) : <EOL> super ( _VersionAction , self ) . __init__ ( <EOL> option_strings = option_strings , <EOL> dest = dest , <EOL> default = default , <EOL> nargs = <NUM_LIT:0> , <EOL> help = help ) <EOL> self . version = version <EOL> def __call__ ( self , parser , namespace , values , option_string = None ) : <EOL> version = self . version <EOL> if version is None : <EOL> version = parser . version <EOL> formatter = parser . _get_formatter ( ) <EOL> formatter . add_text ( version ) <EOL> parser . exit ( message = formatter . format_help ( ) ) <EOL> class _SubParsersAction ( Action ) : <EOL> class _ChoicesPseudoAction ( Action ) : <EOL> def __init__ ( self , name , help ) : <EOL> sup = super ( _SubParsersAction . _ChoicesPseudoAction , self ) <EOL> sup . __init__ ( option_strings = [ ] , dest = name , help = help ) <EOL> def __init__ ( self , <EOL> option_strings , <EOL> prog , <EOL> parser_class , <EOL> dest = SUPPRESS , <EOL> help = None , <EOL> metavar = None ) : <EOL> self . _prog_prefix = prog <EOL> self . _parser_class = parser_class <EOL> self . _name_parser_map = { } <EOL> self . _choices_actions = [ ] <EOL> super ( _SubParsersAction , self ) . __init__ ( <EOL> option_strings = option_strings , <EOL> dest = dest , <EOL> nargs = PARSER , <EOL> choices = self . _name_parser_map , <EOL> help = help , <EOL> metavar = metavar ) <EOL> def add_parser ( self , name , ** kwargs ) : <EOL> if kwargs . get ( '<STR_LIT>' ) is None : <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT>' % ( self . _prog_prefix , name ) <EOL> if '<STR_LIT>' in kwargs : <EOL> help = kwargs . pop ( '<STR_LIT>' ) <EOL> choice_action = self . _ChoicesPseudoAction ( name , help ) <EOL> self . _choices_actions . append ( choice_action ) <EOL> parser = self . _parser_class ( ** kwargs ) <EOL> self . _name_parser_map [ name ] = parser <EOL> return parser <EOL> def _get_subactions ( self ) : <EOL> return self . _choices_actions <EOL> def __call__ ( self , parser , namespace , values , option_string = None ) : <EOL> parser_name = values [ <NUM_LIT:0> ] <EOL> arg_strings = values [ <NUM_LIT:1> : ] <EOL> if self . dest is not SUPPRESS : <EOL> setattr ( namespace , self . dest , parser_name ) <EOL> try : <EOL> parser = self . _name_parser_map [ parser_name ] <EOL> except KeyError : <EOL> tup = parser_name , '<STR_LIT:U+002CU+0020>' . join ( self . _name_parser_map ) <EOL> msg = _ ( '<STR_LIT>' % tup ) <EOL> raise ArgumentError ( self , msg ) <EOL> namespace , arg_strings = parser . parse_known_args ( arg_strings , namespace ) <EOL> if arg_strings : <EOL> vars ( namespace ) . setdefault ( _UNRECOGNIZED_ARGS_ATTR , [ ] ) <EOL> getattr ( namespace , _UNRECOGNIZED_ARGS_ATTR ) . extend ( arg_strings ) <EOL> class FileType ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , mode = '<STR_LIT:r>' , bufsize = None ) : <EOL> self . _mode = mode <EOL> self . _bufsize = bufsize <EOL> def __call__ ( self , string ) : <EOL> if string == '<STR_LIT:->' : <EOL> if '<STR_LIT:r>' in self . _mode : <EOL> return _sys . stdin <EOL> elif '<STR_LIT:w>' in self . _mode : <EOL> return _sys . stdout <EOL> else : <EOL> msg = _ ( '<STR_LIT>' % self . _mode ) <EOL> raise ValueError ( msg ) <EOL> if self . _bufsize : <EOL> return open ( string , self . _mode , self . _bufsize ) <EOL> else : <EOL> return open ( string , self . _mode ) <EOL> def __repr__ ( self ) : <EOL> args = [ self . _mode , self . _bufsize ] <EOL> args_str = '<STR_LIT:U+002CU+0020>' . join ( [ repr ( arg ) for arg in args if arg is not None ] ) <EOL> return '<STR_LIT>' % ( type ( self ) . __name__ , args_str ) <EOL> class Namespace ( _AttributeHolder ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , ** kwargs ) : <EOL> for name in kwargs : <EOL> setattr ( self , name , kwargs [ name ] ) <EOL> __hash__ = None <EOL> def __eq__ ( self , other ) : <EOL> return vars ( self ) == vars ( other ) <EOL> def __ne__ ( self , other ) : <EOL> return not ( self == other ) <EOL> def __contains__ ( self , key ) : <EOL> return key in self . __dict__ <EOL> class _ActionsContainer ( object ) : <EOL> def __init__ ( self , <EOL> description , <EOL> prefix_chars , <EOL> argument_default , <EOL> conflict_handler ) : <EOL> super ( _ActionsContainer , self ) . __init__ ( ) <EOL> self . description = description <EOL> self . argument_default = argument_default <EOL> self . prefix_chars = prefix_chars <EOL> self . conflict_handler = conflict_handler <EOL> self . _registries = { } <EOL> self . register ( '<STR_LIT:action>' , None , _StoreAction ) <EOL> self . register ( '<STR_LIT:action>' , '<STR_LIT:store>' , _StoreAction ) <EOL> self . register ( '<STR_LIT:action>' , '<STR_LIT>' , _StoreConstAction ) <EOL> self . register ( '<STR_LIT:action>' , '<STR_LIT:store_true>' , _StoreTrueAction ) <EOL> self . register ( '<STR_LIT:action>' , '<STR_LIT>' , _StoreFalseAction ) <EOL> self . register ( '<STR_LIT:action>' , '<STR_LIT>' , _AppendAction ) <EOL> self . register ( '<STR_LIT:action>' , '<STR_LIT>' , _AppendConstAction ) <EOL> self . register ( '<STR_LIT:action>' , '<STR_LIT:count>' , _CountAction ) <EOL> self . register ( '<STR_LIT:action>' , '<STR_LIT>' , _HelpAction ) <EOL> self . register ( '<STR_LIT:action>' , '<STR_LIT:version>' , _VersionAction ) <EOL> self . register ( '<STR_LIT:action>' , '<STR_LIT>' , _SubParsersAction ) <EOL> self . _get_handler ( ) <EOL> self . _actions = [ ] <EOL> self . _option_string_actions = { } <EOL> self . _action_groups = [ ] <EOL> self . _mutually_exclusive_groups = [ ] <EOL> self . _defaults = { } <EOL> self . _negative_number_matcher = _re . compile ( r'<STR_LIT>' ) <EOL> self . _has_negative_number_optionals = [ ] <EOL> def register ( self , registry_name , value , object ) : <EOL> registry = self . _registries . setdefault ( registry_name , { } ) <EOL> registry [ value ] = object <EOL> def _registry_get ( self , registry_name , value , default = None ) : <EOL> return self . _registries [ registry_name ] . get ( value , default ) <EOL> def set_defaults ( self , ** kwargs ) : <EOL> self . _defaults . update ( kwargs ) <EOL> for action in self . _actions : <EOL> if action . dest in kwargs : <EOL> action . default = kwargs [ action . dest ] <EOL> def get_default ( self , dest ) : <EOL> for action in self . _actions : <EOL> if action . dest == dest and action . default is not None : <EOL> return action . default <EOL> return self . _defaults . get ( dest , None ) <EOL> def add_argument ( self , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> chars = self . prefix_chars <EOL> if not args or len ( args ) == <NUM_LIT:1> and args [ <NUM_LIT:0> ] [ <NUM_LIT:0> ] not in chars : <EOL> if args and '<STR_LIT>' in kwargs : <EOL> raise ValueError ( '<STR_LIT>' ) <EOL> kwargs = self . _get_positional_kwargs ( * args , ** kwargs ) <EOL> else : <EOL> kwargs = self . _get_optional_kwargs ( * args , ** kwargs ) <EOL> if '<STR_LIT:default>' not in kwargs : <EOL> dest = kwargs [ '<STR_LIT>' ] <EOL> if dest in self . _defaults : <EOL> kwargs [ '<STR_LIT:default>' ] = self . _defaults [ dest ] <EOL> elif self . argument_default is not None : <EOL> kwargs [ '<STR_LIT:default>' ] = self . argument_default <EOL> action_class = self . _pop_action_class ( kwargs ) <EOL> if not _callable ( action_class ) : <EOL> raise ValueError ( '<STR_LIT>' % action_class ) <EOL> action = action_class ( ** kwargs ) <EOL> type_func = self . _registry_get ( '<STR_LIT:type>' , action . type , action . type ) <EOL> if not _callable ( type_func ) : <EOL> raise ValueError ( '<STR_LIT>' % type_func ) <EOL> return self . _add_action ( action ) <EOL> def add_argument_group ( self , * args , ** kwargs ) : <EOL> group = _ArgumentGroup ( self , * args , ** kwargs ) <EOL> self . _action_groups . append ( group ) <EOL> return group <EOL> def add_mutually_exclusive_group ( self , ** kwargs ) : <EOL> group = _MutuallyExclusiveGroup ( self , ** kwargs ) <EOL> self . _mutually_exclusive_groups . append ( group ) <EOL> return group <EOL> def _add_action ( self , action ) : <EOL> self . _check_conflict ( action ) <EOL> self . _actions . append ( action ) <EOL> action . container = self <EOL> for option_string in action . option_strings : <EOL> self . _option_string_actions [ option_string ] = action <EOL> for option_string in action . option_strings : <EOL> if self . _negative_number_matcher . match ( option_string ) : <EOL> if not self . _has_negative_number_optionals : <EOL> self . _has_negative_number_optionals . append ( True ) <EOL> return action <EOL> def _remove_action ( self , action ) : <EOL> self . _actions . remove ( action ) <EOL> def _add_container_actions ( self , container ) : <EOL> title_group_map = { } <EOL> for group in self . _action_groups : <EOL> if group . title in title_group_map : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise ValueError ( msg % ( group . title ) ) <EOL> title_group_map [ group . title ] = group <EOL> group_map = { } <EOL> for group in container . _action_groups : <EOL> if group . title not in title_group_map : <EOL> title_group_map [ group . title ] = self . add_argument_group ( <EOL> title = group . title , <EOL> description = group . description , <EOL> conflict_handler = group . conflict_handler ) <EOL> for action in group . _group_actions : <EOL> group_map [ action ] = title_group_map [ group . title ] <EOL> for group in container . _mutually_exclusive_groups : <EOL> mutex_group = self . add_mutually_exclusive_group ( <EOL> required = group . required ) <EOL> for action in group . _group_actions : <EOL> group_map [ action ] = mutex_group <EOL> for action in container . _actions : <EOL> group_map . get ( action , self ) . _add_action ( action ) <EOL> def _get_positional_kwargs ( self , dest , ** kwargs ) : <EOL> if '<STR_LIT>' in kwargs : <EOL> msg = _ ( "<STR_LIT>" ) <EOL> raise TypeError ( msg ) <EOL> if kwargs . get ( '<STR_LIT>' ) not in [ OPTIONAL , ZERO_OR_MORE ] : <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> if kwargs . get ( '<STR_LIT>' ) == ZERO_OR_MORE and '<STR_LIT:default>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = True <EOL> return dict ( kwargs , dest = dest , option_strings = [ ] ) <EOL> def _get_optional_kwargs ( self , * args , ** kwargs ) : <EOL> option_strings = [ ] <EOL> long_option_strings = [ ] <EOL> for option_string in args : <EOL> if not option_string [ <NUM_LIT:0> ] in self . prefix_chars : <EOL> msg = _ ( '<STR_LIT>' <EOL> '<STR_LIT>' ) <EOL> tup = option_string , self . prefix_chars <EOL> raise ValueError ( msg % tup ) <EOL> option_strings . append ( option_string ) <EOL> if option_string [ <NUM_LIT:0> ] in self . prefix_chars : <EOL> if len ( option_string ) > <NUM_LIT:1> : <EOL> if option_string [ <NUM_LIT:1> ] in self . prefix_chars : <EOL> long_option_strings . append ( option_string ) <EOL> dest = kwargs . pop ( '<STR_LIT>' , None ) <EOL> if dest is None : <EOL> if long_option_strings : <EOL> dest_option_string = long_option_strings [ <NUM_LIT:0> ] <EOL> else : <EOL> dest_option_string = option_strings [ <NUM_LIT:0> ] <EOL> dest = dest_option_string . lstrip ( self . prefix_chars ) <EOL> if not dest : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise ValueError ( msg % option_string ) <EOL> dest = dest . replace ( '<STR_LIT:->' , '<STR_LIT:_>' ) <EOL> return dict ( kwargs , dest = dest , option_strings = option_strings ) <EOL> def _pop_action_class ( self , kwargs , default = None ) : <EOL> action = kwargs . pop ( '<STR_LIT:action>' , default ) <EOL> return self . _registry_get ( '<STR_LIT:action>' , action , action ) <EOL> def _get_handler ( self ) : <EOL> handler_func_name = '<STR_LIT>' % self . conflict_handler <EOL> try : <EOL> return getattr ( self , handler_func_name ) <EOL> except AttributeError : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise ValueError ( msg % self . conflict_handler ) <EOL> def _check_conflict ( self , action ) : <EOL> confl_optionals = [ ] <EOL> for option_string in action . option_strings : <EOL> if option_string in self . _option_string_actions : <EOL> confl_optional = self . _option_string_actions [ option_string ] <EOL> confl_optionals . append ( ( option_string , confl_optional ) ) <EOL> if confl_optionals : <EOL> conflict_handler = self . _get_handler ( ) <EOL> conflict_handler ( action , confl_optionals ) <EOL> def _handle_conflict_error ( self , action , conflicting_actions ) : <EOL> message = _ ( '<STR_LIT>' ) <EOL> conflict_string = '<STR_LIT:U+002CU+0020>' . join ( [ option_string <EOL> for option_string , action <EOL> in conflicting_actions ] ) <EOL> raise ArgumentError ( action , message % conflict_string ) <EOL> def _handle_conflict_resolve ( self , action , conflicting_actions ) : <EOL> for option_string , action in conflicting_actions : <EOL> action . option_strings . remove ( option_string ) <EOL> self . _option_string_actions . pop ( option_string , None ) <EOL> if not action . option_strings : <EOL> action . container . _remove_action ( action ) <EOL> class _ArgumentGroup ( _ActionsContainer ) : <EOL> def __init__ ( self , container , title = None , description = None , ** kwargs ) : <EOL> update = kwargs . setdefault <EOL> update ( '<STR_LIT>' , container . conflict_handler ) <EOL> update ( '<STR_LIT>' , container . prefix_chars ) <EOL> update ( '<STR_LIT>' , container . argument_default ) <EOL> super_init = super ( _ArgumentGroup , self ) . __init__ <EOL> super_init ( description = description , ** kwargs ) <EOL> self . title = title <EOL> self . _group_actions = [ ] <EOL> self . _registries = container . _registries <EOL> self . _actions = container . _actions <EOL> self . _option_string_actions = container . _option_string_actions <EOL> self . _defaults = container . _defaults <EOL> self . _has_negative_number_optionals = container . _has_negative_number_optionals <EOL> def _add_action ( self , action ) : <EOL> action = super ( _ArgumentGroup , self ) . _add_action ( action ) <EOL> self . _group_actions . append ( action ) <EOL> return action <EOL> def _remove_action ( self , action ) : <EOL> super ( _ArgumentGroup , self ) . _remove_action ( action ) <EOL> self . _group_actions . remove ( action ) <EOL> class _MutuallyExclusiveGroup ( _ArgumentGroup ) : <EOL> def __init__ ( self , container , required = False ) : <EOL> super ( _MutuallyExclusiveGroup , self ) . __init__ ( container ) <EOL> self . required = required <EOL> self . _container = container <EOL> def _add_action ( self , action ) : <EOL> if action . required : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise ValueError ( msg ) <EOL> action = self . _container . _add_action ( action ) <EOL> self . _group_actions . append ( action ) <EOL> return action <EOL> def _remove_action ( self , action ) : <EOL> self . _container . _remove_action ( action ) <EOL> self . _group_actions . remove ( action ) <EOL> class ArgumentParser ( _AttributeHolder , _ActionsContainer ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , <EOL> prog = None , <EOL> usage = None , <EOL> description = None , <EOL> epilog = None , <EOL> version = None , <EOL> parents = [ ] , <EOL> formatter_class = HelpFormatter , <EOL> prefix_chars = '<STR_LIT:->' , <EOL> fromfile_prefix_chars = None , <EOL> argument_default = None , <EOL> conflict_handler = '<STR_LIT:error>' , <EOL> add_help = True ) : <EOL> if version is not None : <EOL> import warnings <EOL> warnings . warn ( <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" <EOL> """<STR_LIT>""" , DeprecationWarning ) <EOL> superinit = super ( ArgumentParser , self ) . __init__ <EOL> superinit ( description = description , <EOL> prefix_chars = prefix_chars , <EOL> argument_default = argument_default , <EOL> conflict_handler = conflict_handler ) <EOL> if prog is None : <EOL> prog = _os . path . basename ( _sys . argv [ <NUM_LIT:0> ] ) <EOL> self . prog = prog <EOL> self . usage = usage <EOL> self . epilog = epilog <EOL> self . version = version <EOL> self . formatter_class = formatter_class <EOL> self . fromfile_prefix_chars = fromfile_prefix_chars <EOL> self . add_help = add_help <EOL> add_group = self . add_argument_group <EOL> self . _positionals = add_group ( _ ( '<STR_LIT>' ) ) <EOL> self . _optionals = add_group ( _ ( '<STR_LIT>' ) ) <EOL> self . _subparsers = None <EOL> def identity ( string ) : <EOL> return string <EOL> self . register ( '<STR_LIT:type>' , None , identity ) <EOL> if '<STR_LIT:->' in prefix_chars : <EOL> default_prefix = '<STR_LIT:->' <EOL> else : <EOL> default_prefix = prefix_chars [ <NUM_LIT:0> ] <EOL> if self . add_help : <EOL> self . add_argument ( <EOL> default_prefix + '<STR_LIT:h>' , default_prefix * <NUM_LIT:2> + '<STR_LIT>' , <EOL> action = '<STR_LIT>' , default = SUPPRESS , <EOL> help = _ ( '<STR_LIT>' ) ) <EOL> if self . version : <EOL> self . add_argument ( <EOL> default_prefix + '<STR_LIT:v>' , default_prefix * <NUM_LIT:2> + '<STR_LIT:version>' , <EOL> action = '<STR_LIT:version>' , default = SUPPRESS , <EOL> version = self . version , <EOL> help = _ ( "<STR_LIT>" ) ) <EOL> for parent in parents : <EOL> self . _add_container_actions ( parent ) <EOL> try : <EOL> defaults = parent . _defaults <EOL> except AttributeError : <EOL> pass <EOL> else : <EOL> self . _defaults . update ( defaults ) <EOL> def _get_kwargs ( self ) : <EOL> names = [ <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT:description>' , <EOL> '<STR_LIT:version>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> '<STR_LIT>' , <EOL> ] <EOL> return [ ( name , getattr ( self , name ) ) for name in names ] <EOL> def add_subparsers ( self , ** kwargs ) : <EOL> if self . _subparsers is not None : <EOL> self . error ( _ ( '<STR_LIT>' ) ) <EOL> kwargs . setdefault ( '<STR_LIT>' , type ( self ) ) <EOL> if '<STR_LIT:title>' in kwargs or '<STR_LIT:description>' in kwargs : <EOL> title = _ ( kwargs . pop ( '<STR_LIT:title>' , '<STR_LIT>' ) ) <EOL> description = _ ( kwargs . pop ( '<STR_LIT:description>' , None ) ) <EOL> self . _subparsers = self . add_argument_group ( title , description ) <EOL> else : <EOL> self . _subparsers = self . _positionals <EOL> if kwargs . get ( '<STR_LIT>' ) is None : <EOL> formatter = self . _get_formatter ( ) <EOL> positionals = self . _get_positional_actions ( ) <EOL> groups = self . _mutually_exclusive_groups <EOL> formatter . add_usage ( self . usage , positionals , groups , '<STR_LIT>' ) <EOL> kwargs [ '<STR_LIT>' ] = formatter . format_help ( ) . strip ( ) <EOL> parsers_class = self . _pop_action_class ( kwargs , '<STR_LIT>' ) <EOL> action = parsers_class ( option_strings = [ ] , ** kwargs ) <EOL> self . _subparsers . _add_action ( action ) <EOL> return action <EOL> def _add_action ( self , action ) : <EOL> if action . option_strings : <EOL> self . _optionals . _add_action ( action ) <EOL> else : <EOL> self . _positionals . _add_action ( action ) <EOL> return action <EOL> def _get_optional_actions ( self ) : <EOL> return [ action <EOL> for action in self . _actions <EOL> if action . option_strings ] <EOL> def _get_positional_actions ( self ) : <EOL> return [ action <EOL> for action in self . _actions <EOL> if not action . option_strings ] <EOL> def parse_args ( self , args = None , namespace = None ) : <EOL> args , argv = self . parse_known_args ( args , namespace ) <EOL> if argv : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> self . error ( msg % '<STR_LIT:U+0020>' . join ( argv ) ) <EOL> return args <EOL> def parse_known_args ( self , args = None , namespace = None ) : <EOL> if args is None : <EOL> args = _sys . argv [ <NUM_LIT:1> : ] <EOL> if namespace is None : <EOL> namespace = Namespace ( ) <EOL> for action in self . _actions : <EOL> if action . dest is not SUPPRESS : <EOL> if not hasattr ( namespace , action . dest ) : <EOL> if action . default is not SUPPRESS : <EOL> default = action . default <EOL> if isinstance ( action . default , basestring ) : <EOL> default = self . _get_value ( action , default ) <EOL> setattr ( namespace , action . dest , default ) <EOL> for dest in self . _defaults : <EOL> if not hasattr ( namespace , dest ) : <EOL> setattr ( namespace , dest , self . _defaults [ dest ] ) <EOL> try : <EOL> namespace , args = self . _parse_known_args ( args , namespace ) <EOL> if hasattr ( namespace , _UNRECOGNIZED_ARGS_ATTR ) : <EOL> args . extend ( getattr ( namespace , _UNRECOGNIZED_ARGS_ATTR ) ) <EOL> delattr ( namespace , _UNRECOGNIZED_ARGS_ATTR ) <EOL> return namespace , args <EOL> except ArgumentError : <EOL> err = _sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . error ( str ( err ) ) <EOL> def _parse_known_args ( self , arg_strings , namespace ) : <EOL> if self . fromfile_prefix_chars is not None : <EOL> arg_strings = self . _read_args_from_files ( arg_strings ) <EOL> action_conflicts = { } <EOL> for mutex_group in self . _mutually_exclusive_groups : <EOL> group_actions = mutex_group . _group_actions <EOL> for i , mutex_action in enumerate ( mutex_group . _group_actions ) : <EOL> conflicts = action_conflicts . setdefault ( mutex_action , [ ] ) <EOL> conflicts . extend ( group_actions [ : i ] ) <EOL> conflicts . extend ( group_actions [ i + <NUM_LIT:1> : ] ) <EOL> option_string_indices = { } <EOL> arg_string_pattern_parts = [ ] <EOL> arg_strings_iter = iter ( arg_strings ) <EOL> for i , arg_string in enumerate ( arg_strings_iter ) : <EOL> if arg_string == '<STR_LIT>' : <EOL> arg_string_pattern_parts . append ( '<STR_LIT:->' ) <EOL> for arg_string in arg_strings_iter : <EOL> arg_string_pattern_parts . append ( '<STR_LIT:A>' ) <EOL> else : <EOL> option_tuple = self . _parse_optional ( arg_string ) <EOL> if option_tuple is None : <EOL> pattern = '<STR_LIT:A>' <EOL> else : <EOL> option_string_indices [ i ] = option_tuple <EOL> pattern = '<STR_LIT:O>' <EOL> arg_string_pattern_parts . append ( pattern ) <EOL> arg_strings_pattern = '<STR_LIT>' . join ( arg_string_pattern_parts ) <EOL> seen_actions = set ( ) <EOL> seen_non_default_actions = set ( ) <EOL> def take_action ( action , argument_strings , option_string = None ) : <EOL> seen_actions . add ( action ) <EOL> argument_values = self . _get_values ( action , argument_strings ) <EOL> if argument_values is not action . default : <EOL> seen_non_default_actions . add ( action ) <EOL> for conflict_action in action_conflicts . get ( action , [ ] ) : <EOL> if conflict_action in seen_non_default_actions : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> action_name = _get_action_name ( conflict_action ) <EOL> raise ArgumentError ( action , msg % action_name ) <EOL> if argument_values is not SUPPRESS : <EOL> action ( self , namespace , argument_values , option_string ) <EOL> def consume_optional ( start_index ) : <EOL> option_tuple = option_string_indices [ start_index ] <EOL> action , option_string , explicit_arg = option_tuple <EOL> match_argument = self . _match_argument <EOL> action_tuples = [ ] <EOL> while True : <EOL> if action is None : <EOL> extras . append ( arg_strings [ start_index ] ) <EOL> return start_index + <NUM_LIT:1> <EOL> if explicit_arg is not None : <EOL> arg_count = match_argument ( action , '<STR_LIT:A>' ) <EOL> chars = self . prefix_chars <EOL> if arg_count == <NUM_LIT:0> and option_string [ <NUM_LIT:1> ] not in chars : <EOL> action_tuples . append ( ( action , [ ] , option_string ) ) <EOL> char = option_string [ <NUM_LIT:0> ] <EOL> option_string = char + explicit_arg [ <NUM_LIT:0> ] <EOL> new_explicit_arg = explicit_arg [ <NUM_LIT:1> : ] or None <EOL> optionals_map = self . _option_string_actions <EOL> if option_string in optionals_map : <EOL> action = optionals_map [ option_string ] <EOL> explicit_arg = new_explicit_arg <EOL> else : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise ArgumentError ( action , msg % explicit_arg ) <EOL> elif arg_count == <NUM_LIT:1> : <EOL> stop = start_index + <NUM_LIT:1> <EOL> args = [ explicit_arg ] <EOL> action_tuples . append ( ( action , args , option_string ) ) <EOL> break <EOL> else : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise ArgumentError ( action , msg % explicit_arg ) <EOL> else : <EOL> start = start_index + <NUM_LIT:1> <EOL> selected_patterns = arg_strings_pattern [ start : ] <EOL> arg_count = match_argument ( action , selected_patterns ) <EOL> stop = start + arg_count <EOL> args = arg_strings [ start : stop ] <EOL> action_tuples . append ( ( action , args , option_string ) ) <EOL> break <EOL> assert action_tuples <EOL> for action , args , option_string in action_tuples : <EOL> take_action ( action , args , option_string ) <EOL> return stop <EOL> positionals = self . _get_positional_actions ( ) <EOL> def consume_positionals ( start_index ) : <EOL> match_partial = self . _match_arguments_partial <EOL> selected_pattern = arg_strings_pattern [ start_index : ] <EOL> arg_counts = match_partial ( positionals , selected_pattern ) <EOL> for action , arg_count in zip ( positionals , arg_counts ) : <EOL> args = arg_strings [ start_index : start_index + arg_count ] <EOL> start_index += arg_count <EOL> take_action ( action , args ) <EOL> positionals [ : ] = positionals [ len ( arg_counts ) : ] <EOL> return start_index <EOL> extras = [ ] <EOL> start_index = <NUM_LIT:0> <EOL> if option_string_indices : <EOL> max_option_string_index = max ( option_string_indices ) <EOL> else : <EOL> max_option_string_index = - <NUM_LIT:1> <EOL> while start_index <= max_option_string_index : <EOL> next_option_string_index = min ( [ <EOL> index <EOL> for index in option_string_indices <EOL> if index >= start_index ] ) <EOL> if start_index != next_option_string_index : <EOL> positionals_end_index = consume_positionals ( start_index ) <EOL> if positionals_end_index > start_index : <EOL> start_index = positionals_end_index <EOL> continue <EOL> else : <EOL> start_index = positionals_end_index <EOL> if start_index not in option_string_indices : <EOL> strings = arg_strings [ start_index : next_option_string_index ] <EOL> extras . extend ( strings ) <EOL> start_index = next_option_string_index <EOL> start_index = consume_optional ( start_index ) <EOL> stop_index = consume_positionals ( start_index ) <EOL> extras . extend ( arg_strings [ stop_index : ] ) <EOL> if positionals : <EOL> self . error ( _ ( '<STR_LIT>' ) ) <EOL> for action in self . _actions : <EOL> if action . required : <EOL> if action not in seen_actions : <EOL> name = _get_action_name ( action ) <EOL> self . error ( _ ( '<STR_LIT>' ) % name ) <EOL> for group in self . _mutually_exclusive_groups : <EOL> if group . required : <EOL> for action in group . _group_actions : <EOL> if action in seen_non_default_actions : <EOL> break <EOL> else : <EOL> names = [ _get_action_name ( action ) <EOL> for action in group . _group_actions <EOL> if action . help is not SUPPRESS ] <EOL> msg = _ ( '<STR_LIT>' ) <EOL> self . error ( msg % '<STR_LIT:U+0020>' . join ( names ) ) <EOL> return namespace , extras <EOL> def _read_args_from_files ( self , arg_strings ) : <EOL> new_arg_strings = [ ] <EOL> for arg_string in arg_strings : <EOL> if arg_string [ <NUM_LIT:0> ] not in self . fromfile_prefix_chars : <EOL> new_arg_strings . append ( arg_string ) <EOL> else : <EOL> try : <EOL> args_file = open ( arg_string [ <NUM_LIT:1> : ] ) <EOL> try : <EOL> arg_strings = [ ] <EOL> for arg_line in args_file . read ( ) . splitlines ( ) : <EOL> for arg in self . convert_arg_line_to_args ( arg_line ) : <EOL> arg_strings . append ( arg ) <EOL> arg_strings = self . _read_args_from_files ( arg_strings ) <EOL> new_arg_strings . extend ( arg_strings ) <EOL> finally : <EOL> args_file . close ( ) <EOL> except IOError : <EOL> err = _sys . exc_info ( ) [ <NUM_LIT:1> ] <EOL> self . error ( str ( err ) ) <EOL> return new_arg_strings <EOL> def convert_arg_line_to_args ( self , arg_line ) : <EOL> return [ arg_line ] <EOL> def _match_argument ( self , action , arg_strings_pattern ) : <EOL> nargs_pattern = self . _get_nargs_pattern ( action ) <EOL> match = _re . match ( nargs_pattern , arg_strings_pattern ) <EOL> if match is None : <EOL> nargs_errors = { <EOL> None : _ ( '<STR_LIT>' ) , <EOL> OPTIONAL : _ ( '<STR_LIT>' ) , <EOL> ONE_OR_MORE : _ ( '<STR_LIT>' ) , <EOL> } <EOL> default = _ ( '<STR_LIT>' ) % action . nargs <EOL> msg = nargs_errors . get ( action . nargs , default ) <EOL> raise ArgumentError ( action , msg ) <EOL> return len ( match . group ( <NUM_LIT:1> ) ) <EOL> def _match_arguments_partial ( self , actions , arg_strings_pattern ) : <EOL> result = [ ] <EOL> for i in range ( len ( actions ) , <NUM_LIT:0> , - <NUM_LIT:1> ) : <EOL> actions_slice = actions [ : i ] <EOL> pattern = '<STR_LIT>' . join ( [ self . _get_nargs_pattern ( action ) <EOL> for action in actions_slice ] ) <EOL> match = _re . match ( pattern , arg_strings_pattern ) <EOL> if match is not None : <EOL> result . extend ( [ len ( string ) for string in match . groups ( ) ] ) <EOL> break <EOL> return result <EOL> def _parse_optional ( self , arg_string ) : <EOL> if not arg_string : <EOL> return None <EOL> if not arg_string [ <NUM_LIT:0> ] in self . prefix_chars : <EOL> return None <EOL> if arg_string in self . _option_string_actions : <EOL> action = self . _option_string_actions [ arg_string ] <EOL> return action , arg_string , None <EOL> if len ( arg_string ) == <NUM_LIT:1> : <EOL> return None <EOL> if '<STR_LIT:=>' in arg_string : <EOL> option_string , explicit_arg = arg_string . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) <EOL> if option_string in self . _option_string_actions : <EOL> action = self . _option_string_actions [ option_string ] <EOL> return action , option_string , explicit_arg <EOL> option_tuples = self . _get_option_tuples ( arg_string ) <EOL> if len ( option_tuples ) > <NUM_LIT:1> : <EOL> options = '<STR_LIT:U+002CU+0020>' . join ( [ option_string <EOL> for action , option_string , explicit_arg in option_tuples ] ) <EOL> tup = arg_string , options <EOL> self . error ( _ ( '<STR_LIT>' ) % tup ) <EOL> elif len ( option_tuples ) == <NUM_LIT:1> : <EOL> option_tuple , = option_tuples <EOL> return option_tuple <EOL> if self . _negative_number_matcher . match ( arg_string ) : <EOL> if not self . _has_negative_number_optionals : <EOL> return None <EOL> if '<STR_LIT:U+0020>' in arg_string : <EOL> return None <EOL> return None , arg_string , None <EOL> def _get_option_tuples ( self , option_string ) : <EOL> result = [ ] <EOL> chars = self . prefix_chars <EOL> if option_string [ <NUM_LIT:0> ] in chars and option_string [ <NUM_LIT:1> ] in chars : <EOL> if '<STR_LIT:=>' in option_string : <EOL> option_prefix , explicit_arg = option_string . split ( '<STR_LIT:=>' , <NUM_LIT:1> ) <EOL> else : <EOL> option_prefix = option_string <EOL> explicit_arg = None <EOL> for option_string in self . _option_string_actions : <EOL> if option_string . startswith ( option_prefix ) : <EOL> action = self . _option_string_actions [ option_string ] <EOL> tup = action , option_string , explicit_arg <EOL> result . append ( tup ) <EOL> elif option_string [ <NUM_LIT:0> ] in chars and option_string [ <NUM_LIT:1> ] not in chars : <EOL> option_prefix = option_string <EOL> explicit_arg = None <EOL> short_option_prefix = option_string [ : <NUM_LIT:2> ] <EOL> short_explicit_arg = option_string [ <NUM_LIT:2> : ] <EOL> for option_string in self . _option_string_actions : <EOL> if option_string == short_option_prefix : <EOL> action = self . _option_string_actions [ option_string ] <EOL> tup = action , option_string , short_explicit_arg <EOL> result . append ( tup ) <EOL> elif option_string . startswith ( option_prefix ) : <EOL> action = self . _option_string_actions [ option_string ] <EOL> tup = action , option_string , explicit_arg <EOL> result . append ( tup ) <EOL> else : <EOL> self . error ( _ ( '<STR_LIT>' ) % option_string ) <EOL> return result <EOL> def _get_nargs_pattern ( self , action ) : <EOL> nargs = action . nargs <EOL> if nargs is None : <EOL> nargs_pattern = '<STR_LIT>' <EOL> elif nargs == OPTIONAL : <EOL> nargs_pattern = '<STR_LIT>' <EOL> elif nargs == ZERO_OR_MORE : <EOL> nargs_pattern = '<STR_LIT>' <EOL> elif nargs == ONE_OR_MORE : <EOL> nargs_pattern = '<STR_LIT>' <EOL> elif nargs == REMAINDER : <EOL> nargs_pattern = '<STR_LIT>' <EOL> elif nargs == PARSER : <EOL> nargs_pattern = '<STR_LIT>' <EOL> else : <EOL> nargs_pattern = '<STR_LIT>' % '<STR_LIT>' . join ( '<STR_LIT:A>' * nargs ) <EOL> if action . option_strings : <EOL> nargs_pattern = nargs_pattern . replace ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> nargs_pattern = nargs_pattern . replace ( '<STR_LIT:->' , '<STR_LIT>' ) <EOL> return nargs_pattern <EOL> def _get_values ( self , action , arg_strings ) : <EOL> if action . nargs not in [ PARSER , REMAINDER ] : <EOL> arg_strings = [ s for s in arg_strings if s != '<STR_LIT>' ] <EOL> if not arg_strings and action . nargs == OPTIONAL : <EOL> if action . option_strings : <EOL> value = action . const <EOL> else : <EOL> value = action . default <EOL> if isinstance ( value , basestring ) : <EOL> value = self . _get_value ( action , value ) <EOL> self . _check_value ( action , value ) <EOL> elif ( not arg_strings and action . nargs == ZERO_OR_MORE and <EOL> not action . option_strings ) : <EOL> if action . default is not None : <EOL> value = action . default <EOL> else : <EOL> value = arg_strings <EOL> self . _check_value ( action , value ) <EOL> elif len ( arg_strings ) == <NUM_LIT:1> and action . nargs in [ None , OPTIONAL ] : <EOL> arg_string , = arg_strings <EOL> value = self . _get_value ( action , arg_string ) <EOL> self . _check_value ( action , value ) <EOL> elif action . nargs == REMAINDER : <EOL> value = [ self . _get_value ( action , v ) for v in arg_strings ] <EOL> elif action . nargs == PARSER : <EOL> value = [ self . _get_value ( action , v ) for v in arg_strings ] <EOL> self . _check_value ( action , value [ <NUM_LIT:0> ] ) <EOL> else : <EOL> value = [ self . _get_value ( action , v ) for v in arg_strings ] <EOL> for v in value : <EOL> self . _check_value ( action , v ) <EOL> return value <EOL> def _get_value ( self , action , arg_string ) : <EOL> type_func = self . _registry_get ( '<STR_LIT:type>' , action . type , action . type ) <EOL> if not _callable ( type_func ) : <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise ArgumentError ( action , msg % type_func ) <EOL> try : <EOL> result = type_func ( arg_string ) <EOL> except ArgumentTypeError : <EOL> name = getattr ( action . type , '<STR_LIT>' , repr ( action . type ) ) <EOL> msg = str ( _sys . exc_info ( ) [ <NUM_LIT:1> ] ) <EOL> raise ArgumentError ( action , msg ) <EOL> except ( TypeError , ValueError ) : <EOL> name = getattr ( action . type , '<STR_LIT>' , repr ( action . type ) ) <EOL> msg = _ ( '<STR_LIT>' ) <EOL> raise ArgumentError ( action , msg % ( name , arg_string ) ) <EOL> return result <EOL> def _check_value ( self , action , value ) : <EOL> if action . choices is not None and value not in action . choices : <EOL> tup = value , '<STR_LIT:U+002CU+0020>' . join ( map ( repr , action . choices ) ) <EOL> msg = _ ( '<STR_LIT>' ) % tup <EOL> raise ArgumentError ( action , msg ) <EOL> def format_usage ( self ) : <EOL> formatter = self . _get_formatter ( ) <EOL> formatter . add_usage ( self . usage , self . _actions , <EOL> self . _mutually_exclusive_groups ) <EOL> return formatter . format_help ( ) <EOL> def format_help ( self ) : <EOL> formatter = self . _get_formatter ( ) <EOL> formatter . add_usage ( self . usage , self . _actions , <EOL> self . _mutually_exclusive_groups ) <EOL> formatter . add_text ( self . description ) <EOL> for action_group in self . _action_groups : <EOL> formatter . start_section ( action_group . title ) <EOL> formatter . add_text ( action_group . description ) <EOL> formatter . add_arguments ( action_group . _group_actions ) <EOL> formatter . end_section ( ) <EOL> formatter . add_text ( self . epilog ) <EOL> return formatter . format_help ( ) <EOL> def format_version ( self ) : <EOL> import warnings <EOL> warnings . warn ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> formatter = self . _get_formatter ( ) <EOL> formatter . add_text ( self . version ) <EOL> return formatter . format_help ( ) <EOL> def _get_formatter ( self ) : <EOL> return self . formatter_class ( prog = self . prog ) <EOL> def print_usage ( self , file = None ) : <EOL> if file is None : <EOL> file = _sys . stdout <EOL> self . _print_message ( self . format_usage ( ) , file ) <EOL> def print_help ( self , file = None ) : <EOL> if file is None : <EOL> file = _sys . stdout <EOL> self . _print_message ( self . format_help ( ) , file ) <EOL> def print_version ( self , file = None ) : <EOL> import warnings <EOL> warnings . warn ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' , <EOL> DeprecationWarning ) <EOL> self . _print_message ( self . format_version ( ) , file ) <EOL> def _print_message ( self , message , file = None ) : <EOL> if message : <EOL> if file is None : <EOL> file = _sys . stderr <EOL> file . write ( message ) <EOL> def exit ( self , status = <NUM_LIT:0> , message = None ) : <EOL> if message : <EOL> self . _print_message ( message , _sys . stderr ) <EOL> _sys . exit ( status ) <EOL> def error ( self , message ) : <EOL> """<STR_LIT>""" <EOL> self . print_usage ( _sys . stderr ) <EOL> self . exit ( <NUM_LIT:2> , _ ( '<STR_LIT>' ) % ( self . prog , message ) ) </s>
