
y XV                @   so  d  Z  d Z d d d d d d d d	 d
 d d d d d d d g Z d d l Z d d l Z d d l Z d d l	 Z
 d d l Z d d l m Z y e Wn" e k
 r d d l m Z Yn Xy e Wn e k
 r e Z Yn Xy e Wn! e k
 r	d d d  Z Yn Xd d   Z d Z d Z d Z d Z d Z d  Z d! Z Gd" d#   d# e  Z d$ d%   Z  Gd& d   d e  Z! Gd' d   d e!  Z" Gd( d	   d	 e"  Z# Gd) d   d e!  Z$ d* d+   Z% Gd, d   d e&  Z' Gd- d   d e&  Z( Gd. d   d e  Z) Gd/ d0   d0 e)  Z* Gd1 d2   d2 e)  Z+ Gd3 d4   d4 e+  Z, Gd5 d6   d6 e+  Z- Gd7 d8   d8 e)  Z. Gd9 d:   d: e)  Z/ Gd; d<   d< e)  Z0 Gd= d>   d> e)  Z1 Gd? d@   d@ e)  Z2 GdA dB   dB e)  Z3 GdC d   d e  Z4 GdD d
   d
 e  Z5 GdE dF   dF e  Z6 GdG dH   dH e6  Z7 GdI dJ   dJ e7  Z8 GdK d   d e e6  Z9 d S)La
  Command-line parsing library

This module is an optparse-inspired command-line parsing library that:

    - handles both optional and positional arguments
    - produces highly informative usage messages
    - supports parsers that dispatch to sub-parsers

The following is a simple usage example that sums integers from the
command-line and writes the result to a file::

    parser = argparse.ArgumentParser(
        description='sum the integers at the command line')
    parser.add_argument(
        'integers', metavar='int', nargs='+', type=int,
        help='an integer to be summed')
    parser.add_argument(
        '--log', default=sys.stdout, type=argparse.FileType('w'),
        help='the file where the sum should be written')
    args = parser.parse_args()
    args.log.write('%s' % sum(args.integers))
    args.log.close()

The module contains the following public classes:

    - ArgumentParser -- The main entry point for command-line parsing. As the
        example above shows, the add_argument() method is used to populate
        the parser with actions for optional and positional arguments. Then
        the parse_args() method is invoked to convert the args at the
        command-line into an object with attributes.

    - ArgumentError -- The exception raised by ArgumentParser objects when
        there are errors with the parser's actions. Errors raised while
        parsing the command-line are caught by ArgumentParser and emitted
        as command-line messages.

    - FileType -- A factory for defining types of files to be created. As the
        example above shows, instances of FileType are typically passed as
        the type= argument of add_argument() calls.

    - Action -- The base class for parser actions. Typically actions are
        selected by passing strings like 'store_true' or 'append_const' to
        the action= argument of add_argument(). However, for greater
        customization of ArgumentParser actions, subclasses of Action may
        be defined and passed as the action= argument.

    - HelpFormatter, RawDescriptionHelpFormatter, RawTextHelpFormatter,
        ArgumentDefaultsHelpFormatter -- Formatter classes which
        may be passed as the formatter_class= argument to the
        ArgumentParser constructor. HelpFormatter is the default,
        RawDescriptionHelpFormatter and RawTextHelpFormatter tell the parser
        not to change the formatting for help text, and
        ArgumentDefaultsHelpFormatter adds information about argument defaults
        to the help.

All other classes in this module are considered implementation details.
(Also note that HelpFormatter and RawDescriptionHelpFormatter are only
considered public as object names -- the API of the formatter objects is
still considered an implementation detail.)
z1.2.1ArgumentParserArgumentErrorArgumentTypeErrorFileTypeHelpFormatterArgumentDefaultsHelpFormatterRawDescriptionHelpFormatterRawTextHelpFormatter	NamespaceActionONE_OR_MOREOPTIONALPARSER	REMAINDERSUPPRESSZERO_OR_MORE    N)gettext)SetFc             C   s-   t  |   } | j   | r) | j   n  | S)N)listsortreverse)iterabler   result r   H/home/ubuntu/projects/ifolica/build/gunicorn/gunicorn/argparse_compat.pysortedl   s
    
r   c             C   s   t  |  d  p t  |  d  S)N__call__	__bases__)hasattr)objr   r   r   	_callablet   s    r    z==SUPPRESS==?*+zA...z...Z_unrecognized_argsc               @   s:   e  Z d  Z d Z d d   Z d d   Z d d   Z d S)	_AttributeHoldera  Abstract base class that provides __repr__.

    The __repr__ method returns a string in the format::
        ClassName(attr=name, attr=name, ...)
    The attributes are determined either by a class-level attribute,
    '_kwarg_names', or by inspecting the instance __dict__.
    c             C   s   t  |   j } g  } x' |  j   D] } | j t |   q" Wx1 |  j   D]# \ } } | j d | | f  qL Wd | d j |  f S)Nz%s=%rz%s(%s)z, )type__name__	_get_argsappendrepr_get_kwargsjoin)selfZ	type_namearg_stringsargnamevaluer   r   r   __repr__   s    z_AttributeHolder.__repr__c             C   s   t  |  j j    S)N)r   __dict__items)r,   r   r   r   r*      s    z_AttributeHolder._get_kwargsc             C   s   g  S)Nr   )r,   r   r   r   r'      s    z_AttributeHolder._get_argsN)r&   
__module____qualname____doc__r1   r*   r'   r   r   r   r   r$      s   	r$   c             C   s8   t  |  | d   d  k r+ t |  | |  n  t  |  |  S)N)getattrsetattr)	namespacer/   r0   r   r   r   _ensure_value   s    r:   c               @   sX  e  Z d  Z d Z d d d d d  Z d d   Z d	 d
   Z Gd d   d e  Z d d   Z	 d d   Z
 d d   Z d d   Z d d d  Z d d   Z d d   Z d d   Z d d   Z d d    Z d! d"   Z d# d$   Z d% d&   Z d' d(   Z d) d*   Z d+ d,   Z d- d.   Z d/ d0   Z d1 d2   Z d3 d4   Z d5 d6   Z d S)7r   zFormatter for generating usage messages and argument help strings.

    Only the name of this class is considered a public API. All the methods
    provided by the class are considered an implementation detail.
          Nc             C   s   | d  k rQ y t  t j d  } Wn t t f k
 rC d } Yn X| d 8} n  | |  _ | |  _ | |  _ | |  _ d |  _	 d |  _
 d |  _ |  j |  d   |  _ |  j |  _ t j d  |  _ t j d  |  _ d  S)NCOLUMNSP   r;   r   z\s+z\n\n\n+)int_osenvironKeyError
ValueError_prog_indent_increment_max_help_position_width_current_indent_level_action_max_length_Section_root_section_current_section_recompile_whitespace_matcher_long_break_matcher)r,   progindent_incrementmax_help_positionwidthr   r   r   __init__   s"    							zHelpFormatter.__init__c             C   s%   |  j  |  j 7_  |  j d 7_ d  S)N   )rH   rE   rI   )r,   r   r   r   _indent   s    zHelpFormatter._indentc             C   s@   |  j  |  j 8_  |  j  d k s- t d   |  j d 8_ d  S)Nr   zIndent decreased below 0.rW   )rH   rE   AssertionErrorrI   )r,   r   r   r   _dedent   s    zHelpFormatter._dedentc               @   s+   e  Z d  Z d d d  Z d d   Z d S)zHelpFormatter._SectionNc             C   s(   | |  _  | |  _ | |  _ g  |  _ d  S)N)	formatterparentheadingr3   )r,   r[   r\   r]   r   r   r   rV      s    			zHelpFormatter._Section.__init__c             C   s   |  j  d  k	 r |  j j   n  |  j j } x! |  j D] \ } } | |   q5 W| d d   |  j D  } |  j  d  k	 r |  j j   n  | s d S|  j t k	 r |  j d  k	 r |  j j } d | d |  j f } n d } | d | | d g  S)Nc             S   s"   g  |  ] \ } } | |    q Sr   r   ).0funcargsr   r   r   
<listcomp>   s   	 z6HelpFormatter._Section.format_help.<locals>.<listcomp> z%*s%s:

)	r\   r[   rX   _join_partsr3   rZ   r]   r   rH   )r,   r+   r_   r`   Z	item_helpcurrent_indentr]   r   r   r   format_help   s    z"HelpFormatter._Section.format_help)r&   r4   r5   rV   rf   r   r   r   r   rK      s   rK   c             C   s   |  j  j j | | f  d  S)N)rM   r3   r(   )r,   r_   r`   r   r   r   	_add_item   s    zHelpFormatter._add_itemc             C   sB   |  j    |  j |  |  j |  } |  j | j g   | |  _ d  S)N)rX   rK   rM   rg   rf   )r,   r]   sectionr   r   r   start_section   s    
zHelpFormatter.start_sectionc             C   s   |  j  j |  _  |  j   d  S)N)rM   r\   rZ   )r,   r   r   r   end_section  s    zHelpFormatter.end_sectionc             C   s5   | t  k	 r1 | d  k	 r1 |  j |  j | g  n  d  S)N)r   rg   _format_text)r,   textr   r   r   add_text	  s    zHelpFormatter.add_textc             C   s8   | t  k	 r4 | | | | f } |  j |  j |  n  d  S)N)r   rg   _format_usage)r,   usageactionsgroupsprefixr`   r   r   r   	add_usage  s    zHelpFormatter.add_usagec             C   s   | j  t k	 r |  j } | |  g } x* |  j |  D] } | j | |   q7 Wt d d   | D  } | |  j } t |  j |  |  _ |  j |  j	 | g  n  d  S)Nc             S   s   g  |  ] } t  |   q Sr   )len)r^   sr   r   r   ra     s   	 z.HelpFormatter.add_argument.<locals>.<listcomp>)
helpr   _format_action_invocation_iter_indented_subactionsr(   maxrH   rJ   rg   _format_action)r,   actionZget_invocationZinvocations	subactionZinvocation_lengthZaction_lengthr   r   r   add_argument  s    		zHelpFormatter.add_argumentc             C   s"   x | D] } |  j  |  q Wd  S)N)r}   )r,   rp   r{   r   r   r   add_arguments$  s    zHelpFormatter.add_argumentsc             C   sD   |  j  j   } | r@ |  j j d |  } | j d  d } n  | S)Nz

rc   )rL   rf   rQ   substrip)r,   rv   r   r   r   rf   +  s
    zHelpFormatter.format_helpc             C   s   d j  d d   | D  S)Nrb   c             S   s(   g  |  ] } | r | t  k	 r |  q Sr   )r   )r^   partr   r   r   ra   3  s   	z-HelpFormatter._join_parts.<locals>.<listcomp>)r+   )r,   Zpart_stringsr   r   r   rd   2  s    zHelpFormatter._join_partsc                s  | d  k r t  d  } n  | d  k	 r@ | t d |  j  } n| d  k rl | rl d t d |  j  } n| d  k rd t d |  j  } g  } g  } x4 | D], } | j r | j |  q | j |  q W|  j }	 |	 | | |  }
 d j d d   | |
 g D  } |  j |  j   t	 |  t	 |    k rd } |	 | |  } |	 | |  } t
 j | |  } t
 j | |  } d j |  | k st  d j |  | k st  d    f d d	  } t	 |  t	 |  d
   k rrd t	 |  t	 |  d } | rD| | g | | |  } | j | | |   q| rf| | g | | |  } q| g } n} d t	 |  } | | } | | |  } t	 |  d k rg  } | j | | |   | j | | |   n  | g | } d j |  } qn  d | | f S)Nzusage: rR   z%(prog)s c             S   s   g  |  ] } | r |  q Sr   r   )r^   ru   r   r   r   ra   S  s   	 z/HelpFormatter._format_usage.<locals>.<listcomp>z\(.*?\)+|\[.*?\]+|\S+c                s  g  } g  } | d  k	 r+ t  |  d } n t  |  d } x| |  D]t } | d t  |    k r | j | d j |   g  } t  |  d } n  | j |  | t  |  d 7} qB W| r | j | d j |   n  | d  k	 r
| d t  |  d   | d <n  | S)NrW   r   r   )rt   r(   r+   )partsindentrr   lineslineZline_lenr   )
text_widthr   r   	get_linesc  s"    !z.HelpFormatter._format_usage.<locals>.get_linesg      ?rW   rc   z%s%s

)_dictrD   option_stringsr(   _format_actions_usager+   rG   rH   rt   rN   findallrY   extend)r,   ro   rp   rq   rr   rR   Z	optionalspositionalsr{   formatZaction_usageZpart_regexpZ	opt_usageZ	pos_usageZ	opt_partsZ	pos_partsr   r   r   r   r   )r   r   rn   7  sZ    		" 
zHelpFormatter._format_usagec             C   s  t    } i  } x&| D]} y | j | j d  } Wn t k
 rM w Yq X| t | j  } | | |  | j k r x | j D] } | j |  q W| j s | | k r | | d 7<n
 d | | <d | | <n1 | | k r | | d 7<n
 d | | <d | | <x( t | d |  D] }	 d	 | |	 <qWq q Wg  }
 xt |  D]w\ }	 } | j	 t
 k r|
 j d   | j |	  d	 k r| j |	  q| j |	 d  d	 k r| j |	 d  qqK| j s8|  j | | j  } | | k r(| d d k r(| d d k r(| d d  } q(n  |
 j |  qK| j d } | j d k rad
 | } n1 | j j   } |  j | |  } d | | f } | j r| | k rd | } n  |
 j |  qKWx1 t | d d D] }	 | |	 g |
 |	 |	  <qWd j d d   |
 D  } d } d } t j d | d |  } t j d | d |  } t j d | | f d |  } t j d d |  } | j   } | S)Nr   z [[]z (()rW   |z%sz%s %sz[%s]r   Tr   c             S   s"   g  |  ] } | d  k	 r |  q S)Nr   )r^   itemr   r   r   ra     s   	 z7HelpFormatter._format_actions_usage.<locals>.<listcomp>z[\[(]z[\])]z(%s) z\1z (%s)z%s *%srb   z\(([^|]*)\)r   )setindex_group_actionsrC   rt   addrequiredrange	enumeraterv   r   r(   getpopr   _format_argsdestnargsupperr   r+   rN   r   r   )r,   rp   rq   group_actionsZinsertsgroupstartendr{   ir   r   option_stringdefaultargs_stringrl   opencloser   r   r   r     sp    		


	 z#HelpFormatter._format_actions_usagec             C   sY   d | k r% | t  d |  j  } n  |  j |  j } d |  j } |  j | | |  d S)Nz%(prog)rR   r   z

)r   rD   rG   rH   
_fill_text)r,   rl   r   r   r   r   r   rk     s
    zHelpFormatter._format_textc             C   s  t  |  j d |  j  } |  j | } | |  j d } |  j |  } | j sn |  j d | f } d | } n\ t |  | k r |  j d | | f } d | } d } n" |  j d | f } d | } | } | g } | j rS|  j |  }	 |  j	 |	 |  }
 | j
 d | d |
 d f  xT |
 d d   D]  } | j
 d | d | f  q,Wn | j d  sr| j
 d  n  x- |  j |  D] } | j
 |  j |   qW|  j |  S)Nr;   rb   z%*s%s
z	%*s%-*s  r   rW   rc   )minrJ   rF   rG   rH   rw   rv   rt   _expand_help_split_linesr(   endswithrx   rz   rd   )r,   r{   help_position
help_widthZaction_widthZaction_headertupindent_firstr   	help_text
help_linesr   r|   r   r   r   rz     s6    	
	
		!zHelpFormatter._format_actionc             C   s   | j  s+ |  j | | j  d  \ } | Sg  } | j d k rS | j | j   nL | j j   } |  j | |  } x( | j  D] } | j d | | f  q~ Wd j |  Sd  S)NrW   r   z%s %sz, )	r   _metavar_formatterr   r   r   r   r   r(   r+   )r,   r{   metavarr   r   r   r   r   r   r   rw   )  s    	z'HelpFormatter._format_action_invocationc                sr   | j  d  k	 r | j    nA | j d  k	 rV d d   | j D } d d j |    n |     f d d   } | S)Nc             S   s   g  |  ] } t  |   q Sr   )str)r^   choicer   r   r   ra   D  s   	 z4HelpFormatter._metavar_formatter.<locals>.<listcomp>z{%s},c                s"   t    t  r   S  f |  Sd  S)N)
isinstancetuple)Z
tuple_size)r   r   r   r   I  s    z0HelpFormatter._metavar_formatter.<locals>.format)r   choicesr+   )r,   r{   default_metavarZchoice_strsr   r   )r   r   r   @  s    z HelpFormatter._metavar_formatterc             C   s  |  j  | |  } | j d  k r4 d | d  } n | j t k rV d | d  } n | j t k rx d | d  } n | j t k r d | d  } nr | j t k r d } nZ | j t k r d | d  } n8 d	 d
   t | j  D } d j |  | | j  } | S)Nz%srW   z[%s]z[%s [%s ...]]r;   z%s [%s ...]z...z%s ...c             S   s   g  |  ] } d   q S)z%sr   )r^   r   r   r   r   ra   _  s   	 z.HelpFormatter._format_args.<locals>.<listcomp>r   )	r   r   r   r   r   r   r   r   r+   )r,   r{   r   Zget_metavarr   formatsr   r   r   r   P  s     	zHelpFormatter._format_argsc             C   s   t  t |  d |  j } x. t |  D]  } | | t k r( | | =q( q( Wx; t |  D]- } t | | d  rY | | j | | <qY qY W| j d  d  k	 r d j d d   | d D  } | | d <n  |  j	 |  | S)NrR   r&   r   z, c             S   s   g  |  ] } t  |   q Sr   )r   )r^   cr   r   r   ra   l  s   	 z.HelpFormatter._expand_help.<locals>.<listcomp>)
r   varsrD   r   r   r   r&   r   r+   _get_help_string)r,   r{   paramsr/   Zchoices_strr   r   r   r   c  s     zHelpFormatter._expand_helpc             c   sS   y | j  } Wn t k
 r! Yn. X|  j   x |   D] } | Vq6 W|  j   d  S)N)_get_subactionsAttributeErrorrX   rZ   )r,   r{   Zget_subactionsr|   r   r   r   rx   p  s    
	z'HelpFormatter._iter_indented_subactionsc             C   s+   |  j  j d |  j   } t j | |  S)Nr   )rP   r   r   	_textwrapwrap)r,   rl   rU   r   r   r   r   {  s    zHelpFormatter._split_linesc             C   s7   |  j  j d |  j   } t j | | d | d | S)Nr   initial_indentsubsequent_indent)rP   r   r   r   fill)r,   rl   rU   r   r   r   r   r     s    zHelpFormatter._fill_textc             C   s   | j  S)N)rv   )r,   r{   r   r   r   r     s    zHelpFormatter._get_help_string)r&   r4   r5   r6   rV   rX   rZ   objectrK   rg   ri   rj   rm   rs   r}   r~   rf   rd   rn   r   rk   rz   rw   r   r   r   rx   r   r   r   r   r   r   r   r      s8   !\`/c               @   s"   e  Z d  Z d Z d d   Z d S)r   zHelp message formatter which retains any formatting in descriptions.

    Only the name of this class is considered a public API. All the methods
    provided by the class are considered an implementation detail.
    c                s)   d j    f d d   | j d  D  S)Nrb   c                s   g  |  ] }   |  q Sr   r   )r^   r   )r   r   r   ra     s   	 z:RawDescriptionHelpFormatter._fill_text.<locals>.<listcomp>T)r+   
splitlines)r,   rl   rU   r   r   )r   r   r     s    z&RawDescriptionHelpFormatter._fill_textN)r&   r4   r5   r6   r   r   r   r   r   r     s   c               @   s"   e  Z d  Z d Z d d   Z d S)r   zHelp message formatter which retains formatting of all help text.

    Only the name of this class is considered a public API. All the methods
    provided by the class are considered an implementation detail.
    c             C   s
   | j    S)N)r   )r,   rl   rU   r   r   r   r     s    z!RawTextHelpFormatter._split_linesN)r&   r4   r5   r6   r   r   r   r   r   r     s   c               @   s"   e  Z d  Z d Z d d   Z d S)r   zHelp message formatter which adds default values to argument help.

    Only the name of this class is considered a public API. All the methods
    provided by the class are considered an implementation detail.
    c             C   sb   | j  } d | j  k r^ | j t k	 r^ t t g } | j sK | j | k r[ | d 7} q[ q^ n  | S)Nz
%(default)z (default: %(default)s))rv   r   r   r   r   r   r   )r,   r{   rv   Zdefaulting_nargsr   r   r   r     s    	z.ArgumentDefaultsHelpFormatter._get_help_stringN)r&   r4   r5   r6   r   r   r   r   r   r     s   c             C   si   |  d  k r d  S|  j  r) d j |  j   S|  j d  t f k rE |  j S|  j d  t f k ra |  j Sd  Sd  S)N/)r   r+   r   r   r   )argumentr   r   r   _get_action_name  s    	r   c               @   s.   e  Z d  Z d Z d d   Z d d   Z d S)r   zAn error from creating or using an argument (optional or positional).

    The string value of this exception is the message, augmented with
    information about the argument that caused it.
    c             C   s   t  |  |  _ | |  _ d  S)N)r   argument_namemessage)r,   r   r   r   r   r   rV     s    zArgumentError.__init__c             C   s;   |  j  d  k r d } n d } | t d |  j d |  j   S)Nz%(message)sz'argument %(argument_name)s: %(message)sr   r   )r   r   r   )r,   r   r   r   r   __str__  s
    	zArgumentError.__str__N)r&   r4   r5   r6   rV   r   r   r   r   r   r     s   c               @   s   e  Z d  Z d Z d S)r   z@An error from trying to convert a command line string to a type.N)r&   r4   r5   r6   r   r   r   r   r     s   c            
   @   sU   e  Z d  Z d Z d d d d d d d d d d  Z d d   Z d d d	  Z d S)
r
   ad	  Information about how to convert command line strings to Python objects.

    Action objects are used by an ArgumentParser to represent the information
    needed to parse a single argument from one or more strings from the
    command line. The keyword arguments to the Action constructor are also
    all attributes of Action instances.

    Keyword Arguments:

        - option_strings -- A list of command-line option strings which
            should be associated with this action.

        - dest -- The name of the attribute to hold the created object(s)

        - nargs -- The number of command-line arguments that should be
            consumed. By default, one argument will be consumed and a single
            value will be produced.  Other values include:
                - N (an integer) consumes N arguments (and produces a list)
                - '?' consumes zero or one arguments
                - '*' consumes zero or more arguments (and produces a list)
                - '+' consumes one or more arguments (and produces a list)
            Note that the difference between the default and nargs=1 is that
            with the default, a single value will be produced, while with
            nargs=1, a list containing a single value will be produced.

        - const -- The value to be produced if the option is specified and the
            option uses an action that takes no values.

        - default -- The value to be produced if the option is not specified.

        - type -- The type which the command-line arguments should be converted
            to, should be one of 'string', 'int', 'float', 'complex' or a
            callable object that accepts a single string argument. If None,
            'string' is assumed.

        - choices -- A container of values that should be allowed. If not None,
            after a command-line argument has been converted to the appropriate
            type, an exception will be raised if it is not a member of this
            collection.

        - required -- True if the action must always be specified at the
            command line. This is only meaningful for optional command-line
            arguments.

        - help -- The help string describing the argument.

        - metavar -- The name to be used for the option's argument with the
            help string. If None, the 'dest' value will be used as the name.
    NFc             C   s^   | |  _  | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ |
 |  _	 d  S)N)
r   r   r   constr   r%   r   r   rv   r   )r,   r   r   r   r   r   r%   r   r   rv   r   r   r   r   rV     s    									zAction.__init__c          	      s8   d d d d d d d d d	 g	 }   f d
 d   | D S)Nr   r   r   r   r   r%   r   rv   r   c                s%   g  |  ] } | t    |  f  q Sr   )r7   )r^   r/   )r,   r   r   ra   2  s   	 z&Action._get_kwargs.<locals>.<listcomp>r   )r,   namesr   )r,   r   r*   &  s    	zAction._get_kwargsc             C   s   t  t d    d  S)Nz.__call__() not defined)NotImplementedErrorr   )r,   parserr9   valuesr   r   r   r   r   4  s    zAction.__call__)r&   r4   r5   r6   rV   r*   r   r   r   r   r   r
     s   1c                   sI   e  Z d  Z d d d d d d d d   f d d  Z d d d  Z   S)_StoreActionNFc                s   | d k r t  d   n  | d  k	 rF | t k rF t  d t   n  t t |   j d | d | d | d | d | d	 | d
 | d | d |	 d |
  
d  S)Nr   znargs for store actions must be > 0; if you have nothing to store, actions such as store true or store const may be more appropriatez nargs must be %r to supply constr   r   r   r   r   r%   r   r   rv   r   )rC   r   superr   rV   )r,   r   r   r   r   r   r%   r   r   rv   r   )	__class__r   r   rV   :  s    z_StoreAction.__init__c             C   s   t  | |  j |  d  S)N)r8   r   )r,   r   r9   r   r   r   r   r   r   W  s    z_StoreAction.__call__)r&   r4   r5   rV   r   r   r   )r   r   r   8  s   r   c                   s=   e  Z d  Z d d d d   f d d  Z d d d  Z   S)_StoreConstActionNFc                sA   t  t |   j d | d | d d d | d | d | d |  d  S)	Nr   r   r   r   r   r   r   rv   )r   r   rV   )r,   r   r   r   r   r   rv   r   )r   r   r   rV   ]  s    z_StoreConstAction.__init__c             C   s   t  | |  j |  j  d  S)N)r8   r   r   )r,   r   r9   r   r   r   r   r   r   n  s    z_StoreConstAction.__call__)r&   r4   r5   rV   r   r   r   )r   r   r   [  s
   
r   c                   s+   e  Z d  Z d d d   f d d  Z   S)_StoreTrueActionFNc                s;   t  t |   j d | d | d d d | d | d |  d  S)Nr   r   r   Tr   r   rv   )r   r   rV   )r,   r   r   r   r   rv   )r   r   r   rV   t  s    z_StoreTrueAction.__init__)r&   r4   r5   rV   r   r   )r   r   r   r  s   r   c                   s+   e  Z d  Z d d d   f d d  Z   S)_StoreFalseActionTFNc                s;   t  t |   j d | d | d d d | d | d |  d  S)Nr   r   r   Fr   r   rv   )r   r   rV   )r,   r   r   r   r   rv   )r   r   r   rV     s    z_StoreFalseAction.__init__)r&   r4   r5   rV   r   r   )r   r   r     s   r   c                   sI   e  Z d  Z d d d d d d d d   f d d  Z d d d  Z   S)_AppendActionNFc                s   | d k r t  d   n  | d  k	 rF | t k rF t  d t   n  t t |   j d | d | d | d | d | d	 | d
 | d | d |	 d |
  
d  S)Nr   znargs for append actions must be > 0; if arg strings are not supplying the value to append, the append const action may be more appropriatez nargs must be %r to supply constr   r   r   r   r   r%   r   r   rv   r   )rC   r   r   r   rV   )r,   r   r   r   r   r   r%   r   r   rv   r   )r   r   r   rV     s    z_AppendAction.__init__c             C   sB   t  j t | |  j g    } | j |  t | |  j |  d  S)N)_copycopyr:   r   r(   r8   )r,   r   r9   r   r   r3   r   r   r   r     s    z_AppendAction.__call__)r&   r4   r5   rV   r   r   r   )r   r   r     s   r   c                   s=   e  Z d  Z d d d d   f d d  Z d d d  Z   S)_AppendConstActionNFc                sG   t  t |   j d | d | d d d | d | d | d | d	 |  d  S)
Nr   r   r   r   r   r   r   rv   r   )r   r   rV   )r,   r   r   r   r   r   rv   r   )r   r   r   rV     s    z_AppendConstAction.__init__c             C   sE   t  j t | |  j g    } | j |  j  t | |  j |  d  S)N)r   r   r:   r   r(   r   r8   )r,   r   r9   r   r   r3   r   r   r   r     s    z_AppendConstAction.__call__)r&   r4   r5   rV   r   r   r   )r   r   r     s
   r   c                   s:   e  Z d  Z d d d   f d d  Z d d d  Z   S)_CountActionNFc                s;   t  t |   j d | d | d d d | d | d |  d  S)Nr   r   r   r   r   r   rv   )r   r   rV   )r,   r   r   r   r   rv   )r   r   r   rV     s    z_CountAction.__init__c             C   s0   t  | |  j d  d } t | |  j |  d  S)Nr   rW   )r:   r   r8   )r,   r   r9   r   r   Z	new_countr   r   r   r     s    z_CountAction.__call__)r&   r4   r5   rV   r   r   r   )r   r   r     s   	r   c                   s:   e  Z d  Z e e d   f d d  Z d d d  Z   S)_HelpActionNc                s5   t  t |   j d | d | d | d d d |  d  S)Nr   r   r   r   r   rv   )r   r   rV   )r,   r   r   r   rv   )r   r   r   rV     s    z_HelpAction.__init__c             C   s   | j    | j   d  S)N)
print_helpexit)r,   r   r9   r   r   r   r   r   r     s    
z_HelpAction.__call__)r&   r4   r5   r   rV   r   r   r   )r   r   r     s   r   c                   s=   e  Z d  Z d e e d   f d d  Z d d d  Z   S)_VersionActionNz&show program's version number and exitc                s>   t  t |   j d | d | d | d d d |  | |  _ d  S)Nr   r   r   r   r   rv   )r   r   rV   version)r,   r   r   r   r   rv   )r   r   r   rV     s    z_VersionAction.__init__c             C   sT   |  j  } | d  k r! | j  } n  | j   } | j |  | j d | j    d  S)Nr   )r   _get_formatterrm   r   rf   )r,   r   r9   r   r   r   r[   r   r   r   r     s    	z_VersionAction.__call__)r&   r4   r5   r   rV   r   r   r   )r   r   r     s
   	r   c                   sh   e  Z d  Z Gd d   d e  Z e d d   f d d  Z d d   Z d d	   Z d d
 d  Z	   S)_SubParsersActionc                   s"   e  Z d  Z   f d d   Z   S)z&_SubParsersAction._ChoicesPseudoActionc                s2   t  t j |   } | j d g  d | d |  d  S)Nr   r   rv   )r   r   _ChoicesPseudoActionrV   )r,   r/   rv   sup)r   r   r   rV     s    z/_SubParsersAction._ChoicesPseudoAction.__init__)r&   r4   r5   rV   r   r   )r   r   r     s   r   Nc                sb   | |  _  | |  _ i  |  _ g  |  _ t t |   j d | d | d t d |  j d | d |  d  S)Nr   r   r   r   rv   r   )_prog_prefix_parser_class_name_parser_map_choices_actionsr   r   rV   r   )r,   r   rR   parser_classr   rv   r   )r   r   r   rV     s    					z_SubParsersAction.__init__c             K   s   | j  d  d  k r/ d |  j | f | d <n  d | k ro | j d  } |  j | |  } |  j j |  n  |  j |   } | |  j | <| S)NrR   z%s %srv   )r   r   r   r   r   r(   r   r   )r,   r/   kwargsrv   Zchoice_actionr   r   r   r   
add_parser1  s    z_SubParsersAction.add_parserc             C   s   |  j  S)N)r   )r,   r   r   r   r   A  s    z!_SubParsersAction._get_subactionsc       	      C   s   | d } | d d   } |  j  t k	 r? t | |  j  |  n  y |  j | } WnI t k
 r | d j |  j  f } t d |  } t |  |   Yn X| j | |  \ } } | r t	 |  j
 t g   t | t  j |  n  d  S)Nr   rW   z, zunknown parser %r (choices: %s))r   r   r8   r   rB   r+   r   r   parse_known_argsr   
setdefault_UNRECOGNIZED_ARGS_ATTRr7   r   )	r,   r   r9   r   r   parser_namer-   r   msgr   r   r   r   D  s    
z_SubParsersAction.__call__)
r&   r4   r5   r
   r   r   rV   r   r   r   r   r   )r   r   r     s   
r   c               @   s@   e  Z d  Z d Z d d d d  Z d d   Z d d	   Z d S)
r   a  Factory for creating file object types

    Instances of FileType are typically passed as type= arguments to the
    ArgumentParser add_argument() method.

    Keyword Arguments:
        - mode -- A string indicating how the file is to be opened. Accepts the
            same values as the builtin open() function.
        - bufsize -- The file's desired buffer size. Accepts the same values as
            the builtin open() function.
    rNc             C   s   | |  _  | |  _ d  S)N)_mode_bufsize)r,   modebufsizer   r   r   rV   n  s    	zFileType.__init__c             C   s   | d k rZ d |  j  k r" t j Sd |  j  k r8 t j St d |  j   } t |   n  |  j ry t | |  j  |  j  St | |  j   Sd  S)N-r   wzargument "-" with mode %r)r   _sysstdinstdoutr   rC   r   r   )r,   stringr   r   r   r   r   r  s    	zFileType.__call__c             C   sE   |  j  |  j g } d j d d   | D  } d t |   j | f S)Nz, c             S   s(   g  |  ] } | d  k	 r t  |   q S)N)r)   )r^   r.   r   r   r   ra     s   	 z%FileType.__repr__.<locals>.<listcomp>z%s(%s))r   r   r+   r%   r&   )r,   r`   Zargs_strr   r   r   r1     s    zFileType.__repr__)r&   r4   r5   r6   rV   r   r1   r   r   r   r   r   a  s   c               @   sL   e  Z d  Z d Z d d   Z d Z d d   Z d d   Z d	 d
   Z d S)r	   zSimple object for storing attributes.

    Implements equality by attribute names and values, and provides a simple
    string representation.
    c             K   s)   x" | D] } t  |  | | |  q Wd  S)N)r8   )r,   r   r/   r   r   r   rV     s    zNamespace.__init__Nc             C   s   t  |   t  |  k S)N)r   )r,   otherr   r   r   __eq__  s    zNamespace.__eq__c             C   s   |  | k S)Nr   )r,   r  r   r   r   __ne__  s    zNamespace.__ne__c             C   s   | |  j  k S)N)r2   )r,   keyr   r   r   __contains__  s    zNamespace.__contains__)	r&   r4   r5   r6   rV   __hash__r  r	  r  r   r   r   r   r	     s   c                   s   e  Z d  Z   f d d   Z d d   Z d d d  Z d d	   Z d
 d   Z d d   Z d d   Z	 d d   Z
 d d   Z d d   Z d d   Z d d   Z d d   Z d d d  Z d d   Z d  d!   Z d" d#   Z d$ d%   Z   S)&_ActionsContainerc                sg  t  t |   j   | |  _ | |  _ | |  _ | |  _ i  |  _ |  j d d  t	  |  j d d t	  |  j d d t
  |  j d d t  |  j d d t  |  j d d t  |  j d d t  |  j d d t  |  j d d	 t  |  j d d
 t  |  j d d t  |  j   g  |  _ i  |  _ g  |  _ g  |  _ i  |  _ t j d  |  _ g  |  _ d  S)Nr{   storestore_const
store_truestore_falser(   append_constcountrv   r   parsersz^-\d+$|^-\d*\.\d+$)r   r  rV   descriptionargument_defaultprefix_charsconflict_handler_registriesregisterr   r   r   r   r   r   r   r   r   r   _get_handler_actions_option_string_actions_action_groups_mutually_exclusive_groups	_defaultsrN   rO   _negative_number_matcher_has_negative_number_optionals)r,   r  r  r  r  )r   r   r   rV     s2    					
					z_ActionsContainer.__init__c             C   s#   |  j  j | i   } | | | <d  S)N)r  r   )r,   registry_namer0   r   registryr   r   r   r    s    z_ActionsContainer.registerNc             C   s   |  j  | j | |  S)N)r  r   )r,   r#  r0   r   r   r   r   _registry_get  s    z_ActionsContainer._registry_getc             K   sJ   |  j  j |  x3 |  j D]( } | j | k r | | j | _ q q Wd  S)N)r   updater  r   r   )r,   r   r{   r   r   r   set_defaults  s    z_ActionsContainer.set_defaultsc             C   sL   x6 |  j  D]+ } | j | k r
 | j d  k	 r
 | j Sq
 W|  j j | d   S)N)r  r   r   r   r   )r,   r   r{   r   r   r   get_default  s    z_ActionsContainer.get_defaultc             O   sZ  |  j  } | s6 t |  d k rl | d d | k rl | rW d | k rW t d   n  |  j | |   } n |  j | |   } d | k r | d } | |  j k r |  j | | d <q |  j d k	 r |  j | d <q n  |  j |  } t |  st d |   n  | |   } |  j	 d | j
 | j
  } t |  sMt d	 |   n  |  j |  S)
z
        add_argument(dest, ..., name=value, ...)
        add_argument(option_string, option_string, ..., name=value, ...)
        rW   r   r   z+dest supplied twice for positional argumentr   Nzunknown action "%s"r%   z%r is not callable)r  rt   rC   _get_positional_kwargs_get_optional_kwargsr   r  _pop_action_classr    r%  r%   _add_action)r,   r`   r   charsr   Zaction_classr{   	type_funcr   r   r   r}     s(    		-
z_ActionsContainer.add_argumentc             O   s&   t  |  | |  } |  j j |  | S)N)_ArgumentGroupr  r(   )r,   r`   r   r   r   r   r   add_argument_group  s    z$_ActionsContainer.add_argument_groupc             K   s#   t  |  |  } |  j j |  | S)N)_MutuallyExclusiveGroupr  r(   )r,   r   r   r   r   r   add_mutually_exclusive_group#  s    z._ActionsContainer.add_mutually_exclusive_groupc             C   s   |  j  |  |  j j |  |  | _ x | j D] } | |  j | <q0 WxB | j D]7 } |  j j |  rQ |  j s |  j j d  q qQ qQ W| S)NT)	_check_conflictr  r(   	containerr   r  r!  matchr"  )r,   r{   r   r   r   r   r,  (  s    		z_ActionsContainer._add_actionc             C   s   |  j  j |  d  S)N)r  remove)r,   r{   r   r   r   _remove_action=  s    z _ActionsContainer._remove_actionc             C   sO  i  } xO |  j  D]D } | j | k rG t d  } t | | j   n  | | | j <q Wi  } xv | j  D]k } | j | k r |  j d | j d | j d | j  | | j <n  x" | j D] } | | j | | <q Wqh WxD | j D]9 } |  j	 d | j
  } x | j D] } | | | <qWq Wx* | j D] } | j | |   j |  q(Wd  S)Nz.cannot merge actions - two groups are named %rtitler  r  r   )r  r8  r   rC   r0  r  r  r   r  r2  r   r  r   r,  )r,   r4  Ztitle_group_mapr   r   Z	group_mapr{   mutex_groupr   r   r   _add_container_actions@  s,    				z(_ActionsContainer._add_container_actionsc             K   s   d | k r' t  d  } t |   n  | j d  t t g k rO d | d <n  | j d  t k r} d | k r} d | d <n  t | d | d g  S)Nr   z1'required' is an invalid argument for positionalsr   Tr   r   r   )r   	TypeErrorr   r   r   r   )r,   r   r   r   r   r   r   r)  h  s    !z(_ActionsContainer._get_positional_kwargsc       
      O   sV  g  } g  } x | D] } | d |  j  k rZ t d  } | |  j  f } t | |   n  | j |  | d |  j  k r t |  d k r | d |  j  k r | j |  q q q q W| j d d   } | d  k r@| r | d }	 n
 | d }	 |	 j |  j   } | s+t d  } t | |   n  | j d d  } n  t | d | d | S)	Nr   z8invalid option string %r: must start with a character %rrW   r   z%dest= is required for options like %rr  r   r   )	r  r   rC   r(   rt   r   lstripreplacer   )
r,   r`   r   r   Zlong_option_stringsr   r   r   r   Zdest_option_stringr   r   r   r*  x  s.    
z&_ActionsContainer._get_optional_kwargsc             C   s%   | j  d |  } |  j d | |  S)Nr{   )r   r%  )r,   r   r   r{   r   r   r   r+    s    z#_ActionsContainer._pop_action_classc             C   sV   d |  j  } y t |  |  SWn1 t k
 rQ t d  } t | |  j    Yn Xd  S)Nz_handle_conflict_%sz%invalid conflict_resolution value: %r)r  r7   r   r   rC   )r,   Zhandler_func_namer   r   r   r   r    s    z_ActionsContainer._get_handlerc             C   sr   g  } xC | j  D]8 } | |  j k r |  j | } | j | | f  q q W| rn |  j   } | | |  n  d  S)N)r   r  r(   r  )r,   r{   Zconfl_optionalsr   Zconfl_optionalr  r   r   r   r3    s    z!_ActionsContainer._check_conflictc             C   s?   t  d  } d j d d   | D  } t | | |   d  S)Nz conflicting option string(s): %sz, c             S   s   g  |  ] \ } } |  q Sr   r   )r^   r   r{   r   r   r   ra     s   	z<_ActionsContainer._handle_conflict_error.<locals>.<listcomp>)r   r+   r   )r,   r{   conflicting_actionsr   Zconflict_stringr   r   r   _handle_conflict_error  s    z(_ActionsContainer._handle_conflict_errorc             C   sZ   xS | D]K \ } } | j  j |  |  j j | d   | j  s | j j |  q q Wd  S)N)r   r6  r  r   r4  r7  )r,   r{   r>  r   r   r   r   _handle_conflict_resolve  s
    	z*_ActionsContainer._handle_conflict_resolve)r&   r4   r5   rV   r  r%  r'  r(  r}   r0  r2  r,  r7  r:  r)  r*  r+  r  r3  r?  r@  r   r   )r   r   r    s$   4	
((#	r  c                   sL   e  Z d  Z d d   f d d  Z   f d d   Z   f d d   Z   S)r/  Nc                s   | j  } | d | j  | d | j  | d | j  t t |   j } | d | |  | |  _ g  |  _ | j	 |  _	 | j
 |  _
 | j |  _ | j |  _ | j |  _ d  S)Nr  r  r  r  )r   r  r  r  r   r/  rV   r8  r   r  r  r  r   r"  )r,   r4  r8  r  r   r&  Z
super_init)r   r   r   rV     s    			z_ArgumentGroup.__init__c                s,   t  t |   j |  } |  j j |  | S)N)r   r/  r,  r   r(   )r,   r{   )r   r   r   r,    s    z_ArgumentGroup._add_actionc                s*   t  t |   j |  |  j j |  d  S)N)r   r/  r7  r   r6  )r,   r{   )r   r   r   r7    s    z_ArgumentGroup._remove_action)r&   r4   r5   rV   r,  r7  r   r   )r   r   r/    s   r/  c                   s=   e  Z d  Z d   f d d  Z d d   Z d d   Z   S)r1  Fc                s,   t  t |   j |  | |  _ | |  _ d  S)N)r   r1  rV   r   
_container)r,   r4  r   )r   r   r   rV     s    	z _MutuallyExclusiveGroup.__init__c             C   sJ   | j  r$ t d  } t |   n  |  j j |  } |  j j |  | S)Nz-mutually exclusive arguments must be optional)r   r   rC   rA  r,  r   r(   )r,   r{   r   r   r   r   r,    s    	z#_MutuallyExclusiveGroup._add_actionc             C   s$   |  j  j |  |  j j |  d  S)N)rA  r7  r   r6  )r,   r{   r   r   r   r7    s    z&_MutuallyExclusiveGroup._remove_action)r&   r4   r5   rV   r,  r7  r   r   )r   r   r1    s   r1  c                   s  e  Z d  Z d Z d d d d d g  e d d d d d   f d d  Z d d	   Z d
 d   Z d d   Z d d   Z	 d d   Z
 d d d d  Z d d d d  Z d d   Z d d   Z d d   Z d d   Z d d   Z d  d!   Z d" d#   Z d$ d%   Z d& d'   Z d( d)   Z d* d+   Z d, d-   Z d. d/   Z d0 d1   Z d2 d3   Z d d4 d5  Z d d6 d7  Z d d8 d9  Z d d: d;  Z d< d d= d>  Z  d? d@   Z!   S)Ar   aa  Object for parsing command line strings into Python objects.

    Keyword Arguments:
        - prog -- The name of the program (default: sys.argv[0])
        - usage -- A usage message (default: auto-generated from arguments)
        - description -- A description of what the program does
        - epilog -- Text following the argument descriptions
        - parents -- Parsers whose arguments should be copied into this one
        - formatter_class -- HelpFormatter class for printing help messages
        - prefix_chars -- Characters that prefix optional arguments
        - fromfile_prefix_chars -- Characters that prefix files containing
            additional arguments
        - argument_default -- The default value for all arguments
        - conflict_handler -- String indicating how to handle conflicts
        - add_help -- Add a -h/-help option
    Nr  errorTc                s  | d  k	 r+ d d  l  } | j d t  n  t t |   j } | d | d | d |
 d |  | d  k r t j j t	 j
 d  } n  | |  _ | |  _ | |  _ | |  _ | |  _ |	 |  _ | |  _ |  j } | t d   |  _ | t d   |  _ d  |  _ d	 d
   } |  j d d  |  d | k r3d } n
 | d } |  j r}|  j | d | d d d d d t d t d  n  |  j r|  j | d | d d d d d t d |  j d t d  n  xM | D]E } |  j |  y | j } Wn t k
 rYqX|  j j |  qWd  S)Nr   zThe "version" argument to ArgumentParser is deprecated. Please use "add_argument(..., action='version', version="N", ...)" insteadr  r  r  r  zpositional argumentszoptional argumentsc             S   s   |  S)Nr   )r  r   r   r   identityA  s    z)ArgumentParser.__init__.<locals>.identityr%   r  hr;   rv   r{   r   zshow this help message and exitvr   z&show program's version number and exit)warningswarnDeprecationWarningr   r   rV   r@   pathbasenamer  argvrR   ro   epilogr   formatter_classfromfile_prefix_charsadd_helpr0  r   _positionals
_optionals_subparsersr  r}   r   r:  r   r   r&  )r,   rR   ro   r  rL  r   parentsrM  r  rN  r  r  rO  rF  Z	superinitZ	add_grouprC  Zdefault_prefixr\   defaults)r   r   r   rV     s\    
										
			zArgumentParser.__init__c                s2   d d d d d d d g }   f d d	   | D S)
NrR   ro   r  r   rM  r  rO  c                s%   g  |  ] } | t    |  f  q Sr   )r7   )r^   r/   )r,   r   r   ra   n  s   	 z.ArgumentParser._get_kwargs.<locals>.<listcomp>r   )r,   r   r   )r,   r   r*   d  s    	zArgumentParser._get_kwargsc       	      K   sG  |  j  d  k	 r% |  j t d   n  | j d t |    d | k sS d | k r t | j d d   } t | j d d    } |  j | |  |  _  n |  j |  _  | j d  d  k r|  j	   } |  j
   } |  j } | j |  j | | d  | j   j   | d <n  |  j | d  } | d	 g  |  } |  j  j |  | S)
Nz(cannot have multiple subparser argumentsr   r8  r  subcommandsrR   rb   r  r   )rR  rB  r   r   r%   r   r0  rP  r   r   _get_positional_actionsr  rs   ro   rf   r   r+  r,  )	r,   r   r8  r  r[   r   rq   Zparsers_classr{   r   r   r   add_subparserss  s$    	zArgumentParser.add_subparsersc             C   s0   | j  r |  j j |  n |  j j |  | S)N)r   rQ  r,  rP  )r,   r{   r   r   r   r,    s    	zArgumentParser._add_actionc             C   s   d d   |  j  D S)Nc             S   s   g  |  ] } | j  r |  q Sr   )r   )r^   r{   r   r   r   ra     s   	z8ArgumentParser._get_optional_actions.<locals>.<listcomp>)r  )r,   r   r   r   _get_optional_actions  s    	z$ArgumentParser._get_optional_actionsc             C   s   d d   |  j  D S)Nc             S   s   g  |  ] } | j  s |  q Sr   )r   )r^   r{   r   r   r   ra     s   	z:ArgumentParser._get_positional_actions.<locals>.<listcomp>)r  )r,   r   r   r   rV    s    	z&ArgumentParser._get_positional_actionsc             C   sK   |  j  | |  \ } } | rG t d  } |  j | d j |   n  | S)Nzunrecognized arguments: %sr   )r   r   rB  r+   )r,   r`   r9   rK  r   r   r   r   
parse_args  s
    zArgumentParser.parse_argsc             C   s  | d  k r" t  j d d   } n  | d  k r: t   } n  x |  j D] } | j t k	 rD t | | j  s | j t k	 r | j } t | j t	  r |  j
 | |  } n  t | | j |  q q qD qD Wx: |  j D]/ } t | |  s t | | |  j |  q q Wy[ |  j | |  \ } } t | t  rW| j t | t   t | t  n  | | f SWn5 t k
 rt  j   d } |  j t |   Yn Xd  S)NrW   )r  rK  r	   r  r   r   r   r   r   
basestring
_get_valuer8   r   _parse_known_argsr   r   r7   delattrr   exc_inforB  r   )r,   r`   r9   r{   r   r   errr   r   r   r     s0    	 zArgumentParser.parse_known_argsc                s  	 j  d  k	 r! 	 j    n  i    x~ 	 j D]s } | j } xa t | j  D]P \ } }   j | g   } | j | d  |   | j | | d d    qP Wq1 Wi   g  } t   }	 x t |	  D] \ } }
 |
 d k r| j d  x_ |	 D] }
 | j d  q Wq 	 j	 |
  } | d  k r7d } n |  | <d } | j |  q Wd j
 |   t    t    d       	 f d d       	  f d	 d
   } 	 j       	  f d d   } g   d 
  rt   } n d } x 
 | k rt 
 f d d    D  } 
 | k rs| 
  } | 
 k rj| 
 qqs| 
 n  
  k r 
 |  }  j |  | 
 n  | 
  
 qW| 
  }  j  | d     r	 j t d   n  xO 	 j D]D } | j r|  k rBt |  } 	 j t d  |  qBqqWx} 	 j D]r } | j rPx` | j D] } |  k riPqiqiWd d   | j D } t d  } 	 j | d j
 |   qPqPW  f S)NrW   z--r  AOrb   c                s    j  |    j |  |  } | |  j k	 r  j  |   xW   j |  g   D]@ } |  k rN t d  } t |  } t |  | |   qN qN Wn  | t k	 r |    | |  n  d  S)Nznot allowed with argument %s)r   _get_valuesr   r   r   r   r   r   )r{   Zargument_stringsr   Zargument_valuesZconflict_actionr   Zaction_name)action_conflictsr9   seen_actionsseen_non_default_actionsr,   r   r   take_action  s    z5ArgumentParser._parse_known_args.<locals>.take_actionc                s   |  } | \ } } }  j  } g  } x| d  k rP  j   |   |  d S| d  k	 ry| | d  }  j } | d k r| d | k r| j | g  | f  | d }	 |	 | d } | d d   p d  }
  j } | | k r | | } |
 } qvt d  } t | | |   q| d k rW|  d } | g } | j | | | f  Pqt d  } t | | |   q+ |  d }  | d   } | | |  } | | }   | |  } | j | | | f  Pq+ W| st  x' | D] \ } } }  | | |  qW| S)NrW   r`  r   zignored explicit argument %r)_match_argumentr(   r  r  r   r   rY   )start_indexoption_tupler{   r   explicit_argZmatch_argumentZaction_tuples	arg_countr-  charZnew_explicit_argZoptionals_mapr   stopr`   r   Zselected_patterns)r-   arg_strings_patternextrasoption_string_indicesr,   rf  r   r   consume_optional  sP    
		
	
	
	

z:ArgumentParser._parse_known_args.<locals>.consume_optionalc                s    j  }  |  d   } |  |  } xH t  |  D]7 \ } }   |  |  |  } |  | 7}   | |  q8 W t |  d    d  d   <|  S)N)_match_arguments_partialziprt   )rh  Zmatch_partialZselected_patternZ
arg_countsr{   rk  r`   )r-   rn  r   r,   rf  r   r   consume_positionalsa  s    	
 z=ArgumentParser._parse_known_args.<locals>.consume_positionalsr   c                s"   g  |  ] } |   k r |  q Sr   r   )r^   r   )rh  r   r   ra     s   	z4ArgumentParser._parse_known_args.<locals>.<listcomp>ztoo few argumentszargument %s is requiredc             S   s+   g  |  ]! } | j  t k	 r t |   q Sr   )rv   r   r   )r^   r{   r   r   r   ra     s   	z#one of the arguments %s is requiredr   r   )rN  _read_args_from_filesr  r   r   r   r   iterr(   _parse_optionalr+   r   rV  ry   r   rB  r   r  r   r   )r,   r-   r9   r9  r   r   Zmutex_actionZ	conflictsZarg_string_pattern_partsZarg_strings_iter
arg_stringri  patternrq  rt  Zmax_option_string_indexZnext_option_string_indexZpositionals_end_indexstringsZ
stop_indexr{   r/   r   r   r   r   )rc  r-   rn  ro  r9   rp  r   rd  re  r,   rh  rf  r   r\    s    	#	
		!!J			!		!z ArgumentParser._parse_known_argsc             C   s  g  } x | D] } | d |  j  k r6 | j |  q y t | d d    } zj g  } xA | j   j   D]- } x$ |  j |  D] } | j |  q Wqk W|  j |  } | j |  Wd  | j   XWq t	 k
 r t
 j   d } |  j t |   Yq Xq W| S)Nr   rW   )rN  r(   r   readr   convert_arg_line_to_argsru  r   r   IOErrorr  r^  rB  r   )r,   r-   Znew_arg_stringsrx  Z	args_filearg_liner.   r_  r   r   r   ru    s$    z$ArgumentParser._read_args_from_filesc             C   s   | g S)Nr   )r,   r~  r   r   r   r|    s    z'ArgumentParser.convert_arg_line_to_argsc             C   s   |  j  |  } t j | |  } | d  k r i t d  d  6t d  t 6t d  t 6} t d  | j } | j | j |  } t | |   n  t	 | j
 d   S)Nzexpected one argumentzexpected at most one argumentzexpected at least one argumentzexpected %s argument(s)rW   )_get_nargs_patternrN   r5  r   r   r   r   r   r   rt   r   )r,   r{   rn  nargs_patternr5  Znargs_errorsr   r   r   r   r   rg    s    zArgumentParser._match_argumentc                s   g  } x t  t |  d d  D]z } | d  |  } d j   f d d   | D  } t j | |  } | d  k	 r | j d d   | j   D  Pq q W| S)Nr   rW   rb   c                s   g  |  ] }   j  |   q Sr   )r  )r^   r{   )r,   r   r   ra     s   	z;ArgumentParser._match_arguments_partial.<locals>.<listcomp>c             S   s   g  |  ] } t  |   q Sr   )rt   )r^   r  r   r   r   ra     s   	 r   )r   rt   r+   rN   r5  r   rq   )r,   rp   rn  r   r   Zactions_slicery  r5  r   )r,   r   rr    s     z'ArgumentParser._match_arguments_partialc       	      C   sq  | s
 d  S| d |  j  k r! d  S| |  j k rJ |  j | } | | d  f St |  d k r` d  Sd | k r | j d d  \ } } | |  j k r |  j | } | | | f Sn  |  j |  } t |  d k rd j d d   | D  } | | f } |  j t d  |  n t |  d k r2| \ } | S|  j j	 |  rT|  j
 sTd  Sn  d | k rdd  Sd  | d  f S)	Nr   rW   =z, c             S   s   g  |  ] \ } } } |  q Sr   r   )r^   r{   r   rj  r   r   r   ra     s   	z2ArgumentParser._parse_optional.<locals>.<listcomp>z#ambiguous option: %s could match %sr   )r  r  rt   split_get_option_tuplesr+   rB  r   r!  r5  r"  )	r,   rx  r{   r   rj  Zoption_tuplesoptionsr   ri  r   r   r   rw    s:    		zArgumentParser._parse_optionalc       
      C   s  g  } |  j  } | d | k r | d | k r d | k rV | j d d  \ } } n | } d  } x<|  j D]A } | j |  rl |  j | } | | | f } | j |  ql ql Wn | d | k r| d | k r| } d  } | d  d  } | d d   }	 x |  j D]y } | | k rH|  j | } | | |	 f } | j |  q
| j |  r
|  j | } | | | f } | j |  q
q
Wn |  j t d  |  | S)Nr   rW   r  r;   zunexpected option string: %s)r  r  r  
startswithr(   rB  r   )
r,   r   r   r-  Zoption_prefixrj  r{   r   Zshort_option_prefixZshort_explicit_argr   r   r   r  7  s8    	  z!ArgumentParser._get_option_tuplesc             C   s   | j  } | d  k r d } n | t k r3 d } nk | t k rH d } nV | t k r] d } nA | t k rr d } n, | t k r d } n d d j d	 |  } | j r | j d d
  } | j d d
  } n  | S)Nz(-*A-*)z(-*A?-*)z	(-*[A-]*)z
(-*A[A-]*)z([-AO]*)z(-*A[-AO]*)z(-*%s-*)z-*r`  rb   r  )	r   r   r   r   r   r   r+   r   r=  )r,   r{   r   r  r   r   r   r  c  s$    								z!ArgumentParser._get_nargs_patternc                s    j  t t g k r+ d d   | D } n  | r   j  t k r   j rV   j } n	   j } t | t  r j	   |  }  j
   |  qnV| r   j  t k r   j r   j d  k	 r   j } n | }  j
   |  nt |  d k r?  j  d  t g k r?| \ }  j	   |  }  j
   |  n   j  t k rm   f d d   | D } n   j  t k r   f d d   | D }  j
   | d  n=    f d d   | D } x | D] }  j
   |  qW| S)Nc             S   s"   g  |  ] } | d  k r |  q S)z--r   )r^   ru   r   r   r   ra     s   	 z.ArgumentParser._get_values.<locals>.<listcomp>rW   c                s"   g  |  ] }  j    |   q Sr   )r[  )r^   rE  )r{   r,   r   r   ra     s   	 c                s"   g  |  ] }  j    |   q Sr   )r[  )r^   rE  )r{   r,   r   r   ra     s   	 r   c                s"   g  |  ] }  j    |   q Sr   )r[  )r^   rE  )r{   r,   r   r   ra     s   	 )r   r   r   r   r   r   r   r   rZ  r[  _check_valuer   rt   )r,   r{   r-   r0   rx  rE  r   )r{   r,   r   rb    s8    		
'	zArgumentParser._get_valuesc             C   s  |  j  d | j | j  } t |  sI t d  } t | | |   n  y | |  } Wn t k
 r t | j d t | j   } t t	 j
   d  } t | |   Yn[ t t f k
 r
t | j d t | j   } t d  } t | | | | f   Yn X| S)Nr%   z%r is not callabler&   rW   zinvalid %s value: %r)r%  r%   r    r   r   r   r7   r)   r   r  r^  r;  rC   )r,   r{   rx  r.  r   r   r/   r   r   r   r[    s    zArgumentParser._get_valuec             C   se   | j  d  k	 ra | | j  k ra | d j t t | j    f } t d  | } t | |   n  d  S)Nz, z#invalid choice: %r (choose from %s))r   r+   mapr)   r   r   )r,   r{   r0   r   r   r   r   r   r    s    !zArgumentParser._check_valuec             C   s2   |  j    } | j |  j |  j |  j  | j   S)N)r   rs   ro   r  r  rf   )r,   r[   r   r   r   format_usage  s    
zArgumentParser.format_usagec             C   s   |  j    } | j |  j |  j |  j  | j |  j  xK |  j D]@ } | j | j	  | j | j  | j
 | j  | j   qB W| j |  j  | j   S)N)r   rs   ro   r  r  rm   r  r  ri   r8  r~   r   rj   rL  rf   )r,   r[   Zaction_groupr   r   r   rf     s    
zArgumentParser.format_helpc             C   sB   d d  l  } | j d t  |  j   } | j |  j  | j   S)Nr   zkThe format_version method is deprecated -- the "version" argument to ArgumentParser is no longer supported.)rF  rG  rH  r   rm   r   rf   )r,   rF  r[   r   r   r   format_version 	  s    zArgumentParser.format_versionc             C   s   |  j  d |  j  S)NrR   )rM  rR   )r,   r   r   r   r   
	  s    zArgumentParser._get_formatterc             C   s2   | d  k r t  j } n  |  j |  j   |  d  S)N)r  r  _print_messager  )r,   filer   r   r   print_usage	  s    zArgumentParser.print_usagec             C   s2   | d  k r t  j } n  |  j |  j   |  d  S)N)r  r  r  rf   )r,   r  r   r   r   r   	  s    zArgumentParser.print_helpc             C   s6   d d  l  } | j d t  |  j |  j   |  d  S)Nr   zjThe print_version method is deprecated -- the "version" argument to ArgumentParser is no longer supported.)rF  rG  rH  r  r  )r,   r  rF  r   r   r   print_version	  s
    zArgumentParser.print_versionc             C   s2   | r. | d  k r t  j } n  | j |  n  d  S)N)r  stderrwrite)r,   r   r  r   r   r   r  "	  s    zArgumentParser._print_messager   c             C   s-   | r |  j  | t j  n  t j |  d  S)N)r  r  r  r   )r,   statusr   r   r   r   r   +	  s    zArgumentParser.exitc             C   s7   |  j  t j  |  j d t d  |  j | f  d S)zerror(message: string)

        Prints a usage message incorporating the message to stderr and
        exits.

        If you override this in a subclass, it should not return -- it
        should either exit or raise an exception.
        r;   z%s: error: %s
N)r  r  r  r   r   rR   )r,   r   r   r   r   rB  0	  s    	zArgumentParser.error)"r&   r4   r5   r6   r   rV   r*   rW  r,  rX  rV  rY  r   r\  ru  r|  rg  rr  rw  r  r  rb  r[  r  r  rf   r  r   r  r   r  r  r   rB  r   r   )r   r   r     sR   E#9,,1

	):r6   __version____all__r   r   osr@   rerN   sysr  textwrapr   r   r   r   	NameErrorZsetsr   rZ  r   r   r    r   r   r   r   r   r   r   r   r$   r:   r   r   r   r   r   	Exceptionr   r   r
   r   r   r   r   r   r   r   r   r   r   r   r	   r  r/  r1  r   r   r   r   r   <module>>   s   	
 	[#%M+ *!