a
    eÖ0h”(  ã                   @   sÚ   d Z ddlmZ ddlZddlZddlZddlZddlmZ ddl	m
Z
 ddlmZ ddlmZ ddlmZmZ dd	lmZ dd
lmZ e e¡ZG dd„ dejƒZG dd„ deƒZG dd„ dejƒZG dd„ deƒZdS )zBase option parser setupé    )Úabsolute_importN)Ú	strtobool)Úsuppress)Ústring_types)ÚUNKNOWN_ERROR)ÚConfigurationÚConfigurationError)Úget_terminal_size)Úredact_auth_from_urlc                   @   sR   e Zd Z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S )ÚPrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.c                 O   s@   d|d< d|d< t ƒ d d |d< tjj| g|¢R i |¤Ž d S )Né   Úmax_help_positioné   Úindent_incrementr   é   Úwidth)r	   ÚoptparseÚIndentedHelpFormatterÚ__init__)ÚselfÚargsÚkwargs© r   úF/var/www/auris/lib/python3.9/site-packages/pip/_internal/cli/parser.pyr      s    zPrettyHelpFormatter.__init__c                 C   s
   |   |¡S )N)Ú_format_option_strings)r   Úoptionr   r   r   Úformat_option_strings#   s    z)PrettyHelpFormatter.format_option_stringsú <{}>ú, c                 C   s~   g }|j r| |j d ¡ |jr0| |jd ¡ t|ƒdkrH| d|¡ | ¡ rt|jp^|j ¡ }| | 	| ¡ ¡¡ d 
|¡S )zð
        Return a comma-separated list of option strings and metavars.

        :param option:  tuple of (short opt, long opt), e.g: ('-f', '--format')
        :param mvarfmt: metavar format string
        :param optsep:  separator
        r   r   Ú )Ú_short_optsÚappendÚ
_long_optsÚlenÚinsertÚtakes_valueÚmetavarÚdestÚlowerÚformatÚjoin)r   r   ÚmvarfmtÚoptsepÚoptsr&   r   r   r   r   &   s    z*PrettyHelpFormatter._format_option_stringsc                 C   s   |dkrdS |d S )NÚOptionsr   z:
r   )r   Úheadingr   r   r   Úformat_heading=   s    z"PrettyHelpFormatter.format_headingc                 C   s   d  |  t |¡d¡¡}|S )zz
        Ensure there is only one newline between usage and the first heading
        if there is no description.
        z
Usage: {}
ú  )r)   Úindent_linesÚtextwrapÚdedent)r   ÚusageÚmsgr   r   r   Úformat_usageB   s    ÿz PrettyHelpFormatter.format_usagec                 C   sV   |rNt | jdƒrd}nd}| d¡}| ¡ }|  t |¡d¡}d ||¡}|S dS d S )NÚmainÚCommandsÚDescriptionÚ
r1   z{}:
{}
r   )ÚhasattrÚparserÚlstripÚrstripr2   r3   r4   r)   )r   ÚdescriptionÚlabelr   r   r   Úformat_descriptionK   s    
z&PrettyHelpFormatter.format_descriptionc                 C   s   |r|S dS d S )Nr   r   )r   Úepilogr   r   r   Úformat_epilog]   s    z!PrettyHelpFormatter.format_epilogc                    s"   ‡ fdd„|  d¡D ƒ}d |¡S )Nc                    s   g | ]}ˆ | ‘qS r   r   )Ú.0Úline©Úindentr   r   Ú
<listcomp>e   ó    z4PrettyHelpFormatter.indent_lines.<locals>.<listcomp>r;   )Úsplitr*   )r   ÚtextrH   Ú	new_linesr   rG   r   r2   d   s    z PrettyHelpFormatter.indent_linesN)r   r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r0   r7   rB   rD   r2   r   r   r   r   r      s   
	r   c                   @   s   e Zd ZdZdd„ ZdS )ÚUpdatingDefaultsHelpFormatterzÚCustom help formatter for use in ConfigOptionParser.

    This is updates the defaults before expanding them, allowing
    them to show up correctly in the help listing.

    Also redact auth from url type options
    c                 C   s†   d }| j d ur.| j  | j j¡ | j j |j¡}tj | |¡}|r‚|jdkr‚t	|t
ƒrZ|g}t	|tƒshg }|D ]}| |t|ƒ¡}ql|S )NÚURL)r=   Ú_update_defaultsÚdefaultsÚgetr'   r   r   Úexpand_defaultr&   Ú
isinstancer   ÚlistÚreplacer
   )r   r   Údefault_valuesÚ	help_textÚvalr   r   r   rW   r   s    


ÿz,UpdatingDefaultsHelpFormatter.expand_defaultN)rN   rO   rP   rQ   rW   r   r   r   r   rR   i   s   rR   c                   @   s    e Zd Zdd„ Zedd„ ƒZdS )ÚCustomOptionParserc                 O   s,   | j |i |¤Ž}| j ¡  | j ||¡ |S )z*Insert an OptionGroup at a given position.)Úadd_option_groupÚoption_groupsÚpopr$   )r   Úidxr   r   Úgroupr   r   r   Úinsert_option_groupŠ   s    
z&CustomOptionParser.insert_option_groupc                 C   s*   | j dd… }| jD ]}| |j ¡ q|S )z<Get a list of all options, including those in option groups.N)Úoption_listr`   Úextend)r   ÚresÚir   r   r   Úoption_list_all“   s    
z"CustomOptionParser.option_list_allN)rN   rO   rP   rd   Úpropertyri   r   r   r   r   r^   ˆ   s   	r^   c                   @   s@   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ Zdd„ Z	dS )ÚConfigOptionParserzsCustom option parser which updates its defaults by checking the
    configuration files and environmental variablesc                 O   sJ   |  d¡| _|  dd¡}t|ƒ| _| js,J ‚tjj| g|¢R i |¤Ž d S )NÚnameÚisolatedF)ra   rl   r   Úconfigr   ÚOptionParserr   )r   r   r   rm   r   r   r   r   ¡   s
    

zConfigOptionParser.__init__c              
   C   sR   z|  ||¡W S  tjyL } z$td |¡ƒ t d¡ W Y d }~n
d }~0 0 d S )Nz*An error occurred during configuration: {}é   )Úcheck_valuer   ÚOptionValueErrorÚprintr)   ÚsysÚexit)r   r   Úkeyr]   Úexcr   r   r   Úcheck_defaultª   s
    z ConfigOptionParser.check_defaultc                 c   s”   d| j dg}dd„ |D ƒ}| j ¡ D ]D\}}|s>t d|¡ q$| dd¡\}}||v r$||  ||f¡ q$|D ] }|| D ]\}}||fV  qzqnd S )NÚglobalz:env:c                 S   s   i | ]
}|g “qS r   r   )rE   rl   r   r   r   Ú
<dictcomp>¶   rJ   zGConfigOptionParser._get_ordered_configuration_items.<locals>.<dictcomp>z7Ignoring configuration key '%s' as it's value is empty.Ú.r   )rl   rn   ÚitemsÚloggerÚdebugrK   r!   )r   Úoverride_orderÚsection_itemsÚsection_keyr]   Úsectionrv   r   r   r   Ú _get_ordered_configuration_items±   s    þz3ConfigOptionParser._get_ordered_configuration_itemsc              
      sâ  t  ˆj¡ˆ_tƒ }ˆ ¡ D ]œ\‰ }ˆ dˆ  ¡‰ˆdu r>qˆjdv r~zt|ƒ}W n$ t	yx   ˆ 
d |ˆ ¡¡ Y n0 n2ˆjdkrtt	ƒ t|ƒ}W d  ƒ n1 s°0    Y  tt	ƒ t|ƒ}W d  ƒ n1 sà0    Y  t|tƒrþ|dk r°ˆ 
d |ˆ ¡¡ nžˆjdkr>| ¡ }‡ ‡‡fd	d
„|D ƒ}nrˆjdkr¢| ˆj¡ ˆ ¡ }ˆ ||¡}ˆjptd}ˆjp€i }ˆjˆ||ˆg|¢R i |¤Ž nˆ ˆˆ |¡}||ˆj< q|D ]‰ tˆjˆ ƒ|ˆ < qÀdˆ_|S )z¢Updates the given defaults with values from the config files and
        the environ. Does a little special handling for certain types of
        options (lists).z--N)Ú
store_trueÚstore_falsezm{} is not a valid value for {} option, please specify a boolean value like yes/no, true/false or 1/0 instead.Úcountr   z¤{} is not a valid value for {} option, please instead specify either a non-negative integer or a boolean value like yes/no or false/true which is equivalent to 1/0.r!   c                    s   g | ]}ˆ  ˆˆ |¡‘qS r   )rx   )rE   Úv©rv   r   r   r   r   rI   ó   rJ   z7ConfigOptionParser._update_defaults.<locals>.<listcomp>Úcallbackr   )r   ÚValuesrU   ÚvaluesÚsetrƒ   Ú
get_optionÚactionr   Ú
ValueErrorÚerrorr)   r   ÚintrX   rK   Úaddr'   Úget_opt_stringÚconvert_valueÚcallback_argsÚcallback_kwargsr‰   rx   Úgetattr)r   rU   Ú	late_evalr]   Úopt_strr   r   r   rˆ   r   rT   É   sT    
þÿ
&
&ýÿ z#ConfigOptionParser._update_defaultsc              
   C   s®   | j st | j¡S z| j ¡  W n4 tyT } z|  tt	|ƒ¡ W Y d}~n
d}~0 0 |  
| j ¡ ¡}|  ¡ D ]4}| |j¡}t|tƒrn| ¡ }| ||¡||j< qnt |¡S )z‹Overriding to make updating the defaults after instantiation of
        the option parser possible, _update_defaults() does the dirty work.N)Úprocess_default_valuesr   rŠ   rU   rn   Úloadr   ru   r   ÚstrrT   ÚcopyÚ_get_all_optionsrV   r'   rX   r   r“   rq   )r   ÚerrrU   r   Údefaultr™   r   r   r   Úget_default_values  s    &
z%ConfigOptionParser.get_default_valuesc                 C   s"   |   tj¡ |  td |¡¡ d S )Nz{}
)Úprint_usagert   Ústderrru   r   r)   )r   r6   r   r   r   r     s    zConfigOptionParser.errorN)
rN   rO   rP   rQ   r   rx   rƒ   rT   r¡   r   r   r   r   r   rk      s   	=rk   )rQ   Ú
__future__r   Úloggingr   rt   r3   Údistutils.utilr   Zpip._vendor.contextlib2r   Zpip._vendor.sixr   Úpip._internal.cli.status_codesr   Úpip._internal.configurationr   r   Úpip._internal.utils.compatr	   Úpip._internal.utils.miscr
   Ú	getLoggerrN   r}   r   r   rR   ro   r^   rk   r   r   r   r   Ú<module>   s"   
P