
    6hO                       S SK Jr  S SKrS SKrS SKrSSKJr  SSKJrJ	r	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JrJr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%  SS	K&J'r'  SS
K(J)r)  S r*S r+S r,S r-SS jr.S r/ SS jr0 " S S5      r1g)    )annotationsN   )_   )	ErrorResponseHTTP_SERVER_ERROR	cspvaluesget_contact	get_mtimeismember	paritygen
staticfilestatusmessage)configitemsencodingerror
extensionshgpathutil	profilingpycompat	registrarscmutil	templatertemplateutiluiutil)	hgweb_modrequestwebutilwsgicgi)rcutil)dateutilc                    U  VVs/ s H,  u  p[         R                  " U5      R                  S5      U4PM.     snn$ s  snnf )N   /)r   pconvertstrip)itemsnamepaths      >/usr/lib/python3/dist-packages/mercurial/hgweb/hgwebdir_mod.py
cleannamesr,   8   s5    FKLe
T]]4 &&t,d3eLLLs   3=c                   / n[        U 5       H  u  p#[        R                  R                  U5      u  pE SSS.U   n[        R                  R                  [        R                  " U5      5      n[        R                  " USUS9n UR                  [        X$U 5      5        M     U$ ! [         a    UR                  X#45         M  f = f)NFT)   *s   **)	followsymrecurse)r,   osr*   splitKeyErrorappendnormpathr   abspathr   	walkreposextendurlrepos)pathsreposprefixrootrootheadroottailr0   s          r+   	findreposr@   <   s    E"5)WW]]40
	"40:G 77##DLL$:;!!(dGLXf67 * L  	LL&(	s   B''CCc              #     #    U Hl  n[         R                  R                  U5      nU S-   [        R                  " U[        U5      S 5      R                  S5      -   R                  S5      U4v   Mn     g7f)az  yield url paths and filesystem paths from a list of repo paths

>>> conv = lambda seq: [(v, util.pconvert(p)) for v,p in seq]
>>> conv(urlrepos(b'hg', b'/opt', [b'/opt/r', b'/opt/r/r', b'/opt']))
[('hg/r', '/opt/r'), ('hg/r/r', '/opt/r/r'), ('hg', '/opt')]
>>> conv(urlrepos(b'', b'/opt', [b'/opt/r', b'/opt/r/r', b'/opt']))
[('r', '/opt/r'), ('r/r', '/opt/r/r'), ('', '/opt')]
r%   N)r1   r*   r5   r   r&   lenlstripr'   )r<   r>   r:   r*   s       r+   r9   r9   O   se      ww%TMDMM$s8}*?@GGMM
%+t 	 s   A4A6c                    UR                   nU R                  SSSS9nU(       a  U(       a  [        XU5      (       a  gU R                  SSSS9nU(       a  [        XU5      (       a  gg)a  Check allow_read and deny_read config options of a repo's ui object
to determine user permissions.  By default, with neither option set (or
both empty), allow all users to read the repo.  There are two ways a
user can be denied read access:  (1) deny_read is not empty, and the
user is unauthenticated or deny_read contains user (or *), and (2)
allow_read is not empty and the user is not in allow_read.  Return True
if user is allowed to read the repo, else return False.   webs	   deny_readT	untrustedFs
   allow_read)
remoteuser
configlistr   )r   requser	deny_read
allow_reads        r+   readallowedrN   _   s^     >>DfldCI$(2Y"?"?v}EJ"J77    c              #    ^#    U R                  SS5      nU R                  SS5      n[        5       n[        5       nU GH3  u  pUR                  U5      (       d  M  U[        U5      S  nSn
SU;   aw  U(       d  M=  UR	                  S5      nUS   nU(       d  OPX;   a  Mb  X;   a  OCSn
UnSR                  USS  5      nU	S [        U5      * S-
   n	 [        R                  " X	5        Sn
UR                  R                  S5      UR                  S5      UR                  S5      /nSSR                  S	 U 5       5      -   S-   nU
(       a~   [        U	5      [        R                  " 5       S   4nS
S
US-   UUS
S
UUS   US   -
  [         R"                  " / 5      S[         R$                  " / SS9S.nUR'                  U5        Uv   GM  U R)                  5       m[*        R,                  " 5       (       a1   TR/                  [0        R2                  R                  U	SS5      5        [:        R<                  4U4S jjnTR                  SSSS9(       a  GM  [?        TU5      (       d  GM)   [        R                  " X	5      n [        UR@                  5      [        R                  " 5       S   4n[C        U5      nU" SS5      nUR'                  U5        U" SSU5      nTRE                  SSSS9nU=(       d    SURG                  5       =(       d    SUUUU=(       d    SURG                  5       =(       d    SUUS   US   -
  [H        RJ                  " TSU5      S [         R$                  " USS9S.nUv   GM6     g ! [        [        R                  4 a     GNf = f! [         a     GMh  f = f! [4         a+  nTR7                  [9        S5      U	U4-  5         S nAGM  S nAff = f! [         a"    TR7                  [9        S5      U	-  5         GM  [        R                   a"    TR7                  [9        S5      U	-  5         GM  f = f! [         a     GM  f = f7f)NrE   s   descends   collapseFr%   r   Tr   c              3  6   #    U  H  o(       d  M  Uv   M     g 7fN ).0ps     r+   	<genexpr>"rawindexentries.<locals>.<genexpr>   s     5%Q1qq%s   
	rO   s   label)r)   )   contacts   contact_sort   names	   name_sort   url   descriptions   description_sort
   lastchanges   lastchange_sorts   archivess   isdirectory   labelss   .hgs   hgrcs   error reading %s/.hg/hgrc: %s
c                &   > TR                  XUSS9$ )NTrF   )config)sectionr)   defaultus      r+   getrawindexentries.<locals>.get   s    88G7d8CCrO   s   hiddenrF   s!   error accessing repository at %s
r[   rY   r]   s   unknowns   tip)&
configboolset
startswithrB   r2   joinr   
repositoryOSErrorr   	RepoErrorapppathr'   r   r#   makedater   mappinglist
hybridlistaddcopyr"   use_repo_hgrc
readconfigr1   r*   	Exceptionwarnr   uimod_unsetrN   spathr
   rI   upperr    archivelist)r   r;   rJ   subdirdescendcollapse	seenreposseendirsr)   r*   	directory	namepartsrootname	discardedpartsurldrowerc   rcontactdescriptionlabelsrb   s                           @r+   rawindexentriesr   v   s    mmFJ/G}}V[1HIuH
v&&CKM"	4<

4(I |H%& 	 !IIim4	 1s9~o12MM"+ %I
 KKd#LLJJt

 TYY5%555< t_h&7&7&9!&<=  !$" #%( $%aD1Q4K)55b9 $'222HEC LLIGGI!!RWW\\$@A
 (-|| 	D <<	T<:1c""	b'A	177#X%6%6%8%;<A c"&.1d67D)fi4@-:$]]_:
'5:!,!2!2!4!B
 !!qt ,,Q< #..vHE
 	u @  1   8  q;<ayHI   	FF1:;dBC 	FF1:;dBC	
  		s   CQM7)A!Q#N.BQ30N*#AQ(O"?-Q,CQ7NQNQ
N'"Q&N''Q*
O4OQOQ"'Q	Q0Q=QQQ
QQQQc              #     ^#    [        XX7S9nSn	U(       a  XU4:w  a  SU-  m[        UU4S jUS9n[        U[        U5      5       H  u  pXS'   U
v   M     g 7f)N)r{   NFs   %s_sortc                   > U T   $ rR   rS   )xsortkeys    r+   <lambda>"_indexentriesgen.<locals>.<lambda>  s	    !G*rO   )keyreverses   parity)r   sortedzipr   )contextr   r;   rJ   stripecount
sortcolumn
descendingr{   rowssortdefaultr   parityr   s               @r+   _indexentriesgenr      sc      2c9DKk*%==z)d 4jI4;!78I	 9s   AAc                @    XX#XEU4n[         R                  " [        US9$ )N)args)r   mappinggeneratorr   )r   r;   rJ   r   r   r   r{   r   s           r+   indexentriesr     s&     sHD(()9EErO   c                  P    \ rS rSrSrSS jrS rS rS rS r	S	 r
SS
 jrS rSrg)hgwebdiri  zHTTP server for multiple repositories.

Given a configuration, different repositories will be served depending
on the request path.

Instances are typically used as WSGI applications.
Nc                   Xl         X l        S U l        SU l        S U l        U R                  5         SU l        U(       dA  [        R                  " U R                  5        [        R                  " U R                  5        g g )Nr   )
confbaseuir   lastrefreshmotdrefreshrequests_countr   loadall
populateui)selfr   r   s      r+   __init__hgwebdir.__init__  s_    		tww'!!$''* rO   c                6	   U R                   (       a  U R                   R                  SS5      nO"[        R                  S   S   nUR                  nUS:  a'  U R
                  U-   [        R                  " 5       :  a  g U R                  (       a  U R                  R                  5       nOZ[        R                   R                  5       nUR                  SSSS5        UR                  SSS	S5        UR                  S
SS	S5        [        U R                  [        [        [         45      (       d  SS0n["        R$                  R'                  U R                  5      (       d,  [(        R*                  " [-        S5      U R                  -  5      eUR/                  U R                  USS9  / nUR                  S5       H0  u  pgUR1                  SU5       H  nUR3                  Xh45        M     M2     Ok[        U R                  [        [         45      (       a  U R                  nO9[        U R                  [        5      (       a  U R                  R5                  5       n[6        R8                  " U5        [;        W5      n	UR                  S5       H  u  p[<        R>                  " U
5      n
[@        RB                  " USS9 H~  n["        R$                  RE                  U5      n[<        R>                  " U5      nURG                  U
5      (       a  U[I        U
5      S  nU	R3                  URK                  S5      U45        M     M     Xl&        X0l         U R                   R                  SS5      U l'        SU l(        U R                   RS                  SS5      [T        l*        U R                   RS                  SS5      U l+        U R                   RS                  SSSS9U l,        U R                   RS                  SS5      U l-        U RZ                  (       a  []        U RZ                  5      U l-        U R                   RS                  SS5      n
U
RG                  S5      (       a  U
SS  n
U
R_                  S5      (       a  U
S S n
Xl0        [        R                  " 5       U l        g ) NrE   s   refreshintervalr   s   uis   report_untrusteds   offs   hgwebdirs   nonttys   trues   progresss   disables   hgwebs   pathss   hgweb-pathss   config file %s not found!T)remaptrusts   collections)r/   r%   s   experimentals    web.full-garbage-collection-rate   encoding   styles	   templatesFrF   s   stripess   prefixr   )1r   	configintr   	coreitemsra   r   timer   rq   rv   load	setconfig
isinstancer   dictlisttupler1   r*   existsr   Abortr   rs   rI   r4   r(   r   r   r@   r   r&   r   r7   r5   rg   rB   rC   r;   gc_full_collect_rategc_full_collections_doner_   r   styletemplatepathr   intendswithr<   )r   refreshintervalitemrb   mapr:   r)   ignoredr*   r;   r<   r=   repos                r+   r   hgwebdir.refresh%  sr   77"gg//8JKO((01CDD"llO a  ?2TYY[@;;  "AAKK2FKHKKy';? KKZ(C$))dD%%899^,C77>>$)),,kk!$@"ADII"MNNLL#TL:E!"~!>LL>DLL$. ? "? 		D%=11IIE		4((IIOO%Ea % MM.9LF]]6*F))$$?ww''-}}T*??6**F.Ddkk$/67 @ : 
$(GG$5$5@%
! )*% GGNN6;?WW^^FH5
 GGNNLE + 
  77>>&*="4#3#34D	2T""ABZF??4  CR[F99;rO   c                    [         R                  R                  SS5      R                  S5      (       d  [	        S5      e[
        R                  " U 5        g )Ns   GATEWAY_INTERFACErO   s   CGI/1.sJ   This function is only intended to be called while running as a CGI script.)r   environrc   rg   RuntimeErrorr!   launch)r   s    r+   runhgwebdir.runl  sN    ##$8#>II
 
 9  	trO   c                    U R                   R                  SS5      n[        R                  " XS9n[        R                  " XB5      nU R                  XE5      $ )NrE      baseurl)
altbaseurl)r   r_   
requestmodparserequestfromenvwsgiresponserun_wsgi)r   envrespondbaseurlrJ   ress         r+   __call__hgwebdir.__call__v  sE    ''..4,,SE%%c3}}S&&rO   c              #    #    U R                   R                  SS5      n[        R                  " U R                   US9    U R	                  X5       S h  vN   U R
                  nU =R                  S-  sl        US:  a>  U R                  U-  S:X  a+  [        R                  " 5         U =R                  S-  sl	        O[        R                  " SS9   S S S 5        g  N! U R
                  nU =R                  S-  sl        US:  a>  U R                  U-  S:X  a+  [        R                  " 5         U =R                  S-  sl	        f [        R                  " SS9  f = f! , (       d  f       g = f7f)Ns	   profilings   enabled)enabledr   r   )
generation)
r   re   r   profile_runwsgir   r   gccollectr   )r   rJ   r   r   rates        r+   r   hgwebdir.run_wsgi}  s    ''$$\:>tww8-==222 00 ##q(#!8 3 3d :a ?JJL11Q61JJ!,5 982 00 ##q(#!8 3 3d :a ?JJL11Q61JJ!,5 98sH   <E-E CCCA:E	E-CA;EE
E*&E-c           	       ^^ U R                  5         [        U R                  5      u  p4U(       a  X2R                  S'   UR                  R                  S5      mU R                  X5      n UR                  SS[        R                  05      nSUl	        XbR                  S'   TR                  S5      (       d  SUR                  ;   an  TR                  S5      (       a  TS	S  nOUR                  S   nU R                  R                  S
SSS9n[        U R                  XU5        UR                  5       A$ [!        U R"                  5      n	T(       a  TS:X  a  TU	;  a  U R%                  XU5      A$ TR'                  S5      (       aC  TU	;  a=  TS [)        S5      *  m[+        U4S jU	 5       5      (       a  U R%                  XUT5      A$ U4S jn
U
" 5        H  nU	R-                  U5      nU(       d  M  UR.                  R1                  5        VVs0 s H  u  pUR3                  S5      U_M     nnn[4        R6                  " UUU R                  R                  S
S5      UR8                  S9n [:        R<                  " U R                  R?                  5       U5      n[@        RB                  " U5      RE                  X5      s  A$    TS-   mU	 Vs/ s H  nUR                  T5      (       d  M  UPM     sn(       a  U R%                  XUT5      A$ SUl	        URW                  URY                  SST05      5        UR                  5       A$ s  snnf ! [F         a5  n[        RH                  " URJ                  5      n[M        [N        U5      eS nAf[P        RR                   a  n[M        [N        [U        U5      5      eS nAff = fs  snf ! [L         a  n[[        UR\                  [^        R`                  " U5      5      Ul	        URW                  URY                  SSURb                  =(       d    S05      5        UR                  5       s S nAA$ S nAff = f! Af = f)Ns   Content-Security-Policyr%   s   mimetyper   s   200 Script output followss   Content-Types   static/s   static   rE   FrF      indexs   /indexc              3  D   >#    U  H  oR                  T5      v   M     g 7frR   )rg   )rT   r   r{   s     r+   rV   $hgwebdir._runwsgi.<locals>.<genexpr>  s     ;U||F++Us    c               3  V   >#    T v   [         R                  " T 5       S h  vN   g  N7frR   )r   finddirs)virtuals   r+   _virtualdirs'hgwebdir._runwsgi.<locals>._virtualdirs  s     #,,W555s   )')latin1r   )reponamer   bodyfhs   404 Not Founds   notfounds   repos   errorrO   )2r   r	   r   headersdispatchpathr'   r   renderr   statusrg   qsparamsr_   r   r   sendresponser   r;   	makeindexr   rB   anyrc   rawenvr(   decoder   r   r   r   ri   rq   r   hgwebr   rj   
strtolocalstrerrorr   r   r   rk   bytes
setbodygengenerater   coder   bytestrmessage)r   rJ   r   cspnoncetmplctypefnamestaticr;   r   virtualreporealkvuenvr   instmsgr   r   r{   r   s                        @@r+   r   hgwebdir._runwsgi  s   tww'
69KK23""((.~~c)O	KKk8;L;L-MNE 6CJ+0KK( !!*--cll1J%%j11#ABKELL3E	UK4,,fSA'')@ y $Ew(2u8L~~c5r k 	**we/C !1CM>2;U;;;>>#D&Ad a6
  ,~yy-4 ;>**:J:J:L:L$!*A-:L   %88!,#'77>>&*#E  #zzCL!}}TWW\\^TB(t4==cGG0 W  .6 t^F 95aALL$859~~cf=  *CJNN4==w6HIJ##% M # D&11$--@+,=sCC ?? L+,=uT{KKL
 :  	&&qvvx/?/?/BCCJNNh1993C(DE ##%%	& s   ,C	O	 79O	 2AO	 &O	 5O	 M0>O	 /AMO	 O	 O/O5O	 9O	 O	 
O0NO#N<<OO	 	
QA4QQQ QQ Qc           
        U R                  5         / SQnSu  pgSUR                  ;   a3  UR                  S   nUR                  S5      nU(       a  USS  nXe;  a  SnU Vs/ s H1  nSU-  SU(       + =(       a    X:H  =(       a    S=(       d    SU4-  4PM3     n	nU R                  5         [        U R                  U R
                  UU R                  UUUS	9n
U
U[        R                  " S
U-   U R                  5      UUS.nUR                  U	5        UR                  UR                  SU5      5        UR                  5       $ s  snf )N)rY   r[   rX   r\   r   s   sort   -r   rO   s   sort_%ss   %s%s)r   r   r{   r%   )s   entriess   subdirs   pathdefs
   sortcolumns
   descendingr   )r   r   rg   r   r   r;   r   r   makebreadcrumbr<   updater  r  r   )r   rJ   r   r  r{   sortabler   r   columnsortentriesmappings               r+   r   hgwebdir.makeindex  sQ   G!,
cll"g.J#..t4J'^
) 
 #

 # V##^<(<F$M# # 	 

 	GGJJ!!
  !00L%%
 	tt}}Xw78!!C

s    8Ec           	     8  ^ ^ U 4S jm0 n[         R                  " UTT R                  5      u  nu  pVnXTS   :X  a  XSS'   [        R                  " US5      nT" SS5      n	T" SS5      n
T" SS5      =(       d    UR
                  R                  S	5      S
-   nUR                  S	5      (       d  US	-  n[        R                  UR
                  S	-   U	U
UUUUS.n[        R                  " U5      nU" SSS9UU 4S j5       n[        R                  R                  XgUS9$ )Nc                 `   > UR                  SS5        TR                  R                  " U 0 UD6$ )NrG   T)
setdefaultr   r_   )r   kwargsr   s     r+   r_   "hgwebdir.templater.<locals>.config%  s+    k4077>>42622rO   r   r      ?rE      logourl   logoimg	   staticurlr%   s   /static/)r   rZ   r*  r+  r,  s   sessionvarsr   s   nonce   motdrS   )requiresc              3  \   >#    TR                   b  TR                   v   g T" SS5      v   g 7f)NrE   r-  )r   )r   r"  r_   r   s     r+   r    hgwebdir.templater.<locals>.motdF  s&     yy$iiVW--s   ),)fpdefaults)r   getstyler   r    sessionvarsrl   rstripr   r   r   templatekeywordr   frommapfile)r   rJ   r  varsstylesr   mapfiler1  r4  logourllogoimg	staticurlr2  r6  r   r_   s   `              @r+   r   hgwebdir.templater$  s;   	3 '0'9'9**(
$$ 1I"N))$5,,6<( 6{{!!$'+5 	 !!$''I "**KK$&#'	
 $33H=	2	.	. 
/	. ""..X / 
 	
rO   )r   r   r   r   r   r   r<   r;   r   r   r   r   r   rR   rO   )__name__
__module____qualname____firstlineno____doc__r   r   r   r   r   r   r   r   __static_attributes__rS   rO   r+   r   r     s4    +E'N'-<Xt-"^+
rO   r   r?  )rO   FrO   )2
__future__r   r   r1   r   i18nr   commonr   r   r	   r
   r   r   r   r   r    r   r   r   r   r   r   r   r   r   r   r   r   r   rv   r   r   r   r   r    r!   configurationr"   utilsr#   r,   r@   r9   rN   r   r   r   r   rS   rO   r+   <module>rL     s    # 	 	  
 
 
   "  # M& .D" KNF@
 @
rO   