
    6hDI                        S SK Jr  S SKrS SKrSSK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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5      r# " S S5      r$S r%g)    )annotationsN   )ErrorResponseHTTP_BAD_REQUEST	cspvalues	permhooksstatusmessage   )encodingerror
extensions	formatterhghook	profilingpycompat	registrarrepoviewtemplatefilters	templatertemplateutiluiwireprotoserver)commonrequestwebcommandswebutilwsgicgic                h    U R                   R                  SS 5      U" SS5      S4nU[        X25      4$ )N   style   webs   paper)qsparamsget	_stylemap)reqconfigfntemplatepathstyless       ;/usr/lib/python3/dist-packages/mercurial/hgweb/hgweb_mod.pygetstyler*   1   s<    4("F
 9V222    c                   U  H  nU(       aa  U[         R                  [         R                  4;   d=  [         R                  U;   d)  [         R                  (       a  [         R                  U;   a  Mm  [
        R                  R                  US5      SU-   S4nU H*  n[        R                  " XA5      u  pVU(       d  M$  X%U4s  s  $    M     [        SU-  5      e)zReturn path to mapfile for a given style.

Searches mapfile in the following locations:
1. templatepath/style/map
2. templatepath/map-style
3. templatepath/map
s   maps   map-s   No hgweb templates found in %r)r   oscurdirospardirosseposaltsepospathjoinr   try_open_templateRuntimeError)r(   r2   style	locationslocationmapfilefps          r)   r$   r$   :   s      **H,=,=>>~~&  !!U*WW\\%0'E/6J	!H#55hEKGwr)) " " 84?
@@r+   c                   U R                  S5      (       a  U SS n U(       a  SU-   U -   n U nUR                  S5      (       a  USS n/ nU nS/UR                  S5      -   n[        U5       HE  nU(       a  U(       d    O6UR	                  XFS.5        [
        R                  R                  U5      nMG     [        R                  " [        U5      5      $ )zReturn a 'URL breadcrumb' list

A 'URL breadcrumb' is a list of URL-name pairs,
corresponding to each of the path items on a URL.
This can be used to create path navigation entries.
   /Nr   r+   )   url   name)
endswith
startswithsplitreversedappendr1   r2   dirnamer   mappinglist)urlprefixrelpath
breadcrumburlel	pathitemspathels          r)   makebreadcrumbrN   W   s     ||D#2hVmc!G$!"+JEd++I9%U5:;&	 &
 ##HZ$899r+   c                  H    \ rS rSrSrS rS rS rS rS r	S r
S	 rS
 rSrg)requestcontextq   zHolds state/context for an individual request.

Servers can be multi-threaded. Holding state on the WSGI application
is prone to race conditions. Instances of this class exist to hold
mutable and race-free state for requests.
c                   X l         UR                  U l        X0l        X@l        UR                  n[
        R                  " X#5      (       aG  UbD  US-   [        R                  ;   a-  U R                   R                  UR                  S-   5      U l         U R                  SS5      U l        U R                  SS5      U l        U R                  SS5      U l        U R                  SS5      U l        U R                  SS5      U l        U R#                  SSS	S
9U l        UR&                  U l        [)        U R                   R*                  5      u  U l        U l        g )Ns   .hiddenr!   s
   maxchangess   stripess   maxshortchangess   maxfiless
   allow-pulls	   templatesF	untrusted)reporeponamer%   res
filternamer   hashiddenaccessr   filtertablefiltered	configint
maxchangesstripecountmaxshortchangesmaxfiles
configbool	allowpullconfigr'   websubtabler   r   cspnonce)selfapprU   r%   rW   current_filters         r)   __init__requestcontext.__init__y   s   	 ""4--*+x/C/CC		**4??Z+GHDI..?>>&*=#~~f6HIv{;?
 !KKKN ??(6$*r+   c                r    UR                  SS5        U R                  R                  R                  " U0 UD6$ NrT   T)
setdefaultrU   r   rc   rg   argskwargss      r)   rc   requestcontext.config   s0    +t,yy||""D3F33r+   c                r    UR                  SS5        U R                  R                  R                  " U0 UD6$ rm   )rn   rU   r   ra   ro   s      r)   ra   requestcontext.configbool   0    +t,yy||&&777r+   c                r    UR                  SS5        U R                  R                  R                  " U0 UD6$ rm   )rn   rU   r   r\   ro   s      r)   r\   requestcontext.configint   s0    +t,yy||%%t6v66r+   c                r    UR                  SS5        U R                  R                  R                  " U0 UD6$ rm   )rn   rU   r   
configlistro   s      r)   ry   requestcontext.configlist   ru   r+   c                X    [         R                  " U R                  R                  U5      $ N)r   archivelistrU   r   )rg   nodeids     r)   r}   requestcontext.archivelist   s    ""499<<88r+   c                `  ^  T R                  SS5      nT R                  SS5      nT R                  SS5      =(       d    UR                  R                  S5      S-   nUR                  S5      (       d  US-  n0 n[	        UT R                   T R
                  5      u  nu  pxn	XvS   :X  a  XuS'   [        R                  " US	5      n
T R                  (       d[  T R                  SS
S5      =(       d<    UR                  =(       d)    UR                  =(       d    T R                  R                  T l        0 n[        R                  " U5      nU" S[        S9U 4S j5       nUR                  S-   UUUUR                  T R                  [        R                  U
[!        UR                  5      UT R"                  S.n[        R$                  " U5      nU" SSS9U 4S j5       n[&        R(                  " T R                  R*                  T R                  5      n[,        R,                  R/                  XXUS9$ )Nr!      logourl   logoimg	   staticurlr<   s   /static/r   r       ?r?   r+   s   websub)intypec                F   > [         R                  " U TR                  5      $ r|   )r   websubrd   )textrg   s    r)   websubfilter.requestcontext.templater.<locals>.websubfilter   s    "))$0@0@AAr+   )r>   r   r   r   s   urlbases   repo   encodings   sessionvarss   pathdefr    s   nonce   motd )requiresc              3  6   >#    TR                  SS5      v   g 7f)Nr!   r   )rc   )contextmappingrg   s     r)   motd&requestcontext.templater.<locals>.motd   s     ++fg..s   )r:   filtersdefaults	resources)rc   apppathrstripr@   r*   r'   r   sessionvarsrV   rU   rootr   templatefilterbytesadvertisedbaseurlr   rN   rf   templatekeywordr   templateresourcesr   r   frommapfile)rg   r%   logourllogoimg	staticurlvarsr(   r6   r9   r:   r   r   r   r   r   r   r   tress   `                 r)   r   requestcontext.templater   s    ++fj1++fj1KK- 6{{!!$'+5 	 !!$''I '/d//(
$$ 1I"N))$5}}FGS1 "<<";;" 99>>	 M "11':		%	0	B 
1	B KK$&#--]]!**'&s{{3jj
 $33H=	2	.	/ 
/	/ **499<<C""..G$ / 
 	
r+   c                    U R                   R                  S:w  aJ  [        R                  " U5      nU R                  R                  U R                  R                  X5      5        U R                  R                  5       $ )z=Helper function to send a response generated from a template.s   HEAD)	r%   methodr   byteskwargsrW   
setbodygentmplgeneratesendresponse)rg   namerq   s      r)   sendtemplaterequestcontext.sendtemplate   sV    88??g%))&1FHH		 2 24 @Axx$$&&r+   )rb   re   r]   r`   r_   rf   rU   rV   r%   rW   r^   r'   rd   N)__name__
__module____qualname____firstlineno____doc__rj   rc   ra   r\   ry   r}   r   r   __static_attributes__r   r+   r)   rP   rP   q   s1    "7J48789>
@'r+   rP   c                  j    \ rS rSrSrSS jrS r\R                  S 5       r	S r
S rS	 rS
 rS rSrg)hgweb   a  HTTP server for individual repositories.

Instances of this class serve HTTP responses for a particular
repository.

Instances are typically used as WSGI applications.

Some servers are multi-threaded. On these servers, there may
be multiple active threads inside __call__.
Nc                Z   [        U[        5      (       ay  U(       a  UR                  5       nOJ[        R                  R                  5       n[        R                  " U5        [        R                  " U5        [        R                  " XA5      nOUnUR                  R                  SSSS5        UR                  R                  SSSS5        UR                  R                  SSSS5        UR                  R                  SSSS5        UR                  R                  SSUR                  S5        UR                  R                  SSUR                  S5        UR                  R                  SSS	S5        UR                  R                  SSS	S5        UR                  R                  S
SSS5        UR                  R                  S
SSS5        [        R                  " U R                  U5      5      /U l        U R                   S   U l        [$        R&                  " S5        X l        g )Ns   uis   report_untrusteds   offs   hgwebs   nonttys   trues   forcecwds   signal-safe-locks   falses   progresss   disabler   T)
isinstancer   copyuimodr   loadr   loadall
populateuir   
repository	setconfigbaseuir   cachedlocalrepo_webifyrepo_repos	_lastrepor   redirectrV   )rg   rU   r   r   urs         r)   rj   hgweb.__init__  s   dE""KKMHHMMO""1%%%a(a&A A	u168D	5"5vxH	ui(;	5)Wh?	uk1668<	5+qvvx@
 	
u18XF	5"5xJ 	
{JB	;
GXF))$*:*:1*=>?Qdr+   c                R    [        U5      n[        R                  " U5      U l        U$ r|   )
getwebviewr   
getwebsubsrd   )rg   rU   s     r)   r   hgweb._webifyrepo(  s$    $"--d3r+   c              #    #    U R                   (       a-  U R                   R                  5       nUR                  5       u  p#O,U R                  R	                  5       nUR                  5       u  p#U(       a  U R                  U5      nXl        UR                  U l         Uv   U R                   R                  U5        g! U R                   R                  U5        f = f7f)a  Obtain a repo unique to the caller.

Internally we maintain a stack of cachedlocalrepo instances
to be handed out. If one is available, we pop it and return it,
ensuring it is up to date in the process. If one is not available,
we clone the most recently used repo instance and return it.

It is currently possible for the stack to grow without bounds
if the server allows infinite threads. However, servers should
have a thread limit, thus establishing our limit.
N)r   popfetchr   r   r   mtimerD   )rg   cachedr   createds       r)   _obtainrepohgweb._obtainrepo-  s      ;;[[__&FJAw^^((*FJA  #A\\
	'GKKv&DKKv&s   BCB= !C=CCc                    [         R                  R                  SS5      R                  S5      (       d  [	        S5      e[
        R                  " U 5        g)zuStart a server from CGI environment.

Modern servers should be using WSGI and should avoid this
method, if possible.
s   GATEWAY_INTERFACEr+   s   CGI/1.sJ   This function is only intended to be called while running as a CGI script.N)r   environr#   rA   r5   r   launch)rg   s    r)   run	hgweb.runJ  sP     ##$8#>II
 
 9  	tr+   c                |    [         R                  " U5      n[         R                  " X25      nU R                  X45      $ )zCRun the WSGI application.

This may be called by multiple threads.
)
requestmodparserequestfromenvwsgiresponserun_wsgi)rg   envrespondr%   rW   s        r)   __call__hgweb.__call__Y  s3    
 ,,S1%%c3}}S&&r+   c              #  B  #    U R                  5        nUR                  R                  SS5      n[        R                  " UR                  US9   U R                  XU5       Sh  vN   SSS5        SSS5        g N! , (       d  f       N= f! , (       d  f       g= f7f)zInternal method to run the WSGI application.

This is typically only called by Mercurial. External consumers
should be using instances of this class as the WSGI application.
s	   profilings   enabled)enabledN)r   r   ra   r   profile_runwsgi)rg   r%   rW   rU   r   s        r)   r   hgweb.run_wsgic  sv      4gg((zBG""477G<==4888 =   9 =<  sF   B<BA=%A;&A=*B2	B;A==
B	B
BBc                   [        XX5      nUR                  SS5      [        l        UR                  UR                  R
                  l        UR                  (       a  UR                  UR                  S'   [        R                  " XAX R                  5      nU(       a  UR                  5       $ UR                  b  UR                  nO0UR                  R                  S5      S   R                  S5      S   nUR!                  SS5      nS	UR"                  ;  Ga  U(       Ga  US   (       Ga  UR%                  S5      nUR'                  S
5      n	U	S:w  a  US U	 UR"                  S'   XS-   S  n[)        [*        [,        R.                  " U5      5      (       a  XR"                  S	'   US:X  a  SR1                  U5      UR"                  S'   OU(       a9  US   (       a/  UR%                  S5      R3                  SS5      n
XR"                  S'   U(       aB  SUR"                  ;   a  UR"                  S	 U H  nUR"                  R5                  SU5        M!     UR                  R7                  SS5      nUS:X  a  SU;   a  SUR"                  S'   US:X  a}  UR"                  S   n[8        R:                  R=                  5        HL  u  pUS   nUR?                  U5      (       d  M"  US [A        U5      *  UR"                  S'   XR"                  S'   MN     OUR"                  R7                  S	S5      n URC                  U5      Ul"        URD                  RG                  SS[        R                  05      nUS:w  a  U R                  XAS 5        US:X  a8  URD                  RG                  S0 5      UR"                  S	'   UR"                  S	   nURI                  SS5      (       a  URJ                  (       ds  SU RL                  -  nUR                  R7                  S5      U:X  a6  SUl'         UR                  S	 URS                  S5        UR                  5       $ UUR                  S '   [,        R.                  " U5      [*        RT                  ;  a  S!n[W        [X        U5      eS"Ul'        UUR                  S'   [[        [*        [,        R.                  " U5      5      " U5      $ ! [P         a     Nf = f! [\        R^                  [\        R`                  4 a  n[,        Rb                  " U5      n[)        US#5      (       a.  [e        U[\        Rf                  5      (       d  S$URh                  -  nS%Ul'        WUR                  S'   URk                  S&US'9s S nA$ S nAf[\        Rl                  [\        Rn                  4 aD  nS(Ul'        WUR                  S'   URk                  S&[,        Rb                  " U5      S'9s S nA$ S nAf[\        Rp                   a:  nS)Ul'        WUR                  S'   URk                  S&URr                  S'9s S nA$ S nAf[V         a  nUR                   H  u  nnUUR                  U'   M     [u        URv                  [,        Rb                  " U5      5      Ul'        WUR                  S'   URk                  S&[,        Rb                  " U5      S'9s S nA$ S nAff = f)*Nr!   r   s   Content-Security-Policy   &r      ;r<   r
   s   cmd   -r=   r    r   s   statics   files   %2Fs   nodes
   User-Agentr+   s   revs	   mercurials   raws   archives   types   mimetypes   defaults   caches   W/"%d"s   If-None-Matchs   304 Not Modifieds   Content-Types   ETags   method not founds   200 Script output followsr   s   revision not found: %ss   404 Not Founds   error)r   s   500 Internal Server Errors   403 Forbidden)<rP   rc   r   rawenvrU   r   r   re   headersr   handlewsgirequest
check_permr   dispatchpathquerystring	partitionrB   r"   r   rfindhasattrr   r   sysstrr3   replaceaddr#   r   archivespecsitemsr@   lenr   r   renderra   rf   r   statusKeyErrorsetbodybytes__all__r   r   getattrr   LookupErrorRepoLookupErrorbytestrr   ManifestLookupErrorr   r   	RepoErrorStorageErrorAbortmessager	   code)rg   r%   rW   rU   rctxhandledqueryrp   cmdr6   nodeauafntype_specextctypetagmsgerrekvs                           r)   r   hgweb._runwsgin  s   d#3 !KK<"zz		88 7;hhCKK23!33sOO
 ##%% '$$EOO--d3A6@@FqIE {{4#%$477((1+CIIdOE{),VeX&!)+& {HOOC$899'*V$i(,		$W%DG88A;..vt<D,0LL)#,,.LL1!((!4 " 4Bf}!3)/X&j \\'*#*#7#7#=#=#?KEq'C{{3''02;c#hYW-05W-	 $@ ,,""63/CD	Js+DIII$$k8+<+<=E
 i40cz'+yy'7'7
B'GV$ll6* vx00$**,;;??#34;!4CJKK8 $$S)++--'*G$s#;+>+>>) $$4c:: :
/4O,{HOOC,@A$GG' $ * !!5#8#89 		:""3'CsF##JU..- - 0#((:)CJ+0CKK($$XS$99!3!34 	J5CJ+0CKK($$XX5E5Ea5H$II{{ 	@)CJ+0CKK($$XQYY$?? 	J		1!"A "&qvvx/?/?/BCCJ+0CKK($$XX5E5Ea5H$II	Js   -C5S* #S 0 S* BS* 
S'$S* &S''S* *$[A:V['[59W4.[4[/Y :[ [B[[[c                0    [          H  nU" XU5        M     g r|   )r   )rg   r  r%   oppermhooks        r)   r   hgweb.check_perm  s    !HT# "r+   )r   r   r   rV   rd   )NN)r   r   r   r   r   rj   r   
contextlibcontextmanagerr   r   r   r   r   r   r   r   r+   r)   r   r      sH    	!F
 ' '8'	9IJV$r+   r   c                    U R                   R                  SSSS9nUS:X  a  U R                  5       $ U[        R                  ;   a  U R                  U5      $ U R                  S5      $ )a  The 'web.view' config controls changeset filter to hgweb. Possible
values are ``served``, ``visible`` and ``all``. Default is ``served``.
The ``served`` filter only shows changesets that can be pulled from the
hgweb instance.  The``visible`` filter includes secret changesets but
still excludes "hidden" one.

See the repoview module for details.

The option has been around undocumented since Mercurial 2.5, but no
user ever asked about it. So we better keep it undocumented for now.r!   s   viewTrS   s   alls   served)r   rc   
unfilteredr   rZ   r[   )rU   
viewconfigs     r)   r   r     s]     4@JV  	x++	+}}Z((}}Y''r+   r|   )r+   )&
__future__r   r$  r1   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$   rN   rP   r   r   r   r+   r)   <module>r+     sl    #  	     $ 3A::4E' E'PB$ B$J(r+   