
    Kui6                    h   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jD                        Z# G d de#      Z$ G d dejJ                        Z& G d de&      Z'y)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-]*)c                r    d|d<   d|d<   t        j                         d   dz
  |d<   t        |   |i | y )N   max_help_position   indent_incrementr      width)shutilget_terminal_sizesuper__init__)selfargskwargs	__class__s      b/root/.openclaw/workspace/chatterbox_venv/lib/python3.12/site-packages/pip/_internal/cli/parser.pyr"   zPrettyHelpFormatter.__init__)   sG    &("#%&!" 224Q7!;w$)&)    c                   g }|j                   r"|j                  d|j                   d    d       |j                  r"|j                  d|j                  d    d       t        |      dkD  r|j	                  dd       |j                         rb|j                  J |j                  xs |j                  j                         }|j                  dt        |j                                d       d	j                  |      S )
z=Return a comma-separated list of option strings and metavars.z[optparse.shortargs]r   z[/]z[optparse.longargs]r   z, z [optparse.metavar]<z>[/] )_short_optsappend
_long_optsleninserttakes_valuedestmetavarlowerr	   join)r#   optionoptsr2   s       r'   format_option_stringsz)PrettyHelpFormatter.format_option_strings0   s    KK.v/A/A!/D.ESIJKK-f.?.?.B-C3GHt9q=KK4 ;;***nn;(9(9(;GKK.vgmmo/F.GtLMwwt}r(   c           	        g }| j                   |   }| j                  | j                  z
  dz
  }t        j                  dd|      }t        |      t        |      z
  }t        |      |kD  rd| j                  d|fz  }| j                  }nd| j                  d||z   |fz  }d}|j                  |       |j                  r~| j                  |      }t        j                  || j                        }	|j                  d|d|	d   fz         |j                  |	dd D 
cg c]  }
d| j                  d|
fz   c}
       n|d	   d
k7  r|j                  d
       dj                  |      S c c}
w )z$Overridden method with Rich support.r   z(\[[a-z.]+\])|(\[\/\])r*   z%*s%s
z	%*s%-*s  r   r   N
)option_stringshelp_positioncurrent_indentresubr.   r,   helpexpand_defaulttextwrapwrap
help_widthextendr4   )r#   r5   resultr6   	opt_widthstrippedstyle_tag_lengthindent_first	help_text
help_lineslines              r'   format_optionz!PrettyHelpFormatter.format_optionB   sm    ""6*&&)<)<<q@	 663R>t9s8}4x=9$ 3 3R>>D--L$"5"5r"+.>">"F FDLd;;++F3I!y$//BJMM)|RA&GGHMM'1!"~7# %(:(:B'EE 7 8"XMM$wwv	7s   E&c                0    |dk(  rydt        |      z   dz   S )NOptionsr*   z[optparse.groups]z:[/]
r   )r#   headings     r'   format_headingz"PrettyHelpFormatter.format_heading`   s!    i"VG_4x??r(   c                n    | j                  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:[/] r:   )indent_linesrB   dedentr	   )r#   usagecontentsmsgs       r'   format_usagez PrettyHelpFormatter.format_usagee   s8    
 $$X__U%;TB-fX.>-?rB
r(   c                    |rkt        | j                  d      rd}nd}|j                  d      }|j                         }| j	                  t        j                  |      d      }| d| d}|S y)Nmainz[optparse.groups]Commands:[/]z [optparse.groups]Description:[/]r:   rT   r*   )hasattrparserlstriprstriprU   rB   rV   )r#   descriptionlabels      r'   format_descriptionz&PrettyHelpFormatter.format_descriptionn   ss    t{{F+7: &,,T2K%,,.K++HOOK,H$OK"G2k]"5Kr(   c                    |rt        |      S y)Nr*   r   )r#   epilogs     r'   format_epilogz!PrettyHelpFormatter.format_epilog   s    &>!r(   c                    t        t        | 	  |            }| j                  j	                         D ]   \  }}t        j                  |d| d|      }" |S )z@Overridden HelpFormatter.expand_default() which colorizes flags.z
[optparse.z] \1[/])r	   r!   rA   
highlightsitemsr>   r?   )r#   r5   r@   regexstyler&   s        r'   rA   z"PrettyHelpFormatter.expand_default   sY    eg,V45 OO113 	ELE566%JugW!=tDD	Er(   c                p    |j                  d      D cg c]  }||z   	 }}dj                  |      S c c}w Nr:   )splitr4   )r#   textindentrM   	new_liness        r'   rU   z PrettyHelpFormatter.indent_lines   s7    /3zz$/?@tVd]@	@yy## As   3)r$   r   r%   r   returnNoner5   optparse.Optionrr   str)rQ   rv   rr   rv   )rW   rv   rr   rv   )ra   
str | Nonerr   rv   )re   rw   rr   rv   )ro   rv   rp   rv   rr   rv   )__name__
__module____qualname____doc__stylesrh   r"   r7   rN   rR   rZ   rc   rf   rA   rU   __classcell__r&   s   @r'   r   r      sX    > &#&$	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
    c                   d }| j                   t        | j                   t              sJ | j                   j                  | j                   j                         |j
                  J | j                   j                  j                  |j
                        }t        | !  |      }|rV|j                  dk(  rGt        |t              r|g}t        |t              sg }|D ]  }|j                  |t        |            } |S )NURL)r^   
isinstanceConfigOptionParser_update_defaultsdefaultsr1   getr!   rA   r2   rv   listreplacer   )r#   r5   default_valuesrK   valr&   s        r'   rA   z,UpdatingDefaultsHelpFormatter.expand_default   s    ;;"dkk+=>>>KK(()=)=>;;***![[1155fkkBNG*62	fnn5.#."0!1 nd3!#% N%--c3G3LM	N r(   rt   )rx   ry   rz   r{   rA   r}   r~   s   @r'   r   r      s     r(   r   c                  6    e Zd Z	 	 	 	 	 	 	 	 ddZedd       Zy)CustomOptionParserc                     | j                   |i |}| j                  j                          | j                  j                  ||       |S )z*Insert an OptionGroup at a given position.)add_option_groupoption_groupspopr/   )r#   idxr$   r%   groups        r'   insert_option_groupz&CustomOptionParser.insert_option_group   sH     &%%t6v6 !!#u-r(   c                |    | j                   dd }| j                  D ]  }|j                  |j                           |S )z<Get a list of all options, including those in option groups.N)option_listr   rE   )r#   resis      r'   option_list_allz"CustomOptionParser.option_list_all   s@     q!## 	&AJJq}}%	& 
r(   N)r   intr$   r   r%   r   rr   zoptparse.OptionGroup)rr   zlist[optparse.Option])rx   ry   rz   r   propertyr    r(   r'   r   r      s;    		"	.1			  r(   r   c                  r     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)isolatedc               n    || _         t        |      | _        | j                   sJ t        |   |i | y N)namer   configr!   r"   )r#   r   r   r$   r%   r&   s        r'   r"   zConfigOptionParser.__init__   s6     	#H-yyy$)&)r(   c                    	 |j                  ||      S # t        j                  $ r-}t        d|        t	        j
                  d       Y d }~y d }~ww xY w)Nz(An error occurred during configuration:    )check_valueoptparseOptionValueErrorprintsysexit)r#   r5   keyr   excs        r'   check_defaultz ConfigOptionParser.check_default   sM    	%%c3//(( 	<SEBCHHQKK	s    A#AAc              #    K   d| j                   dg}|D ci c]  }|i  }}| j                  j                         D ]?  \  }}|j                         D ]'  \  }}|j                  dd      \  }}	||v s |||   |	<   ) A |D 
ci c].  }|||   j                         D 
cg c]  \  }
}|s	|
|f c}}
0 }}
}}|D ]  }||   E d {     y c c}w c c}}
w c c}}
}w 7 w)Nglobalz:env:.r   )r   r   ri   rn   )r#   override_orderr   section_items_dict_valuesection_keyr   sectionr   kvsection_itemss                r'    _get_ordered_configuration_itemsz3ConfigOptionParser._get_ordered_configuration_items   s$     #DIIw7 "09
D"H9
 9
 ))+ 	;HAu$)KKM ; S*00a8n,7:&w/4	;	; '
 
 &8&>&D&D&FLda!Aq6LL
 
 & 	.G$W---	.'9
 M
 .sL   C$
CAC$2C$C 
C+C1C7C$C"	C$CC$c           	        t        j                  | j                        | _        t	               }| j                         D ]  \  }}| j                  d|z         }||j                  J |j                  dv r	 t        |      }ni|j                  dk(  rst        t              5  t        |      }ddd       t        t              5  t        |      }ddd       t        |t              r|dk  r| j                  | d| d       n|j                  d	k(  r1|j                         }|D cg c]  }| j!                  |||       }}n|j                  d
k(  r|j"                  J |j%                  |j                         |j'                         }|j)                  ||      }|j*                  xs d}|j,                  xs i }	 |j"                  |||| g|i |	 n| j!                  |||      }|||j                  <    |D ]  }t/        | j                  |      ||<    d| _        |S # t        $ r | j                  | d| d       Y ]w xY w# 1 sw Y   xY w# 1 sw Y   xY wc c}w )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.r,   callbackr   )r   Valuesr   valuessetr   
get_optionr1   actionr   
ValueErrorerrorr   r   r   rn   r   r   addget_opt_stringconvert_valuecallback_argscallback_kwargsgetattr)
r#   r   	late_evalr   r   r5   r   opt_strr$   r%   s
             r'   r   z#ConfigOptionParser._update_defaults  sa    oodmm4E	==? 0	(HC__TCZ0F
 ~;;***}} ==#C.C ')j) )#C.C)j) #c(C#!#s+sQwJJ%9# ?6 6 (*iikCFGat))&#q9GG*,222fkk* //1**7C8++1r//52dLTLVL((c:$'HV[[!a0	(d  	6C#DKK5HSM	6M " JJ%9# ?5 5) )# # Hs0   :H+%II,I++ III	I(	c                p   | j                   st        j                  | j                        S 	 | j                  j                          | j                  | j                  j                               }| j                         D ]k  }|j                  J |j                  |j                        }t        |t              s=|j!                         }|j#                  ||      ||j                  <   m t        j                  |      S # t        $ r)}| j                  t        t        |             Y d}~d}~ww xY w)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   rv   r   copy_get_all_optionsr1   r   r   r   r   )r#   errr   r5   defaultr   s         r'   get_default_valuesz%ConfigOptionParser.get_default_valuesA  s     **??4==11	/KK ((););)=>++- 	MF;;***ll6;;/G'3' //1(.(:(:7G(L%	M x(( " 	/IImSX..	/s   D 	D5D00D5c                t    | j                  t        j                         | j                  t        | d       y rm   )print_usager   stderrr   r   )r#   rY   s     r'   r   zConfigOptionParser.errorW  s(    $		-C5,r(   c                h   dt         j                  v xsJ t        t        t        j
                  j                  dd      xs d            xs dt        j
                  v }t        t        t        j                        ||      }|j                  | j                         j                         d       y )Nz
--no-colorPIP_NO_COLORnoNO_COLOR)themeno_colorfileF)	highlight)r   argvboolr   osenvironr   r   r
   r   r|   r   format_helpr`   )r#   r   r   consoles       r'   
print_helpzConfigOptionParser.print_help[  s     CHH$ (Ibjjnn^TBJdKL(RZZ' 	
 +223hT
 	d&&(//1UCr(   )
r$   r   r   rv   r   r   r%   r   rr   rs   )r5   ru   r   rv   r   r   rr   r   )rr   z&Generator[tuple[str, Any], None, None])r   dict[str, Any]rr   r   )rr   zoptparse.Values)rY   rv   rr   r   r   )r   r   rr   rs   )rx   ry   rz   r{   r"   r   r   r   r   r   r   r}   r~   s   @r'   r   r      sp    7 	** * 	*
 * 
*.	/.>>@),-D Dr(   r   )(r{   
__future__r   loggingr   r   r>   r   r   rB   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   	getLoggerrx   loggerIndentedHelpFormatterr   r   OptionParserr   r   r   r(   r'   <module>r      s     "   	 	  
  %    * ( 8 I 2 D			8	$v$(88 v$r$7 @.. ,\D+ \Dr(   