B
    u9as                @   s  d Z d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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 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?d
 d
eZ*G d@dA dAeZ+G dBdC dCe+Z,G dDdE dEe,Z-G dFd dee+Z.dS )Gz1.1ArgumentParserArgumentErrorArgumentTypeErrorFileTypeHelpFormatterArgumentDefaultsHelpFormatterRawDescriptionHelpFormatterRawTextHelpFormatterMetavarTypeHelpFormatter	NamespaceActionONE_OR_MOREOPTIONALPARSER	REMAINDERSUPPRESSZERO_OR_MORE    N)gettextngettextz==SUPPRESS==?*+zA...z..._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 }x|  D ]}|t| qW x8|  D ],\}}| r`|d||f  q<|||< q<W |r|dt|  d|d|f S )Nz%s=%rz**%sz%s(%s)z, )type__name__	_get_argsappendrepr_get_kwargsisidentifierjoin)self	type_namearg_strings	star_argsargnamevalue r)   /usr/lib/python3.7/argparse.py__repr__r   s    
z_AttributeHolder.__repr__c             C   s   t | j S )N)sorted__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__r+   r   r   r)   r)   r)   r*   r   i   s   	r   c             C   s6   | d krg S t | tkr$| d d  S dd l}|| S )Nr   )r   listcopy)r.   r2   r)   r)   r*   _copy_items   s    r3   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 kr@yt tjd }W n ttfk
r6   d}Y nX |d8 }|| _|| _|| _t|t	|d |d | _|| _
d| _d| _d| _| | d | _| j| _tdtj| _td| _d S )NCOLUMNSP   r4      r   z\s+z\n\n\n+)int_osenvironKeyError
ValueError_prog_indent_increment_max_help_positionminmax_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*   __init__   s&    
zHelpFormatter.__init__c             C   s"   |  j | j7  _ |  jd7  _d S )N   )rD   r?   rE   )r"   r)   r)   r*   _indent   s    zHelpFormatter._indentc             C   s"   |  j | j8  _ |  jd8  _d S )NrT   )rD   r?   rE   )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headingr.   )r"   rW   rX   rY   r)   r)   r*   rS      s    zHelpFormatter._Section.__init__c             C   s   | j d k	r| j  | jj}|dd | jD }| j d k	rD| j  |sLdS | jtk	rz| jd k	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>   s    z6HelpFormatter._Section.format_help.<locals>.<listcomp> z%*s%s:

)	rX   rW   rU   _join_partsr.   rV   rY   r   rD   )r"   r!   	item_helpcurrent_indentrY   r)   r)   r*   format_help   s    



z"HelpFormatter._Section.format_help)N)r   r/   r0   rS   rc   r)   r)   r)   r*   rG      s   
rG   c             C   s   | j j||f d S )N)rI   r.   r   )r"   r[   r\   r)   r)   r*   	_add_item   s    zHelpFormatter._add_itemc             C   s0   |    | | | j|}| |jg  || _d S )N)rU   rG   rI   rd   rc   )r"   rY   sectionr)   r)   r*   start_section   s    zHelpFormatter.start_sectionc             C   s   | j j| _ |   d S )N)rI   rX   rV   )r"   r)   r)   r*   end_section   s    
zHelpFormatter.end_sectionc             C   s$   |t k	r |d k	r | | j|g d S )N)r   rd   _format_text)r"   textr)   r)   r*   add_text   s    zHelpFormatter.add_textc             C   s&   |t k	r"||||f}| | j| d S )N)r   rd   _format_usage)r"   usageactionsgroupsprefixr\   r)   r)   r*   	add_usage   s    zHelpFormatter.add_usagec             C   sz   |j tk	rv| j}||g}x | |D ]}||| q&W tdd |D }|| j }t| j|| _| | j	|g d S )Nc             S   s   g | ]}t |qS r)   )len)rZ   sr)   r)   r*   r]     s    z.HelpFormatter.add_argument.<locals>.<listcomp>)
helpr   _format_action_invocation_iter_indented_subactionsr   rB   rD   rF   rd   _format_action)r"   actionget_invocationinvocations	subactioninvocation_lengthaction_lengthr)   r)   r*   add_argument  s    


zHelpFormatter.add_argumentc             C   s   x|D ]}|  | qW d S )N)r}   )r"   rm   rw   r)   r)   r*   add_arguments  s    
zHelpFormatter.add_argumentsc             C   s.   | j  }|r*| jd|}|dd }|S )Nz

r_   )rH   rc   rN   substrip)r"   rs   r)   r)   r*   rc     s
    
zHelpFormatter.format_helpc             C   s   d dd |D S )Nr^   c             S   s   g | ]}|r|t k	r|qS r)   )r   )rZ   partr)   r)   r*   r]   #  s   z-HelpFormatter._join_parts.<locals>.<listcomp>)r!   )r"   part_stringsr)   r)   r*   r`   "  s    
zHelpFormatter._join_partsc                s  |d krt d}|d k	r,|t| jd }n|d krL|sLdt| jd }n|d krdt| jd }g }g }x(|D ] }|jr|| qt|| qtW | j}	|	|| |}
ddd ||
g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: )rO   z%(prog)s c             S   s   g | ]}|r|qS r)   r)   )rZ   rr   r)   r)   r*   r]   C  s    z/HelpFormatter._format_usage.<locals>.<listcomp>z%\(.*?\)+(?=\s|$)|\[.*?\]+(?=\s|$)|\S+c                s   g }g }|d k	rt |d }nt |d }xb| D ]Z}|d t |  krp|rp||d|  g }t |d }|| |t |d 7 }q0W |r||d|  |d k	r|d t |d  |d< |S )NrT   r   r   )rq   r   r!   )partsindentro   lineslineline_lenr   )
text_widthr)   r*   	get_linesW  s"    

z.HelpFormatter._format_usage.<locals>.get_linesg      ?rT   r_   z%s%s

)N)_dictr>   option_stringsr   _format_actions_usager!   rC   rD   rq   rJ   findallextend)r"   rl   rm   rn   ro   rO   	optionalspositionalsrw   formataction_usagepart_regexp	opt_usage	pos_usage	opt_parts	pos_partsr   r   r   r   r)   )r   r*   rk   '  sV    






zHelpFormatter._format_usagec          	   C   s  t  }i }x|D ]}y||jd }W n tk
r>   wY qX |t|j }||| |jkrx|jD ]}|| qhW |js||kr||  d7  < nd||< d||< n*||kr||  d7  < nd||< d||< xt|d |D ]}	d	||	< qW qW g }
x0t|D ]"\}	}|j	t
krj|
d  ||	d	krF||	 n"||	d d	kr,||	d  n|js| |}| ||}||kr|d dkr|d
 dkr|dd
 }|
| nf|jd }|jdkrd| }n"| |}| ||}d||f }|js"||kr"d| }|
| q
W x(t|ddD ]}	||	 g|
|	|	< q@W ddd |
D }d}d}td| d|}td| d|}td||f d|}tdd|}| }|S )Nr   z [[]z (()rT   |z%sz%s %sz[%s]T)reverser   c             S   s   g | ]}|d k	r|qS )Nr)   )rZ   itemr)   r)   r*   r]     s    z7HelpFormatter._format_actions_usage.<locals>.<listcomp>z[\[(]z[\])]z(%s) z\1z (%s)z%s *%sr^   z\(([^|]*)\))setindex_group_actionsr=   rq   addrequiredrange	enumeraters   r   r   getpopr   #_get_default_metavar_for_positional_format_argsnargs!_get_default_metavar_for_optionalr,   r!   rJ   r   r   )r"   rm   rn   group_actionsinsertsgroupstartendrw   ir   defaultr   option_stringargs_stringri   opencloser)   r)   r*   r     sr    







z#HelpFormatter._format_actions_usagec             C   sF   d|kr|t | jd }t| j| j d}d| j }| |||d S )Nz%(prog))rO      r   z

)r   r>   rB   rC   rD   
_fill_text)r"   ri   r   r   r)   r)   r*   rh     s
    
zHelpFormatter._format_textc             C   sB  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| 	|}	| 
|	|}
|d|d|
d f  x@|
dd  D ]}|d|d|f  qW n|ds|d x$| |D ]}|| | qW | |S )	Nr4   r   r^   z%*s%s
z	%*s%-*s  r   rT   r_   )rA   rF   r@   rB   rC   rD   rt   rs   rq   _expand_help_split_linesr   endswithru   rv   r`   )r"   rw   help_position
help_widthaction_widthaction_headertupindent_firstr   	help_text
help_linesr   rz   r)   r)   r*   rv     s6    




zHelpFormatter._format_actionc             C   s   |j s&| |}| ||d\}|S g }|jdkrB||j  n8| |}| ||}x |j D ]}|d||f  q`W d|S d S )NrT   r   z%s %sz, )	r   r   _metavar_formatterr   r   r   r   r   r!   )r"   rw   r   metavarr   r   r   r)   r)   r*   rt     s    


z'HelpFormatter._format_action_invocationc                sP   |j d k	r|j  n.|jd k	r<dd |jD }dd|  n|  fdd}|S )Nc             S   s   g | ]}t |qS r)   )str)rZ   choicer)   r)   r*   r]   :  s    z4HelpFormatter._metavar_formatter.<locals>.<listcomp>z{%s},c                s   t  tr S  f|  S d S )N)
isinstancetuple)
tuple_size)resultr)   r*   r   ?  s    
z0HelpFormatter._metavar_formatter.<locals>.format)r   choicesr!   )r"   rw   default_metavarchoice_strsr   r)   )r   r*   r   6  s    

z HelpFormatter._metavar_formatterc             C   s   |  ||}|jd kr$d|d }n|jtkr<d|d }n|jtkrTd|d }nx|jtkrld|d }n`|jtkr|d}nP|jtkrd|d }n8|jtkrd	}n(d
d t|jD }d	|||j }|S )Nz%srT   z[%s]z[%s [%s ...]]r4   z%s [%s ...]z...z%s ...r^   c             S   s   g | ]}d qS )z%sr)   )rZ   r   r)   r)   r*   r]   W  s    z.HelpFormatter._format_args.<locals>.<listcomp>r   )
r   r   r   r   r   r   r   r   r   r!   )r"   rw   r   get_metavarr   formatsr)   r)   r*   r   F  s$    






zHelpFormatter._format_argsc             C   s   t t|| jd}x"t|D ]}|| tkr||= qW x,t|D ] }t|| dr@|| j||< q@W |dd k	rddd |d D }||d< | 	|| S )N)rO   r   r   z, c             S   s   g | ]}t |qS r)   )r   )rZ   cr)   r)   r*   r]   d  s    z.HelpFormatter._expand_help.<locals>.<listcomp>)
r   varsr>   r1   r   hasattrr   r   r!   _get_help_string)r"   rw   paramsr'   choices_strr)   r)   r*   r   [  s    
zHelpFormatter._expand_helpc             c   s@   y
|j }W n tk
r   Y nX |   | E d H  |   d S )N)_get_subactionsAttributeErrorrU   rV   )r"   rw   get_subactionsr)   r)   r*   ru   h  s    
z'HelpFormatter._iter_indented_subactionsc             C   s&   | j d| }dd l}|||S )Nr   r   )rM   r   r   textwrapwrap)r"   ri   rR   r   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)rM   r   r   r   fill)r"   ri   rR   r   r   r)   r)   r*   r   y  s
    zHelpFormatter._fill_textc             C   s   |j S )N)rs   )r"   rw   r)   r)   r*   r     s    zHelpFormatter._get_help_stringc             C   s
   |j  S )N)destupper)r"   rw   r)   r)   r*   r     s    z/HelpFormatter._get_default_metavar_for_optionalc             C   s   |j S )N)r   )r"   rw   r)   r)   r*   r     s    z1HelpFormatter._get_default_metavar_for_positional)r4   r5   N)N)r   r/   r0   rS   rU   rV   objectrG   rd   rf   rg   rj   rp   r}   r~   rc   r`   rk   r   rh   rv   rt   r   r   r   ru   r   r   r   r   r   r)   r)   r)   r*   r      s:   	  

`a/
c               @   s   e Zd Zdd ZdS )r   c                s    d  fdd|jddD S )Nr^   c             3   s   | ]} | V  qd S )Nr)   )rZ   r   )r   r)   r*   	<genexpr>  s    z9RawDescriptionHelpFormatter._fill_text.<locals>.<genexpr>T)keepends)r!   
splitlines)r"   ri   rR   r   r)   )r   r*   r     s    z&RawDescriptionHelpFormatter._fill_textN)r   r/   r0   r   r)   r)   r)   r*   r     s   c               @   s   e Zd Zdd ZdS )r   c             C   s   |  S )N)r   )r"   ri   rR   r)   r)   r*   r     s    z!RawTextHelpFormatter._split_linesN)r   r/   r0   r   r)   r)   r)   r*   r     s   c               @   s   e Zd Zdd ZdS )r   c             C   s>   |j }d|j kr:|jtk	r:ttg}|js2|j|kr:|d7 }|S )Nz
%(default)z (default: %(default)s))rs   r   r   r   r   r   r   )r"   rw   rs   defaulting_nargsr)   r)   r*   r     s    

z.ArgumentDefaultsHelpFormatter._get_help_stringN)r   r/   r0   r   r)   r)   r)   r*   r     s   c               @   s   e Zd Zdd Zdd ZdS )r	   c             C   s   |j jS )N)r   r   )r"   rw   r)   r)   r*   r     s    z:MetavarTypeHelpFormatter._get_default_metavar_for_optionalc             C   s   |j jS )N)r   r   )r"   rw   r)   r)   r*   r     s    z<MetavarTypeHelpFormatter._get_default_metavar_for_positionalN)r   r/   r0   r   r   r)   r)   r)   r*   r	     s   c             C   sN   | d krd S | j rd| j S | jd tfkr2| jS | jd tfkrF| jS d S d S )N/)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 )N)r   argument_namemessage)r"   r   r   r)   r)   r*   rS     s    
zArgumentError.__init__c             C   s(   | j d k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   r/   r0   rS   r   r)   r)   r)   r*   r     s   c               @   s   e Zd ZdS )r   N)r   r/   r0   r)   r)   r)   r*   r     s   c               @   s(   e Zd Zd	ddZdd Zd
ddZdS )r   NFc             C   s@   || _ || _|| _|| _|| _|| _|| _|| _|	| _|
| _	d S )N)
r   r   r   constr   r   r   r   rs   r   )r"   r   r   r   r   r   r   r   r   rs   r   r)   r)   r*   rS   "  s    zAction.__init__c          	      s(   ddddddddd	g	} fd
d|D S )Nr   r   r   r   r   r   r   rs   r   c                s   g | ]}|t  |fqS r)   )getattr)rZ   r'   )r"   r)   r*   r]   D  s    z&Action._get_kwargs.<locals>.<listcomp>r)   )r"   namesr)   )r"   r*   r   8  s    zAction._get_kwargsc             C   s   t tdd S )Nz.__call__() not defined)NotImplementedErrorr   )r"   parser	namespacevaluesr   r)   r)   r*   __call__F  s    zAction.__call__)NNNNNFNN)N)r   r/   r0   rS   r   r   r)   r)   r)   r*   r     s   6       
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 k	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 appropriatez nargs must be %r to supply const)
r   r   r   r   r   r   r   r   rs   r   )r=   r   superr   rS   )r"   r   r   r   r   r   r   r   r   rs   r   )	__class__r)   r*   rS   L  s    
z_StoreAction.__init__c             C   s   t || j| d S )N)setattrr   )r"   r   r   r   r   r)   r)   r*   r   i  s    z_StoreAction.__call__)NNNNNFNN)N)r   r/   r0   rS   r   __classcell__r)   r)   )r   r*   r   J  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   rs   )r   r   rS   )r"   r   r   r   r   r   rs   r   )r   r)   r*   rS   o  s    
z_StoreConstAction.__init__c             C   s   t || j| j d S )N)r   r   r   )r"   r   r   r   r   r)   r)   r*   r     s    z_StoreConstAction.__call__)NFNN)N)r   r/   r0   rS   r   r   r)   r)   )r   r*   r   m  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   rs   )r   r   rS   )r"   r   r   r   r   rs   )r   r)   r*   rS     s    
z_StoreTrueAction.__init__)FFN)r   r/   r0   rS   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 )NF)r   r   r   r   r   rs   )r   r   rS   )r"   r   r   r   r   rs   )r   r)   r*   rS     s    
z_StoreFalseAction.__init__)TFN)r   r/   r0   rS   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 )	_AppendActionNFc                sT   |dkrt d|d k	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 appropriatez nargs must be %r to supply const)
r   r   r   r   r   r   r   r   rs   r   )r=   r   r   r   rS   )r"   r   r   r   r   r   r   r   r   rs   r   )r   r)   r*   rS     s    
z_AppendAction.__init__c             C   s2   t || jd }t|}|| t|| j| d S )N)r   r   r3   r   r   )r"   r   r   r   r   r.   r)   r)   r*   r     s    
z_AppendAction.__call__)NNNNNFNN)N)r   r/   r0   rS   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 )	_AppendConstActionNFc          
      s$   t t| j||d|||||d d S )Nr   )r   r   r   r   r   r   rs   r   )r   r  rS   )r"   r   r   r   r   r   rs   r   )r   r)   r*   rS     s    
z_AppendConstAction.__init__c             C   s4   t || jd }t|}|| j t|| j| d S )N)r   r   r3   r   r   r   )r"   r   r   r   r   r.   r)   r)   r*   r     s    z_AppendConstAction.__call__)NFNN)N)r   r/   r0   rS   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 )	_CountActionNFc                s    t t| j||d|||d d S )Nr   )r   r   r   r   r   rs   )r   r  rS   )r"   r   r   r   r   rs   )r   r)   r*   rS     s    
z_CountAction.__init__c             C   s0   t || jd }|d krd}t|| j|d  d S )Nr   rT   )r   r   r   )r"   r   r   r   r   countr)   r)   r*   r     s    z_CountAction.__call__)NFN)N)r   r/   r0   rS   r   r   r)   r)   )r   r*   r    s     	r  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   rs   )r   r  rS   )r"   r   r   r   rs   )r   r)   r*   rS      s    
z_HelpAction.__init__c             C   s   |   |  d S )N)
print_helpexit)r"   r   r   r   r   r)   r)   r*   r     s    z_HelpAction.__call__)N)r   r/   r0   r   rS   r   r   r)   r)   )r   r*   r    s   r  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 )Nr   )r   r   r   r   rs   )r   r  rS   version)r"   r   r  r   r   rs   )r   r)   r*   rS     s    
z_VersionAction.__init__c             C   sD   | j }|d kr|j }| }|| || tj |  d S )N)r  _get_formatterrj   _print_messagerc   _sysstdoutr  )r"   r   r   r   r   r  rW   r)   r)   r*   r   !  s    
z_VersionAction.__call__)N)r   r/   r0   r   rS   r   r   r)   r)   )r   r*   r    s
   	r  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 )Nz (%s)z, )r   r   rs   r   )r!   r   r  _ChoicesPseudoActionrS   )r"   r'   aliasesrs   r   r   sup)r   r)   r*   rS   /  s    
z/_SubParsersAction._ChoicesPseudoAction.__init__)r   r/   r0   rS   r   r)   r)   )r   r*   r  -  s   r  FNc          	      s<   || _ || _i | _g | _tt| j||t| j|||d d S )N)r   r   r   r   r   rs   r   )_prog_prefix_parser_class_name_parser_map_choices_actionsr   r  rS   r   )r"   r   rO   parser_classr   r   rs   r   )r   r)   r*   rS   7  s    	
z_SubParsersAction.__init__c             K   s   | dd kr d| j|f |d< |dd}d|krX|d}| |||}| j| | jf |}|| j|< x|D ]}|| j|< qtW |S )NrO   z%s %sr  r)   rs   )r   r  r   r  r  r   r  r  )r"   r'   kwargsr  rs   choice_actionr   aliasr)   r)   r*   
add_parserN  s    


z_SubParsersAction.add_parserc             C   s   | j S )N)r  )r"   r)   r)   r*   r   e  s    z!_SubParsersAction._get_subactionsc             C   s   |d }|dd  }| j tk	r,t|| j | y| j| }W n< tk
rv   |d| jd}td| }t| |Y nX ||d \}	}x$t	|	
 D ]\}
}t||
| qW |rt	|tg  t|t| d S )Nr   rT   z, )parser_namer   z5unknown parser %(parser_name)r (choices: %(choices)s))r   r   r   r  r<   r!   r   r   parse_known_argsr   r.   
setdefault_UNRECOGNIZED_ARGS_ATTRr   r   )r"   r   r   r   r   r  r$   r\   msgsubnamespacekeyr(   r)   r)   r*   r   h  s"    
	z_SubParsersAction.__call__)N)r   r/   r0   r   r  r   rS   r  r   r   r   r)   r)   )r   r*   r  +  s   r  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 )N)_mode_bufsize	_encoding_errors)r"   modebufsizeencodingerrorsr)   r)   r*   rS     s    zFileType.__init__c          
   C   s   |dkr>d| j krtjS d| j kr(tjS td| j  }t|yt|| j | j| j| j	S  t
k
r } ztd}t|||f W d d }~X Y nX d S )N-r!  wzargument "-" with mode %rzcan't open '%s': %s)r"  r  stdinr  r   r=   r   r#  r$  r%  OSErrorr   )r"   stringr  er   r)   r)   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)  z, c             S   s   g | ]}|d krt |qS )r   )r   )rZ   r&   r)   r)   r*   r]     s    z%FileType.__repr__.<locals>.<listcomp>c             S   s$   g | ]\}}|d k	rd||f qS )Nz%s=%rr)   )rZ   kwr&   r)   r)   r*   r]     s    z%s(%s))r"  r#  r$  r%  r!   r   r   )r"   r\   r  args_strr)   r)   r*   r+     s
    zFileType.__repr__)r!  r   NN)r   r/   r0   rS   r   r+   r)   r)   r)   r*   r     s   
c               @   s$   e Zd Zdd Zdd Zdd ZdS )r
   c             K   s"   x|D ]}t | |||  qW d S )N)r   )r"   r  r'   r)   r)   r*   rS     s    
zNamespace.__init__c             C   s   t |tstS t| t|kS )N)r   r
   NotImplementedr   )r"   otherr)   r)   r*   __eq__  s    
zNamespace.__eq__c             C   s
   || j kS )N)r-   )r"   r   r)   r)   r*   __contains__  s    zNamespace.__contains__N)r   r/   r0   rS   r4  r5  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  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 |   g | _i | _g | _g | _i | _td| _g | _d S )Nrw   storestore_const
store_truestore_falser   append_constr  rs   r  parsersz^-\d+$|^-\d*\.\d+$)r   r6  rS   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	_defaultsrJ   rK   _negative_number_matcher_has_negative_number_optionals)r"   r=  r?  r>  r@  )r   r)   r*   rS     s2    z_ActionsContainer.__init__c             C   s   | j |i }|||< d S )N)rA  r  )r"   registry_namer(   r   registryr)   r)   r*   rB    s    z_ActionsContainer.registerNc             C   s   | j | ||S )N)rA  r   )r"   rK  r(   r   r)   r)   r*   _registry_get  s    z_ActionsContainer._registry_getc             K   s6   | j | x$| jD ]}|j|kr||j |_qW d S )N)rH  updaterD  r   r   )r"   r  rw   r)   r)   r*   set_defaults  s    
z_ActionsContainer.set_defaultsc             C   s8   x(| j D ]}|j|kr|jd k	r|jS qW | j|d S )N)rD  r   r   rH  r   )r"   r   rw   r)   r)   r*   get_default   s    
z_ActionsContainer.get_defaultc             O   s.  | j }|r&t|dkrH|d d |krH|r:d|kr:td| j||}n| j||}d|kr|d }|| jkr~| j| |d< n| jd k	r| j|d< | |}t|std|f |f |}| 	d|j
|j
}t|std|f t| d	r$y|  |d  W n tk
r"   td
Y nX | |S )NrT   r   r   z+dest supplied twice for positional argumentr   zunknown action "%s"r   z%r is not callabler	  z,length of metavar tuple does not match nargs)r?  rq   r=   _get_positional_kwargs_get_optional_kwargsrH  r>  _pop_action_classcallablerM  r   r   r	  r   	TypeError_add_action)r"   r\   r  charsr   action_classrw   	type_funcr)   r)   r*   r}   *  s2    	 




z_ActionsContainer.add_argumentc             O   s    t | f||}| j| |S )N)_ArgumentGrouprF  r   )r"   r\   r  r   r)   r)   r*   add_argument_groupY  s    z$_ActionsContainer.add_argument_groupc             K   s   t | f|}| j| |S )N)_MutuallyExclusiveGrouprG  r   )r"   r  r   r)   r)   r*   add_mutually_exclusive_group^  s    z._ActionsContainer.add_mutually_exclusive_groupc             C   sh   |  | | j| | |_x|jD ]}|| j|< q$W x,|jD ]"}| j|r>| js>| jd q>W |S )NT)	_check_conflictrD  r   	containerr   rE  rI  matchrJ  )r"   rw   r   r)   r)   r*   rV  c  s    
z_ActionsContainer._add_actionc             C   s   | j | d S )N)rD  remove)r"   rw   r)   r)   r*   _remove_actionx  s    z _ActionsContainer._remove_actionc             C   s   i }x8| j D ].}|j|kr0td}t||j |||j< qW i }xR|j D ]H}|j|krt| j|j|j|jd||j< x|jD ]}||j ||< q|W qJW x4|jD ]*}| j	|j
d}x|jD ]}|||< qW qW x |jD ]}||| | qW d S )Nz.cannot merge actions - two groups are named %r)titler=  r@  )r   )rF  rc  r   r=   r[  r=  r@  r   rG  r]  r   rD  r   rV  )r"   r_  title_group_mapr   r  	group_maprw   mutex_groupr)   r)   r*   _add_container_actions{  s,    


z(_ActionsContainer._add_container_actionsc             K   s^   d|krt d}t||dttgkr2d|d< |dtkrPd|krPd|d< t||g dS )Nr   z1'required' is an invalid argument for positionalsr   Tr   )r   r   )r   rU  r   r   r   r   )r"   r   r  r  r)   r)   r*   rQ    s    z(_ActionsContainer._get_positional_kwargsc       	      O   s   g }g }xv|D ]n}|d | j kr@|| j d}td}t|| || |d | j krt|dkr|d | j kr|| qW |dd }|d kr|r|d }n|d }|| j }|std}t|| |dd}t|||d	S )
Nr   )optionr?  zNinvalid option string %(option)r: must start with a character %(prefix_chars)rrT   r   z%dest= is required for options like %rr*  r   )r   r   )	r?  r   r=   r   rq   r   lstripreplacer   )	r"   r\   r  r   long_option_stringsr   r  r   dest_option_stringr)   r)   r*   rR    s0    



z&_ActionsContainer._get_optional_kwargsc             C   s   | d|}| d||S )Nrw   )r   rM  )r"   r  r   rw   r)   r)   r*   rS    s    z#_ActionsContainer._pop_action_classc             C   sD   d| j  }y
t| |S  tk
r>   td}t|| j  Y nX d S )Nz_handle_conflict_%sz%invalid conflict_resolution value: %r)r@  r   r   r   r=   )r"   handler_func_namer  r)   r)   r*   rC    s    

z_ActionsContainer._get_handlerc             C   sP   g }x0|j D ]&}|| jkr| j| }|||f qW |rL|  }||| d S )N)r   rE  r   rC  )r"   rw   confl_optionalsr   confl_optionalr@  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: %sz, c             S   s   g | ]\}}|qS r)   r)   )rZ   r   rw   r)   r)   r*   r]     s   z<_ActionsContainer._handle_conflict_error.<locals>.<listcomp>)r   rq   r!   r   )r"   rw   conflicting_actionsr   conflict_stringr)   r)   r*   _handle_conflict_error  s    


z(_ActionsContainer._handle_conflict_errorc             C   sB   x<|D ]4\}}|j | | j|d  |j s|j| qW d S )N)r   ra  rE  r   r_  rb  )r"   rw   rp  r   r)   r)   r*   _handle_conflict_resolve  s
    z*_ActionsContainer._handle_conflict_resolve)N)N)r   r/   r0   rS   rB  rM  rO  rP  r}   r[  r]  rV  rb  rg  rQ  rR  rS  rC  r^  rr  rs  r   r)   r)   )r   r*   r6    s$   4
	
/($
		r6  c                   s6   e Zd Zd fdd	Z fddZ fddZ  ZS )	rZ  Nc                s   |j }|d|j |d|j |d|j tt| j}|f d|i| || _g | _|j	| _	|j
| _
|j| _|j| _|j| _|j| _d S )Nr@  r?  r>  r=  )r  r@  r?  r>  r   rZ  rS   rc  r   rA  rD  rE  rH  rJ  rG  )r"   r_  rc  r=  r  rN  
super_init)r   r)   r*   rS     s    z_ArgumentGroup.__init__c                s    t t| |}| j| |S )N)r   rZ  rV  r   r   )r"   rw   )r   r)   r*   rV  "  s    z_ArgumentGroup._add_actionc                s    t t| | | j| d S )N)r   rZ  rb  r   ra  )r"   rw   )r   r)   r*   rb  '  s    z_ArgumentGroup._remove_action)NN)r   r/   r0   rS   rV  rb  r   r)   r)   )r   r*   rZ  
  s   rZ  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 )N)r   r\  rS   r   
_container)r"   r_  r   )r   r)   r*   rS   .  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=   ru  rV  r   r   )r"   rw   r  r)   r)   r*   rV  3  s    z#_MutuallyExclusiveGroup._add_actionc             C   s   | j | | j| d S )N)ru  rb  r   ra  )r"   rw   r)   r)   r*   rb  ;  s    z&_MutuallyExclusiveGroup._remove_action)F)r   r/   r0   rS   rV  rb  r   r)   r)   )r   r*   r\  ,  s   r\  c                   s&  e Zd Zddddg e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*  errorTc          	      s&  t t| j}||||	|
d |d kr6tjtjd }|| _|| _	|| _
|| _|| _|| _|| _| j}|td| _|td| _d | _dd }| dd | d|krdn|d }| jr| j|d	 |d
 d dttdd xD|D ]<}| | y
|j}W n tk
r   Y qX | j| qW d S )N)r=  r?  r>  r@  r   zpositional argumentszoptional argumentsc             S   s   | S )Nr)   )r.  r)   r)   r*   identityy  s    z)ArgumentParser.__init__.<locals>.identityr   r*  hr4   rs   zshow this help message and exit)rw   r   rs   )r   r   rS   r:   pathbasenamer  argvrO   rl   epilogformatter_classfromfile_prefix_charsadd_helpallow_abbrevr[  r   _positionals
_optionals_subparsersrB  r}   r   rg  rH  r   rN  )r"   rO   rl   r=  r|  parentsr}  r?  r~  r>  r@  r  r  	superinit	add_grouprw  default_prefixrX   defaults)r   r)   r*   rS   S  sB    


zArgumentParser.__init__c                s"   ddddddg} fdd|D S )	NrO   rl   r=  r}  r@  r  c                s   g | ]}|t  |fqS r)   )r   )rZ   r'   )r"   r)   r*   r]     s    z.ArgumentParser._get_kwargs.<locals>.<listcomp>r)   )r"   r   r)   )r"   r*   r     s    zArgumentParser._get_kwargsc       	      K   s   | j d k	r| td |dt|  d|ks8d|krht|dd}t|dd }| ||| _ n| j| _ |dd kr| 	 }| 
 }| j}|| j||d |  |d< | |d}|f d	g i|}| j | |S )
Nz(cannot have multiple subparser argumentsr  rc  r=  subcommandsrO   r^   r<  r   )r  rv  r   r  r   r   r[  r  r   r	  _get_positional_actionsrG  rp   rl   rc   r   rS  rV  )	r"   r  rc  r=  rW   r   rn   parsers_classrw   r)   r)   r*   add_subparsers  s$    
zArgumentParser.add_subparsersc             C   s$   |j r| j| n| j| |S )N)r   r  rV  r  )r"   rw   r)   r)   r*   rV    s    zArgumentParser._add_actionc             C   s   dd | j D S )Nc             S   s   g | ]}|j r|qS r)   )r   )rZ   rw   r)   r)   r*   r]     s   z8ArgumentParser._get_optional_actions.<locals>.<listcomp>)rD  )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S r)   )r   )rZ   rw   r)   r)   r*   r]     s   z:ArgumentParser._get_positional_actions.<locals>.<listcomp>)rD  )r"   r)   r)   r*   r    s    z&ArgumentParser._get_positional_actionsc             C   s4   |  ||\}}|r0td}| |d|  |S )Nzunrecognized arguments: %sr   )r  r   rv  r!   )r"   r\   r   r{  r  r)   r)   r*   
parse_args  s
    zArgumentParser.parse_argsc             C   s  |d krt jdd  }nt|}|d kr.t }x>| jD ]4}|jtk	r6t||js6|jtk	r6t	||j|j q6W x*| j
D ] }t||svt	||| j
|  qvW y<| ||\}}t|tr|t|t t|t ||fS  tk
r   t  d }| t| Y nX d S )NrT   )r  r{  r1   r
   rD  r   r   r   r   r   rH  _parse_known_argsr  r   r   delattrr   exc_inforv  r   )r"   r\   r   rw   r   errr)   r)   r*   r    s,    




zArgumentParser.parse_known_argsc                s"  	j d k	r	i  x`	jD ]V}|j}xJt|jD ]<\}} |g }||d |  |||d d   q6W q W i g }t}	xnt|	D ]b\}}
|
dkr|d xF|	D ]}
|d qW q		|
}|d krd}n||< d}|| qW d
|t t d 	fdd		fd	d
}	 	fdd}g d
rpt}nd}x|
|krt
fddD }
|kr|
}|
kr|
qvn|

kr
| }| |
|

qvW |
}|d   g }x	jD ]|}|kr|jr>|t| nT|jd k	rt|jtrt|jr|jt|jkrt|j	||j qW |r	tdd
|  xb	jD ]X}|jrxH|jD ]}|krP qW dd |jD }td}	|d
|  qW fS )NrT   z--r*  AOr^   c                s    |  | |}|| jk	rf |  x: | g D ]*}|kr8td}t|}t| || q8W |tk	r|| || d S )Nznot allowed with argument %s)r   _get_valuesr   r   r   r   r   r   )rw   argument_stringsr   argument_valuesconflict_actionr  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 }x>|d kr> |   | d S |d k	r||d}j}|dkr|d |kr||g |f |d }	|	|d  }|dd  pd }
j}||kr|| }|
}ntd}t||| n@|dkr| d }|g}||||f P ntd}t||| q | d }|d  }|||}|| } || }||||f P q W x |D ]\}}}||| qdW |S )NrT   r  r   zignored explicit argument %r)_match_argumentr   r?  rE  r   r   )start_indexoption_tuplerw   r   explicit_argmatch_argumentaction_tuples	arg_countrW  charnew_explicit_argoptionals_mapr  stopr\   r   selected_patterns)r$   arg_strings_patternextrasoption_string_indicesr"   r  r)   r*   consume_optionalB  sN    



z:ArgumentParser._parse_known_args.<locals>.consume_optionalc                sr   j }| d  }||}x8t|D ]*\}} | | |  }| |7 } || q(W t|d  d d < | S )N)_match_arguments_partialziprq   )r  match_partialselected_pattern
arg_countsrw   r  r\   )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)   )rZ   r   )r  r)   r*   r]     s   z4ArgumentParser._parse_known_args.<locals>.<listcomp>z(the following arguments are required: %sz, c             S   s   g | ]}|j tk	rt|qS r)   )rs   r   r   )rZ   rw   r)   r)   r*   r]     s   z#one of the arguments %s is requiredr   )N)r~  _read_args_from_filesrG  r   r   r  r   iterr   _parse_optionalr!   r   r  rB   rA   rD  r   r   r   r   r   r   r   r   r   
_get_valuerv  r   )r"   r$   r   rf  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_actionsrw   r   r   r  r)   )r  r$   r  r  r   r  r   r  r  r"   r  r  r*   r    s    





J










z ArgumentParser._parse_known_argsc          
   C   s   g }x|D ]}|r |d | j kr,|| q
ylt|dd  R}g }x2|  D ]"}x| |D ]}|| qbW qRW | |}|| W d Q R X W q
 tk
r   t	
 d }| t| Y q
X q
W |S )Nr   rT   )r~  r   r   readr   convert_arg_line_to_argsr  r   r-  r  r  rv  r   )r"   r$   new_arg_stringsr  	args_filearg_liner&   r  r)   r)   r*   r    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   st   |  |}t||}|d krfd tdttdttdi}tdd|j|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 argumentsrT   )_get_nargs_patternrJ   r`  r   r   r   r   r   r   r   rq   r   )r"   rw   r  nargs_patternr`  nargs_errorsr   r  r)   r)   r*   r    s    

zArgumentParser._match_argumentc                st   g }xjt t|ddD ]V}|d | }d fdd|D }t||}|d k	r|dd | D  P qW |S )Nr   r   r^   c                s   g | ]}  |qS r)   )r  )rZ   rw   )r"   r)   r*   r]   ,  s   z;ArgumentParser._match_arguments_partial.<locals>.<listcomp>c             S   s   g | ]}t |qS r)   )rq   )rZ   r.  r)   r)   r*   r]   0  s    )r   rq   r!   rJ   r`  r   rn   )r"   rm   r  r   r   actions_slicer  r`  r)   )r"   r*   r  &  s    
z'ArgumentParser._match_arguments_partialc       
      C   s  |sd S |d | j krd S || jkr8| j| }||d fS t|dkrHd S d|kr~|dd\}}|| jkr~| j| }|||fS | jr| |}t|dkrddd |D }||d}td}| ||  nt|dkr|\}	|	S | j	
|r| jsd S d	|kr
d S d |d fS )
Nr   rT   =z, c             S   s   g | ]\}}}|qS r)   r)   )rZ   rw   r   r  r)   r)   r*   r]   V  s   z2ArgumentParser._parse_optional.<locals>.<listcomp>)rh  matchesz4ambiguous option: %(option)s could match %(matches)sr   )r?  rE  rq   splitr  _get_option_tuplesr!   r   rv  rI  r`  rJ  )
r"   r  rw   r   r  option_tuplesoptionsr\   r  r  r)   r)   r*   r  6  s>    










zArgumentParser._parse_optionalc       
      C   s2  g }| j }|d |kr~|d |kr~d|kr<|dd\}}n|}d }x| jD ],}||rL| j| }|||f}|| qLW n|d |kr|d |kr|}d }|d d }|dd  }	xr| jD ]T}||kr| j| }|||	f}|| q||r| j| }|||f}|| qW n| td|  |S )Nr   rT   r  r4   zunexpected option string: %s)r?  r  rE  
startswithr   rv  r   )
r"   r   r   rW  option_prefixr  rw   r   short_option_prefixshort_explicit_argr)   r)   r*   r  q  s8    







z!ArgumentParser._get_option_tuplesc             C   s   |j }|d k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  r^   r*  )
r   r   r   r   r   r   r   r!   r   rj  )r"   rw   r   r  r)   r)   r*   r    s(    z!ArgumentParser._get_nargs_patternc             C   s4   |  ||\}}|r0td}| |d|  |S )Nzunrecognized arguments: %sr   )parse_known_intermixed_argsr   rv  r!   )r"   r\   r   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zl| j}z| jd krp|  dd  | _x( D ] }|j|_t|_|j|_	t|_qvW | 
||\}}xR D ]J}t||jrt||jg krddlm} |d	|j|f  t||j qW W d x D ]}|j|_|j	|_qW X |  }zRx|D ]}|j|_d
|_q4W x| jD ]}	|	j|	_d
|	_qTW | 
||\}}
W d x|D ]}|j|_qW x| jD ]}	|	j|	_qW X W d || _X ||
fS )Nc             S   s   g | ]}|j ttgkr|qS r)   )r   r   r   )rZ   rw   r)   r)   r*   r]     s    z>ArgumentParser.parse_known_intermixed_args.<locals>.<listcomp>z3parse_intermixed_args: positional arg with nargs=%sr   c                s&   g | ]}|j D ]}| kr|jqqS r)   )r   r   )rZ   r   rw   )r   r)   r*   r]     s    z;parse_intermixed_args: positional in mutuallyExclusiveGroup   )warnzDo not expect %s in %sF)r  rU  r   rG  rl   format_usage
save_nargsr   r   save_defaultr  r   r   r   warningsr  r  r  r   save_required)r"   r\   r   a
save_usagerw   remaining_argsr  r   r   r  r)   )r   r*   r    sX    







z*ArgumentParser.parse_known_intermixed_argsc                s   j ttgkr2y|d W n tk
r0   Y nX |sz j tkrz jrN j}n j}t	|t
rv |} | n|s j tkr js jd k	r j}n|} | nt|dkr j d tgkr|\} |} | n j tkr fdd|D }nt j tkr@ fdd|D } |d  nB j tkrRt}n0 fdd|D }x|D ]} | qlW |S )Nz--rT   c                s   g | ]}  |qS r)   )r  )rZ   v)rw   r"   r)   r*   r]   F	  s    z.ArgumentParser._get_values.<locals>.<listcomp>c                s   g | ]}  |qS r)   )r  )rZ   r  )rw   r"   r)   r*   r]   J	  s    r   c                s   g | ]}  |qS r)   )r  )rZ   r  )rw   r"   r)   r*   r]   S	  s    )r   r   r   ra  r=   r   r   r   r   r   r   r  _check_valuer   rq   r   )r"   rw   r$   r(   r  r  r)   )rw   r"   r*   r  "	  sB    


zArgumentParser._get_valuesc          	   C   s   |  d|j|j}t|s0td}t||| y||}W n tk
r~   t|jdt|j}tt	
 d }t||Y nL ttfk
r   t|jdt|j}||d}td}t||| Y nX |S )Nr   z%r is not callabler   rT   )r   r(   z!invalid %(type)s value: %(value)r)rM  r   rT  r   r   r   r   r   r   r  r  rU  r=   )r"   rw   r  rY  r  r   r'   r\   r)   r)   r*   r  Z	  s     
zArgumentParser._get_valuec             C   sF   |j d k	rB||j krB|dtt|j d}td}t||| d S )Nz, )r(   r   z3invalid choice: %(value)r (choose from %(choices)s))r   r!   mapr   r   r   )r"   rw   r(   r\   r  r)   r)   r*   r  t	  s
    zArgumentParser._check_valuec             C   s$   |   }|| j| j| j | S )N)r	  rp   rl   rD  rG  rc   )r"   rW   r)   r)   r*   r  	  s    zArgumentParser.format_usagec             C   sx   |   }|| j| j| j || j x:| jD ]0}||j	 ||j |
|j |  q0W || j | S )N)r	  rp   rl   rD  rG  rj   r=  rF  rf   rc  r~   r   rg   r|  rc   )r"   rW   action_groupr)   r)   r*   rc   	  s    zArgumentParser.format_helpc             C   s   | j | jdS )N)rO   )r}  rO   )r"   r)   r)   r*   r	  	  s    zArgumentParser._get_formatterc             C   s"   |d krt j}| |  | d S )N)r  r  r
  r  )r"   filer)   r)   r*   print_usage	  s    zArgumentParser.print_usagec             C   s"   |d krt j}| |  | d S )N)r  r  r
  rc   )r"   r  r)   r)   r*   r  	  s    zArgumentParser.print_helpc             C   s    |r|d krt j}|| d S )N)r  stderrwrite)r"   r   r  r)   r)   r*   r
  	  s    zArgumentParser._print_messager   c             C   s    |r|  |tj t| d S )N)r
  r  r  r  )r"   statusr   r)   r)   r*   r  	  s    zArgumentParser.exitc             C   s0   |  tj | j|d}| dtd|  d S )N)rO   r   r4   z%(prog)s: error: %(message)s
)r  r  r  rO   r  r   )r"   r   r\   r)   r)   r*   rv  	  s    	zArgumentParser.error)NN)NN)NN)NN)N)N)N)r   N)"r   r/   r0   r   rS   r   r  rV  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rc   r	  r  r  r
  r  rv  r   r)   r)   )r   r*   r   @  sR   4

# w;,1

M8


	
)/__version____all__osr:   rerJ   sysr  r   r   r   r   r   r   r   r   r   r  r   r   r3   r   r   r   r   r	   r   	Exceptionr   r   r   r   r   r   r   r   r  r  r  r  r  r   r
   r6  rZ  r\  r   r)   r)   r)   r*   <module>@   sx      u	[#&b6  5"