o
    ©„jC7  ã                   @  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ZddlZddl	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 dd	lmZ dd
lmZmZ ddlmZ ddlmZ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é    )ÚannotationsN)Ú	Generator)Úsuppress)ÚAnyÚNoReturn©Úescape)ÚTheme)ÚUNKNOWN_ERROR)ÚConfigurationÚConfigurationError)Ú
PipConsole)Úredact_auth_from_urlÚ	strtoboolc                      sŽ   e Zd ZdZdddddœZddd	œZd+‡ fdd„Zd,dd„Zd,dd„Zd-dd„Z	d.dd„Z
d/d d!„Zd0d#d$„Zd,‡ fd%d&„Zd1d)d*„Z‡  ZS )2ÚPrettyHelpFormatterz4A prettier/less verbose help formatter for optparse.ÚgreenÚcyanz	bold blueÚyellow)zoptparse.shortargszoptparse.longargszoptparse.groupszoptparse.metavarÚ	shortargsÚlongargs)z\s(-{1}[\w]+[\w-]*)z\s(-{2}[\w]+[\w-]*)Úargsr   ÚkwargsÚreturnÚNonec                   s:   d|d< d|d< t  ¡ d d |d< tƒ j|i |¤Ž d S )Né   Úmax_help_positioné   Úindent_incrementr   é   Úwidth)ÚshutilÚget_terminal_sizeÚsuperÚ__init__)Úselfr   r   ©Ú	__class__© úV/var/www/html/django_cbt/venv/lib/python3.10/site-packages/pip/_internal/cli/parser.pyr#   )   s   zPrettyHelpFormatter.__init__Úoptionúoptparse.OptionÚstrc                 C  s¢   g }|j r| d|j d › d�¡ |jr | d|jd › d�¡ t|ƒdkr,| dd¡ | ¡ rL|jdus7J ‚|jp>|j ¡ }| dt	| ¡ ƒ› d	�¡ d
 
|¡S )z=Return a comma-separated list of option strings and metavars.z[optparse.shortargs]r   z[/]z[optparse.longargs]r   z, Nz [optparse.metavar]<z>[/]Ú )Ú_short_optsÚappendÚ
_long_optsÚlenÚinsertÚtakes_valueÚdestÚmetavarÚlowerr   Újoin)r$   r)   Úoptsr4   r'   r'   r(   Úformat_option_strings0   s   
z)PrettyHelpFormatter.format_option_stringsc           
        sü   g }ˆ j | }ˆ jˆ j d }t dd|¡}t|ƒt|ƒ }t|ƒ|kr0dˆ jd|f }ˆ j}ndˆ jd|| |f }d}| |¡ |jrnˆ  |¡}t	 
|ˆ j¡}	| d|d|	d f ¡ | ‡ fdd„|	d	d
… D ƒ¡ n|d dkry| d¡ d |¡S )z$Overridden method with Rich support.r   z(\[[a-z.]+\])|(\[\/\])r,   ú%*s%s
z	%*s%-*s  r   c                   s   g | ]
}d ˆ j d|f ‘qS )r9   r,   )Úhelp_position©Ú.0Úline©r$   r'   r(   Ú
<listcomp>Y   s    ÿz5PrettyHelpFormatter.format_option.<locals>.<listcomp>r   NéÿÿÿÿÚ
)Úoption_stringsr:   Úcurrent_indentÚreÚsubr0   r.   ÚhelpÚexpand_defaultÚtextwrapÚwrapÚ
help_widthÚextendr6   )
r$   r)   Úresultr7   Ú	opt_widthÚstrippedÚstyle_tag_lengthÚindent_firstÚ	help_textÚ
help_linesr'   r>   r(   Úformat_optionB   s.   
ÿ



ÿ

z!PrettyHelpFormatter.format_optionÚheadingc                 C  s   |dkrdS dt |ƒ d S )NÚOptionsr,   z[optparse.groups]z:[/]
r   )r$   rT   r'   r'   r(   Úformat_heading`   s   z"PrettyHelpFormatter.format_headingÚusagec                 C  s&   |   t |¡d¡}dt|ƒ› d�}|S )zz
        Ensure there is only one newline between usage and the first heading
        if there is no description.
        ú  z
[optparse.groups]Usage:[/] rA   )Úindent_linesrH   Údedentr   )r$   rW   ÚcontentsÚmsgr'   r'   r(   Úformat_usagee   s   z PrettyHelpFormatter.format_usageÚdescriptionú
str | Nonec                 C  sV   |r)t | jdƒrd}nd}| d¡}| ¡ }|  t |¡d¡}|› d|› d�}|S dS )NÚmainz[optparse.groups]Commands:[/]z [optparse.groups]Description:[/]rA   rX   r,   )ÚhasattrÚparserÚlstripÚrstriprY   rH   rZ   )r$   r^   Úlabelr'   r'   r(   Úformat_descriptionn   s   
z&PrettyHelpFormatter.format_descriptionÚepilogc                 C  s   |rt |ƒS dS )Nr,   r   )r$   rg   r'   r'   r(   Úformat_epilog�   s   z!PrettyHelpFormatter.format_epilogc                   s>   t tƒ  |¡ƒ}| j ¡ D ]\}}t |d|› d�|¡}q|S )z@Overridden HelpFormatter.expand_default() which colorizes flags.z
[optparse.z] \1[/])r   r"   rG   Ú
highlightsÚitemsrD   rE   )r$   r)   rF   ÚregexÚstyler%   r'   r(   rG   ˆ   s   z"PrettyHelpFormatter.expand_defaultÚtextÚindentc                   s"   ‡ fdd„|  d¡D ƒ}d |¡S )Nc                   s   g | ]}ˆ | ‘qS r'   r'   r;   ©rn   r'   r(   r?   �   s    z4PrettyHelpFormatter.indent_lines.<locals>.<listcomp>rA   )Úsplitr6   )r$   rm   rn   Ú	new_linesr'   ro   r(   rY   �   s   
z PrettyHelpFormatter.indent_lines)r   r   r   r   r   r   ©r)   r*   r   r+   )rT   r+   r   r+   )rW   r+   r   r+   )r^   r_   r   r+   )rg   r_   r   r+   )rm   r+   rn   r+   r   r+   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ústylesri   r#   r8   rS   rV   r]   rf   rh   rG   rY   Ú__classcell__r'   r'   r%   r(   r      s&    üþ




	
r   c                      s"   e Zd ZdZd‡ fdd„Z‡  Z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
    r)   r*   r   r+   c                   s¢   d }| j d ur&t| j tƒsJ ‚| j  | j j¡ |jd usJ ‚| j j |j¡}tƒ  |¡}|rO|j	dkrOt|t
ƒr;|g}t|tƒsBg }|D ]
}| |t|ƒ¡}qD|S )NÚURL)rb   Ú
isinstanceÚConfigOptionParserÚ_update_defaultsÚdefaultsr3   Úgetr"   rG   r4   r+   ÚlistÚreplacer   )r$   r)   Údefault_valuesrQ   Úvalr%   r'   r(   rG   �   s   


z,UpdatingDefaultsHelpFormatter.expand_defaultrr   )rs   rt   ru   rv   rG   rx   r'   r'   r%   r(   ry   ”   s    ry   c                   @  s$   e Zd Zddd	„Zeddd„ƒZdS )ÚCustomOptionParserÚidxÚintr   r   r   r   úoptparse.OptionGroupc                 O  s,   | j |i |¤Ž}| j ¡  | j ||¡ |S )z*Insert an OptionGroup at a given position.)Úadd_option_groupÚoption_groupsÚpopr1   )r$   r…   r   r   Úgroupr'   r'   r(   Úinsert_option_groupµ   s   
z&CustomOptionParser.insert_option_groupúlist[optparse.Option]c                 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‰   rK   )r$   ÚresÚir'   r'   r(   Úoption_list_allÀ   s   
z"CustomOptionParser.option_list_allN)r…   r†   r   r   r   r   r   r‡   )r   r�   )rs   rt   ru   rŒ   Úpropertyr‘   r'   r'   r'   r(   r„   ´   s    
r„   c                      s~   e Zd ZdZddœd,‡ fdd„Zd-dd„Zd.dd„Zd/dd„Zd0dd„Zd1d!d"„Z	d2d3d&d'„Z
d2d4d(d)„Zd2d4d*d+„Z‡  ZS )5r|   zsCustom option parser which updates its defaults by checking the
    configuration files and environmental variablesF)Úisolatedr   r   Únamer+   r“   Úboolr   r   r   c                  s0   || _ t|ƒ| _| j sJ ‚tƒ j|i |¤Ž d S ©N)r”   r   Úconfigr"   r#   )r$   r”   r“   r   r   r%   r'   r(   r#   Î   s   

zConfigOptionParser.__init__r)   r*   Úkeyrƒ   c              
   C  sP   z|  ||¡W S  tjy' } ztd|› �ƒ t d¡ W Y d }~d S d }~ww )Nz(An error occurred during configuration: é   )Úcheck_valueÚoptparseÚOptionValueErrorÚprintÚsysÚexit)r$   r)   r˜   rƒ   Úexcr'   r'   r(   Úcheck_defaultÛ   s   €þz ConfigOptionParser.check_defaultú&Generator[tuple[str, Any], None, None]c           	      #  s”   � d| j dg}dd„ |D ƒ‰ | j ¡ D ]\}}| ¡ D ]\}}| dd¡\}}||v r1|ˆ | |< qq‡ fdd„|D ƒ}|D ]	}|| E d H  q>d S )NÚglobalz:env:c                 S  s   i | ]}|i “qS r'   r'   ©r<   r”   r'   r'   r(   Ú
<dictcomp>ë   s    ÿzGConfigOptionParser._get_ordered_configuration_items.<locals>.<dictcomp>Ú.r   c                   s$   i | ]}|d d„ ˆ |   ¡ D ƒ“qS )c                 S  s   g | ]
\}}|r||f‘qS r'   r'   )r<   ÚkÚvr'   r'   r(   r?   ù   s    zRConfigOptionParser._get_ordered_configuration_items.<locals>.<dictcomp>.<listcomp>)rj   r¤   ©Úsection_items_dictr'   r(   r¥   ø   s    ÿÿ)r”   r—   rj   rp   )	r$   Úoverride_orderÚ_ÚvalueÚsection_keyrƒ   Úsectionr˜   Úsection_itemsr'   r©   r(   Ú _get_ordered_configuration_itemsâ   s$   €ÿ€ü
þÿz3ConfigOptionParser._get_ordered_configuration_itemsr~   údict[str, Any]c              
     sò  t  ˆj¡ˆ_tƒ }ˆ ¡ D ]Ø\‰ }ˆ dˆ  ¡‰ˆdu rqˆjdus%J ‚ˆjdv rEzt	|ƒ}W n° t
yD   ˆ |› dˆ › d�¡ Y n�w ˆjdkr�tt
ƒ� t	|ƒ}W d  ƒ n1 s]w   Y  tt
ƒ� t|ƒ}W d  ƒ n1 suw   Y  t|tƒrƒ|dk rŽˆ |› dˆ › d�¡ nRˆjd	kr¤| ¡ }‡ ‡‡fd
d„|D ƒ}n=ˆjdkrÚˆjdus°J ‚| ˆj¡ ˆ ¡ }ˆ ||¡}ˆjpÄd}ˆ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_falsez is not a valid value for zO option, please specify a boolean value like yes/no, true/false or 1/0 instead.Úcountr   z† 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'   )r¡   )r<   r¨   ©r˜   r)   r$   r'   r(   r?   -  s    z7ConfigOptionParser._update_defaults.<locals>.<listcomp>Úcallbackr'   )r›   ÚValuesr~   ÚvaluesÚsetr±   Ú
get_optionr3   Úactionr   Ú
ValueErrorÚerrorr   r†   r{   rp   r·   ÚaddÚget_opt_stringÚconvert_valueÚcallback_argsÚcallback_kwargsr¡   Úgetattr)r$   r~   Ú	late_evalrƒ   Úopt_strr   r   r'   r¶   r(   r}     sX   
ÿÿ


ÿ

ÿÿ€



 z#ConfigOptionParser._update_defaultsúoptparse.Valuesc              
   C  s¼   | j s	t | j¡S z| j ¡  W n ty* } z|  tt	|ƒ¡ W Y d}~nd}~ww |  
| j ¡ ¡}|  ¡ D ]!}|jdus@J ‚| |j¡}t|t	ƒrX| ¡ }| ||¡||j< q7t |¡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¸   r~   r—   Úloadr   rŸ   r
   r+   r}   ÚcopyÚ_get_all_optionsr3   r   r{   rÀ   rš   )r$   Úerrr~   r)   ÚdefaultrÆ   r'   r'   r(   Úget_default_valuesA  s"   €ÿ
€
z%ConfigOptionParser.get_default_valuesr\   r   c                 C  s"   |   tj¡ |  t|› d�¡ d S )NrA   )Úprint_usagerž   ÚstderrrŸ   r
   )r$   r\   r'   r'   r(   r¾   W  s   zConfigOptionParser.errorNÚfiler   c                 C  sB   dt jv ptttj dd¡pdƒƒpdtjv }ttt	j
ƒ||d�S )Nz
--no-colorÚPIP_NO_COLORÚnoÚNO_COLOR)ÚthemeÚno_colorrÑ   )rž   Úargvr•   r   ÚosÚenvironr   r   r	   r   rw   )r$   rÑ   rÖ   r'   r'   r(   Ú_create_console_for_help[  s   
ÿýÿz+ConfigOptionParser._create_console_for_helpc                 C  s*   | j r|  |¡}|j|  ¡ dd� d S d S ©NF)Ú	highlight)rW   rÚ   r�   Ú	get_usage©r$   rÑ   Úconsoler'   r'   r(   rÏ   g  s   
þzConfigOptionParser.print_usagec                 C  s$   |   |¡}|j|  ¡  ¡ dd� d S rÛ   )rÚ   r�   Úformat_helprd   rÞ   r'   r'   r(   Ú
print_helpl  s   
zConfigOptionParser.print_help)
r   r   r”   r+   r“   r•   r   r   r   r   )r)   r*   r˜   r+   rƒ   r   r   r   )r   r¢   )r~   r²   r   r²   )r   rÇ   )r\   r+   r   r   r–   )rÑ   r   r   r   )rÑ   r   r   r   )rs   rt   ru   rv   r#   r¡   r±   r}   rÎ   r¾   rÚ   rÏ   rá   rx   r'   r'   r%   r(   r|   Ê   s    ü



@
r|   )(rv   Ú
__future__r   Úloggingr›   rØ   rD   r    rž   rH   Úcollections.abcr   Ú
contextlibr   Útypingr   r   Úpip._vendor.rich.markupr   Úpip._vendor.rich.themer	   Úpip._internal.cli.status_codesr
   Úpip._internal.configurationr   r   Úpip._internal.utils.loggingr   Úpip._internal.utils.miscr   r   Ú	getLoggerrs   ÚloggerÚIndentedHelpFormatterr   ry   ÚOptionParserr„   r|   r'   r'   r'   r(   Ú<module>   s.    
y 