
    6h                        S SK Jr  S SKrS SKJrJrJrJr  SSKJ	r	  SSK
JrJrJrJrJrJrJr  SSK
JrJrJrJrJr  S	r      SS
 jrSS jrSS jr   S             SS jjrg)    )annotationsN)Any
CollectionDictOptional   )_)cmdutilerror	formatterpycompatrequirementsuiutil   )ConfigLevelTEDIT_LEVELSLEVEL_SHAREDNO_REPO_EDIT_LEVELSrcutileditc                  ^ TR                  [        5      (       d  [        U4S j[         5       5      (       aK  [        R
                  " T/[        Q76   [         H  nTR                  U5      (       d  M  Us  $    [        S   $ g)zreturn the level we should edit, if any.

Parse the command option to detect when an edit is requested, and if so the
configuration level we should edit.
c              3  F   >#    U  H  nTR                  U5      v   M     g 7fN)get).0ooptss     A/usr/lib/python3/dist-packages/mercurial/configuration/command.py	<genexpr>"find_edit_level.<locals>.<genexpr>*   s     !C{!$((1++{s   !r   N)r   	EDIT_FLAGanyr   r
   check_at_most_one_arg)r   repor   levels     ` r   find_edit_levelr'       sb     xx	c!C{!CCC%%d9[9 Exx ! 1~    c                   UcB  U[         ;  a8  S[        R                  " U5      -  n[        R                  " [        U5      5      eU[        :X  as  UR                  5       (       d!  [        S5      n[        R                  " U5      e[        R                  UR                  ;  a  [        R                  " [        S5      5      eSnUb  UR                  n[        R                  " U5      n0 nU H/  u  pxn	US:w  a  M  UR                  U/ 5      R                  U	5        M1     X&;  a  SU-  n[        R                  " U5      eXb   n
U
 H)  n[         R"                  R%                  U5      (       d  M)    OT   [&        R(                  R+                  U5      nU
S   nUb+  [,        R.                  " U[,        R0                  " U5      5        U R3                  5       nU R5                  SX4-  [        R                  [        S	5      S
S9  g)z8let the user edit configuration file for the given levelNs#   can't use --%s outside a repositorys,   repository is not shared; can't use --sharedsN   share safe feature not enabled; unable to edit shared source repository config   pathzunknown config level: %sr   s   %s "%s"s   edit faileds   config_edit)onerr	errprefix
blockedtag)r   r   bytestrr   
InputErrorr	   r   sharedr   SHARESAFE_REQUIREMENTrootr   all_rc_components
setdefaultappendProgrammingErrorospathexistsuimodsamplehgrcsr   r   	writefiletonativeeol	geteditorsystem)r   r%   r&   msg	repo_pathall_rcsrc_by_levellvlrc_typevaluespathsf
samplehgrceditors                 r   edit_configrK   3   s    |%884x7G7G7NNqv&&{{}}CDC""3''--T5F5FF""F  III	&&y1GK 'fgsB'..v6 !(
 (50$$S))E77>>!  &&**51
!H!NN1d..z:;\\^FII{"N#!	  r(   c                    [         R                  " 5        He  u  p#nUS:X  a  U R                  SU-  5        M"  US:X  a  U R                  SUS   US   4-  5        MF  US:X  a  MN  [        R                  " SU-  5      e   g	)
zshow the component used to build the config

XXX this skip over various source and ignore the repository config, so it
XXX is probably useless old code.
r*   s   read config from: %s
s   resources!   read config from: resource:%s.%s
r   r   s   itemss   unknown rctype: %sN)r   rccomponentsdebugr   r6   )r   r%   _lvltrH   s        r   show_componentrQ   i   s{     ))+
<HH.23+HH:adAaD\IJ(](()>)BCC ,r(   c                H   U R                  SU5      n/ =pSn
U(       a6  U Vs/ s H  nSU;  d  M  UPM     nnU Vs/ s H  nSU;   d  M  UPM     n	nSn
[        U	5      S:H  =(       a    U(       + n[        U5      n[        U	5      n	SnU R                  XES9nU GHi  u  nnnU R	                  UUU5      n[
        R                  " U5      nU R                  UU5      nUR                  5       (       a  U=(       d    SnUR                  SS	5      nUS-   U-   nU
(       a  X;   d  UU	;   d  M  UR                  5         UR                  US
SU5        U(       a#  UR                  US9  UR                  SSU5        OUR                  SSUU5        [         R                  " U5      (       a  UR                  US9  OI[        U[         5      (       a4  [#        S U 5       5      (       a  UR                  UR%                  USS9S9  SnGMl     UR'                  5         U$ s  snf s  snf )a#  Display config value to the user

The display is done using a dedicated `formatter` object.


:value_filters:
    if non-empty filter the display value according to these filters. If
    the filter does not match any value, the function return False. True
    otherwise.

:formatter_option:
    options passed to the formatter

:untrusted:
    When set, use untrusted value instead of ignoring them

:all_known:
    Display all known config item, not just the one with an explicit value.

:show_source:
    Show where each value has been defined.
s   configF   .Tr   )	untrusted	all_knowns   none   
s   \ns   sources   %s: )names   values   %s
s
   name values   %s=%s
)defaultvaluec              3  N   #    U  H  n[         R                  " U5      v   M     g 7fr   )r   isprintable)r   es     r   r    show_config.<locals>.<genexpr>   s!      4
.:I!!!$$ls   #%)r   lenset
walkconfigconfigsourcer   r.   configdefaultisplainreplace	startitem	condwritedatawriterZ   
isinstancelistall
formatlistend)r   r%   value_filtersformatter_optionsrT   rU   show_sourcefmselsections
selentriesfilteredv	uniqueselmatchedentriessectionrW   valuesourcerX   	entrynames                        r   show_configr|   {   s   > 
i!2	3B!!KH"/A-Q4q=q-A!.<A$!)a
<J1$8[Ik"KZJGmmimEG 'u$	:  '''6::<<&wFMM%0EdNT)	W3yJ7N

[)Wf=GGG#HHXw.HH]J	5A  ..GGG.d++ 4
.:4
 1
 1
 GG|(!KGL1 !(2 FFHNG B<s   
HH
HH)r   uimod.uir   zDict[str, Any]returnzOptional[ConfigLevelT])r   r}   r&   r   r~   None)r   r}   r~   r   )FFF)r   r}   rm   zCollection[bytes]rn   dictrT   boolrU   r   ro   r   r~   r   )
__future__r   r7   typingr   r   r   r   i18nr	    r
   r   r   r   r   r   r:   r   r   r   r   r   r   r"   r'   rK   rQ   r|    r(   r   <module>r      s    # 	 2 2     	  	&3lD. FF %F 	F
 F F F 
Fr(   