Your IP : 3.15.202.169


Current Path : /opt/alt/python35/lib64/python3.5/__pycache__/
Upload File :
Current File : //opt/alt/python35/lib64/python3.5/__pycache__/argparse.cpython-35.opt-2.pyc



���]`�@sdZddddddddd	d
ddd
ddddgZddlZddlZddlZddlZ	ddl
ZddlZ
ddlmZmZdZdZdZdZdZdZdZGdd�de�Zdd�ZGd d�de�ZGd!d�de�ZGd"d�de�ZGd#d�de�ZGd$d	�d	e�Zd%d&�Z Gd'd�de!�Z"Gd(d�de!�Z#Gd)d�de�Z$Gd*d+�d+e$�Z%Gd,d-�d-e$�Z&Gd.d/�d/e&�Z'Gd0d1�d1e&�Z(Gd2d3�d3e$�Z)Gd4d5�d5e$�Z*Gd6d7�d7e$�Z+Gd8d9�d9e$�Z,Gd:d;�d;e$�Z-Gd<d=�d=e$�Z.Gd>d�de�Z/Gd?d
�d
e�Z0Gd@dA�dAe�Z1GdBdC�dCe1�Z2GdDdE�dEe2�Z3GdFd�dee1�Z4dS)Gz1.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==�?�*�+zA...z...�_unrecognized_argsc@s4eZdZdd�Zdd�Zdd�ZdS)�_AttributeHoldercCs�t|�j}g}x'|j�D]}|jt|��q"Wx1|j�D]#\}}|jd||f�qLWd|dj|�fS)Nz%s=%rz%s(%s)z, )�type�__name__�	_get_args�append�repr�_get_kwargs�join)�self�	type_name�arg_strings�arg�name�value�r'�-/opt/alt/python35/lib64/python3.5/argparse.py�__repr__vsz_AttributeHolder.__repr__cCst|jj��S)N)�sorted�__dict__�items)r!r'r'r(rsz_AttributeHolder._get_kwargscCsgS)Nr')r!r'r'r(r�sz_AttributeHolder._get_argsN)r�
__module__�__qualname__r)rrr'r'r'r(rms		rcCs5t||d�dkr(t|||�t||�S)N)�getattr�setattr)�	namespacer%r&r'r'r(�
_ensure_value�sr2c@sjeZdZddddd�Zdd�Zdd	�ZGd
d�de�Zdd
�Zdd�Z	dd�Z
dd�Zddd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zd d!�Zd"d#�Zd$d%�Zd&d'�Zd(d)�Zd*d+�Zd,d-�Zd.d/�Zd0d1�Zd2d3�Zd4d5�Zd6d7�Zd8d9�ZdS):r��NcCs�|dkrNyttjd�}Wnttfk
rCd}YnX|d8}||_||_||_t|t	|d|d��|_||_
d|_d|_d|_
|j|d�|_|j|_tjdtj�|_tjd�|_dS)N�COLUMNS�Pr3�rz\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&
							zHelpFormatter.__init__cCs%|j|j7_|jd7_dS)N�)rCr>rD)r!r'r'r(�_indent�szHelpFormatter._indentcCs%|j|j8_|jd8_dS)NrS)rCr>rD)r!r'r'r(�_dedent�szHelpFormatter._dedentc@s+eZdZddd�Zdd�ZdS)zHelpFormatter._SectionNcCs(||_||_||_g|_dS)N)�	formatter�parent�headingr,)r!rVrWrXr'r'r(rR�s			zHelpFormatter._Section.__init__cCs�|jdk	r|jj�|jj}x!|jD]\}}||�q2W|dd�|jD��}|jdk	r�|jj�|s�dS|jtk	r�|jdk	r�|jj}d|d|jf}nd}|d||dg�S)NcSs"g|]\}}||��qSr'r')�.0�func�argsr'r'r(�
<listcomp>�s	z6HelpFormatter._Section.format_help.<locals>.<listcomp>�z%*s%s:
�
)	rWrVrT�_join_partsr,rUrXrrC)r!r rZr[�	item_help�current_indentrXr'r'r(�format_help�s

z"HelpFormatter._Section.format_help)rr-r.rRrbr'r'r'r(rF�srFcCs|jjj||f�dS)N)rHr,r)r!rZr[r'r'r(�	_add_item�szHelpFormatter._add_itemcCsB|j�|j||j|�}|j|jg�||_dS)N)rTrFrHrcrb)r!rX�sectionr'r'r(�
start_section�s
zHelpFormatter.start_sectioncCs|jj|_|j�dS)N)rHrWrU)r!r'r'r(�end_section�szHelpFormatter.end_sectioncCs2|tk	r.|dk	r.|j|j|g�dS)N)rrc�_format_text)r!�textr'r'r(�add_text�szHelpFormatter.add_textcCs5|tk	r1||||f}|j|j|�dS)N)rrc�
_format_usage)r!�usage�actions�groups�prefixr[r'r'r(�	add_usage�szHelpFormatter.add_usagecCs�|jtk	r�|j}||�g}x*|j|�D]}|j||��q7Wtdd�|D��}||j}t|j|�|_|j|j	|g�dS)NcSsg|]}t|��qSr')�len)rY�sr'r'r(r\s	z.HelpFormatter.add_argument.<locals>.<listcomp>)
�helpr�_format_action_invocation�_iter_indented_subactionsrrArCrErc�_format_action)r!�action�get_invocation�invocations�	subaction�invocation_length�
action_lengthr'r'r(�add_argument�s	
	zHelpFormatter.add_argumentcCs"x|D]}|j|�qWdS)N)r|)r!rlrvr'r'r(�
add_argumentss
zHelpFormatter.add_argumentscCsA|jj�}|r=|jjd|�}|jd�d}|S)Nz

r^)rGrbrM�sub�strip)r!rrr'r'r(rbs
zHelpFormatter.format_helpcCsdjdd�|D��S)Nr]cSs(g|]}|r|tk	r|�qSr')r)rY�partr'r'r(r\s	z-HelpFormatter._join_parts.<locals>.<listcomp>)r )r!�part_stringsr'r'r(r_szHelpFormatter._join_partscs�|dkrtd�}|dk	r=|td|j�}n�|dkri|ridtd|j�}nY|dkr�dtd|j�}g}g}x4|D],}|jr�|j|�q�|j|�q�W|j}	|	|||�}
djdd�||
gD��}|j|j�t	|�t	|��kr�d}|	||�}|	||�}
t
j||�}t
j||
�}d�fdd	�}t	|�t	|�d
�kr9dt	|�t	|�d}|r||g|||�}|j|||��q�|r-||g|||�}q�|g}nzdt	|�}||}|||�}t	|�dkr�g}|j|||��|j|||��|g|}dj|�}d
||fS)Nzusage: rNz%(prog)s� cSsg|]}|r|�qSr'r')rYrqr'r'r(r\=s	z/HelpFormatter._format_usage.<locals>.<listcomp>z\(.*?\)+|\[.*?\]+|\S+csg}g}|dk	r+t|�d}nt|�d}x|D]w}|dt|��kr�|r�|j|dj|��g}t|�d}|j|�|t|�d7}qBW|r�|j|dj|��|dk	r|dt|�d�|d<|S)NrSr�r)rprr )�parts�indentrn�lines�line�line_lenr�)�
text_widthr'r(�	get_linesMs"
 
z.HelpFormatter._format_usage.<locals>.get_linesg�?rSr^z%s%s

)
�_�dictr=�option_stringsr�_format_actions_usager rBrCrprI�findall�extend)r!rkrlrmrnrN�	optionals�positionalsrv�format�action_usage�part_regexp�	opt_usage�	pos_usage�	opt_parts�	pos_partsr�r�r�r�r')r�r(rj!sV
		" 

zHelpFormatter._format_usagec
Cs�t�}i}x#|D]}y|j|jd�}Wntk
rMwYqX|t|j�}|||�|jkrx|jD]}|j|�q�W|js�||kr�||d7<n
d||<d||<n1||kr�||d7<n
d||<d||<x%t|d|�D]}	d	||	<qWqWg}
x�t|�D]w\}	}|j	t
kr�|
jd�|j|	�d	kr�|j
|	�q�|j|	d�d	kr�|j
|	d�qH|js8|j|�}|j||�}||kr(|ddkr(|ddkr(|dd�}|
j|�qH|jd}
|jdkrad
|
}n1|j|�}|j||�}d|
|f}|jr�||kr�d|}|
j|�qHWx1t|d
d�D]}	||	g|
|	|	�<q�Wdjdd�|
D��}d}d}tjd|d|�}tjd|d|�}tjd||fd|�}tjdd|�}|j�}|S)Nrz [�[�]z (�(�)rS�|z%sz%s %sz[%s]�reverseTr�cSs"g|]}|dk	r|�qS)Nr')rY�itemr'r'r(r\�s	z7HelpFormatter._format_actions_usage.<locals>.<listcomp>z[\[(]z[\])]z(%s) z\1z (%s)z%s *%sr]z\(([^|]*)\)���r�)�set�index�_group_actionsr<rp�add�required�range�	enumeraterrrr�get�popr��#_get_default_metavar_for_positional�_format_args�nargs�!_get_default_metavar_for_optionalr*r rIr~r)r!rlrm�
group_actions�inserts�group�start�endrv�ir��defaultr��
option_string�args_stringrh�open�closer'r'r(r�}sr	

	




	 


z#HelpFormatter._format_actions_usagecCs_d|kr"|td|j�}t|j|jd�}d|j}|j|||�dS)Nz%(prog)rN�r�z

)r�r=rArBrC�
_fill_text)r!rhr�r�r'r'r(rg�s

zHelpFormatter._format_textc
Cs�t|jd|j�}t|j|d�}||jd}|j|�}|jsw|jd|f}d|}n\t|�|kr�|jd||f}d|}d}n"|jd|f}d|}|}|g}|jr\|j	|�}	|j
|	|�}
|jd|d|
df�xQ|
dd�D] }|jd|d|f�q5Wn|jd�sx|jd�x-|j
|�D]}|j|j|��q�W|j|�S)	Nr3r�r]z%*s%s
z	%*s%-*s  rrSr^)r@rEr?rArBrCrsrrrp�_expand_help�_split_linesr�endswithrtrur_)
r!rv�
help_position�
help_width�action_width�
action_header�tup�indent_firstr��	help_text�
help_linesr�ryr'r'r(ru�s6
	

	
		!
zHelpFormatter._format_actioncCs�|js7|j|�}|j||�d�\}|Sg}|jdkr_|j|j�nL|j|�}|j||�}x(|jD]}|jd||f�q�Wdj|�SdS)NrSrz%s %sz, )	r�r��_metavar_formatterr�r�r�r�rr )r!rvr��metavarr�r�r�r'r'r(rss	z'HelpFormatter._format_action_invocationcsr|jdk	r|j�nA|jdk	rVdd�|jD�}ddj|��n|��fdd�}|S)NcSsg|]}t|��qSr')�str)rY�choicer'r'r(r\0s	z4HelpFormatter._metavar_formatter.<locals>.<listcomp>z{%s}�,cs"t�t�r�S�f|SdS)N)�
isinstance�tuple)�
tuple_size)�resultr'r(r�5sz0HelpFormatter._metavar_formatter.<locals>.format)r��choicesr )r!rv�default_metavar�choice_strsr�r')r�r(r�,sz HelpFormatter._metavar_formattercCs|j||�}|jdkr4d|d�}n�|jtkrVd|d�}n�|jtkrxd|d�}n�|jtkr�d|d�}nr|jtkr�d}nZ|jtkr�d|d�}n8d	d
�t|j�D�}dj|�||j�}|S)Nz%srSz[%s]z
[%s [%s ...]]r3z%s [%s ...]z...z%s ...cSsg|]}d�qS)z%sr')rYr�r'r'r(r\Ks	z.HelpFormatter._format_args.<locals>.<listcomp>r�)	r�r�r
rrrrr�r )r!rvr��get_metavarr��formatsr'r'r(r�<s 	zHelpFormatter._format_argscCs�tt|�d|j�}x+t|�D]}||tkr(||=q(Wx8t|�D]*}t||d�rV||j||<qVW|jd�dk	r�djdd�|dD��}||d<|j	|�|S)NrNrr�z, cSsg|]}t|��qSr')r�)rY�cr'r'r(r\Xs	z.HelpFormatter._expand_help.<locals>.<listcomp>)
r��varsr=�listr�hasattrrr�r �_get_help_string)r!rv�paramsr%�choices_strr'r'r(r�Os 
zHelpFormatter._expand_helpccsFy
|j}Wntk
r!Yn!X|j�|�EdH|j�dS)N)�_get_subactions�AttributeErrorrTrU)r!rv�get_subactionsr'r'r(rt\s


z'HelpFormatter._iter_indented_subactionscCs+|jjd|�j�}tj||�S)Nr�)rLr~r�	_textwrap�wrap)r!rhrQr'r'r(r�fszHelpFormatter._split_linescCs7|jjd|�j�}tj||d|d|�S)Nr��initial_indent�subsequent_indent)rLr~rr��fill)r!rhrQr�r'r'r(r�jszHelpFormatter._fill_textcCs|jS)N)rr)r!rvr'r'r(r�oszHelpFormatter._get_help_stringcCs
|jj�S)N)�dest�upper)r!rvr'r'r(r�rsz/HelpFormatter._get_default_metavar_for_optionalcCs|jS)N)r�)r!rvr'r'r(r�usz1HelpFormatter._get_default_metavar_for_positional)rr-r.rRrTrU�objectrFrcrerfriror|r}rbr_rjr�rgrursr�r�r�rtr�r�r�r�r�r'r'r'r(r�s:	!\a/

c@seZdZdd�ZdS)rcs,dj�fdd�|jdd�D��S)Nr]c3s|]}�|VqdS)Nr')rYr�)r�r'r(�	<genexpr>�sz9RawDescriptionHelpFormatter._fill_text.<locals>.<genexpr>�keependsT)r �
splitlines)r!rhrQr�r')r�r(r��sz&RawDescriptionHelpFormatter._fill_textN)rr-r.r�r'r'r'r(rysc@seZdZdd�ZdS)rcCs
|j�S)N)r�)r!rhrQr'r'r(r��sz!RawTextHelpFormatter._split_linesN)rr-r.r�r'r'r'r(r�sc@seZdZdd�ZdS)rcCsY|j}d|jkrU|jtk	rUttg}|jsK|j|krU|d7}|S)Nz
%(default)z (default: %(default)s))rrr�rr
rr�r�)r!rvrr�defaulting_nargsr'r'r(r��s	
z.ArgumentDefaultsHelpFormatter._get_help_stringN)rr-r.r�r'r'r'r(r�sc@s(eZdZdd�Zdd�ZdS)r	cCs
|jjS)N)rr)r!rvr'r'r(r��sz:MetavarTypeHelpFormatter._get_default_metavar_for_optionalcCs
|jjS)N)rr)r!rvr'r'r(r��sz<MetavarTypeHelpFormatter._get_default_metavar_for_positionalN)rr-r.r�r�r'r'r'r(r	�scCsi|dkrdS|jr)dj|j�S|jdtfkrE|jS|jdtfkra|jSdSdS)N�/)r�r r�rr�)�argumentr'r'r(�_get_action_name�s	r�c@s(eZdZdd�Zdd�ZdS)rcCst|�|_||_dS)N)r��
argument_name�message)r!r�r�r'r'r(rR�szArgumentError.__init__cCs;|jdkrd}nd}|td|jd|j�S)Nz%(message)sz'argument %(argument_name)s: %(message)sr�r�)r�r�r�)r!r�r'r'r(�__str__�s
	zArgumentError.__str__N)rr-r.rRr�r'r'r'r(r�sc@seZdZdS)rN)rr-r.r'r'r'r(r�sc
@sOeZdZdddddddddd�Zdd�Zddd�ZdS)	rNFcCs^||_||_||_||_||_||_||_||_|	|_|
|_	dS)N)
r�r�r��constr�rr�r�rrr�)r!r�r�r�r�r�rr�r�rrr�r'r'r(rRs									zAction.__init__c	s8ddddddddd	g	}�fd
d�|D�S)Nr�r�r�r�r�rr�rrr�cs%g|]}|t�|�f�qSr')r/)rYr%)r!r'r(r\3s	z&Action._get_kwargs.<locals>.<listcomp>r')r!�namesr')r!r(r's	zAction._get_kwargscCsttd���dS)Nz.__call__() not defined)�NotImplementedErrorr�)r!�parserr1�valuesr�r'r'r(�__call__5szAction.__call__)rr-r.rRrr�r'r'r'r(r�s6csIeZdZdddddddd�fdd�Zddd�Z�S)�_StoreActionNFcs�|dkrtd��|dk	r@|tkr@tdt��tt|�jd|d|d|d|d|d	|d
|d|d|	d
|
�
dS)Nrz�nargs for store actions must be > 0; if you have nothing to store, actions such as store true or store const may be more appropriatez nargs must be %r to supply constr�r�r�r�r�rr�r�rrr�)r<r
�superr�rR)r!r�r�r�r�r�rr�r�rrr�)�	__class__r'r(rR;sz_StoreAction.__init__cCst||j|�dS)N)r0r�)r!r�r1r�r�r'r'r(r�Xsz_StoreAction.__call__)rr-r.rRr�r'r')r�r(r�9sr�cs=eZdZdddd�fdd�Zddd�Z�S)�_StoreConstActionNFcsAtt|�jd|d|ddd|d|d|d|�dS)	Nr�r�r�rr�r�r�rr)r�r�rR)r!r�r�r�r�r�rrr�)r�r'r(rR^sz_StoreConstAction.__init__cCst||j|j�dS)N)r0r�r�)r!r�r1r�r�r'r'r(r�osz_StoreConstAction.__call__)rr-r.rRr�r'r')r�r(r�\s

r�cs+eZdZddd�fdd�Z�S)�_StoreTrueActionFNc
s;tt|�jd|d|ddd|d|d|�dS)Nr�r�r�Tr�r�rr)r�r�rR)r!r�r�r�r�rr)r�r'r(rRusz_StoreTrueAction.__init__)rr-r.rRr'r')r�r(r�ssr�cs+eZdZddd�fdd�Z�S)�_StoreFalseActionTFNc
s;tt|�jd|d|ddd|d|d|�dS)Nr�r�r�Fr�r�rr)r�r�rR)r!r�r�r�r�rr)r�r'r(rR�sz_StoreFalseAction.__init__)rr-r.rRr'r')r�r(r��sr�csIeZdZdddddddd�fdd�Zddd�Z�S)�
_AppendActionNFcs�|dkrtd��|dk	r@|tkr@tdt��tt|�jd|d|d|d|d|d	|d
|d|d|	d
|
�
dS)Nrz�nargs for append actions must be > 0; if arg strings are not supplying the value to append, the append const action may be more appropriatez nargs must be %r to supply constr�r�r�r�r�rr�r�rrr�)r<r
r�r�rR)r!r�r�r�r�r�rr�r�rrr�)r�r'r(rR�sz_AppendAction.__init__cCsBtjt||jg��}|j|�t||j|�dS)N)�_copy�copyr2r�rr0)r!r�r1r�r�r,r'r'r(r��s
z_AppendAction.__call__)rr-r.rRr�r'r')r�r(r��sr�cs=eZdZdddd�fdd�Zddd�Z�S)�_AppendConstActionNFcsGtt|�jd|d|ddd|d|d|d|d	|�dS)
Nr�r�r�rr�r�r�rrr�)r�r�rR)r!r�r�r�r�r�rrr�)r�r'r(rR�sz_AppendConstAction.__init__cCsEtjt||jg��}|j|j�t||j|�dS)N)r�r�r2r�rr�r0)r!r�r1r�r�r,r'r'r(r��sz_AppendConstAction.__call__)rr-r.rRr�r'r')r�r(r��s
r�cs:eZdZddd�fdd�Zddd�Z�S)�_CountActionNFc
s;tt|�jd|d|ddd|d|d|�dS)Nr�r�r�rr�r�rr)r�rrR)r!r�r�r�r�rr)r�r'r(rR�sz_CountAction.__init__cCs0t||jd�d}t||j|�dS)NrrS)r2r�r0)r!r�r1r�r��	new_countr'r'r(r��sz_CountAction.__call__)rr-r.rRr�r'r')r�r(r�s	rcs:eZdZeed�fdd�Zddd�Z�S)�_HelpActionNcs5tt|�jd|d|d|ddd|�dS)Nr�r�r�r�rrr)r�rrR)r!r�r�r�rr)r�r'r(rR�sz_HelpAction.__init__cCs|j�|j�dS)N)�
print_help�exit)r!r�r1r�r�r'r'r(r��s
z_HelpAction.__call__)rr-r.rrRr�r'r')r�r(r�srcs=eZdZdeed�fdd�Zddd�Z�S)�_VersionActionNz&show program's version number and exitcs>tt|�jd|d|d|ddd|�||_dS)Nr�r�r�r�rrr)r�rrR�version)r!r�rr�r�rr)r�r'r(rR�sz_VersionAction.__init__cCs^|j}|dkr|j}|j�}|j|�|j|j�tj�|j�dS)N)r�_get_formatterri�_print_messagerb�_sys�stdoutr)r!r�r1r�r�rrVr'r'r(r�s		
z_VersionAction.__call__)rr-r.rrRr�r'r')r�r(r�s
	rcsheZdZGdd�de�Zedd�fdd�Zdd�Zdd	�Zdd
d�Z	�S)�_SubParsersActioncs"eZdZ�fdd�Z�S)z&_SubParsersAction._ChoicesPseudoActionc	s_|}}|r'|ddj|�7}ttj|�}|jdgd|d|d|�dS)Nz (%s)z, r�r�rrr�)r r�r�_ChoicesPseudoActionrR)r!r%�aliasesrrr�r��sup)r�r'r(rRs
z/_SubParsersAction._ChoicesPseudoAction.__init__)rr-r.rRr'r')r�r(rsrNc
sh||_||_tj�|_g|_tt|�jd|d|dt	d|jd|d|�dS)Nr�r�r�r�rrr�)
�_prog_prefix�
_parser_class�_collections�OrderedDict�_name_parser_map�_choices_actionsr�rrRr)r!r�rN�parser_classr�rrr�)r�r'r(rR"s				z_SubParsersAction.__init__cKs�|jd�dkr,d|j|f|d<|jdf�}d|kr~|jd�}|j|||�}|jj|�|j|�}||j|<x|D]}||j|<q�W|S)NrNz%s %sr
rr)r�rr�rrrrr)r!r%�kwargsr
rr�
choice_actionr��aliasr'r'r(�
add_parser7s

z_SubParsersAction.add_parsercCs|jS)N)r)r!r'r'r(r�Nsz!_SubParsersAction._get_subactionsc
Cs |d}|dd�}|jtk	r<t||j|�y|j|}WnOtk
r�d|ddj|j�i}td�|}t||��YnX|j|d�\}	}x0t	|	�j
�D]\}
}t||
|�q�W|rt	|�jtg�t
|t�j|�dS)NrrS�parser_namer�z, z5unknown parser %(parser_name)r (choices: %(choices)s))r�rr0rr;r r�r�parse_known_argsr�r,�
setdefault�_UNRECOGNIZED_ARGS_ATTRr/r�)r!r�r1r�r�rr#r[�msg�subnamespace�keyr&r'r'r(r�Qs"

	z_SubParsersAction.__call__)
rr-r.rrrrRrr�r�r'r')r�r(rsrc@s@eZdZdd
dddd�Zdd�Zdd	�ZdS)r�rrSNcCs(||_||_||_||_dS)N)�_mode�_bufsize�	_encoding�_errors)r!�mode�bufsize�encoding�errorsr'r'r(rR�s			zFileType.__init__cCs�|dkrWd|jkr"tjSd|jkr8tjStd�|j}t|��y&t||j|j|j|j	�SWnGt
k
r�}z'td�}t|||f��WYdd}~XnXdS)N�-r!�wzargument "-" with mode %rzcan't open '%s': %s)r"r	�stdinr
r�r<r�r#r$r%�OSErrorr)r!�stringr�er�r'r'r(r��szFileType.__call__cCst|j|jf}d|jfd|jfg}djdd�|D�dd�|D��}dt|�j|fS)Nr(r)z, cSs(g|]}|dkrt|��qS)rSr�)r)rYr$r'r'r(r\�s	z%FileType.__repr__.<locals>.<listcomp>cSs2g|](\}}|dk	rd||f�qS)Nz%s=%rr')rY�kwr$r'r'r(r\�s		z%s(%s))r"r#r$r%r rr)r!r[r�args_strr'r'r(r)�s
zFileType.__repr__r�)rr-r.rRr�r)r'r'r'r(rvsc@s4eZdZdd�Zdd�Zdd�ZdS)r
cKs)x"|D]}t||||�qWdS)N)r0)r!rr%r'r'r(rR�s
zNamespace.__init__cCs)t|t�stSt|�t|�kS)N)r�r
�NotImplementedr�)r!�otherr'r'r(�__eq__�szNamespace.__eq__cCs
||jkS)N)r+)r!r r'r'r(�__contains__�szNamespace.__contains__N)rr-r.rRr4r5r'r'r'r(r
�scs�eZdZ�fdd�Zdd�Zddd�Zdd	�Zd
d�Zdd
�Zdd�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zddd�Zdd�Zd d!�Zd"d#�Zd$d%�Z�S)&�_ActionsContainercsgtt|�j�||_||_||_||_i|_|jddt	�|jddt	�|jddt
�|jddt�|jddt�|jddt
�|jddt�|jddt�|jdd	t�|jdd
t�|jddt�|j�g|_i|_g|_g|_i|_tjd�|_g|_dS)
Nrv�store�store_const�
store_true�store_falser�append_const�countrrr�parsersz^-\d+$|^-\d*\.\d+$)r�r6rR�description�argument_default�prefix_chars�conflict_handler�_registries�registerr�r�r�r�r�r�rrrr�_get_handler�_actions�_option_string_actions�_action_groups�_mutually_exclusive_groups�	_defaultsrIrJ�_negative_number_matcher�_has_negative_number_optionals)r!r>r@r?rA)r�r'r(rR�s2					
					z_ActionsContainer.__init__cCs#|jj|i�}|||<dS)N)rBr)r!�
registry_namer&r��registryr'r'r(rC�sz_ActionsContainer.registerNcCs|j|j||�S)N)rBr�)r!rLr&r�r'r'r(�
_registry_get�sz_ActionsContainer._registry_getcKsG|jj|�x0|jD]%}|j|kr||j|_qWdS)N)rI�updaterEr�r�)r!rrvr'r'r(�set_defaultssz_ActionsContainer.set_defaultscCsLx6|jD]+}|j|kr
|jdk	r
|jSq
W|jj|d�S)N)rEr�r�rIr�)r!r�rvr'r'r(�get_default	sz_ActionsContainer.get_defaultcOs�|j}|s6t|�dkri|dd|kri|rTd|krTtd��|j||�}n|j||�}d|kr�|d}||jkr�|j||d<n|jdk	r�|j|d<|j|�}t|�s�td|f��||�}|j	d|j
|j
�}t|�sDtd|f��t|d	�r�y|j�j
|d�Wntk
r�td
��YnX|j|�S)NrSrr�z+dest supplied twice for positional argumentr�zunknown action "%s"rz%r is not callablerz,length of metavar tuple does not match nargs)r@rpr<�_get_positional_kwargs�_get_optional_kwargsrIr?�_pop_action_class�callablerNrr�rr��	TypeError�_add_action)r!r[r�charsr��action_classrv�	type_funcr'r'r(r|s2		-


z_ActionsContainer.add_argumentcOs&t|||�}|jj|�|S)N)�_ArgumentGrouprGr)r!r[rr�r'r'r(�add_argument_groupBsz$_ActionsContainer.add_argument_groupcKs#t||�}|jj|�|S)N)�_MutuallyExclusiveGrouprHr)r!rr�r'r'r(�add_mutually_exclusive_groupGsz._ActionsContainer.add_mutually_exclusive_groupcCs�|j|�|jj|�||_x|jD]}||j|<q0Wx<|jD]1}|jj|�rQ|jsQ|jjd�qQW|S)NT)	�_check_conflictrEr�	containerr�rFrJ�matchrK)r!rvr�r'r'r(rWLs
		z_ActionsContainer._add_actioncCs|jj|�dS)N)rE�remove)r!rvr'r'r(�_remove_actionasz _ActionsContainer._remove_actioncCsIi}xL|jD]A}|j|krDtd�}t||j��|||j<qWi}xs|jD]h}|j|kr�|jd|jd|jd|j�||j<x"|jD]}||j||<q�WqeWxD|jD]9}|j	d|j
�}x|jD]}|||<qWq�Wx*|jD]}|j||�j
|�q"WdS)Nz.cannot merge actions - two groups are named %r�titler>rAr�)rGrdr�r<r\r>rAr�rHr^r�rEr�rW)r!r`�title_group_mapr�r�	group_maprv�mutex_groupr'r'r(�_add_container_actionsds,				z(_ActionsContainer._add_container_actionscKs�d|kr$td�}t|��|jd�ttgkrId|d<|jd�tkrtd|krtd|d<t|d|dg�S)Nr�z1'required' is an invalid argument for positionalsr�Tr�r�r�)r�rVr�r
rr�)r!r�rrr'r'r(rR�s
!
z(_ActionsContainer._get_positional_kwargsc	OsJg}g}x�|D]�}|d|jkr]d|d|ji}td�}t||��|j|�|d|jkrt|�dkr|d|jkr|j|�qW|jdd�}|dkr4|r�|d}n
|d}|j|j�}|s"td�}t||��|jdd	�}t|d|d
|�S)Nr�optionr@zNinvalid option string %(option)r: must start with a character %(prefix_chars)rrSr�z%dest= is required for options like %rr*r�r�)	r@r�r<rrpr��lstrip�replacer�)	r!r[rr��long_option_stringsr�rr��dest_option_stringr'r'r(rS�s0



z&_ActionsContainer._get_optional_kwargscCs%|jd|�}|jd||�S)Nrv)r�rN)r!rr�rvr'r'r(rT�sz#_ActionsContainer._pop_action_classcCsVd|j}yt||�SWn1tk
rQtd�}t||j��YnXdS)Nz_handle_conflict_%sz%invalid conflict_resolution value: %r)rAr/r�r�r<)r!�handler_func_namerr'r'r(rD�s

z_ActionsContainer._get_handlercCslg}x@|jD]5}||jkr|j|}|j||f�qW|rh|j�}|||�dS)N)r�rFrrD)r!rv�confl_optionalsr��confl_optionalrAr'r'r(r_�s
z!_ActionsContainer._check_conflictcCsKtddt|��}djdd�|D��}t|||��dS)Nzconflicting option string: %szconflicting option strings: %sz, cSsg|]\}}|�qSr'r')rYr�rvr'r'r(r\�s	z<_ActionsContainer._handle_conflict_error.<locals>.<listcomp>)rrpr r)r!rv�conflicting_actionsr��conflict_stringr'r'r(�_handle_conflict_error�s
z(_ActionsContainer._handle_conflict_errorcCsWxP|D]H\}}|jj|�|jj|d�|js|jj|�qWdS)N)r�rbrFr�r`rc)r!rvrqr�r'r'r(�_handle_conflict_resolve�s
	z*_ActionsContainer._handle_conflict_resolve)rr-r.rRrCrNrPrQr|r\r^rWrcrhrRrSrTrDr_rsrtr'r')r�r(r6�s$4	
/($		r6csLeZdZdd�fdd�Z�fdd�Z�fdd�Z�S)r[Ncs�|j}|d|j�|d|j�|d|j�tt|�j}|d||�||_g|_|j	|_	|j
|_
|j|_|j|_|j
|_
|j|_dS)NrAr@r?r>)rrAr@r?r�r[rRrdr�rBrErFrIrKrH)r!r`rdr>rrO�
super_init)r�r'r(rR�s			z_ArgumentGroup.__init__cs,tt|�j|�}|jj|�|S)N)r�r[rWr�r)r!rv)r�r'r(rWsz_ArgumentGroup._add_actioncs*tt|�j|�|jj|�dS)N)r�r[rcr�rb)r!rv)r�r'r(rcsz_ArgumentGroup._remove_action)rr-r.rRrWrcr'r')r�r(r[�sr[cs=eZdZd�fdd�Zdd�Zdd�Z�S)r]Fcs,tt|�j|�||_||_dS)N)r�r]rRr��
_container)r!r`r�)r�r'r(rRs	z _MutuallyExclusiveGroup.__init__cCsG|jr!td�}t|��|jj|�}|jj|�|S)Nz-mutually exclusive arguments must be optional)r�r�r<rvrWr�r)r!rvrr'r'r(rWs	z#_MutuallyExclusiveGroup._add_actioncCs$|jj|�|jj|�dS)N)rvrcr�rb)r!rvr'r'r(rc$sz&_MutuallyExclusiveGroup._remove_action)rr-r.rRrWrcr'r')r�r(r]sr]cs�eZdZddddgedddddd�fdd�Zdd�Zd	d
�Zdd�Zd
d�Zdd�Z	dddd�Z
dddd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zdd1d2�Zdd3d4�Zdd5d6�Zd7dd8d9�Zd:d;�Z�S)<rNr*�errorTc
s�tt|�j}
|
d|d|d|	d|
�|dkrVtjjtjd�}||_||_	||_
||_||_||_
||_|j}|td��|_|td��|_d|_dd	�}|jd
d|�d|krdn|d}|j
rI|j|d|d
ddddtdtd��xM|D]E}|j|�y
|j}Wntk
r�YqPX|jj|�qPWdS)Nr>r@r?rArzpositional argumentszoptional argumentscSs|S)Nr')r.r'r'r(�identitybsz)ArgumentParser.__init__.<locals>.identityrr*�hr3rrrvr�zshow this help message and exit)r�rrRr9�path�basenamer	�argvrNrk�epilog�formatter_class�fromfile_prefix_chars�add_help�allow_abbrevr\r��_positionals�
_optionals�_subparsersrCr|rrhrIr�rO)r!rNrkr>r}�parentsr~r@rr?rAr�r��	superinit�	add_grouprx�default_prefixrW�defaults)r�r'r(rR<sB										




zArgumentParser.__init__cs/ddddddg}�fdd�|D�S)	NrNrkr>r~rAr�cs%g|]}|t�|�f�qSr')r/)rYr%)r!r'r(r\�s	z.ArgumentParser._get_kwargs.<locals>.<listcomp>r')r!r�r')r!r(r|s	zArgumentParser._get_kwargsc	KsA|jdk	r"|jtd��|jdt|��d|ksPd|kr�t|jdd��}t|jdd��}|j||�|_n|j|_|jd�dkr	|j	�}|j
�}|j}|j|j
||d�|j�j�|d<|j|d�}|d	g|�}|jj|�|S)
Nz(cannot have multiple subparser argumentsrrdr>�subcommandsrNr]r=r�)r�rwr�rrr�r\r�r�r�_get_positional_actionsrHrorkrbrrTrW)	r!rrdr>rVr�rm�
parsers_classrvr'r'r(�add_subparsers�s$	zArgumentParser.add_subparserscCs0|jr|jj|�n|jj|�|S)N)r�r�rWr�)r!rvr'r'r(rW�s	zArgumentParser._add_actioncCsdd�|jD�S)NcSsg|]}|jr|�qSr')r�)rYrvr'r'r(r\�s	z8ArgumentParser._get_optional_actions.<locals>.<listcomp>)rE)r!r'r'r(�_get_optional_actions�s	z$ArgumentParser._get_optional_actionscCsdd�|jD�S)NcSsg|]}|js|�qSr')r�)rYrvr'r'r(r\�s	z:ArgumentParser._get_positional_actions.<locals>.<listcomp>)rE)r!r'r'r(r��s	z&ArgumentParser._get_positional_actionscCsH|j||�\}}|rDtd�}|j|dj|��|S)Nzunrecognized arguments: %sr�)rr�rwr )r!r[r1r|rr'r'r(�
parse_args�s
zArgumentParser.parse_argscCsk|dkr"tjdd�}nt|�}|dkrCt�}xW|jD]L}|jtk	rMt||j�sM|jtk	rMt	||j|j�qMWx7|j
D],}t||�s�t	|||j
|�q�WyX|j||�\}}t|t�r$|j
t|t��t|t�||fSWn5tk
rftj�d}|jt|��YnXdS)NrS)r	r|r�r
rEr�rr�r�r0rI�_parse_known_argsrr�r/�delattrr�exc_inforwr�)r!r[r1rvr��errr'r'r(r�s,	

zArgumentParser.parse_known_argscs.�	jdk	r�	j���i�x~�	jD]s}|j}xat|j�D]P\}}�j|g�}|j|d|��|j||dd��qMWq.Wi�g}t��}	x�t|	�D]�\}}
|
dkr|jd�x_|	D]}
|jd�q�Wq��	j	|
�}|dkr4d}n|�|<d}|j|�q�Wdj
|��t��t��d�����	fdd�������	�fd	d
�}
�	j������	�fdd�}g�d
�
�rt
��}nd}x��
|kr�t�
fdd��D��}�
|krm|�
�}|�
krg|�
qn|�
�
�kr���
|�}�j|�|�
|
�
��
qW|�
�}�j�|d��g}x��	jD]�}|�kr�|jr|jt|��q�|jdk	r�t|jt�r�t�|j�r�|jt�|j�kr�t�|j�	j||j��q�W|r��	jtd�dj
|��xw�	jD]l}|jr�xZ|jD]}|�kr�Pq�Wdd�|jD�}td�}�	j|dj
|��q�W��fS)NrSz--r*�A�Or]cs��j|��j||�}||jk	r��j|�xQ�j|g�D]=}|�krNtd�}t|�}t|||��qNW|tk	r�|��||�dS)Nznot allowed with argument %s)r��_get_valuesr�r�r�r�rr)rv�argument_stringsr��argument_values�conflict_actionr�action_name)�action_conflictsr1�seen_actions�seen_non_default_actionsr!r'r(�take_actions

z5ArgumentParser._parse_known_args.<locals>.take_actioncs�|}|\}}}�j}g}x�|dkrP�j�|�|dS|dk	ry||d�}�j}|dkr|d|kr|j|g|f�|d}	|	|d}|dd�p�d}
�j}||kr�||}|
}qvtd�}t|||��q�|dkrW|d}
|g}|j|||f�Pq�td�}t|||��q+|d}�|d�}|||�}||}
�||
�}|j|||f�Pq+Wx'|D]\}}}�|||�q�W|
S)NrSr�rzignored explicit argument %r)�_match_argumentrr@rFr�r)�start_index�option_tuplervr��explicit_arg�match_argument�
action_tuples�	arg_countrX�char�new_explicit_arg�
optionals_mapr�stopr[r��selected_patterns)r#�arg_strings_pattern�extras�option_string_indicesr!r�r'r(�consume_optional+sN
		
	
	
	

z:ArgumentParser._parse_known_args.<locals>.consume_optionalcs��j}�|d�}|�|�}xHt�|�D]7\}}�|||�}||7}�||�q8W�t|�d��dd�<|S)N)�_match_arguments_partial�ziprp)r��
match_partial�selected_pattern�
arg_countsrvr�r[)r#r�r�r!r�r'r(�consume_positionalsxs	
 z=ArgumentParser._parse_known_args.<locals>.consume_positionalsrcs"g|]}|�kr|�qSr'r')rYr�)r�r'r(r\�s	z4ArgumentParser._parse_known_args.<locals>.<listcomp>z(the following arguments are required: %sz, cSs+g|]!}|jtk	rt|��qSr')rrrr�)rYrvr'r'r(r\�s	z#one of the arguments %s is requiredr�r�)r�_read_args_from_filesrHr�r�rr��iterr�_parse_optionalr r�r�rAr@rEr�r�r�r�r�r�r�r/r0�
_get_valuerwr�)r!r#r1rgr�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_actionsrvr�r�rr')r�r#r�r�r1r�r�r�r�r!r�r�r(r��s�	#

	
		!!J

			
z ArgumentParser._parse_known_argscCsg}x�|D]�}|s-|d|jkr=|j|�q
y�t|dd���m}g}xA|j�j�D]-}x$|j|�D]}|j|�q�WqrW|j|�}|j|�WdQRXWq
tk
r�t	j
�d}|jt|��Yq
Xq
W|S)NrrS)
rrr��readr��convert_arg_line_to_argsr�r�r-r	r�rwr�)r!r#�new_arg_stringsr��	args_file�arg_liner$r�r'r'r(r��s 

z$ArgumentParser._read_args_from_filescCs|gS)Nr')r!r�r'r'r(r��sz'ArgumentParser.convert_arg_line_to_argscCs�|j|�}tj||�}|dkr�dtd�ttd�ttd�i}tdd|j�|j}|j|j|�}t	||��t
|jd��S)Nzexpected one argumentzexpected at most one argumentzexpected at least one argumentzexpected %s argumentzexpected %s argumentsrS)�_get_nargs_patternrIrar�r
rrr�r�rrpr�)r!rvr��
nargs_patternra�nargs_errorsr�rr'r'r(r��szArgumentParser._match_argumentcs�g}x�tt|�dd�D]w}|d|�}dj�fdd�|D��}tj||�}|dk	r|jdd�|j�D��PqW|S)NrrSr]csg|]}�j|��qSr')r�)rYrv)r!r'r(r\s	z;ArgumentParser._match_arguments_partial.<locals>.<listcomp>cSsg|]}t|��qSr')rp)rYr.r'r'r(r\s	r�)r�rpr rIrar�rm)r!rlr�r�r��
actions_slicer�rar')r!r(r�s
 z'ArgumentParser._match_arguments_partialc
Cs�|s
dS|d|jkr!dS||jkrJ|j|}||dfSt|�dkr`dSd|kr�|jdd�\}}||jkr�|j|}|||fS|jrD|j|�}t|�dkr%djdd�|D��}d|d|i}td	�}|j||�nt|�dkrD|\}	|	S|j	j
|�rc|jscdSd
|krsdSd|dfS)NrrS�=z, cSsg|]\}}}|�qSr'r')rYrvr�r�r'r'r(r\?s	z2ArgumentParser._parse_optional.<locals>.<listcomp>ri�matchesz4ambiguous option: %(option)s could match %(matches)sr�)r@rFrp�splitr��_get_option_tuplesr r�rwrJrarK)
r!r�rvr�r��
option_tuples�optionsr[rr�r'r'r(r�s>



	
		zArgumentParser._parse_optionalc
Cs�g}|j}|d|kr�|d|kr�d|krV|jdd�\}}n|}d}x6|jD]>}|j|�rl|j|}|||f}|j|�qlWn�|d|kr�|d|kr�|}d}|dd�}|dd�}	x�|jD]v}||krE|j|}|||	f}|j|�q|j|�r|j|}|||f}|j|�qWn|jtd�|�|S)NrrSr�r3zunexpected option string: %s)r@r�rF�
startswithrrwr�)
r!r�r�rX�
option_prefixr�rvr��short_option_prefix�short_explicit_argr'r'r(r�Zs8	 
 

z!ArgumentParser._get_option_tuplescCs�|j}|dkrd}n�|tkr3d}nk|tkrHd}nV|tkr]d}nA|tkrrd}n,|tkr�d}nddjd	|�}|jr�|jdd
�}|jdd
�}|S)Nz(-*A-*)z(-*A?-*)z	(-*[A-]*)z
(-*A[A-]*)z([-AO]*)z(-*A[-AO]*)z(-*%s-*)z-*r�r]r*)	r�r
rrrrr r�rk)r!rvr�r�r'r'r(r��s$								z!ArgumentParser._get_nargs_patterncs��jttgkr;y|jd�Wntk
r:YnX|r��jtkr��jrf�j}n	�j}t	|t
�r��j�|�}�j�|�nV|r��jt
kr��jr��jdk	r��j}n|}�j�|�nt|�dkrL�jdtgkrL|\}�j�|�}�j�|�n��jtkrz��fdd�|D�}n�jtkr���fdd�|D�}�j�|d�n=��fdd�|D�}x|D]}�j�|�q�W|S)Nz--rScs"g|]}�j�|��qSr')r�)rY�v)rvr!r'r(r\�s	z.ArgumentParser._get_values.<locals>.<listcomp>cs"g|]}�j�|��qSr')r�)rYr�)rvr!r'r(r\�s	rcs"g|]}�j�|��qSr')r�)rYr�)rvr!r'r(r\�s	)r�rrrbr<r
r�r�r�r�r�r��_check_valuerrp)r!rvr#r&r�r�r')rvr!r(r��s>
		
'	
zArgumentParser._get_valuescCs|jd|j|j�}t|�sFtd�}t|||��y||�}Wn�tk
r�t|jdt|j��}tt	j
�d�}t||��Yngttfk
rt|jdt|j��}d|d|i}td�}t|||��YnX|S)Nrz%r is not callablerrSr&z!invalid %(type)s value: %(value)r)
rNrrUr�rrr/rr�r	r�rVr<)r!rvr�rZrr�r%r[r'r'r(r��s 
zArgumentParser._get_valuecCsh|jdk	rd||jkrdd|ddjtt|j��i}td�}t|||��dS)Nr&r�z, z3invalid choice: %(value)r (choose from %(choices)s))r�r �maprr�r)r!rvr&r[rr'r'r(r�	s
!zArgumentParser._check_valuecCs2|j�}|j|j|j|j�|j�S)N)rrorkrErHrb)r!rVr'r'r(�format_usage	s
zArgumentParser.format_usagecCs�|j�}|j|j|j|j�|j|j�xK|jD]@}|j|j	�|j|j�|j
|j�|j�qBW|j|j
�|j�S)N)rrorkrErHrir>rGrerdr}r�rfr}rb)r!rV�action_groupr'r'r(rb	s
zArgumentParser.format_helpcCs|jd|j�S)NrN)r~rN)r!r'r'r(r(	szArgumentParser._get_formattercCs/|dkrtj}|j|j�|�dS)N)r	r
rr�)r!�filer'r'r(�print_usage.	s	zArgumentParser.print_usagecCs/|dkrtj}|j|j�|�dS)N)r	r
rrb)r!r�r'r'r(r3	s	zArgumentParser.print_helpcCs,|r(|dkrtj}|j|�dS)N)r	�stderr�write)r!r�r�r'r'r(r8	s	zArgumentParser._print_messagercCs*|r|j|tj�tj|�dS)N)rr	r�r)r!�statusr�r'r'r(rA	szArgumentParser.exitcCsC|jtj�d|jd|i}|jdtd�|�dS)NrNr�r3z%(prog)s: error: %(message)s
)r�r	r�rNrr�)r!r�r[r'r'r(rwF	s	zArgumentParser.error)rr-r.rrRrr�rWr�r�r�rr�r�r�r�r�r�r�r�r�r�r�r�rbrr�rrrrwr'r')r�r(r)sL4#�;,,4	)5�__version__�__all__�collectionsrr�r��osr9�rerI�sysr	�textwrapr�rr�rrr
rrrrrr�rr2rrrrr	r��	Exceptionrrrr�r�r�r�r�r�rrrrrr
r6r[r]rr'r'r'r(�<module>@sx	
��
	[#%`6�4"

?>