a �DOgG�@sdZgd�ZddlZddlZddlZddlmZ m Z dZ dZ dZ dZd Zd Zd ZGd d �d e�Zdd�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�ZGdd�de�Zdd�ZGdd�de�ZGdd�de�ZGd d!�d!e�ZGd"d#�d#e�ZGd$d%�d%e�Z Gd&d'�d'e�Z!Gd(d)�d)e!�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+Gdd?�d?e�Z-Gd@dA�dAe-�Z.GdBdC�dCe.�Z/GdDdE�dEee-�Z0dS)Fz1.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==�?�*�+zA...�...�_unrecognized_argsc@s$eZdZdd�Zdd�Zdd�ZdS)�_AttributeHoldercCs�t|�j}g}i}|��D]}|�t|��q|��D],\}}|��rZ|�d||f�q6|||<q6|rz|�dt|��d|d�|�fS)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/lib64/python3.9/argparse.py�__repr__ts   z_AttributeHolder.__repr__cCst|j���S�N)�list�__dict__�items�r'r.r.r/r$�sz_AttributeHolder._get_kwargscCsgSr1r.r5r.r.r/r!�sz_AttributeHolder._get_argsN)r � __module__� __qualname__r0r$r!r.r.r.r/rks rcCs6|dur gSt|�tur$|dd�Sddl}|�|�S�Nr)rr2�copy)r4r9r.r.r/� _copy_items�s   r:c@s�eZdZd:dd�Zdd�Zdd �ZGd d �d e�Zd d �Zdd�Z dd�Z dd�Z d;dd�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.r.r/�__init__�s" �zHelpFormatter.__init__cCs"|j|j7_|jd7_dS�N��rGrBrHr5r.r.r/�_indent�szHelpFormatter._indentcCs"|j|j8_|jd8_dSrWrYr5r.r.r/�_dedent�szHelpFormatter._dedentc@seZdZddd�Zdd�ZdS)zHelpFormatter._SectionNcCs||_||_||_g|_dSr1)� formatter�parent�headingr4)r'r\r]r^r.r.r/rV�szHelpFormatter._Section.__init__cCs�|jdur|j��|jj}|dd�|jD��}|jdurD|j��|sLdS|jturz|jdurz|jj}d|d|jf}nd}|d||dg�S)NcSsg|]\}}||��qSr.r.)�.0�func�argsr.r.r/� ��z6HelpFormatter._Section.format_help..�z%*s%s: � ) r]r\rZ� _join_partsr4r[r^rrG)r'r&� item_help�current_indentr^r.r.r/� format_help�s    z"HelpFormatter._Section.format_help)N)r r6r7rVrir.r.r.r/rJ�s rJcCs|jj�||f�dSr1)rLr4r")r'r`rar.r.r/� _add_item�szHelpFormatter._add_itemcCs0|��|�||j|�}|�|jg�||_dSr1)rZrJrLrjri)r'r^�sectionr.r.r/� start_section�szHelpFormatter.start_sectioncCs|jj|_|��dSr1)rLr]r[r5r.r.r/� end_section�s zHelpFormatter.end_sectioncCs$|tur |dur |�|j|g�dSr1)rrj� _format_text)r'�textr.r.r/�add_text�szHelpFormatter.add_textcCs&|tur"||||f}|�|j|�dSr1)rrj� _format_usage)r'�usage�actions�groups�prefixrar.r.r/� add_usage�s zHelpFormatter.add_usagecCsr|jturn|j}||�g}|�|�D]}|�||��q$ttt|��}||j}t|j |�|_ |� |j |g�dSr1) �helpr�_format_action_invocation�_iter_indented_subactionsr"rD�map�lenrGrIrj�_format_action)r'�action�get_invocation� invocations� subaction�invocation_length� action_lengthr.r.r/� add_arguments   �zHelpFormatter.add_argumentcCs|D]}|�|�qdSr1)r�)r'rsr}r.r.r/� add_argumentsszHelpFormatter.add_argumentscCs.|j��}|r*|j�d|�}|�d�d}|S)N� re)rKrirQ�sub�strip)r'rwr.r.r/ris  zHelpFormatter.format_helpcCsd�dd�|D��S)NrdcSsg|]}|r|tur|�qSr.)r)r_�partr.r.r/rb"s �z-HelpFormatter._join_parts..)r&)r'� part_stringsr.r.r/rf!s �zHelpFormatter._join_partscs|durtd�}|dur,|t|jd�}�n�|durL|sLdt|jd�}�n�|du�rdt|jd�}g}g}|D] }|jr�|�|�qr|�|�qr|j} | |||�} d�dd�|| fD��}|j|j�t |�t |��k�rd} | ||�} | ||�} t � | | �}t � | | �}d�fdd � }t |�t |�d �k�r�dt |�t |�d }|�r|||g|||�}|� |||��n |�r�||g|||�}n|g}nZdt |�}||}|||�}t |�d k�r�g}|� |||��|� |||��|g|}d �|�}d ||fS)Nzusage: �rRz%(prog)s� cSsg|] }|r|�qSr.r.)r_�sr.r.r/rbBrcz/HelpFormatter._format_usage..z%\(.*?\)+(?=\s|$)|\[.*?\]+(?=\s|$)|\S+cs�g}g}|durt|�d}n t|�d}|D]Z}|dt|��krn|rn|�|d�|��g}t|�d}|�|�|t|�d7}q.|r�|�|d�|��|dur�|dt|�d�|d<|S)NrXr�r)r{r"r&)�parts�indentru�lines�line�line_lenr��� text_widthr.r/� get_linesVs"   z.HelpFormatter._format_usage..get_linesg�?rXrez%s%s )N) �_�dictrA�option_stringsr"�_format_actions_usager&rFrGr{rM�findall�extend)r'rrrsrtrurR� optionals� positionalsr}�format� action_usage� part_regexp� opt_usage� pos_usage� opt_parts� pos_partsr�r�r�r�r.r�r/rq&sX     �        zHelpFormatter._format_usagec Cst�}i}|D�]*}|js(td|����z|�|jd�}WntyRYqYq0|t|j�}|||�|jkr|jD]}|�|�qz|js�||vr�||d7<nd||<||vr�||d7<nd||<nF||vr�||d7<nd||<||v�r||d7<nd||<t|d |�D]} d || <�q*qg} t|�D�]"\} }|j t u�r�| � d�|� | �d k�r�|� | �n"|� | d �d k�rj|� | d �n�|j�s|�|�} |�|| �} ||v�r�| ddk�r�| d dk�r�| d d �} | � | �nf|jd} |jdk�r$|��} n"|�|�} |�|| �}d | |f} |j�s`||v�r`d | } | � | ��qHt|dd�D]} || g| | | �<�qzd�dd�| D��}d}d}t�d|d|�}t�d|d|�}t�d||fd|�}t�dd|�}|��}|S)Nz empty group rz [�[�]z (�(�)rX�|������%s %s�[%s]T)�reverser�cSsg|]}|dur|�qSr1r.)r_�itemr.r.r/rb�rcz7HelpFormatter._format_actions_usage..z[\[(]z[\])]z(%s) z\1� (%s)z%s *%srdz \(([^|]*)\))�set�_group_actions� ValueError�indexr{�add�required�range� enumeraterwrr"�get�popr��#_get_default_metavar_for_positional� _format_args�nargs� format_usage�!_get_default_metavar_for_optional�sortedr&rMr�r�)r'rsrt� group_actions�inserts�group�start�endr}�ir��defaultr�� option_string� args_stringro�open�closer.r.r/r��s~                     z#HelpFormatter._format_actions_usagecCsFd|vr|t|jd�}t|j|jd�}d|j}|�|||�dS)Nz%(prog)r�� r�r�)r�rArDrFrG� _fill_text)r'ror�r�r.r.r/rn�s  zHelpFormatter._format_textc CsNt|jd|j�}t|j|d�}||jd}|�|�}|jsV|jd|f}d|}n@t|�|kr~|jd||f}d|}d}n|jd|f}d|}|}|g}|j�r |j� ��r |� |�} | �r"|� | |�} |� d|d| df�| dd�D]} |� d|d| f�q�n|� d��s"|� d�|�|�D]} |� |�| ���q,|�|�S) Nr;r�rdz%*s%s z %*s%-*s rrXre)rCrIrErDrFrGrxrwr{r�� _expand_help� _split_linesr"�endswithryr|rf) r'r}� help_position� help_width� action_width� action_header�tup� indent_firstr�� help_text� help_linesr�r�r.r.r/r|�s: �         zHelpFormatter._format_actioncCs�|js&|�|�}|�||�d�\}|Sg}|jdkrB|�|j�n4|�|�}|�||�}|jD]}|�d||f�q^d�|�SdS)NrXrr�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_invocationcsP|jdur|j�n.|jdur.z{%s}�,cst�t�r�S�f|SdSr1)� isinstance�tuple)� tuple_size��resultr.r/r�Hs z0HelpFormatter._metavar_formatter..format)r��choicesr&)r'r}�default_metavar� choice_strsr�r.r�r/r�?s   z HelpFormatter._metavar_formattercCs |�||�}|jdur$d|d�}n�|jtkr.zinvalid nargs valuer�) r�r�rrr{r rrrr�� TypeErrorr�r&)r'r}r�� get_metavarr�r��formatsr.r.r/r�Os0            zHelpFormatter._format_argscCs�tt|�|jd�}t|�D]}||tur||=qt|�D] }t||d�r:||j||<q:|�d�dur�d�dd�|dD��}||d<|� |�|S)Nr�r r�rcSsg|] }t|��qSr.r��r_�cr.r.r/rbtrcz.HelpFormatter._expand_help..) r��varsrAr2r�hasattrr r�r&�_get_help_string)r'r}�paramsr,� choices_strr.r.r/r�ks   zHelpFormatter._expand_helpccs>z |j}WntyYn0|��|�EdH|��dSr1)�_get_subactions�AttributeErrorrZr[)r'r}�get_subactionsr.r.r/ryxs   z'HelpFormatter._iter_indented_subactionscCs&|j�d|���}ddl}|�||�S)Nr�r)rPr�r��textwrap�wrap)r'rorUr�r.r.r/r��szHelpFormatter._split_linescCs,|j�d|���}ddl}|j||||d�S)Nr�r)�initial_indent�subsequent_indent)rPr�r�r��fill)r'rorUr�r�r.r.r/r��s �zHelpFormatter._fill_textcCs|jSr1)rw�r'r}r.r.r/r��szHelpFormatter._get_help_stringcCs |j��Sr1)�dest�upperr�r.r.r/r��sz/HelpFormatter._get_default_metavar_for_optionalcCs|jSr1)r�r�r.r.r/r��sz1HelpFormatter._get_default_metavar_for_positional)r;r<N)N)r r6r7rVrZr[�objectrJrjrlrmrprvr�r�rirfrqr�rnr|rxr�r�r�ryr�r�r�r�r�r.r.r.r/r�s< �  `j0  rc@seZdZdd�ZdS)rcs d��fdd�|jdd�D��S)Nrdc3s|]}�|VqdSr1r.)r_r��r�r.r/� �rcz9RawDescriptionHelpFormatter._fill_text..T)�keepends)r&� splitlines)r'rorUr�r.r�r/r��sz&RawDescriptionHelpFormatter._fill_textN)r r6r7r�r.r.r.r/r�src@seZdZdd�ZdS)r cCs|��Sr1)r�)r'rorUr.r.r/r��sz!RawTextHelpFormatter._split_linesN)r r6r7r�r.r.r.r/r �sr c@seZdZdd�ZdS)rcCs>|j}d|jvr:|jtur:ttg}|js2|j|vr:|d7}|S)Nz %(default)� (default: %(default)s))rwr�rrrr�r�)r'r}rw�defaulting_nargsr.r.r/r��s  z.ArgumentDefaultsHelpFormatter._get_help_stringN)r r6r7r�r.r.r.r/r�src@seZdZdd�Zdd�ZdS)r cCs|jjSr1�rr r�r.r.r/r��sz:MetavarTypeHelpFormatter._get_default_metavar_for_optionalcCs|jjSr1rr�r.r.r/r��sz.r.�r'�namesr.r5r/r$Js zAction._get_kwargscCs |jdSr8�r�r5r.r.r/r�YszAction.format_usagecCsttd���dS)Nz.__call__() not defined)�NotImplementedErrorr��r'�parser� namespace�valuesr�r.r.r/�__call__\szAction.__call__)NNNNNFNN)N)r r6r7rVr$r�rr.r.r.r/r s6� r cs0eZdZd �fdd� Zd dd�Zdd�Z�ZS) rNFc s~g} |D]2} | �| �| �d�rd| dd�} | �| �q|dur\|dur\|tur\|d7}t�j| |d||||||d� dS)N�--�--no-r;rr) r�r�r�r�rr�r�rwr�)r"� startswithr�superrV) r'r�r�r�rr�r�rwr��_option_stringsr��� __class__r.r/rV`s&    �zBooleanOptionalAction.__init__cCs$||jvr t||j|�d� �dS)Nr)r��setattrr�rrr.r.r/r�s zBooleanOptionalAction.__call__cCs d�|j�S)Nz | )r&r�r5r.r.r/r��sz"BooleanOptionalAction.format_usage)NNNFNN)N)r r6r7rVrr�� __classcell__r.r.rr/r_s� rcs(eZdZd�fdd� Zddd�Z�ZS) � _StoreActionNFc sT|dkrtd��|dur,|tkr,tdt��tt|�j||||||||| | 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 appropriate� nargs must be %r to supply constr )r�rrr#rVr rr.r/rV�s   �z_StoreAction.__init__cCst||j|�dSr1)r!r�rr.r.r/r�sz_StoreAction.__call__)NNNNNFNN)N�r r6r7rVrr"r.r.rr/r#�s�r#cs(eZdZd�fdd� Zddd�Z�ZS) �_StoreConstActionNFc s"tt|�j||d||||d�dS)Nr)r�r�r�r r�r�rw)rr&rV�r'r�r�r r�r�rwr�rr.r/rV�s �z_StoreConstAction.__init__cCst||j|j�dSr1)r!r�r rr.r.r/r�sz_StoreConstAction.__call__)NFNN)Nr%r.r.rr/r&�s �r&cseZdZd�fdd� Z�ZS)�_StoreTrueActionFNcs tt|�j||d|||d�dS)NT�r�r�r r�r�rw)rr(rV�r'r�r�r�r�rwrr.r/rV�s �z_StoreTrueAction.__init__)FFN�r r6r7rVr"r.r.rr/r(�s�r(cseZdZd�fdd� Z�ZS)�_StoreFalseActionTFNcs tt|�j||d|||d�dS)NFr))rr,rVr*rr.r/rV�s �z_StoreFalseAction.__init__)TFNr+r.r.rr/r,�s�r,cs(eZdZd�fdd� Zddd�Z�ZS) � _AppendActionNFc sT|dkrtd��|dur,|tkr,tdt��tt|�j||||||||| | 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 appropriater$r )r�rrr-rVr rr.r/rV�s   �z_AppendAction.__init__cCs2t||jd�}t|�}|�|�t||j|�dSr1)rr�r:r"r!�r'rrrr�r4r.r.r/rs z_AppendAction.__call__)NNNNNFNN)Nr%r.r.rr/r-�s�r-cs(eZdZd�fdd� Zddd�Z�ZS) �_AppendConstActionNFc s$tt|�j||d|||||d�dS)Nr)r�r�r�r r�r�rwr�)rr/rVr'rr.r/rV s �z_AppendConstAction.__init__cCs4t||jd�}t|�}|�|j�t||j|�dSr1)rr�r:r"r r!r.r.r.r/rs z_AppendConstAction.__call__)NFNN)Nr%r.r.rr/r/ s �r/cs(eZdZd�fdd� Zddd�Z�ZS) � _CountActionNFcs tt|�j||d|||d�dS)Nr)r�r�r�r�r�rw)rr0rVr*rr.r/rV's �z_CountAction.__init__cCs0t||jd�}|durd}t||j|d�dS�NrrX)rr�r!)r'rrrr��countr.r.r/r5sz_CountAction.__call__)NFN)Nr%r.r.rr/r0%s �r0cs.eZdZeedf�fdd� Zddd�Z�ZS)� _HelpActionNcstt|�j|||d|d�dS�Nr)r�r�r�r�rw)rr3rV)r'r�r�r�rwrr.r/rV>s �z_HelpAction.__init__cCs|��|��dSr1)� print_help�exitrr.r.r/rJsz_HelpAction.__call__)N�r r6r7rrVrr"r.r.rr/r3<s � r3cs0eZdZdeedf�fdd� Zddd�Z�ZS)�_VersionActionNz&show program's version number and exitcs$tt|�j|||d|d�||_dSr4)rr8rV�version)r'r�r9r�r�rwrr.r/rVQs �z_VersionAction.__init__cCsD|j}|dur|j}|��}|�|�|�|��tj�|��dSr1)r9�_get_formatterrp�_print_messageri�_sys�stdoutr6)r'rrrr�r9r\r.r.r/r_s z_VersionAction.__call__)Nr7r.r.rr/r8Os �r8csPeZdZGdd�de�Zedddf�fdd� Zdd�Zd d �Zd d d �Z �Z S)�_SubParsersActioncseZdZ�fdd�Z�ZS)z&_SubParsersAction._ChoicesPseudoActioncs@|}}|r|dd�|�7}ttj|�}|jg|||d�dS)Nr�r)r�r�rwr�)r&rr>�_ChoicesPseudoActionrV)r'r,�aliasesrwr�r��suprr.r/rVms  �z/_SubParsersAction._ChoicesPseudoAction.__init__r+r.r.rr/r?ksr?FNc s<||_||_i|_g|_tt|�j||t|j|||d�dS)N)r�r�r�r�r�rwr�)� _prog_prefix� _parser_class�_name_parser_map�_choices_actionsrr>rVr)r'r�rR� parser_classr�r�rwr�rr.r/rVus  �z_SubParsersAction.__init__cKs�|�d�dur d|j|f|d<|�dd�}d|vrX|�d�}|�|||�}|j�|�|jfi|��}||j|<|D]}||j|<qv|S)NrRr�r@r.rw)r�rBr�r?rEr"rCrD)r'r,�kwargsr@rw� choice_actionr�aliasr.r.r/� add_parser�s     z_SubParsersAction.add_parsercCs|jSr1)rEr5r.r.r/r��sz!_SubParsersAction._get_subactionsc Cs�|d}|dd�}|jtur,t||j|�z|j|}Wn:tyt|d�|j�d�}td�|}t||��Yn0|�|d�\} }t | �� �D]\} } t|| | �q�|r�t |�� t g�t |t ��|�dS)NrrXr)� parser_namer�z5unknown parser %(parser_name)r (choices: %(choices)s))r�rr!rD�KeyErrorr&r�r�parse_known_argsr�r4� setdefault�_UNRECOGNIZED_ARGS_ATTRrr�) r'rrrr�rKr)ra�msg� subnamespace�keyr-r.r.r/r�s$    �  z_SubParsersAction.__call__)N) r r6r7r r?rrVrJr�rr"r.r.rr/r>is�r>c@seZdZddd�ZdS)� _ExtendActionNcCs2t||jd�}t|�}|�|�t||j|�dSr1)rr�r:r�r!r.r.r.r/r�s z_ExtendAction.__call__)N)r r6r7rr.r.r.r/rS�srSc@s&eZdZd dd�Zdd�Zdd �ZdS) r�rr�NcCs||_||_||_||_dSr1)�_mode�_bufsize� _encoding�_errors)r'�mode�bufsize�encoding�errorsr.r.r/rV�szFileType.__init__c s�|dkrnd�jvr*d�jvr$tjjStjSt�fdd�dD��rXd�jvrRtjjStjStd��j}t|��zt|�j�j �j �j �WSt y�}z*||d�}td �}t ||��WYd}~n d}~00dS) N�-rT�bc3s|]}|�jvVqdSr1)rUr�r5r.r/r��rcz$FileType.__call__..�waxzargument "-" with mode %r)�filename�errorz$can't open '%(filename)s': %(error)s)rUr<�stdin�buffer�anyr=r�r�r�rVrWrX�OSErrorr)r'�stringrP�erar r.r5r/r�s � zFileType.__call__cCsT|j|jf}d|jfd|jfg}d�dd�|D�dd�|D��}dt|�j|fS)Nr[r\rcSsg|]}|dkrt|��qS)r�)r#)r_r+r.r.r/rb�rcz%FileType.__repr__..cSs$g|]\}}|durd||f�qS)Nrr.)r_�kwr+r.r.r/rbs �r)rUrVrWrXr&rr )r'rarG�args_strr.r.r/r0�s   �zFileType.__repr__)rTr�NN)r r6r7rVrr0r.r.r.r/r�s rc@s$eZdZdd�Zdd�Zdd�ZdS)r cKs|D]}t||||�qdSr1)r!)r'rGr,r.r.r/rVszNamespace.__init__cCst|t�stSt|�t|�kSr1)r�r �NotImplementedr�)r'�otherr.r.r/�__eq__s zNamespace.__eq__cCs ||jvSr1)r3)r'rRr.r.r/� __contains__szNamespace.__contains__N)r r6r7rVrlrmr.r.r.r/r sr cs�eZdZ�fdd�Zdd�Zd&dd�Zdd �Zd d �Zd d �Zdd�Z dd�Z dd�Z dd�Z dd�Z dd�Zdd�Zd'dd�Zdd�Zd d!�Zd"d#�Zd$d%�Z�ZS)(�_ActionsContainercstt|���||_||_||_||_i|_|�ddt �|�ddt �|�ddt �|�ddt �|�ddt �|�ddt �|�ddt�|�ddt�|�dd t�|�dd t�|�dd t�|�dd t�|��g|_i|_g|_g|_i|_t�d �|_g|_dS)Nr}�store� store_const� store_true� store_falser"� append_constr2rwr9�parsersr�z^-\d+$|^-\d*\.\d+$)rrnrV� description�argument_default� prefix_chars�conflict_handler� _registries�registerr#r&r(r,r-r/r0r3r8r>rS� _get_handler�_actions�_option_string_actions�_action_groups�_mutually_exclusive_groups� _defaultsrMrN�_negative_number_matcher�_has_negative_number_optionals)r'rurwrvrxrr.r/rVs4 z_ActionsContainer.__init__cCs|j�|i�}|||<dSr1)ryrN)r'� registry_namer-r��registryr.r.r/rzSsz_ActionsContainer.registerNcCs|j|�||�Sr1)ryr�)r'r�r-r�r.r.r/� _registry_getWsz_ActionsContainer._registry_getcKs2|j�|�|jD]}|j|vr||j|_qdSr1)r��updater|r�r�)r'rGr}r.r.r/� set_defaults]s   z_ActionsContainer.set_defaultscCs8|jD]"}|j|kr|jdur|jSq|j�|d�Sr1)r|r�r�r�r�)r'r�r}r.r.r/� get_defaultfs  z_ActionsContainer.get_defaultcOsP|j}|r&t|�dkrL|dd|vrL|r:d|vr:td��|j|i|��}n|j|i|��}d|vr�|d}||jvr�|j||d<n|jdur�|j|d<|�|�}t|�s�td|f��|fi|��}|� d|j |j �}t|�s�td|f��|t u�rtd |f��t |d ��rFz|� ��|d�Wnt�yDtd ��Yn0|�|�S) NrXrr�z+dest supplied twice for positional argumentr�zunknown 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)rwr{r��_get_positional_kwargs�_get_optional_kwargsr�rv�_pop_action_class�callabler�rrr�r:r�r�� _add_action)r'rarG�charsr�� action_classr}� type_funcr.r.r/r�ps:        � z_ActionsContainer.add_argumentcOs&t|g|�Ri|��}|j�|�|Sr1)�_ArgumentGroupr~r")r'rarGr�r.r.r/�add_argument_group�s z$_ActionsContainer.add_argument_groupcKs t|fi|��}|j�|�|Sr1)�_MutuallyExclusiveGrouprr")r'rGr�r.r.r/�add_mutually_exclusive_group�s z._ActionsContainer.add_mutually_exclusive_groupcCs`|�|�|j�|�||_|jD]}||j|<q"|jD]"}|j�|�r8|js8|j�d�q8|S)NT) �_check_conflictr|r"� containerr�r}r��matchr�)r'r}r�r.r.r/r��s      z_ActionsContainer._add_actioncCs|j�|�dSr1)r|�remover�r.r.r/�_remove_action�sz _ActionsContainer._remove_actioncCs�i}|jD].}|j|vr.td�}t||j��|||j<q i}|jD]D}|j|vrn|j|j|j|jd�||j<|jD]}||j||<qtqD|jD]&}|j |j d�}|jD] }|||<q�q�|j D]}|� ||�� |�q�dS)Nz.cannot merge actions - two groups are named %r)�titlerurx)r�)r~r�r�r�r�rurxr�rr�r�r|r�r�)r'r��title_group_mapr�rP� group_mapr}� mutex_groupr.r.r/�_add_container_actions�s0     �   �   z(_ActionsContainer._add_container_actionscKs^d|vrtd�}t|��|�d�ttfvr2d|d<|�d�tkrPd|vrPd|d<t||gd�S)Nr�z1'required' is an invalid argument for positionalsr�Tr��r�r�)r�r�r�rrr�)r'r�rGrPr.r.r/r��sz(_ActionsContainer._get_positional_kwargsc Os�g}g}|D]`}|d|jvr>||jd�}td�}t||��|�|�t|�dkr |d|jvr |�|�q |�dd�}|dur�|r�|d}n|d}|�|j�}|s�td�}t||��|�dd�}t|||d �S) Nr)�optionrwzNinvalid option string %(option)r: must start with a character %(prefix_chars)rrXr�z%dest= is required for options like %rr]r�r�) rwr�r�r"r{r��lstrip�replacer�) r'rarGr��long_option_stringsr�rPr��dest_option_stringr.r.r/r��s.�        z&_ActionsContainer._get_optional_kwargscCs|�d|�}|�d||�S)Nr})r�r�)r'rGr�r}r.r.r/r�s z#_ActionsContainer._pop_action_classcCsDd|j}z t||�WSty>td�}t||j��Yn0dS)Nz_handle_conflict_%sz%invalid conflict_resolution value: %r)rxrr�r�r�)r'�handler_func_namerPr.r.r/r{#s    z_ActionsContainer._get_handlercCsLg}|jD]&}||jvr |j|}|�||f�q |rH|��}|||�dSr1)r�r}r"r{)r'r}�confl_optionalsr��confl_optionalrxr.r.r/r�,s   z!_ActionsContainer._check_conflictcCs6tddt|��}d�dd�|D��}t|||��dS)Nzconflicting option string: %szconflicting option strings: %srcSsg|] \}}|�qSr.r.)r_r�r}r.r.r/rb>s�z<_ActionsContainer._handle_conflict_error..)rr{r&r)r'r}�conflicting_actionsr �conflict_stringr.r.r/�_handle_conflict_error:s� �z(_ActionsContainer._handle_conflict_errorcCs>|D]4\}}|j�|�|j�|d�|js|j�|�qdSr1)r�r�r}r�r�r�)r'r}r�r�r.r.r/�_handle_conflict_resolveCs   z*_ActionsContainer._handle_conflict_resolve)N)N)r r6r7rVrzr�r�r�r�r�r�r�r�r�r�r�r�r{r�r�r�r"r.r.rr/rns$ 5   3("   rncs6eZdZd�fdd� Z�fdd�Z�fdd�Z�ZS) r�Nc s�|j}|d|j�|d|j�|d|j�tt|�j}|fd|i|��||_g|_|j |_ |j |_ |j |_ |j |_ |j |_ |j|_dS)Nrxrwrvru)rNrxrwrvrr�rVr�r�ryr|r}r�r�r)r'r�r�rurGr�� super_initrr.r/rVTs    �z_ArgumentGroup.__init__cs tt|��|�}|j�|�|Sr1)rr�r�r�r"r�rr.r/r�js z_ArgumentGroup._add_actioncs tt|��|�|j�|�dSr1)rr�r�r�r�r�rr.r/r�osz_ArgumentGroup._remove_action)NN�r r6r7rVr�r�r"r.r.rr/r�Rs r�cs.eZdZd�fdd� Zdd�Zdd�Z�ZS) r�Fcs tt|��|�||_||_dSr1)rr�rVr�� _container)r'r�r�rr.r/rVvsz _MutuallyExclusiveGroup.__init__cCs2|jrtd�}t|��|j�|�}|j�|�|S)Nz-mutually exclusive arguments must be optional)r�r�r�r�r�r�r")r'r}rPr.r.r/r�{s   z#_MutuallyExclusiveGroup._add_actioncCs|j�|�|j�|�dSr1)r�r�r�r�r�r.r.r/r��s z&_MutuallyExclusiveGroup._remove_action)Fr�r.r.rr/r�tsr�c s(eZdZddddgedddddddf �fdd� Zdd�Zd d �Zd d �Zd d�Zdd�Z d@dd�Z dAdd�Z dd�Z dd�Z dd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�ZdBd%d&�ZdCd'd(�Zd)d*�Zd+d,�Zd-d.�Zd/d0�Zd1d2�Zd3d4�ZdDd5d6�ZdEd7d8�ZdFd9d:�ZdGdd?�Z �Z!S)HrNr]raTc s&tt|�j}|||| | d�|dur6tj�tjd�}||_||_ ||_ ||_ ||_ | |_ | |_| |_|j}|td��|_|td��|_d|_dd�}|�dd|�d|vr�dn|d}|j r�|j|d |d d d ttd �d �|D]:}|�|�z |j}Wnt�yYq�0|j�|�q�dS)N)rurwrvrxrzpositional argumentszoptional argumentscSs|Sr1r.)rfr.r.r/�identity�sz)ArgumentParser.__init__..identityrr]�hr;rwzshow this help message and exit)r}r�rw)rrrV�_os�path�basenamer<�argvrRrr�epilog�formatter_class�fromfile_prefix_chars�add_help� allow_abbrev� exit_on_errorr�r�� _positionals� _optionals� _subparsersrzr�rr�r�r�r�)r'rRrrrur��parentsr�rwr�rvrxr�r�r�� superinit� add_groupr��default_prefixr]�defaultsrr.r/rV�sH ��  zArgumentParser.__init__csgd�}�fdd�|D�S)N)rRrrrur�rxr�csg|]}|t�|�f�qSr.rrr5r.r/rb�rcz.ArgumentParser._get_kwargs..r.rr.r5r/r$�szArgumentParser._get_kwargsc Ks�|jdur|�td��|�dt|��d|vs8d|vrht|�dd��}t|�dd��}|�||�|_n|j|_|�d�dur�|� �}|� �}|j }|� |j ||d�|����|d<|�|d�}|fd gi|��}|j�|�|S) Nz(cannot have multiple subparser argumentsrFr�ru� subcommandsrRrdrtr�)r�rar�rNrr�r�r�r�r:�_get_positional_actionsrrvrrrir�r�r�) r'rGr�rur\r�rt� parsers_classr}r.r.r/�add_subparsers�s$   zArgumentParser.add_subparserscCs$|jr|j�|�n |j�|�|Sr1)r�r�r�r�r�r.r.r/r� s zArgumentParser._add_actioncCsdd�|jD�S)NcSsg|]}|jr|�qSr.r�r_r}r.r.r/rbs�z8ArgumentParser._get_optional_actions..�r|r5r.r.r/�_get_optional_actionss�z$ArgumentParser._get_optional_actionscCsdd�|jD�S)NcSsg|]}|js|�qSr.rr�r.r.r/rbs�z:ArgumentParser._get_positional_actions..r�r5r.r.r/r�s�z&ArgumentParser._get_positional_actionscCs4|�||�\}}|r0td�}|�|d�|��|S�Nzunrecognized arguments: %sr�)rMr�rar&�r'rarr�rPr.r.r/� parse_args s zArgumentParser.parse_argscCs|durtjdd�}nt|�}|dur.t�}|jD]4}|jtur4t||j�s4|jtur4t ||j|j�q4|j D] }t||�spt |||j |�qp|j r�z|� ||�\}}Wq�t y�t��d}|�t|��Yq�0n|� ||�\}}t|t��r|�t|t��t|t�||fSrW)r<r�r2r r|r�rr�r�r!r�r��_parse_known_argsr�exc_inforar�rOr�r�delattr)r'rarr}r��errr.r.r/rM's0          zArgumentParser.parse_known_argscs� jdur� ����i�� jD]R}|j}t|j�D]<\}}��|g�}|�|d|��|�||dd��q2qi�g}t��} t| �D]^\}} | dkr�|�d�| D]} |�d�q�q�� � | �} | dur�d} n | �|<d} |�| �q�d� |��t ��t ��d����� fdd� � ����� � fd d �} � � ������ � fd d �}g�d � ��r`t ��}nd}� |k�r�t� fdd��D��}� |k�r�|� �}|� k�r�|� �qdn|� � �v�r҈� |�}��|�|� | � �� �qd|� �}���|d��g}� jD]|}|�v�r|j�r(|�t|��nT|jdu�rt|jt��rt�|j��r|jt�|j�u�rt�|j� �||j���q|�r�� �td�d� |��� jD]X}|j�r�|jD]}|�v�r��q��q�dd�|jD�}td�}� �|d� |���q���fS)NrXrr]�A�Ordcs|��|���||�}||jurb��|���|g�D]*}|�vr6td�}t|�}t|||��q6|turx|��||�dS)Nznot allowed with argument %s)r�� _get_valuesr�r�r�rrr)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..take_actioncs~�|}|\}}}�j}g}|dur:���|�|dS|du�r||d�}�j}|dkr�|d|vr�|�|g|f�|d} | |d}|dd�p�d} �j} || vr�| |}| }ntd�} t|| |��nB|dkr�|d} |g}|�|||f��q\ntd�} t|| |��q|d}�|d�}|||�}||} �|| �}|�|||f��q\q|D]\}}}�|||��q`| S)NrXr�rzignored explicit argument %r)�_match_argumentr"rwr}r�r)� start_index� option_tupler}r�� explicit_arg�match_argument� action_tuples� arg_countr��char�new_explicit_arg� optionals_maprP�stoprar��selected_patterns)r)�arg_strings_pattern�extras�option_string_indicesr'r�r.r/�consume_optional�sL       z:ArgumentParser._parse_known_args..consume_optionalcsn�j}�|d�}|�|�}t�|�D]*\}}�|||�}||7}�||�q&�t|�d��dd�<|Sr1)�_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..consume_positionalsrr�csg|]}|�kr|�qSr.r.)r_r�)r�r.r/rb�s�z4ArgumentParser._parse_known_args..z(the following arguments are required: %srcSsg|]}|jturt|��qSr.)rwrrr�r.r.r/rb;s �z#one of the arguments %s is requiredr�)N)r��_read_args_from_filesrr�r�rNr��iterr"�_parse_optionalr&r�r�rDrCr|r�rr�r�r�r�r�rr!� _get_valuerar�)r'r)rr�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�rrPr.) r�r)r�r�rr�r�r�r�r'r�r�r/r�Ns�        J   �          � �� � �    �z ArgumentParser._parse_known_argsc Cs�g}|D]�}|r|d|jvr*|�|�qzxt|dd���T}g}|����D]}|�|�D]}|�|�q\qN|�|�}|�|�Wd�n1s�0YWqty�t � �d}|� t |��Yq0q|Sr1) r�r"r��readr��convert_arg_line_to_argsr�r�rer<r�rar�)r'r)�new_arg_stringsr�� args_file�arg_liner+r�r.r.r/r�Ds   ,  z$ArgumentParser._read_args_from_filescCs|gSr1r.)r'rr.r.r/r^sz'ArgumentParser.convert_arg_line_to_argscCsz|�|�}t�||�}|durldtd�ttd�ttd�i}|�|j�}|durbtdd|j�|j}t ||��t |� d��S)Nzexpected one argumentzexpected at most one argumentzexpected at least one argumentzexpected %s argumentzexpected %s argumentsrX) �_get_nargs_patternrMr�r�rr r�r�rrr{r�)r'r}r�� nargs_patternr�� nargs_errorsrPr.r.r/r�as"  � �� zArgumentParser._match_argumentcsrg}tt|�dd�D]X}|d|�}d��fdd�|D��}t�||�}|dur|�dd�|��D��qnq|S)Nrr�rdcsg|]}��|��qSr.)rr�r5r.r/rb}s�z;ArgumentParser._match_arguments_partial..cSsg|] }t|��qSr.)r{)r_rfr.r.r/rb�rc)r�r{r&rMr�r�rt)r'rsr�r�r�� actions_slicer�r�r.r5r/r�ws � z'ArgumentParser._match_arguments_partialc Cs|sdS|d|jvrdS||jvr8|j|}||dfSt|�dkrHdSd|vr~|�dd�\}}||jvr~|j|}|||fS|�|�}t|�dkr�d�dd�|D��}||d�}td�}|�||�nt|�dkr�|\} | S|j� |�r�|j s�dSd |v�rdSd|dfS) NrrX�=rcSsg|]\}}}|�qSr.r.)r_r}r�r�r.r.r/rb�s�z2ArgumentParser._parse_optional..)r��matchesz4ambiguous option: %(option)s could match %(matches)sr�) rwr}r{�split�_get_option_tuplesr&r�rar�r�r�) r'r�r}r�r�� option_tuples�optionsrarPr�r.r.r/r��s>          �    zArgumentParser._parse_optionalc Cs0g}|j}|d|vr�|d|vr�|jr~d|vrB|�dd�\}}n|}d}|jD],}|�|�rP|j|}|||f}|�|�qPn�|d|v�r|d|v�r|}d}|dd�}|dd�} |jD]T}||kr�|j|}||| f}|�|�q�|�|�r�|j|}|||f}|�|�q�n|�td�|�|S)NrrXr r;zunexpected option string: %s)rwr�rr}rr"rar�) r'r�r�r�� option_prefixr�r}r��short_option_prefix�short_explicit_argr.r.r/r�s:             z!ArgumentParser._get_option_tuplescCs�|j}|durd}nf|tkr"d}nX|tkr0d}nJ|tkr>d}n<|tkrLd}n.|tkrZd}n |tkrhd}ndd �d |�}|jr�|� d d �}|� d d �}|S) Nz(-*A-*)z(-*A?-*)z (-*[A-]*)z (-*A[A-]*)z([-AO]*)z (-*A[-AO]*)z(-*-*)z(-*%s-*)z-*r�rdr]) r�rrr rrrr&r�r�)r'r}r�r r.r.r/r�s(  z!ArgumentParser._get_nargs_patterncCs4|�||�\}}|r0td�}|�|d�|��|Sr�)�parse_known_intermixed_argsr�rar&r�r.r.r/�parse_intermixed_args s z$ArgumentParser.parse_intermixed_argsc s�|���dd��D�}|r,td|dj���fdd�|jD�rHtd���z�|j}z�|jdurp|��dd�|_�D] }|j|_t|_|j|_ t|_qt|� ||�\}}�D]J}t ||j �r�t ||j �gkr�ddlm}|d |j |f�t||j �q�W�D]}|j|_|j |_q�n�D]}|j|_|j |_�q0|��}zt|D]}|j|_d |_�q@|jD]} | j| _d | _�q\|� ||�\}} W|D]}|j|_�q�|jD]} | j| _�q�n,|D]}|j|_�q�|jD]} | j| _�q�0W||_n||_0|| fS) NcSsg|]}|jttfvr|�qSr.)r�rrr�r.r.r/rb4 s�z>ArgumentParser.parse_known_intermixed_args..z3parse_intermixed_args: positional arg with nargs=%srcs&g|]}|jD]}|�vr|j�qqSr.)r�r�)r_r�r}�r�r.r/rb: s�z;parse_intermixed_args: positional in mutuallyExclusiveGroup�)�warnzDo not expect %s in %sF)r�r�r�rrrr�� save_nargsrr�� save_defaultrMr�r�r�warningsrr�r�r�� save_required) r'rar�a� save_usager}�remaining_argsrr�r�r�r.rr/r& sn � � �  �   �   �  z*ArgumentParser.parse_known_intermixed_argscs��jttfvr0z|�d�Wnty.Yn0|sx�jtkrx�jrL�j}n�j}t |t �rt�� �|�}�� �|��n|s��jt kr��js��jdur��j}n|}�� �|�n�t|�dkr�jdtfvr�|\}�� �|�}�� �|�n��jtk�r ��fdd�|D�}np�jtk�r>��fdd�|D�}�� �|d�n>�jtk�rPt}n,��fdd�|D�}|D]}�� �|��qh|S)NrrXcsg|]}���|��qSr.�r��r_�v�r}r'r.r/rb� rcz.ArgumentParser._get_values..csg|]}���|��qSr.r!r"r$r.r/rb� rcrcsg|]}���|��qSr.r!r"r$r.r/rb� rc)r�rrr�r�rr�r r�r�r�r�� _check_valuerr{r)r'r}r)r-r�r#r.r$r/r�s sD   �     zArgumentParser._get_valuesc Cs�|�d|j|j�}t|�s0td�}t|||��z ||�}Wn�ty|t|jdt|j��}tt � �d�}t||��YnJt t fy�t|jdt|j��}||d�}td�}t|||��Yn0|S)Nrr�r rX)rr-z!invalid %(type)s value: %(value)r) r�rr�r�rrrr#r�r<r�r�r�)r'r}r�r�rPr�r,rar.r.r/r�� s    zArgumentParser._get_valuecCsF|jdurB||jvrB|d�tt|j��d�}td�}t|||��dS)Nr)r-r�z3invalid choice: %(value)r (choose from %(choices)s))r�r&rzr#r�r)r'r}r-rarPr.r.r/r%� s �zArgumentParser._check_valuecCs$|��}|�|j|j|j�|��Sr1)r:rvrrr|rri)r'r\r.r.r/r�� s  �zArgumentParser.format_usagecCst|��}|�|j|j|j�|�|j�|jD]0}|�|j �|�|j�|� |j �|� �q.|�|j �|��Sr1)r:rvrrr|rrprur~rlr�r�r�rmr�ri)r'r\� action_groupr.r.r/ri� s �       zArgumentParser.format_helpcCs|j|jd�S)Nr�)r�rRr5r.r.r/r:� szArgumentParser._get_formattercCs"|durtj}|�|��|�dSr1)r<r=r;r��r'�filer.r.r/� print_usage� szArgumentParser.print_usagecCs"|durtj}|�|��|�dSr1)r<r=r;rir'r.r.r/r5� szArgumentParser.print_helpcCs |r|durtj}|�|�dSr1)r<�stderr�write)r'r r(r.r.r/r;� szArgumentParser._print_messagercCs |r|�|tj�t�|�dSr1)r;r<r*r6)r'�statusr r.r.r/r6 szArgumentParser.exitcCs0|�tj�|j|d�}|�dtd�|�dS)N)rRr r;z%(prog)s: error: %(message)s )r)r<r*rRr6r�)r'r rar.r.r/ra s  zArgumentParser.error)NN)NN)NN)NN)N)N)N)rN)"r r6r7rrVr$r�r�r�r�r�rMr�r�rr�r�r�rrrrr�r�r%r�rir:r)r5r;r6rar"r.r.rr/r�sV�B  'w:-1  M8    r)1� __version__�__all__�osr��rerM�sysr<rr�rrrrr rrrOr�rr:rrr rr r� Exceptionrrr rr#r&r(r,r-r/r0r3r8r>rSrr rnr�r�rr.r.r.r/�As^   ^)#&] 78"