
    VPi6                    j   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j        e           Z! G d dej"                  Z# G d de#          Z$ G d dej%                  Z& G 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                       e Zd ZdZdddddZddd	Zd" fdZd#dZd#dZd$dZ	d%dZ
d&dZd'dZd# fdZd(d!Z xZS ))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                    d|d<   d|d<   t          j                    d         dz
  |d<    t                      j        |i | d S )N   max_help_position   indent_incrementr      width)shutilget_terminal_sizesuper__init__)selfr   r   	__class__s      l/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/pip/_internal/cli/parser.pyr&   zPrettyHelpFormatter.__init__)   sW    &("#%&!" 244Q7!;w$)&)))))    optionoptparse.Optionstrc                   g }|j         r$|                    d|j         d          d           |j        r$|                    d|j        d          d           t          |          dk    r|                    dd           |                                ra|j        J |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+   optsr7   s       r)   format_option_stringsz)PrettyHelpFormatter.format_option_strings0   s	    	KKKIv/A!/DIIIJJJ 	IKKGf.?.BGGGHHHt99q==KK4    	N;***n;(9(9(;(;GKKLvgmmoo/F/FLLLMMMwwt}}r*   c                    g } j         |         } j         j        z
  dz
  }t          j        dd|          }t          |          t          |          z
  }t          |          |k    rd j        d|fz  } j        }nd j        d||z   |fz  }d}|                    |           |j        rz                     |          }t          j
        | j                  }	|                    d|d|	d         fz             |                     fd|	dd	         D                        n!|d
         dk    r|                    d           d                    |          S )z$Overridden method with Rich support.r!   z(\[[a-z.]+\])|(\[\/\])r/   %*s%s
z	%*s%-*s  r   c                *    g | ]}d j         d|fz  S )r=   r/   )help_position).0liner'   s     r)   
<listcomp>z5PrettyHelpFormatter.format_option.<locals>.<listcomp>Y   s8     7 7 7# %(:B'EE 7 7 7r*   r   N
)option_stringsr?   current_indentresubr3   r1   helpexpand_defaulttextwrapwrap
help_widthextendr9   )
r'   r+   resultr:   	opt_widthstrippedstyle_tag_lengthindent_first	help_text
help_liness
   `         r)   format_optionz!PrettyHelpFormatter.format_optionB   s    "6*&)<<q@	 63R>>t99s8}}4x==9$$ 3R>>D-LL$"5r"+.>">"F FDLd; 	 ++F33I!y$/BBJMM)|RA&GGHHHMM 7 7 7 7'1!""~7 7 7 8 8 8 8"XMM$wwvr*   headingc                <    |dk    rdS dt          |          z   dz   S )NOptionsr/   z[optparse.groups]z:[/]
r   )r'   rW   s     r)   format_headingz"PrettyHelpFormatter.format_heading`   s(    i2"VG__4x??r*   usagec                |    |                      t          j        |          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:[/] rD   )indent_linesrK   dedentr	   )r'   r[   contentsmsgs       r)   format_usagez PrettyHelpFormatter.format_usagee   s@    
 $$X_U%;%;TBBBfX.>.>BBB
r*   description
str | Nonec                    |rut          | j        d          rd}nd}|                    d          }|                                }|                     t          j        |          d          }| d| d}|S dS )Nmainz[optparse.groups]Commands:[/]z [optparse.groups]Description:[/]rD   r]   r/   )hasattrparserlstriprstripr^   rK   r_   )r'   rc   labels      r)   format_descriptionz&PrettyHelpFormatter.format_descriptionn   s     	t{F++ ;7: &,,T22K%,,..K++HOK,H,H$OOK"55k555K2r*   epilogc                (    |rt          |          S dS )Nr/   r   )r'   rm   s     r)   format_epilogz!PrettyHelpFormatter.format_epilog   s     	&>>!2r*   c                    t          t                                          |                    }| j                                        D ]\  }}t          j        |d| d|          } |S )z@Overridden HelpFormatter.expand_default() which colorizes flags.z
[optparse.z] \1[/])r	   r%   rJ   
highlightsitemsrG   rH   )r'   r+   rI   regexstyler(   s        r)   rJ   z"PrettyHelpFormatter.expand_default   sk    egg,,V4455 O1133 	E 	ELE56%!=u!=!=!=tDDDDr*   textindentc                p    fd|                     d          D             }d                    |          S )Nc                    g | ]}|z   S  ry   )r@   rA   rv   s     r)   rB   z4PrettyHelpFormatter.indent_lines.<locals>.<listcomp>   s    @@@tVd]@@@r*   rD   )splitr9   )r'   ru   rv   	new_liness     ` r)   r^   z PrettyHelpFormatter.indent_lines   s:    @@@@tzz$/?/?@@@	yy###r*   )r   r   r   r   r   r   r+   r,   r   r-   )rW   r-   r   r-   )r[   r-   r   r-   )rc   rd   r   r-   )rm   rd   r   r-   )ru   r-   rv   r-   r   r-   )__name__
__module____qualname____doc__stylesrq   r&   r;   rV   rZ   rb   rl   ro   rJ   r^   __classcell__r(   s   @r)   r   r      s       >> &#&$	 F !, * J
* * * * * *   $   <@ @ @ @
      &        $ $ $ $ $ $ $ $r*   r   c                  $     e Zd ZdZd fdZ xZS )UpdatingDefaultsHelpFormatterzCustom 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                   d }| j         mt          | j         t                    sJ | j                             | j         j                   |j        J | j         j                            |j                  }t                                          |          }|rb|j	        dk    rWt          |t                    r|g}t          |t                    sg }|D ]%}|                    |t          |                    }&|S )NURL)rh   
isinstanceConfigOptionParser_update_defaultsdefaultsr6   getr%   rJ   r7   r-   listreplacer   )r'   r+   default_valuesrT   valr(   s        r)   rJ   z,UpdatingDefaultsHelpFormatter.expand_default   s   ;"dk+=>>>>>K(()=>>>;***![155fkBBNGG**622	 		Nfn55.#.. 2"0!1 nd33 $!#% N N%--c3G3L3LMM		r*   r|   )r}   r~   r   r   rJ   r   r   s   @r)   r   r      sG                  r*   r   c                  .    e Zd ZddZedd
            ZdS )CustomOptionParseridxintr   r   r   r   optparse.OptionGroupc                     | j         |i |}| j                                         | j                            ||           |S )z*Insert an OptionGroup at a given position.)add_option_groupoption_groupspopr4   )r'   r   r   r   groups        r)   insert_option_groupz&CustomOptionParser.insert_option_group   sN     &%t6v66   !!#u---r*   list[optparse.Option]c                l    | j         dd         }| j        D ]}|                    |j                    |S )z<Get a list of all options, including those in option groups.N)option_listr   rN   )r'   resis      r)   option_list_allz"CustomOptionParser.option_list_all   sC     qqq!# 	& 	&AJJq}%%%%
r*   N)r   r   r   r   r   r   r   r   )r   r   )r}   r~   r   r   propertyr   ry   r*   r)   r   r      sH        	 	 	 	    X  r*   r   c                  \     e Zd ZdZddd  fdZd!dZd"dZd#dZd$dZd%dZ	d&d'dZ
 xZS )(r   zsCustom option parser which updates its defaults by checking the
    configuration files and environmental variablesF)isolatedr   r   namer-   r   boolr   r   r   c                   || _         t          |          | _        | j         sJ  t                      j        |i | d S N)r   r   configr%   r&   )r'   r   r   r   r   r(   s        r)   r&   zConfigOptionParser.__init__   sJ     	#H--yy$)&)))))r*   r+   r,   keyr   c                    	 |                     ||          S # t          j        $ r1}t          d|            t	          j        d           Y d }~d S d }~ww xY w)Nz(An error occurred during configuration:    )check_valueoptparseOptionValueErrorprintsysexit)r'   r+   r   r   excs        r)   check_defaultz ConfigOptionParser.check_default   so    	%%c3///( 	 	 	BSBBCCCHQKKKKKKKKK	s    A&AA&Generator[tuple[str, Any], None, None]c              #  <  	K   d| j         dg}d |D             	| j                                        D ]G\  }}|                                D ]-\  }}|                    dd          \  }}||v r|	|         |<   .H	fd|D             }|D ]}||         E d {V  d S )Nglobalz:env:c                    i | ]}|i S ry   ry   )r@   r   s     r)   
<dictcomp>zGConfigOptionParser._get_ordered_configuration_items.<locals>.<dictcomp>   s'     9
 9
 9
D"9
 9
 9
r*   .r   c                Z    i | ]'}|d  |                                          D             (S )c                     g | ]\  }}|||fS ry   ry   )r@   kvs      r)   rB   zRConfigOptionParser._get_ordered_configuration_items.<locals>.<dictcomp>.<listcomp>   s%    LLLda!LAq6LLLr*   )rr   )r@   r   section_items_dicts     r)   r   zGConfigOptionParser._get_ordered_configuration_items.<locals>.<dictcomp>   sL     
 
 
 LL&8&>&D&D&F&FLLL
 
 
r*   )r   r   rr   rz   )
r'   override_order_valuesection_keyr   sectionr   section_itemsr   s
            @r)    _get_ordered_configuration_itemsz3ConfigOptionParser._get_ordered_configuration_items   s      #DIw7
9
 9
!/9
 9
 9
 ))++ 	; 	;HAu$)KKMM ; ; S*00a88n,,7:&w/4	;
 
 
 
&
 
 
 & 	. 	.G$W---------	. 	.r*   r   dict[str, Any]c                    t          j         j                   _        t	                      }                                 D ]\  }                     dz             !j        J j        dv r>	 t          |          }n# t          $ r                      | d d           Y nw xY wj        dk    rt          t                    5  t          |          }ddd           n# 1 swxY w Y   t          t                    5  t          |          }ddd           n# 1 swxY w Y   t          |t                    r|dk     r                     | d d           nƉj        d	k    r%|                                } fd
|D             }nj        dk    rtj        J |                    j                                                   }                    ||          }j        pd}j        pi } j        || g|R i | n                     |          }||j        <   |D ]t/           j                  |<   d _        |S )zUpdates 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.r1   c                >    g | ]}                     |          S ry   )r   )r@   r   r   r+   r'   s     r)   rB   z7ConfigOptionParser._update_defaults.<locals>.<listcomp>-  s+    GGGat))&#q99GGGr*   callbackry   )r   Valuesr   valuessetr   
get_optionr6   actionr   
ValueErrorerrorr   r   r   rz   r   addget_opt_stringconvert_valuecallback_argscallback_kwargsr   getattr)	r'   r   	late_evalr   opt_strr   r   r   r+   s	   `      @@r)   r   z#ConfigOptionParser._update_defaults  sQ    odm44EE	==?? 0	( 0	(HC__TCZ00F
 ~;***} ===#C..CC!   JJ 5 5# 5 5 5     '))j)) ) )#C..C) ) ) ) ) ) ) ) ) ) ) ) ) ) )j)) # #c((C# # # # # # # # # # # # # # #!#s++ sQwwJJ 6 6# 6 6 6   (**iikkGGGGGG3GGG*,,222fk*** //11**7C88+1r/52dLTLLLVLLLL((c::$'HV[!! 	6 	6C#DK55HSMMs6   8B		%B21B2C00C4	7C4	D++D/	2D/	optparse.Valuesc                x   | j         st          j        | j                  S 	 | j                                         n?# t          $ r2}|                     t          t          |                     Y d}~nd}~ww xY w| 
                    | j                                                  }|                                 D ]l}|j        J |                    |j                  }t          |t                    r2|                                }|                    ||          ||j        <   mt          j        |          S )zOverriding 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_optionsr6   r   r   r   r   )r'   errr   r+   defaultr   s         r)   get_default_valuesz%ConfigOptionParser.get_default_valuesA  s7    * 	2?4=111	/K! 	/ 	/ 	/IImSXX........	/ ((););)=)=>>++-- 	M 	MF;***ll6;//G'3'' M //11(.(:(:7G(L(L%x(((s   < 
A8(A33A8ra   r   c                    |                      t          j                   |                     t          | d           d S )NrD   )print_usager   stderrr   r   )r'   ra   s     r)   r   zConfigOptionParser.errorW  s8    $$$		-C,,,,,r*   Nfilec                ~   dt           j        v pIt          t          t          j                            dd          pd                    pdt          j        v }t          t          t          j
                  ||          }|                    |                                                                 d           d S )Nz
--no-colorPIP_NO_COLORnoNO_COLOR)themeno_colorr   F)	highlight)r   argvr   r   osenvironr   r   r
   r   r   r   format_helprj   )r'   r   r   consoles       r)   
print_helpzConfigOptionParser.print_help[  s     CH$ (Ibjnn^TBBJdKKLL(RZ' 	
 +233hT
 
 
 	d&&((//11UCCCCCr*   )
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   )ra   r-   r   r   r   )r   r   r   r   )r}   r~   r   r   r&   r   r   r   r   r   r   r   r   s   @r)   r   r      s        7 7 	* * * * * * * *   . . . .>> > > >@) ) ) ),- - - -D D D D D D D D Dr*   r   )(r   
__future__r   loggingr   r   rG   r#   r   rK   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   	getLoggerr}   loggerIndentedHelpFormatterr   r   OptionParserr   r   ry   r*   r)   <module>r     s     " " " " " "   				 				  



  % % % % % %                       * * * * * * ( ( ( ( ( ( 8 8 8 8 8 8 I I I I I I I I 2 2 2 2 2 2 D D D D D D D D		8	$	$v$ v$ v$ v$ v$(8 v$ v$ v$r    $7   @    .   ,\D \D \D \D \D+ \D \D \D \D \Dr*   