a
    zeG                    @   s  d Z g dZddlZddlZddlZddlmZ	m
Z
 dZdZdZdZd	Zd
ZdZG dd deZdd ZG dd deZG dd deZG dd deZG dd deZG dd deZdd ZG dd deZG dd deZG d d! d!eZG d"d# d#eZG d$d% d%eZ G d&d' d'eZ!G d(d) d)e!Z"G d*d+ d+e!Z#G d,d- d-eZ$G d.d/ d/eZ%G d0d1 d1eZ&G d2d3 d3eZ'G d4d5 d5eZ(G d6d7 d7eZ)G d8d9 d9e$Z*G d:d; d;eZ+G d<d= d=eZ,G d>d? d?eZ-G d@dA dAe-Z.G dBdC dCe.Z/G dDdE dEee-Z0dS )Fz1.1)ArgumentParserArgumentErrorArgumentTypeErrorBooleanOptionalActionFileTypeHelpFormatterArgumentDefaultsHelpFormatterRawDescriptionHelpFormatterRawTextHelpFormatterMetavarTypeHelpFormatter	NamespaceActionONE_OR_MOREOPTIONALPARSER	REMAINDERSUPPRESSZERO_OR_MORE    N)gettextngettextz==SUPPRESS==?*+zA......_unrecognized_argsc                   @   s$   e Zd Zdd Zdd Zdd ZdS )_AttributeHolderc                 C   s   t | j}g }i }|  D ]}|t| q|  D ],\}}| rZ|d||f  q6|||< q6|rz|dt|  d|d|f S )N%s=%rz**%s%s(%s), )type__name__	_get_argsappendrepr_get_kwargsisidentifierjoin)self	type_namearg_strings	star_argsargnamevalue r.   /usr/lib/python3.9/argparse.py__repr__t   s    

z_AttributeHolder.__repr__c                 C   s   t | j S N)list__dict__itemsr'   r.   r.   r/   r$      s    z_AttributeHolder._get_kwargsc                 C   s   g S r1   r.   r5   r.   r.   r/   r!      s    z_AttributeHolder._get_argsN)r    
__module____qualname__r0   r$   r!   r.   r.   r.   r/   r   k   s   	r   c                 C   s6   | d u rg S t | tu r$| d d  S dd l}|| S Nr   )r   r2   copy)r4   r9   r.   r.   r/   _copy_items   s    r:   c                   @   s   e Zd Zd:ddZdd Zdd	 ZG d
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.d/ Zd0d1 Zd2d3 Zd4d5 Zd6d7 Zd8d9 ZdS )<r         Nc                 C   s   |d u r"dd l }| j}|d8 }|| _|| _t|t|d |d | _|| _d| _	d| _
d| _| | d | _| j| _tdtj| _td| _d S )Nr   r;      z\s+z\n\n\n+)shutilget_terminal_sizecolumns_prog_indent_incrementminmax_max_help_position_width_current_indent_level_action_max_length_Section_root_section_current_section_recompileASCII_whitespace_matcher_long_break_matcher)r'   progindent_incrementmax_help_positionwidthr>   r.   r.   r/   __init__   s"    
zHelpFormatter.__init__c                 C   s"   |  j | j7  _ |  jd7  _d S N   rG   rB   rH   r5   r.   r.   r/   _indent   s    zHelpFormatter._indentc                 C   s"   |  j | j8  _ |  jd8  _d S rW   rY   r5   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 r1   )	formatterparentheadingr4   )r'   r\   r]   r^   r.   r.   r/   rV      s    zHelpFormatter._Section.__init__c                 C   s   | j d ur| j  | jj}|dd | jD }| j d urD| j  |sLdS | jturz| jd urz| jj}d|d| jf }nd}|d||dgS )Nc                 S   s   g | ]\}}|| qS r.   r.   ).0funcargsr.   r.   r/   
<listcomp>       z6HelpFormatter._Section.format_help.<locals>.<listcomp> z%*s%s:

)	r]   r\   rZ   _join_partsr4   r[   r^   r   rG   )r'   r&   	item_helpcurrent_indentr^   r.   r.   r/   format_help   s    



z"HelpFormatter._Section.format_help)N)r    r6   r7   rV   ri   r.   r.   r.   r/   rJ      s   
rJ   c                 C   s   | j j||f d S r1   )rL   r4   r"   )r'   r`   ra   r.   r.   r/   	_add_item   s    zHelpFormatter._add_itemc                 C   s0   |    | | | j|}| |jg  || _d S r1   )rZ   rJ   rL   rj   ri   )r'   r^   sectionr.   r.   r/   start_section   s    zHelpFormatter.start_sectionc                 C   s   | j j| _ |   d S r1   )rL   r]   r[   r5   r.   r.   r/   end_section   s    
zHelpFormatter.end_sectionc                 C   s$   |t ur |d ur | | j|g d S r1   )r   rj   _format_text)r'   textr.   r.   r/   add_text   s    zHelpFormatter.add_textc                 C   s&   |t ur"||||f}| | j| d S r1   )r   rj   _format_usage)r'   usageactionsgroupsprefixra   r.   r.   r/   	add_usage   s    zHelpFormatter.add_usagec                 C   sr   |j turn| j}||g}| |D ]}||| q$ttt|}|| j }t| j	|| _	| 
| j|g d S r1   )helpr   _format_action_invocation_iter_indented_subactionsr"   rD   maplenrG   rI   rj   _format_action)r'   actionget_invocationinvocations	subactioninvocation_lengthaction_lengthr.   r.   r/   add_argument  s    


zHelpFormatter.add_argumentc                 C   s   |D ]}|  | qd S r1   )r   )r'   rs   r}   r.   r.   r/   add_arguments  s    zHelpFormatter.add_argumentsc                 C   s.   | j  }|r*| jd|}|dd }|S )N

re   )rK   ri   rQ   substrip)r'   rw   r.   r.   r/   ri     s
    
zHelpFormatter.format_helpc                 C   s   d dd |D S )Nrd   c                 S   s   g | ]}|r|t ur|qS r.   )r   )r_   partr.   r.   r/   rb   "  s   z-HelpFormatter._join_parts.<locals>.<listcomp>)r&   )r'   part_stringsr.   r.   r/   rf   !  s    
zHelpFormatter._join_partsc                    s  |d u rt d}|d ur,|t| jd }n|d u rL|sLdt| jd }n|d u rdt| jd }g }g }|D ] }|jr|| qr|| qr| j}	|	|| |}
ddd ||
fD }| j| j  t	|t	|  krd}|	||}|	||}t
||}t
||}d fdd		}t	|t	| d
  krdt	|t	| d  }|r|||g| ||}|||| n |r||g| ||}n|g}nZdt	| }|| }|||}t	|dkrg }|||| |||| |g| }d|}d||f S )Nzusage: rR   z%(prog)s c                 S   s   g | ]}|r|qS r.   r.   )r_   sr.   r.   r/   rb   B  rc   z/HelpFormatter._format_usage.<locals>.<listcomp>z%\(.*?\)+(?=\s|$)|\[.*?\]+(?=\s|$)|\S+c                    s   g }g }|d urt |d }nt |d }| D ]Z}|d t |  krn|rn||d|  g }t |d }|| |t |d 7 }q.|r||d|  |d ur|d t |d  |d< |S )NrX   r   r   )r{   r"   r&   )partsindentru   lineslineline_lenr   
text_widthr.   r/   	get_linesV  s"    
z.HelpFormatter._format_usage.<locals>.get_linesg      ?rX   re   z%s%s

)N)_dictrA   option_stringsr"   _format_actions_usager&   rF   rG   r{   rM   findallextend)r'   rr   rs   rt   ru   rR   	optionalspositionalsr}   formataction_usagepart_regexp	opt_usage	pos_usage	opt_parts	pos_partsr   r   r   r   r.   r   r/   rq   &  sX    





zHelpFormatter._format_usagec              	   C   s  t  }i }|D ]*}|js(td| z||jd }W n tyR   Y qY q0 |t|j }||| |jkr|jD ]}|| qz|js||v r||  d7  < nd||< ||v r||  d7  < nd||< nF||v r||  d7  < nd||< ||v r||  d7  < nd||< t|d	 |D ]}	d
||	< q*qg }
t|D ]"\}	}|j	t
u r|
d  ||	d
kr||	 n"||	d	 d
krj||	d	  n|js| |}| ||}||v r|d dkr|d dkr|d	d }|
| nf|jd }|jdkr$| }n"| |}| ||}d||f }|js`||vr`d| }|
| qHt|ddD ]}	||	 g|
|	|	< qzddd |
D }d}d}td| d|}td| d|}td||f d|}tdd|}| }|S )Nzempty group r   z [[]z (()rX   |%s %s[%s]T)reverser   c                 S   s   g | ]}|d ur|qS r1   r.   )r_   itemr.   r.   r/   rb     rc   z7HelpFormatter._format_actions_usage.<locals>.<listcomp>z[\[(]z[\])]z(%s) z\1 (%s)z%s *%srd   z\(([^|]*)\))set_group_actions
ValueErrorindexr{   addrequiredrange	enumeraterw   r   r"   getpopr   #_get_default_metavar_for_positional_format_argsnargsformat_usage!_get_default_metavar_for_optionalsortedr&   rM   r   r   )r'   rs   rt   group_actionsinsertsgroupstartendr}   ir   defaultr   option_stringargs_stringro   opencloser.   r.   r/   r     s~    










z#HelpFormatter._format_actions_usagec                 C   sF   d|v r|t | jd }t| j| j d}d| j }| |||d S )Nz%(prog)r      r   r   )r   rA   rD   rF   rG   
_fill_text)r'   ro   r   r   r.   r.   r/   rn     s
    
zHelpFormatter._format_textc                 C   sN  t | jd | j}t| j| d}|| j d }| |}|jsV| jd|f}d| }n@t||kr~| jd||f}d| }d}n| jd|f}d| }|}|g}|jr|j	 r| 
|}	|	r"| |	|}
|d|d|
d f  |
dd  D ]}|d|d|f  qn|ds"|d | |D ]}|| | q,| |S )	Nr;   r   rd   z%*s%s
z	%*s%-*s  r   rX   re   )rC   rI   rE   rD   rF   rG   rx   rw   r{   r   _expand_help_split_linesr"   endswithry   r|   rf   )r'   r}   help_position
help_widthaction_widthaction_headertupindent_firstr   	help_text
help_linesr   r   r.   r.   r/   r|     s:    




zHelpFormatter._format_actionc                 C   s   |j s&| |}| ||d\}|S g }|jdkrB||j  n4| |}| ||}|j D ]}|d||f  q^d|S d S )NrX   r   r   r   )	r   r   _metavar_formatterr   r   r   r   r"   r&   )r'   r}   r   metavarr   r   r   r.   r.   r/   rx   '  s    



z'HelpFormatter._format_action_invocationc                    sP   |j d ur|j  n.|jd ur<dd |jD }dd|  n|  fdd}|S )Nc                 S   s   g | ]}t |qS r.   str)r_   choicer.   r.   r/   rb   C  rc   z4HelpFormatter._metavar_formatter.<locals>.<listcomp>z{%s},c                    s   t  tr S  f|  S d S r1   )
isinstancetuple)
tuple_sizeresultr.   r/   r   H  s    
z0HelpFormatter._metavar_formatter.<locals>.format)r   choicesr&   )r'   r}   default_metavarchoice_strsr   r.   r   r/   r   ?  s    

z HelpFormatter._metavar_formatterc                 C   s  |  ||}|jd u r$d|d }n|jtkr<d|d }n|jtkrn|d}t|dkrdd| }nd| }n|jtkrd|d }n|jtkrd}nr|jtkrd	|d }nZ|jtkrd
}nJzdd t	|jD }W n t
y   tdd Y n0 d|||j }|S )N%srX   r   r;   z[%s [%s ...]]z[%s ...]z%s [%s ...]r   z%s ...rd   c                 S   s   g | ]}d qS )r   r.   )r_   r   r.   r.   r/   rb   e  rc   z.HelpFormatter._format_args.<locals>.<listcomp>zinvalid nargs valuer   )r   r   r   r   r{   r   r   r   r   r   	TypeErrorr   r&   )r'   r}   r   get_metavarr   r   formatsr.   r.   r/   r   O  s0    








zHelpFormatter._format_argsc                 C   s   t t|| jd}t|D ]}|| tu r||= qt|D ] }t|| dr:|| j||< q:|dd urddd |d D }||d< | 	|| S )Nr   r    r   r   c                 S   s   g | ]}t |qS r.   r   r_   cr.   r.   r/   rb   t  rc   z.HelpFormatter._expand_help.<locals>.<listcomp>)
r   varsrA   r2   r   hasattrr    r   r&   _get_help_string)r'   r}   paramsr,   choices_strr.   r.   r/   r   k  s    zHelpFormatter._expand_helpc                 c   s>   z
|j }W n ty   Y n0 |   | E d H  |   d S r1   )_get_subactionsAttributeErrorrZ   r[   )r'   r}   get_subactionsr.   r.   r/   ry   x  s    
z'HelpFormatter._iter_indented_subactionsc                 C   s&   | j d| }dd l}|||S )Nr   r   )rP   r   r   textwrapwrap)r'   ro   rU   r   r.   r.   r/   r     s    zHelpFormatter._split_linesc                 C   s,   | j d| }dd l}|j||||dS )Nr   r   )initial_indentsubsequent_indent)rP   r   r   r   fill)r'   ro   rU   r   r   r.   r.   r/   r     s    zHelpFormatter._fill_textc                 C   s   |j S r1   )rw   r'   r}   r.   r.   r/   r     s    zHelpFormatter._get_help_stringc                 C   s
   |j  S r1   )destupperr   r.   r.   r/   r     s    z/HelpFormatter._get_default_metavar_for_optionalc                 C   s   |j S r1   )r   r   r.   r.   r/   r     s    z1HelpFormatter._get_default_metavar_for_positional)r;   r<   N)N)r    r6   r7   rV   rZ   r[   objectrJ   rj   rl   rm   rp   rv   r   r   ri   rf   rq   r   rn   r|   rx   r   r   r   ry   r   r   r   r   r   r.   r.   r.   r/   r      s<   	   

`j0
r   c                   @   s   e Zd Zdd ZdS )r   c                    s    d  fdd|jddD S )Nrd   c                 3   s   | ]} | V  qd S r1   r.   )r_   r   r   r.   r/   	<genexpr>  rc   z9RawDescriptionHelpFormatter._fill_text.<locals>.<genexpr>T)keepends)r&   
splitlines)r'   ro   rU   r   r.   r   r/   r     s    z&RawDescriptionHelpFormatter._fill_textN)r    r6   r7   r   r.   r.   r.   r/   r     s   r   c                   @   s   e Zd Zdd ZdS )r	   c                 C   s   |  S r1   )r   )r'   ro   rU   r.   r.   r/   r     s    z!RawTextHelpFormatter._split_linesN)r    r6   r7   r   r.   r.   r.   r/   r	     s   r	   c                   @   s   e Zd Zdd ZdS )r   c                 C   s>   |j }d|j vr:|jtur:ttg}|js2|j|v r:|d7 }|S )Nz
%(default) (default: %(default)s))rw   r   r   r   r   r   r   )r'   r}   rw   defaulting_nargsr.   r.   r/   r     s    

z.ArgumentDefaultsHelpFormatter._get_help_stringN)r    r6   r7   r   r.   r.   r.   r/   r     s   r   c                   @   s   e Zd Zdd Zdd ZdS )r
   c                 C   s   |j jS r1   r   r    r   r.   r.   r/   r     s    z:MetavarTypeHelpFormatter._get_default_metavar_for_optionalc                 C   s   |j jS r1   r  r   r.   r.   r/   r     s    z<MetavarTypeHelpFormatter._get_default_metavar_for_positionalN)r    r6   r7   r   r   r.   r.   r.   r/   r
     s   r
   c                 C   sh   | d u rd S | j rd| j S | jd tfvr2| jS | jd tfvrF| jS | jr`dd| j d S d S d S )N/{r   })r   r&   r   r   r   r   )argumentr.   r.   r/   _get_action_name  s    r  c                   @   s   e Zd Zdd Zdd ZdS )r   c                 C   s   t || _|| _d S r1   )r  argument_namemessage)r'   r  r	  r.   r.   r/   rV     s    
zArgumentError.__init__c                 C   s(   | j d u rd}nd}|t| j| j d S )Nz%(message)sz'argument %(argument_name)s: %(message)s)r	  r  )r  r   r	  )r'   r   r.   r.   r/   __str__  s    
zArgumentError.__str__N)r    r6   r7   rV   r
  r.   r.   r.   r/   r     s   r   c                   @   s   e Zd ZdS )r   N)r    r6   r7   r.   r.   r.   r/   r     s   r   c                   @   s0   e Zd ZdddZdd Zdd Zdd	d
ZdS )r   NFc                 C   s@   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	d S r1   
r   r   r   constr   r   r   r   rw   r   r'   r   r   r   r  r   r   r   r   rw   r   r.   r.   r/   rV   4  s    zAction.__init__c                    s   g d} fdd|D S )Nr  c                    s   g | ]}|t  |fqS r.   getattrr_   r,   r5   r.   r/   rb   W  rc   z&Action._get_kwargs.<locals>.<listcomp>r.   r'   namesr.   r5   r/   r$   J  s    zAction._get_kwargsc                 C   s
   | j d S r8   r   r5   r.   r.   r/   r   Y  s    zAction.format_usagec                 C   s   t tdd S )Nz.__call__() not defined)NotImplementedErrorr   r'   parser	namespacevaluesr   r.   r.   r/   __call__\  s    zAction.__call__)NNNNNFNN)N)r    r6   r7   rV   r$   r   r  r.   r.   r.   r/   r     s   6        
r   c                       s0   e Zd Zd	 fdd	Zd
ddZdd Z  ZS )r   NFc	                    s~   g }	|D ]2}
|	 |
 |
drd|
dd   }
|	 |
 q|d ur\|d ur\|tur\|d7 }t j|	|d||||||d	 d S )N----no-r;   r   r   )	r   r   r   r   r   r   r   rw   r   )r"   
startswithr   superrV   )r'   r   r   r   r   r   r   rw   r   _option_stringsr   	__class__r.   r/   rV   `  s&    


zBooleanOptionalAction.__init__c                 C   s$   || j v r t|| j|d  d S )Nr  )r   setattrr   r  r  r.   r.   r/   r    s    
zBooleanOptionalAction.__call__c                 C   s   d | jS )Nz | )r&   r   r5   r.   r.   r/   r     s    z"BooleanOptionalAction.format_usage)NNNFNN)N)r    r6   r7   rV   r  r   __classcell__r.   r.   r  r/   r   _  s          
r   c                       s(   e Zd Zd fdd	ZdddZ  ZS )	_StoreActionNFc                    sT   |dkrt d|d ur,|tkr,t dt tt| j|||||||||	|
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 appropriate nargs must be %r to supply constr  )r   r   r  r#  rV   r  r  r.   r/   rV     s     
z_StoreAction.__init__c                 C   s   t || j| d S r1   )r!  r   r  r.   r.   r/   r    s    z_StoreAction.__call__)NNNNNFNN)Nr    r6   r7   rV   r  r"  r.   r.   r  r/   r#    s           r#  c                       s(   e Zd Zd fdd	ZdddZ  ZS )	_StoreConstActionNFc              	      s"   t t| j||d||||d d S )Nr   )r   r   r   r  r   r   rw   )r  r&  rV   r'   r   r   r  r   r   rw   r   r  r.   r/   rV     s    
z_StoreConstAction.__init__c                 C   s   t || j| j d S r1   )r!  r   r  r  r.   r.   r/   r    s    z_StoreConstAction.__call__)NFNN)Nr%  r.   r.   r  r/   r&    s       r&  c                       s   e Zd Zd fdd	Z  ZS )_StoreTrueActionFNc                    s    t t| j||d|||d d S )NTr   r   r  r   r   rw   )r  r(  rV   r'   r   r   r   r   rw   r  r.   r/   rV     s    
z_StoreTrueAction.__init__)FFNr    r6   r7   rV   r"  r.   r.   r  r/   r(    s      r(  c                       s   e Zd Zd fdd	Z  ZS )_StoreFalseActionTFNc                    s    t t| j||d|||d d S )NFr)  )r  r,  rV   r*  r  r.   r/   rV     s    
z_StoreFalseAction.__init__)TFNr+  r.   r.   r  r/   r,    s      r,  c                       s(   e Zd Zd fdd	ZdddZ  ZS )	_AppendActionNFc                    sT   |dkrt d|d ur,|tkr,t dt tt| j|||||||||	|
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 appropriater$  r  )r   r   r  r-  rV   r  r  r.   r/   rV     s     
z_AppendAction.__init__c                 C   s2   t || jd }t|}|| t|| j| d S r1   )r  r   r:   r"   r!  r'   r  r  r  r   r4   r.   r.   r/   r    s    
z_AppendAction.__call__)NNNNNFNN)Nr%  r.   r.   r  r/   r-    s           r-  c                       s(   e Zd Zd fdd	ZdddZ  ZS )	_AppendConstActionNFc              
      s$   t t| j||d|||||d d S )Nr   )r   r   r   r  r   r   rw   r   )r  r/  rV   r'  r  r.   r/   rV     s    
z_AppendConstAction.__init__c                 C   s4   t || jd }t|}|| j t|| j| d S r1   )r  r   r:   r"   r  r!  r.  r.   r.   r/   r    s    z_AppendConstAction.__call__)NFNN)Nr%  r.   r.   r  r/   r/  
  s       r/  c                       s(   e Zd Zd fdd	ZdddZ  ZS )	_CountActionNFc                    s    t t| j||d|||d d S )Nr   )r   r   r   r   r   rw   )r  r0  rV   r*  r  r.   r/   rV   '  s    
z_CountAction.__init__c                 C   s0   t || jd }|d u rd}t|| j|d  d S Nr   rX   )r  r   r!  )r'   r  r  r  r   countr.   r.   r/   r  5  s    z_CountAction.__call__)NFN)Nr%  r.   r.   r  r/   r0  %  s
      r0  c                       s.   e Zd Zeedf fdd	ZdddZ  ZS )_HelpActionNc                    s   t t| j|||d|d d S Nr   )r   r   r   r   rw   )r  r3  rV   )r'   r   r   r   rw   r  r.   r/   rV   >  s    
z_HelpAction.__init__c                 C   s   |   |  d S r1   )
print_helpexitr  r.   r.   r/   r  J  s    z_HelpAction.__call__)Nr    r6   r7   r   rV   r  r"  r.   r.   r  r/   r3  <  s
   r3  c                       s0   e Zd Zdeedf fdd	ZdddZ  ZS )_VersionActionNz&show program's version number and exitc                    s$   t t| j|||d|d || _d S r4  )r  r8  rV   version)r'   r   r9  r   r   rw   r  r.   r/   rV   Q  s    
z_VersionAction.__init__c                 C   sD   | j }|d u r|j }| }|| || tj |  d S r1   )r9  _get_formatterrp   _print_messageri   _sysstdoutr6  )r'   r  r  r  r   r9  r\   r.   r.   r/   r  _  s    
z_VersionAction.__call__)Nr7  r.   r.   r  r/   r8  O  s   r8  c                       sP   e Zd ZG dd deZedddf fdd	Zdd Zd	d
 ZdddZ	  Z
S )_SubParsersActionc                       s   e Zd Z fddZ  ZS )z&_SubParsersAction._ChoicesPseudoActionc                    s@   | }}|r|dd | 7 }ttj| }|jg |||d d S )Nr   r   )r   r   rw   r   )r&   r  r>  _ChoicesPseudoActionrV   )r'   r,   aliasesrw   r   r   supr  r.   r/   rV   m  s    
z/_SubParsersAction._ChoicesPseudoAction.__init__r+  r.   r.   r  r/   r?  k  s   r?  FNc              	      s<   || _ || _i | _g | _tt| j||t| j|||d d S )N)r   r   r   r   r   rw   r   )_prog_prefix_parser_class_name_parser_map_choices_actionsr  r>  rV   r   )r'   r   rR   parser_classr   r   rw   r   r  r.   r/   rV   u  s    	
z_SubParsersAction.__init__c                 K   s   | dd u r d| j|f |d< |dd}d|v rX|d}| |||}| j| | jf i |}|| j|< |D ]}|| j|< qv|S )NrR   r   r@  r.   rw   )r   rB  r   r?  rE  r"   rC  rD  )r'   r,   kwargsr@  rw   choice_actionr  aliasr.   r.   r/   
add_parser  s    

z_SubParsersAction.add_parserc                 C   s   | j S r1   )rE  r5   r.   r.   r/   r     s    z!_SubParsersAction._get_subactionsc                 C   s   |d }|dd  }| j tur,t|| j | z| j| }W n: tyt   |d| jd}td| }t| |Y n0 ||d \}	}t	|	
 D ]\}
}t||
| q|rt	|tg  t|t| d S )Nr   rX   r   )parser_namer   z5unknown parser %(parser_name)r (choices: %(choices)s))r   r   r!  rD  KeyErrorr&   r   r   parse_known_argsr   r4   
setdefault_UNRECOGNIZED_ARGS_ATTRr  r   )r'   r  r  r  r   rK  r)   ra   msgsubnamespacekeyr-   r.   r.   r/   r    s$    

	z_SubParsersAction.__call__)N)r    r6   r7   r   r?  r   rV   rJ  r   r  r"  r.   r.   r  r/   r>  i  s   r>  c                   @   s   e Zd ZdddZdS )_ExtendActionNc                 C   s2   t || jd }t|}|| t|| j| d S r1   )r  r   r:   r   r!  r.  r.   r.   r/   r    s    
z_ExtendAction.__call__)N)r    r6   r7   r  r.   r.   r.   r/   rS    s   rS  c                   @   s&   e Zd Zd
ddZdd Zdd	 ZdS )r   rr   Nc                 C   s   || _ || _|| _|| _d S r1   )_mode_bufsize	_encoding_errors)r'   modebufsizeencodingerrorsr.   r.   r/   rV     s    zFileType.__init__c              
      s   |dkrnd j v r*d j v r$tjjS tjS t fdddD rXd j v rRtjjS tjS td j  }t|zt| j  j	 j
 jW S  ty } z*||d}td	}t|| W Y d }~n
d }~0 0 d S )
N-rT  bc                 3   s   | ]}| j v V  qd S r1   )rU  r   r5   r.   r/   r     rc   z$FileType.__call__.<locals>.<genexpr>waxzargument "-" with mode %r)filenameerrorz$can't open '%(filename)s': %(error)s)rU  r<  stdinbufferanyr=  r   r   r   rV  rW  rX  OSErrorr   )r'   stringrP  era   r	  r.   r5   r/   r    s    

zFileType.__call__c                 C   sT   | j | jf}d| jfd| jfg}ddd |D dd |D  }dt| j|f S )Nr[  r\  r   c                 S   s   g | ]}|d krt |qS )r   )r#   )r_   r+   r.   r.   r/   rb     rc   z%FileType.__repr__.<locals>.<listcomp>c                 S   s$   g | ]\}}|d urd||f qS )Nr   r.   )r_   kwr+   r.   r.   r/   rb      s   r   )rU  rV  rW  rX  r&   r   r    )r'   ra   rG  args_strr.   r.   r/   r0     s    zFileType.__repr__)rT  r   NN)r    r6   r7   rV   r  r0   r.   r.   r.   r/   r     s   
r   c                   @   s$   e Zd Zdd Zdd Zdd ZdS )r   c                 K   s   |D ]}t | |||  qd S r1   )r!  )r'   rG  r,   r.   r.   r/   rV     s    zNamespace.__init__c                 C   s   t |tstS t| t|kS r1   )r   r   NotImplementedr   )r'   otherr.   r.   r/   __eq__  s    
zNamespace.__eq__c                 C   s
   || j v S r1   )r3   )r'   rR  r.   r.   r/   __contains__  s    zNamespace.__contains__N)r    r6   r7   rV   rl  rm  r.   r.   r.   r/   r     s   r   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  ZS )(_ActionsContainerc                    s  t t|   || _|| _|| _|| _i | _| dd t	 | ddt	 | ddt
 | ddt | ddt | ddt | ddt | ddt | dd	t | dd
t | ddt | ddt |   g | _i | _g | _g | _i | _td| _g | _d S )Nr}   storestore_const
store_truestore_falser"   append_constr2  rw   r9  parsersr   z^-\d+$|^-\d*\.\d+$)r  rn  rV   descriptionargument_defaultprefix_charsconflict_handler_registriesregisterr#  r&  r(  r,  r-  r/  r0  r3  r8  r>  rS  _get_handler_actions_option_string_actions_action_groups_mutually_exclusive_groups	_defaultsrM   rN   _negative_number_matcher_has_negative_number_optionals)r'   ru  rw  rv  rx  r  r.   r/   rV     s4    z_ActionsContainer.__init__c                 C   s   | j |i }|||< d S r1   )ry  rN  )r'   registry_namer-   r   registryr.   r.   r/   rz  S  s    z_ActionsContainer.registerNc                 C   s   | j | ||S r1   )ry  r   )r'   r  r-   r   r.   r.   r/   _registry_getW  s    z_ActionsContainer._registry_getc                 K   s2   | j | | jD ]}|j|v r||j |_qd S r1   )r  updater|  r   r   )r'   rG  r}   r.   r.   r/   set_defaults]  s    

z_ActionsContainer.set_defaultsc                 C   s8   | j D ]"}|j|kr|jd ur|j  S q| j|d S r1   )r|  r   r   r  r   )r'   r   r}   r.   r.   r/   get_defaultf  s    
z_ActionsContainer.get_defaultc                 O   sP  | j }|r&t|dkrL|d d |vrL|r:d|v r:td| j|i |}n| j|i |}d|vr|d }|| jv r| j| |d< n| jd ur| j|d< | |}t|std|f |f i |}| 	d|j
|j
}t|std|f |tu rtd	|f t| d
rFz|  |d  W n tyD   tdY n0 | |S )NrX   r   r   z+dest supplied twice for positional argumentr   zunknown action "%s"r   %r is not callablez<%r is a FileType class object, instance of it must be passedr:  z,length of metavar tuple does not match nargs)rw  r{   r   _get_positional_kwargs_get_optional_kwargsr  rv  _pop_action_classcallabler  r   r   r   r:  r   r   _add_action)r'   ra   rG  charsr   action_classr}   	type_funcr.   r.   r/   r   p  s:    	 




z_ActionsContainer.add_argumentc                 O   s&   t | g|R i |}| j| |S r1   )_ArgumentGroupr~  r"   )r'   ra   rG  r   r.   r.   r/   add_argument_group  s    z$_ActionsContainer.add_argument_groupc                 K   s    t | fi |}| j| |S r1   )_MutuallyExclusiveGroupr  r"   )r'   rG  r   r.   r.   r/   add_mutually_exclusive_group  s    z._ActionsContainer.add_mutually_exclusive_groupc                 C   s`   |  | | j| | |_|jD ]}|| j|< q"|jD ]"}| j|r8| js8| jd q8|S )NT)	_check_conflictr|  r"   	containerr   r}  r  matchr  )r'   r}   r   r.   r.   r/   r    s    


z_ActionsContainer._add_actionc                 C   s   | j | d S r1   )r|  remover   r.   r.   r/   _remove_action  s    z _ActionsContainer._remove_actionc                 C   s   i }| j D ].}|j|v r.td}t||j |||j< q
i }|j D ]D}|j|vrn| j|j|j|jd||j< |jD ]}||j ||< qtqD|jD ]&}| j	|j
d}|jD ]}|||< qq|jD ]}||| | qd S )Nz.cannot merge actions - two groups are named %r)titleru  rx  )r   )r~  r  r   r   r  ru  rx  r   r  r  r   r|  r   r  )r'   r  title_group_mapr   rP  	group_mapr}   mutex_groupr.   r.   r/   _add_container_actions  s0    







z(_ActionsContainer._add_container_actionsc                 K   s^   d|v rt d}t||dttfvr2d|d< |dtkrPd|vrPd|d< t||g dS )Nr   z1'required' is an invalid argument for positionalsr   Tr   r   r   )r   r   r   r   r   r   )r'   r   rG  rP  r.   r.   r/   r    s    z(_ActionsContainer._get_positional_kwargsc           	      O   s   g }g }|D ]`}|d | j vr>|| j d}td}t|| || t|dkr|d | j v r|| q|dd }|d u r|r|d }n|d }|| j }|std}t|| |dd}t|||d	S )
Nr   )optionrw  zNinvalid option string %(option)r: must start with a character %(prefix_chars)rrX   r   z%dest= is required for options like %rr]  r   r  )	rw  r   r   r"   r{   r   lstripreplacer   )	r'   ra   rG  r   long_option_stringsr   rP  r   dest_option_stringr.   r.   r/   r    s.    

z&_ActionsContainer._get_optional_kwargsc                 C   s   | d|}| d||S )Nr}   )r   r  )r'   rG  r   r}   r.   r.   r/   r    s    z#_ActionsContainer._pop_action_classc                 C   sD   d| j  }zt| |W S  ty>   td}t|| j  Y n0 d S )Nz_handle_conflict_%sz%invalid conflict_resolution value: %r)rx  r  r   r   r   )r'   handler_func_namerP  r.   r.   r/   r{  #  s    
z_ActionsContainer._get_handlerc                 C   sL   g }|j D ]&}|| jv r
| j| }|||f q
|rH|  }||| d S r1   )r   r}  r"   r{  )r'   r}   confl_optionalsr   confl_optionalrx  r.   r.   r/   r  ,  s    


z!_ActionsContainer._check_conflictc                 C   s6   t ddt|}ddd |D }t||| d S )Nzconflicting option string: %szconflicting option strings: %sr   c                 S   s   g | ]\}}|qS r.   r.   )r_   r   r}   r.   r.   r/   rb   >  s   z<_ActionsContainer._handle_conflict_error.<locals>.<listcomp>)r   r{   r&   r   )r'   r}   conflicting_actionsr	  conflict_stringr.   r.   r/   _handle_conflict_error:  s    
z(_ActionsContainer._handle_conflict_errorc                 C   s>   |D ]4\}}|j | | j|d  |j s|j| qd S r1   )r   r  r}  r   r  r  )r'   r}   r  r   r.   r.   r/   _handle_conflict_resolveC  s
    z*_ActionsContainer._handle_conflict_resolve)N)N)r    r6   r7   rV   rz  r  r  r  r   r  r  r  r  r  r  r  r  r{  r  r  r  r"  r.   r.   r  r/   rn    s$   5
	
3("
		rn  c                       s6   e Zd Zd fdd	Z fddZ fddZ  ZS )	r  Nc                    s   |j }|d|j |d|j |d|j tt| j}|f d|i| || _g | _|j	| _	|j
| _
|j| _|j| _|j| _|j| _d S )Nrx  rw  rv  ru  )rN  rx  rw  rv  r  r  rV   r  r   ry  r|  r}  r  r  r  )r'   r  r  ru  rG  r  
super_initr  r.   r/   rV   T  s    z_ArgumentGroup.__init__c                    s    t t| |}| j| |S r1   )r  r  r  r   r"   r   r  r.   r/   r  j  s    z_ArgumentGroup._add_actionc                    s    t t| | | j| d S r1   )r  r  r  r   r  r   r  r.   r/   r  o  s    z_ArgumentGroup._remove_action)NNr    r6   r7   rV   r  r  r"  r.   r.   r  r/   r  R  s   r  c                       s.   e Zd Zd fdd	Zdd Zdd Z  ZS )	r  Fc                    s    t t| | || _|| _d S r1   )r  r  rV   r   
_container)r'   r  r   r  r.   r/   rV   v  s    z _MutuallyExclusiveGroup.__init__c                 C   s2   |j rtd}t|| j|}| j| |S )Nz-mutually exclusive arguments must be optional)r   r   r   r  r  r   r"   )r'   r}   rP  r.   r.   r/   r  {  s    z#_MutuallyExclusiveGroup._add_actionc                 C   s   | j | | j| d S r1   )r  r  r   r  r   r.   r.   r/   r    s    z&_MutuallyExclusiveGroup._remove_action)Fr  r.   r.   r  r/   r  t  s   r  c                       s(  e Zd Zddddg edddddddf fdd	Zdd Zd	d
 Zdd Zdd Zdd Z	d@ddZ
dAd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dBd%d&ZdCd'd(Zd)d* Zd+d, Zd-d. Zd/d0 Zd1d2 Zd3d4 ZdDd5d6ZdEd7d8ZdFd9d:ZdGd<d=Zd>d? Z   Z!S )Hr   Nr]  ra  Tc              	      s&  t t| j}||||	|
d |d u r6tjtjd }|| _|| _	|| _
|| _|| _|| _|| _|| _| j}|td| _|td| _d | _dd }| dd | d|v rdn|d }| jr| j|d	 |d
 d dttdd |D ]:}| | z
|j}W n ty   Y q0 | j| qd S )N)ru  rw  rv  rx  r   zpositional argumentszoptional argumentsc                 S   s   | S r1   r.   )rf  r.   r.   r/   identity  s    z)ArgumentParser.__init__.<locals>.identityr   r]  hr;   rw   zshow this help message and exit)r}   r   rw   )r  r   rV   _ospathbasenamer<  argvrR   rr   epilogformatter_classfromfile_prefix_charsadd_helpallow_abbrevexit_on_errorr  r   _positionals
_optionals_subparsersrz  r   r   r  r  r   r  )r'   rR   rr   ru  r  parentsr  rw  r  rv  rx  r  r  r  	superinit	add_groupr  default_prefixr]   defaultsr  r.   r/   rV     sH    

zArgumentParser.__init__c                    s   g d} fdd|D S )N)rR   rr   ru  r  rx  r  c                    s   g | ]}|t  |fqS r.   r  r  r5   r.   r/   rb     rc   z.ArgumentParser._get_kwargs.<locals>.<listcomp>r.   r  r.   r5   r/   r$     s    zArgumentParser._get_kwargsc           	      K   s   | j d ur| td |dt|  d|v s8d|v rht|dd}t|dd }| ||| _ n| j| _ |dd u r| 	 }| 
 }| j}|| j||d |  |d< | |d}|f d	g i|}| j | |S )
Nz(cannot have multiple subparser argumentsrF  r  ru  subcommandsrR   rd   rt  r   )r  ra  r   rN  r   r   r  r  r   r:  _get_positional_actionsr  rv   rr   ri   r   r  r  )	r'   rG  r  ru  r\   r   rt   parsers_classr}   r.   r.   r/   add_subparsers  s$    
zArgumentParser.add_subparsersc                 C   s$   |j r| j| n| j| |S r1   )r   r  r  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S r.   r  r_   r}   r.   r.   r/   rb     s   z8ArgumentParser._get_optional_actions.<locals>.<listcomp>r|  r5   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S r.   r  r  r.   r.   r/   rb     s   z:ArgumentParser._get_positional_actions.<locals>.<listcomp>r  r5   r.   r.   r/   r    s    z&ArgumentParser._get_positional_actionsc                 C   s4   |  ||\}}|r0td}| |d|  |S Nzunrecognized arguments: %sr   )rM  r   ra  r&   r'   ra   r  r  rP  r.   r.   r/   
parse_args   s
    zArgumentParser.parse_argsc                 C   s  |d u rt jdd  }nt|}|d u r.t }| jD ]4}|jtur4t||js4|jtur4t	||j|j q4| j
D ] }t||spt	||| j
|  qp| jrz| ||\}}W q ty   t  d }| t| Y q0 n| ||\}}t|tr|t|t t|t ||fS rW   )r<  r  r2   r   r|  r   r   r   r   r!  r  r  _parse_known_argsr   exc_infora  r   rO  r   r  delattr)r'   ra   r  r}   r   errr.   r.   r/   rM  '  s0    





zArgumentParser.parse_known_argsc                    s  	j d ur	i  	jD ]R}|j}t|jD ]<\}} |g }||d |  |||d d   q2qi g }t}	t|	D ]^\}}
|
dkr|d |	D ]}
|d qq		|
}|d u rd}n||< d}|| qd
|t t d 	fdd		fd	d
}	 	fdd}g d
r`t}nd}
|krt
fddD }
|kr|
}|
kr|
qdn|

vr҈
| }| |
|

qd|
}|d   g }	jD ]|}|vr|jr(|t| nT|jd urt|jtrt|jr|jt|ju rt|j	||j q|r	tdd
|  	jD ]X}|jr|jD ]}|v r qqdd |jD }td}	|d
|  qfS )NrX   r  r]  AOrd   c                    s|    |  | |}|| jurb |   | g D ]*}|v r6td}t|}t| || q6|turx| || d S )Nznot allowed with argument %s)r   _get_valuesr   r   r   r  r   r   )r}   argument_stringsr   argument_valuesconflict_actionrP  action_name)action_conflictsr  seen_actionsseen_non_default_actionsr'   r.   r/   take_action}  s    


z5ArgumentParser._parse_known_args.<locals>.take_actionc                    s~  |  }|\}}}j }g }|d u r: |   | d S |d ur||d}j}|dkr|d |vr||g |f |d }	|	|d  }|dd  pd }
j}||v r|| }|
}ntd}t||| nB|dkr| d }|g}||||f q\ntd}t||| q| d }|d  }|||}|| } || }||||f q\q|D ]\}}}||| q`|S )NrX   r  r   zignored explicit argument %r)_match_argumentr"   rw  r}  r   r   )start_indexoption_tupler}   r   explicit_argmatch_argumentaction_tuples	arg_countr  charnew_explicit_argoptionals_maprP  stopra   r   selected_patterns)r)   arg_strings_patternextrasoption_string_indicesr'   r  r.   r/   consume_optional  sL    



z:ArgumentParser._parse_known_args.<locals>.consume_optionalc                    sn   j }| d  }||}t|D ]*\}} | | |  }| |7 } || q&t|d  d d < | S r1   )_match_arguments_partialzipr{   )r  match_partialselected_pattern
arg_countsr}   r  ra   )r)   r  r   r'   r  r.   r/   consume_positionals  s    
z=ArgumentParser._parse_known_args.<locals>.consume_positionalsr   r   c                    s   g | ]}| kr|qS r.   r.   )r_   r   )r  r.   r/   rb     s   z4ArgumentParser._parse_known_args.<locals>.<listcomp>z(the following arguments are required: %sr   c                 S   s   g | ]}|j turt|qS r.   )rw   r   r  r  r.   r.   r/   rb   ;  s   
z#one of the arguments %s is requiredr   )N)r  _read_args_from_filesr  r   r   rN  r   iterr"   _parse_optionalr&   r   r  rD   rC   r|  r   r  r   r   r   r   r   r  r!  
_get_valuera  r   )r'   r)   r  r  r   r   mutex_action	conflictsarg_string_pattern_partsarg_strings_iter
arg_stringr  patternr  r  max_option_string_indexnext_option_string_indexpositionals_end_indexstrings
stop_indexrequired_actionsr}   r   r  rP  r.   )r  r)   r  r  r  r  r   r  r  r'   r  r  r/   r  N  s    





J














z ArgumentParser._parse_known_argsc              	   C   s   g }|D ]}|r|d | j vr*|| qzxt|dd  T}g }|  D ]}| |D ]}|| q\qN| |}|| W d    n1 s0    Y  W q ty   t	
 d }| t| Y q0 q|S r1  )r  r"   r   readr   convert_arg_line_to_argsr  r   re  r<  r  ra  r   )r'   r)   new_arg_stringsr  	args_filearg_liner+   r  r.   r.   r/   r  D  s     
,z$ArgumentParser._read_args_from_filesc                 C   s   |gS r1   r.   )r'   r  r.   r.   r/   r  ^  s    z'ArgumentParser.convert_arg_line_to_argsc                 C   sz   |  |}t||}|d u rld tdttdttdi}||j}|d u rbtdd|j|j }t	||t
|dS )Nzexpected one argumentzexpected at most one argumentzexpected at least one argumentzexpected %s argumentzexpected %s argumentsrX   )_get_nargs_patternrM   r  r   r   r   r   r   r   r   r{   r   )r'   r}   r  nargs_patternr  nargs_errorsrP  r.   r.   r/   r  a  s"    

zArgumentParser._match_argumentc                    sr   g }t t|ddD ]X}|d | }d fdd|D }t||}|d ur|dd | D   qnq|S )Nr   r   rd   c                    s   g | ]}  |qS r.   )r  r  r5   r.   r/   rb   }  s   z;ArgumentParser._match_arguments_partial.<locals>.<listcomp>c                 S   s   g | ]}t |qS r.   )r{   )r_   rf  r.   r.   r/   rb     rc   )r   r{   r&   rM   r  r   rt   )r'   rs   r  r   r   actions_slicer  r  r.   r5   r/   r  w  s    z'ArgumentParser._match_arguments_partialc           
      C   s  |sd S |d | j vrd S || jv r8| j| }||d fS t|dkrHd S d|v r~|dd\}}|| jv r~| j| }|||fS | |}t|dkrddd |D }||d}td}| ||  nt|dkr|\}	|	S | j	|r| j
sd S d	|v rd S d |d fS )
Nr   rX   =r   c                 S   s   g | ]\}}}|qS r.   r.   )r_   r}   r   r  r.   r.   r/   rb     s   z2ArgumentParser._parse_optional.<locals>.<listcomp>)r  matchesz4ambiguous option: %(option)s could match %(matches)sr   )rw  r}  r{   split_get_option_tuplesr&   r   ra  r  r  r  )
r'   r  r}   r   r  option_tuplesoptionsra   rP  r  r.   r.   r/   r    s>    









zArgumentParser._parse_optionalc           
      C   s0  g }| j }|d |v r|d |v r| jr~d|v rB|dd\}}n|}d }| jD ],}||rP| j| }|||f}|| qPn|d |v r|d |vr|}d }|d d }|dd  }	| jD ]T}||kr| j| }|||	f}|| q||r| j| }|||f}|| qn| td|  |S )Nr   rX   r  r;   zunexpected option string: %s)rw  r  r  r}  r  r"   ra  r   )
r'   r   r   r  option_prefixr  r}   r   short_option_prefixshort_explicit_argr.   r.   r/   r    s:    









z!ArgumentParser._get_option_tuplesc                 C   s   |j }|d u rd}nf|tkr"d}nX|tkr0d}nJ|tkr>d}n<|tkrLd}n.|tkrZd}n |tkrhd}ndd	d
|  }|jr|	d	d}|	dd}|S )Nz(-*A-*)z(-*A?-*)z	(-*[A-]*)z
(-*A[A-]*)z([-AO]*)z(-*A[-AO]*)z(-*-*)z(-*%s-*)z-*r  rd   r]  )
r   r   r   r   r   r   r   r&   r   r  )r'   r}   r   r	  r.   r.   r/   r    s(    z!ArgumentParser._get_nargs_patternc                 C   s4   |  ||\}}|r0td}| |d|  |S r  )parse_known_intermixed_argsr   ra  r&   r  r.   r.   r/   parse_intermixed_args	  s
    z$ArgumentParser.parse_intermixed_argsc              	      s  |    dd  D }|r,td|d j  fdd| jD rHtdz| j}z| jd u rp|  dd  | _ D ] }|j|_t|_|j|_	t|_qt| 
||\}} D ]J}t||jrt||jg krddlm} |d	|j|f  t||j qW  D ]}|j|_|j	|_qn D ]}|j|_|j	|_q0 |  }zt|D ]}|j|_d
|_q@| jD ]}	|	j|	_d
|	_q\| 
||\}}
W |D ]}|j|_q| jD ]}	|	j|	_qn,|D ]}|j|_q| jD ]}	|	j|	_q0 W || _n|| _0 ||
fS )Nc                 S   s   g | ]}|j ttfv r|qS r.   )r   r   r   r  r.   r.   r/   rb   4	  s   z>ArgumentParser.parse_known_intermixed_args.<locals>.<listcomp>z3parse_intermixed_args: positional arg with nargs=%sr   c                    s&   g | ]}|j D ]}| v r|jqqS r.   )r   r   )r_   r   r}   r   r.   r/   rb   :	  s   z;parse_intermixed_args: positional in mutuallyExclusiveGroup   )warnzDo not expect %s in %sF)r  r   r   r  rr   r   
save_nargsr   r   save_defaultrM  r   r   r  warningsr  r  r  r   save_required)r'   ra   r  a
save_usager}   remaining_argsr  r   r   r  r.   r  r/   r  &	  sn    






z*ArgumentParser.parse_known_intermixed_argsc                    s   j ttfvr0z|d W n ty.   Y n0 |sx j tkrx jrL j}n j}t	|t
rt |} | n|s j tkr js jd ur j}n|} | nt|dkr j d tfv r|\} |} | n j tkr fdd|D }np j tkr> fdd|D } |d  n> j tkrPt}n, fdd|D }|D ]} | qh|S )Nr  rX   c                    s   g | ]}  |qS r.   r  r_   vr}   r'   r.   r/   rb   	  rc   z.ArgumentParser._get_values.<locals>.<listcomp>c                    s   g | ]}  |qS r.   r!  r"  r$  r.   r/   rb   	  rc   r   c                    s   g | ]}  |qS r.   r!  r"  r$  r.   r/   rb   	  rc   )r   r   r   r  r   r   r   r  r   r   r   r  _check_valuer   r{   r   )r'   r}   r)   r-   r  r#  r.   r$  r/   r  s	  sD    

zArgumentParser._get_valuesc              	   C   s   |  d|j|j}t|s0td}t||| z||}W n ty|   t|jdt|j}tt	
 d }t||Y nJ ttfy   t|jdt|j}||d}td}t||| Y n0 |S )Nr   r  r    rX   )r   r-   z!invalid %(type)s value: %(value)r)r  r   r  r   r   r   r  r#   r   r<  r  r   r   )r'   r}   r  r  rP  r   r,   ra   r.   r.   r/   r  	  s     
zArgumentParser._get_valuec                 C   sF   |j d urB||j vrB|dtt|j d}td}t||| d S )Nr   )r-   r   z3invalid choice: %(value)r (choose from %(choices)s))r   r&   rz   r#   r   r   )r'   r}   r-   ra   rP  r.   r.   r/   r%  	  s    zArgumentParser._check_valuec                 C   s$   |   }|| j| j| j | S r1   )r:  rv   rr   r|  r  ri   )r'   r\   r.   r.   r/   r   	  s
    zArgumentParser.format_usagec                 C   st   |   }|| j| j| j || j | jD ]0}||j	 ||j |
|j |  q.|| j | S r1   )r:  rv   rr   r|  r  rp   ru  r~  rl   r  r   r   rm   r  ri   )r'   r\   action_groupr.   r.   r/   ri   	  s    

zArgumentParser.format_helpc                 C   s   | j | jdS )Nr   )r  rR   r5   r.   r.   r/   r:  	  s    zArgumentParser._get_formatterc                 C   s"   |d u rt j}| |  | d S r1   )r<  r=  r;  r   r'   filer.   r.   r/   print_usage	  s    zArgumentParser.print_usagec                 C   s"   |d u rt j}| |  | d S r1   )r<  r=  r;  ri   r'  r.   r.   r/   r5  	  s    zArgumentParser.print_helpc                 C   s    |r|d u rt j}|| d S r1   )r<  stderrwrite)r'   r	  r(  r.   r.   r/   r;  	  s    zArgumentParser._print_messager   c                 C   s    |r|  |tj t| d S r1   )r;  r<  r*  r6  )r'   statusr	  r.   r.   r/   r6  
  s    zArgumentParser.exitc                 C   s0   |  tj | j|d}| dtd|  d S )N)rR   r	  r;   z%(prog)s: error: %(message)s
)r)  r<  r*  rR   r6  r   )r'   r	  ra   r.   r.   r/   ra  
  s    	zArgumentParser.error)NN)NN)NN)NN)N)N)N)r   N)"r    r6   r7   r   rV   r$   r  r  r  r  r  rM  r  r  r  r  r  r  r  r  r  r  r  r  r%  r   ri   r:  r)  r5  r;  r6  ra  r"  r.   r.   r  r/   r     sV   B

' w:-1

M8


	
r   )1__version____all__osr  rerM   sysr<  r   r   r   r   r   r   r   r   r   rO  r   r   r:   r   r   r	   r   r
   r  	Exceptionr   r   r   r   r#  r&  r(  r,  r-  r/  r0  r3  r8  r>  rS  r   r   rn  r  r  r   r.   r.   r.   r/   <module>A   s^       	^)#&]7  8"