HEX
Server: Apache
System: Linux iad1-shared-b8-33 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User: samfetchero1 (10301780)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/mercurial/hgweb/__pycache__/hgwebdir_mod.cpython-310.pyc
o

�]LbBP�@sddlmZddlZddlZddlZddlmZddlmZm	Z	m
Z
mZmZm
Z
mZmZmZddlmZmZmZmZmZmZmZmZmZmZmZmZmZmZ m!Z!ddlm"Z"m#Z$m%Z%m&Z&dd	l'm(Z(d
d�Z)dd
�Z*dd�Z+dd�Z,ddd�Z-dd�Z.	ddd�Z/Gdd�de0�Z1dS)�)�absolute_importN�)�_�)	�
ErrorResponse�HTTP_SERVER_ERROR�	cspvalues�get_contact�	get_mtime�ismember�	paritygen�
staticfile�
statusmessage)�configitems�encoding�error�
extensions�hg�pathutil�	profiling�pycompat�rcutil�	registrar�scmutil�	templater�templateutil�ui�util)�	hgweb_mod�request�webutil�wsgicgi)�dateutilcCsdd�|D�S)NcSs$g|]\}}t�|��d�|f�qS)�/)r�pconvert�strip)�.0�name�path�r)�>/usr/lib/python3/dist-packages/mercurial/hgweb/hgwebdir_mod.py�
<listcomp>9s$zcleannames.<locals>.<listcomp>r))�itemsr)r)r*�
cleannames8sr-c	Cs�g}t|�D]@\}}tj�|�\}}z	ddd�|}Wnty+|�||f�Yqwtj�t�|��}t	j
|d|d�}|�t|||��q|S)NFT)�*s**)�	followsym�recurse)
r-�osr(�split�KeyError�append�normpathr�abspathr�	walkrepos�extend�urlrepos)�paths�repos�prefix�root�roothead�roottailr0r)r)r*�	findrepos<s�r@ccsL�|D] }tj�|�}|dt�|t|�d���d��d�|fVqdS)a�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)r1r(r5rr$�len�lstripr%)r<r>r:r(r)r)r*r9Os�	"��r9cCsV|j}|jdddd�}|r|rt|||�rdS|jdddd�}|r't|||�r)dSdS)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_readr)r)r*�readallowed_s	rL�c#st�|�dd�}|�dd�}t�}t�}|D�]�\}}	|�|�s q|t|�d�}d}
d|vrv|s1q|�d�}|d}|s=n9||vrBq||vrGn/d}
|}d�|dd��}
|	dt|
�d�}	z
t�||	�d}
Wntt	j
fyuYnw|j�d�|�d�|�d�g}dd�d	d
�|D��d}|
r�zt
|	�t��df}Wn	ty�Yqwdd|d||dd||d|dt�g�dtjgdd
�d�}|�|�|Vq|���t���rz
��tj�|	dd��Wnt�y}z��td�|	|f�WYd}~qd}~wwtjf�fdd�	}�jdddd��rqt �|��s"qzt�||	�}Wn&t�y=��td�|	�Yqt	j
�yP��td�|	�Yqwz
t
|j!�t��df}Wn
t�yhYqwt"|�}|dd�}|�|�|dd|�}�j#dddd�}|�p�d|�$��p�d||||�p�d|�$��p�d||d|dt%�&�d|�dtj|dd
�d�}|VqdS)NrCsdescendscollapseFr#rTrcss�|]}|r|VqdS�Nr))r&�pr)r)r*�	<genexpr>�s�z"rawindexentries.<locals>.<genexpr>rMslabel)r')�contactscontact_sort�names	name_sort�url�descriptionsdescription_sort�
lastchangeslastchange_sortsarchivessisdirectory�labelss.hgshgrcserror reading %s/.hg/hgrc: %s
cs�j|||dd�S)NTrD)�config)�sectionr'�default��ur)r*�get�szrawindexentries.<locals>.getshiddenrDs!error accessing repository at %s
rTrRrVsunknownstip)'�
configbool�set�
startswithrAr2�joinr�
repository�IOErrorr�	RepoError�apppathr%r
r"�makedate�OSErrorr�mappinglist�
hybridlist�add�copyr�
use_repo_hgrc�
readconfigr1r(�	Exception�warnr�uimod�_unsetrL�spathr	rG�upperr �archivelist)rr;rH�subdir�descend�collapse�	seenrepos�seendirsr'r(�	directory�	nameparts�rootname�	discarded�parts�url�d�row�er\�r�contact�description�labelsr)rZr*�rawindexentriesvs��

�
���

����

��r�c#sn�t||||d�}d}	|r"|	||fkr"d|�t|�fdd�|d�}t|t|��D]\}
}||
d<|
Vq)dS)N�rt�NFs%s_sortcs|�SrNr))�x��sortkeyr)r*�<lambda>sz"_indexentriesgen.<locals>.<lambda>)�key�reversesparity)r��sorted�zipr)�contextrr;rH�stripecount�
sortcolumn�
descendingrt�rows�sortdefaultr��parityr)r�r*�_indexentriesgen�s��r�FcCs |||||||f}tjt|d�S)N)�args)r�mappinggeneratorr�)rr;rHr�r�r�rtr�r)r)r*�indexentries	sr�c@sTeZdZdZddd�Zdd�Zdd�Zd	d
�Zdd�Zd
d�Z	ddd�Z
dd�ZdS)�hgwebdirz�HTTP server for multiple repositories.

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

    Instances are typically used as WSGI applications.
    NcCsP||_||_d|_d|_d|_|��d|_|s&t�|j�t�	|j�dSdS)Nr)
�conf�baseuir�lastrefresh�motd�refresh�requests_countr�loadall�
populateui)�selfr�r�r)r)r*�__init__s�zhgwebdir.__init__c
Cs�|jr|j�dd�}n
tjdd}|j}|dkr$|j|t��kr$dS|jr-|j��}nt	j�
�}|�dddd�|�ddd	d�|�d
dd	d�t|j
tttf�s�d
di}tj�|j
�sht�td�|j
��|j|j
|dd�g}|�d�D]\}}|�d|�D]	}|�||f�q�qxnt|j
ttf�r�|j
}nt|j
t�r�|j
��}t�|�t|�}	|�d�D]5\}
}t�|
�}
t j!|dd�D]$}tj�"|�}t�|�}|�#|
�r�|t$|
�d�}|	�|�%d�|f�q�q�|	|_&||_|j�dd�|_'d|_(|j�)dd�t*_*|j�)dd�|_+|jj)dddd�|_,|j�)dd�|_-|j-�r&t.|j-�|_-|j�)dd�}
|
�#d��r9|
dd�}
|
�/d��rE|
dd�}
|
|_0t��|_dS) NrCsrefreshintervalrsuisreport_untrustedsoffshgwebdirsnonttystruesprogresssdisableshgwebspathsshgweb-pathssconfig file %s not found!T)�remap�trustscollections)r/r#sexperimentals web.full-garbage-collection-rate�encoding�styles	templatesFrDsstripessprefixr���)1r�	configintr�	coreitemsrYr��timer�rjro�load�	setconfig�
isinstancer��dict�list�tupler1r(�existsr�AbortrrlrGr4r,rr�r@rr$rr7r5r_rArBr;�gc_full_collect_rate�gc_full_collections_donerWr�style�templatepathr��int�endswithr<)
r��refreshinterval�itemr[�mapr:r'�ignoredr(r;r<r=�repor)r)r*r�&sx
��




���zhgwebdir.refreshcCs*tj�dd��d�std��t�|�dS)NsGATEWAY_INTERFACErMsCGI/1.sJThis function is only intended to be called while running as a CGI script.)r�environr\r_�RuntimeErrorr!�launch�r�r)r)r*�runms��zhgwebdir.runcCs4|j�dd�}tj||d�}t�||�}|�||�S)NrC�baseurl)�
altbaseurl)rrW�
requestmod�parserequestfromenv�wsgiresponse�run_wsgi)r��env�respond�baseurlrH�resr)r)r*�__call__wszhgwebdir.__call__c
cs�|j�dd�}tj|j|d��oz5|�||�D]}|VqW|j}|jd7_|dkr@|j|dkr@t��|j	d7_	n7tjdd�n(|j}|jd7_|dkrh|j|dkrht��|j	d7_	wtjdd�wWd�dSWd�dS1s�wYdS)Ns	profilingsenabled)�enabledrr)�
generation)
rr]r�profile�_runwsgir�r��gc�collectr�)r�rHr�r�r��rater)r)r*r�~s,����"�zhgwebdir.run_wsgics�z}�zI|��t|j�\}}|r||jd<|j�d��|�||�}|�ddtji�}d|_	||jd<��
d�s=d|jvrf��
d�rI�d	d�}n|jd}|jjd
ddd�}t
|j|||�|��WW~St|j�}	�rq�d
kr�|	vr|�|||�WW~S��d�r��|	vr��dtd
���t�fdd�|	D��r�|�|||��WW~S�fdd�}
|
�D]n}|	�|�}|�r|j}
tjr�dd�t�|
�D�}
tj|
||j�d
d�|jd�}zt�|j� �|�}t!�"|��#||�WWW~St$�y	}zt�%|j&�}t't(|��d}~wt)j*�y}zt't(t+|���d}~wwq��d��fdd�|	D��r8|�|||��WW~Sd|_	|�,|�-dd�i��|��WW~St'�y~}z%t.|j/t�0|��|_	|�,|�-dd|j1�pjdi��|��WYd}~W~Sd}~ww~w)NsContent-Security-Policyr#smimetyper�s200 Script output followssContent-Typesstatic/sstatic�rCFrD�indexs/indexc3s�|]}|���VqdSrN�r_�r&r�r�r)r*rP�s�z$hgwebdir._runwsgi.<locals>.<genexpr>c3s"��Vt���D]}|Vq	dSrN)r�finddirs)rO)�virtualr)r*�_virtualdirs�s
��z'hgwebdir._runwsgi.<locals>._virtualdirscSsi|]
\}}|�d�|�qS)�latin1)�decode)r&�k�vr)r)r*�
<dictcomp>�s
��z%hgwebdir._runwsgi.<locals>.<dictcomp>r�)�reponamer��bodyfhcsg|]	}|���r|�qSr)r�r�r�r)r*r+�sz%hgwebdir._runwsgi.<locals>.<listcomp>s
404 Not FoundsnotfoundsreposerrorrM)2r�rr�headers�dispatchpathr%r�renderr�statusr_�qsparamsrWr
r��sendresponser�r;�	makeindexr�rA�anyr\�rawenvr�ispy3�	iteritemsr�r�r�rrarjr�hgwebr�rb�
strtolocal�strerrorrrrrc�bytes�
setbodygen�generater�code�bytestr�message)r�rHr��csp�nonce�tmpl�ctype�fname�staticr;r��virtualrepo�real�uenvr��inst�msgr�r))rtr�r*r��s�




D
�=�6�

���
�����
	����zhgwebdir._runwsgirMc		s�|��gd�}d\��d|jvr)|jd���d���r#�dd���|vr)d���fdd�|D�}|��t|j|j||j��|d	�}||t�d
||j	���d�}|�
|�|�|�d|��|�
�S)
N)rRrTrQrUr�ssort�-rrMcs2g|]}d|d�r|�krdpd|ff�qS)ssort_%ss%s%srrMr))r&�column�r�r�r)r*r+s	�����z&hgwebdir.makeindex.<locals>.<listcomp>)r�r�rtr#)sentriesssubdirspathdefs
sortcolumns
descendingr�)r�r�r_r�rr;r�r�makebreadcrumbr<�updater�r�r�)	r�rHr�r�rt�sortable�sort�entries�mappingr)rr*r��s@


	���
zhgwebdir.makeindexc	s��fdd��i}t�|��j�\}\}}}||dkr||d<t�|d�}�dd�}	�dd�}
�dd	�p;|j�d
�d}|�d
�sE|d
7}tj|jd
|	|
||||d�}t	�
|�}
|
d
dd���fdd��}tjj|||d�S)Ncs|�dd��jj|i|��S)NrET)�
setdefaultrrW)r��kwargsr�r)r*rW+sz"hgwebdir.templater.<locals>.configrr��?rC�logourl�logoimg�	staticurlr#s/static/)r�rSrrrssessionvarsr�snonce�motdr))�requiresc3s(��jdur�jVdS�dd�VdS)NrCr)r�)r�r�rWr�r)r*r�Ls�
z hgwebdir.templater.<locals>.motd)�fp�defaults)
r�getstyler�r �sessionvarsrd�rstripr�rr�templatekeywordr�frommapfile)r�rHr��vars�stylesr��mapfilerr�logourl�logoimg�	staticurlrrr�r)rr*r*s<�


�
�


�zhgwebdir.templaterrN�rM)�__name__�
__module__�__qualname__�__doc__r�r�r�r�r�r�r�rr)r)r)r*r�s

G

^/r�r%)rMFrM)2�
__future__rr�r1r��i18nr�commonrrrr	r
rrr
r�rrrrrrrrrrrrrrrorrrr�r r!�utilsr"r-r@r9rLr�r�r��objectr�r)r)r)r*�<module>s&,D

�