HEX
Server: Apache
System: Linux pdx1-shared-a1-38 6.6.104-grsec-jammy+ #3 SMP Tue Sep 16 00:28:11 UTC 2025 x86_64
User: mmickelson (3396398)
PHP: 8.1.31
Disabled: NONE
Upload Files
File: //usr/lib/python3/dist-packages/mercurial/utils/__pycache__/procutil.cpython-310.pyc
o

�]Lb�l�@s2ddlmZddlZddlZddlZddlZddlZddlZddlZddl	Z	ddl
Z
ddlmZddl
mZmZddlmZmZmZm
Z
ddlmZe�d�Ze
jrYdd	lmZndd
lmZdd�ZGd
d�dej�ZGdd�de�Z ej!�"e �dd�Z#dd�Z$Gdd�de�Z%ej&�"e%�dd�Z'e
j(r�ej)dur�e�Z)nej)j*Z)ej+dur�e�Z+ne'ej+j*�Z+ej,dur�e�Z,ne'ej,j*�Z,e
jr�e�-e+�Z+e�-e,�Z,ee+�r�e#e+�Z+n,ej)Z)ej+Z+ej,Z,e
jr�e�-e+�Z+e�-e,�Z,ee+��re
jr�e#e+�Z+n	e�.e+�/�dd�Z+ej0Z0ej1Z2ej3Z3ej4Z4ej5Z5ej6Z6ej7Z7ej8Z8ej9Z9ej:Z:ej;Z;ej<Z<ej=Z=zej>Z>Wn
e?�y:Ynwzej@Z@Wn
e?�yJYnwe
jAZBdd�ZCGdd�de�ZDd^d!d"�ZEd#d$�ZFd%d&�ZGd_d'd(�ZHd_d)d*�ZId`d+d,�ZJd-d.�ZKd/d0�ZLeLeKd1�ZMd2d3�ZNdaOd4d5�ZPd6d7�ZQd8d9�ZRd:d;�ZSd<d=�ZTd>d?�ZUd@dA�ZVd_dBdC�ZWe
j�r�dDdE�ZXejYZZndFdE�ZXe
j[ZZdGdH�Z\dadIdJ�Z]da^dKdL�Z_dMdN�Z`dOdP�ZadQdR�ZbejcdSdT��Zde
j�r�dUZeeeejfBZg	V			W		dbdXdY�ZhdS	V			W		dbdZd[�Zi	V			W		dbd\d]�Zje
j(�reiZhdSejZhdS)c�)�absolute_importN���_)�getattr�open)�encoding�error�policy�pycompat)�resourceutil�osutil)�windows)�posixcCs z|��WStyYdSw)NF)�isatty�AttributeError)�fp�r�:/usr/lib/python3/dist-packages/mercurial/utils/procutil.pyr.s

�rc@s eZdZdZdd�Zdd�ZdS)�BadFilez3Dummy file object to simulate closed stdio behaviorcC�ttjd���NzBad file descriptor��IOError�errno�EBADF��self�brrr�readinto8�zBadFile.readintocCrrrrrrr�write;r z
BadFile.writeN)�__name__�
__module__�__qualname__�__doc__rr!rrrrr5src@�$eZdZdd�Zdd�Zdd�ZdS)�LineBufferedWrappercC�
||_dS�N��orig�rr+rrr�__init__@�
zLineBufferedWrapper.__init__cC�t|j|�Sr)�rr+�r�attrrrr�__getattr__Cr zLineBufferedWrapper.__getattr__cCs&|j}|�|�}|�d�r|��|S)N�
)r+r!�endswith�flush)r�sr+�resrrrr!Fs


zLineBufferedWrapper.writeN�r"r#r$r-r3r!rrrrr'?�r'cCs,tjrt|tj�s|St|t�r|St|�Sr))r�ispy3�
isinstance�io�BufferedIOBaser'��streamrrr�make_line_bufferedSs

rAcCs$t|t�rt|jt�r
J�|jS|Sr))r<r'r+r?rrr�unwrap_line_buffered_s
rBc@r&)�WriteAllWrappercCr(r)r*r,rrrr-gr.zWriteAllWrapper.__init__cCr/r)r0r1rrrr3jr zWriteAllWrapper.__getattr__cCsD|jj}t|�}t|�}d}||kr ||||d��7}||ks|S�Nr)r+r!�
memoryview�len)rr7�write1�m�total_to_write�
total_writtenrrrr!ms�zWriteAllWrapper.writeNr9rrrrrCfr:rCcCs0tjsJ�t|t�r|St|tj�r|St|�Sr))rr;r<rCr=r>r?rrr�_make_write_all|s

rK�wb�cCs"|dkr
td�|Std�|S)zpreturn a message describing a subprocess status
    (codes from kill are negative - not os.system/wait encoding)rsexited with status %dskilled by signal %dr)�coderrr�explainexit�srOc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�_pfilez;File-like wrapper for a stream opened by subprocess.Popen()cCs||_||_dSr))�_proc�_fp)r�procrrrrr-�s
z_pfile.__init__cCs|j��|j��Sr))rR�closerQ�wait�rrrrrT�s

z_pfile.closecCs
t|j�Sr))�iterrRrVrrr�__iter__�r.z_pfile.__iter__cCr/r))rrRr1rrrr3�r z_pfile.__getattr__cC�|Sr)rrVrrr�	__enter__��z_pfile.__enter__cCs|��dSr))rT)r�exc_type�	exc_value�exc_tbrrr�__exit__�r z_pfile.__exit__N)
r"r#r$r%r-rTrXr3rZr_rrrrrP�srP�rb���cCs2|dkr	t||�S|dkrt||�St�d|��)Nr`swbsunsupported mode: %r)�_popenreader�_popenwriterr	�ProgrammingError)�cmd�mode�bufsizerrr�popen�s


rhcC�&tjt|�d|ttjd�}t||j�S)NT)�shellrg�	close_fds�stdout)�
subprocess�Popen�tonativestr�closefds�PIPErPrl�rerg�prrrrb���rbcCri)NT)rjrgrk�stdin)rmrnrorprqrPrurrrrrrcrtrcc	Cs0tjt|�ddttjtjt|�d�}|j|jfS)NTra)rjrgrkrurl�env)rmrnrorprq�tonativeenvrurl)rervrsrrr�popen2s�	rxcCst||�\}}}}|||fSr))�popen4)rervrurl�stderrrsrrr�popen3!s
r{c
Cs:tjt|�d|ttjtjtjt|�d�}|j|j|j|fS)NT)rjrgrkrurlrzrv)	rmrnrorprqrwrurlrz)rervrgrsrrrry&s�
rycCs.tjt|�dttjtjd�}|�|�\}}|S)z9filter string S through command CMD, returning its outputT)rjrkrurl)rmrnrorprq�communicate)r7rers�pout�perrrrr�
pipefilter4s�rcCs�d\}}z�tjdd�\}}t�|d�}|�|�|��tjdd�\}}t�|�|�d|�}|�d|�}t|�}tjdkrD|d	@rDd
}|rSt	�
td�|t|�f��t
|d��4}|��Wd
�Wz	|rlt�|�Wn	tyvYnwz|r�t�|�WSWSty�YSw1s�wYWz	|r�t�|�Wn	ty�Ynwz
|r�t�|�Wd
SWd
Sty�Yd
Swz	|r�t�|�Wn	ty�Ynwz|r�t�|�WwWwty�Yww)z�filter string S through a pair of temporary files with CMD.
    CMD is used as a template to create the real command to be run,
    with the strings INFILE and OUTFILE replaced by the real names of
    the temporary files generated.)NNs
hg-filter-in-)�prefixrLshg-filter-out-sINFILEsOUTFILE�OpenVMSrMrscommand '%s' failed: %sr`N)r�mkstemp�os�fdopenr!rT�replace�system�sysplatformr	�AbortrrOr�read�unlink�OSError)r7re�inname�outname�infdr�outfdrNrrr�
tempfilterAs~

��
�����
�����
����r�)s	tempfile:spipe:cCsFt�t�D]\}}|�|�r|||t|�d����Sqt||�S)zMfilter a string through a command that transforms its input to its
    outputN)r�	iteritems�_filtertable�
startswithrF�lstripr)r7re�name�fnrrr�filterls

�
r�cCs�tdur[tj�d�}tjd}|rt|�tSt��r3t	tdd�dkr,ttjd�tStt
j�tSt
jsLt
j�t	|dd��d	krLtt
�|j��tSttd
�pYt
j�t
jd��tS)z]return location of the 'hg' executable.

    Defaults to $HG or 'hg' in the search path.
    N�HG�__main__�frozen�
macosx_app�EXECUTABLEPATH�__file__��hgshgr)�
_hgexecutabler�environ�get�sys�modules�_sethgexecutabler�
mainfrozenrr�
sysexecutable�	iswindowsr��path�basename�fsencoder��findexe�sysargv)r��mainmodrrr�hgexecutablexs*
�
�
����r�cCs|adS)z#set location of the 'hg' executableN)r�)r�rrrr��sr�cCs8t|dd�}z
|o|�|��kWStjyYdSw)N�filenoF)rr�r=�UnsupportedOperation)�f�stdfr�rrr�_testfileno�s�r�cC�t|tj�Sr))r�r��	__stdin__�r�rrr�isstdin�r r�cCr�r))r�r��
__stdout__r�rrr�isstdout�r r�cCs�|��||}}t|t�r0t�|���}t�tjtj�}t�	||���t�
|�t�|d�}t|t�rLt�|���}t�	t
��|���t�|d�}||fS)a�Duplicate streams and redirect original if (uin, uout) are stdio

    If uin is stdin, it's redirected to /dev/null. If uout is stdout, it's
    redirected to stderr so the output is still readable.

    Returns (fin, fout) which point to the original (uin, uout) fds, but
    may be copy of (uin, uout). The returned streams can be considered
    "owned" in that print(), exec(), etc. never reach to them.
    �rbrL)r6r�rur��dupr�r�devnull�O_RDONLY�dup2rTr�rlrz)�uin�uout�fin�fout�newfd�nullfdrrr�protectstdio�s




r�cCsJ|��||f||ffD]\}}||ur"t�|��|���|��qdS)z@Restore (uin, uout) streams from possibly duplicated (fin, fout)N)r6r�r�r�rT)r�r�r�r�r��uifrrr�restorestdio�s��r�csBdd��ttj�}|r|��fdd�t�|�D��t�|d<|S)z>return environ with optional override, useful for shelling outcSs*|dus|dur
dS|durdSt�|�S)z9convert python object into string that is useful to shellNF�0T�1)r�bytestr)�valrrr�py2shell�s

zshellenviron.<locals>.py2shellc3s �|]\}}|�|�fVqdSr)r)�.0�k�v�r�rr�	<genexpr>�s�zshellenviron.<locals>.<genexpr>r�)�dictrr��updaterr�r�)r�rvrr�r�shellenviron�s

r�cCst�|t|��Sr))�platform�
shelltocmdexer��rervrrr�
shelltonative�s�r�cCrYr)rr�rrrr��r[cCst�t|�S)zHconvert the environment from bytes to strings suitable for Popen(), etc.)r�rapplyro)rvrrrrw�srwc	Cs�zt��Wn	tyYnwt|�}|dust|�r/tjt|�dtt	|�t
�t|�d�}n,tjt|�dtt	|�t
�t|�tj
tjd�}t|jjd�D]}|�|�qL|��|j}t
jdkrf|d@rfd}|S)	z�enhanced shell command execution.
    run with environment maybe modified, maybe in different dir.

    if out is specified, it is assumed to be a file-like object that has a
    write() method. stdout and stderr will be redirected to out.NT)rjrkrv�cwd)rjrkrvr�rlrz�r�rMr)rlr6�	Exceptionr�r�rm�callrorprwrr�rnrq�STDOUTrW�readliner!rU�
returncoder�)rer�r��outrv�rcrS�linerrrr��s<�
�
�	r�cCsJtjrdtjvr
dSttdd�rt��SdStjp$tj�d�p$tj�d�S)zAre we running in a GUI?sSSH_CONNECTIONF�isguiNTsDISPLAYsWAYLAND_DISPLAY)	r�isdarwinrr�rr
r�r�r�rrrr�_guis

�
�r�cCstdurt�atSr))�_is_guir�rrrr�gui0sr�cCs2t��rttdd�dkrtjdgStjgSt�S)z�Return the command used to execute current hg

    This is different from hgexecutable() because on Windows we want
    to avoid things opening new shell windows like batch files, so we
    get either the python call or current executable.
    r�Nr�r�)	rr�rr�rr�rr��	_gethgcmdrrrr�hgcmd7s
r�c
s�t���fdd�}d}ttdd�}|durt�||�}z9t|�}|�sF|�vs+t|�s>|�s>W|dur<t�tj|�dSdSt�d�|�r#|W|durTt�tj|�SS|durat�tj|�ww)a_Execute the argument list in a detached process.

    condfn is a callable which is called repeatedly and should return
    True once the child process is known to have started successfully.
    At this point, the child process PID is returned. If the child
    process fails to start or finishes before condfn() evaluates to
    True, return -1.
    cs��t���dSr))�addr�rU)�signum�frame��
terminatedrr�handlerYszrundetached.<locals>.handlerN�SIGCHLDrag�������?)�setr�signal�
spawndetached�testpidr��time�sleep)�args�condfnr��prevhandlerr��pidrr�r�rundetachedGs,�
��
��r�c#s��t�tj�g�g����fdd�}z+z	t�tj|�Wnty(�d=YnwdVW�r8t�tj�d��r<t�dS�rIt�tj�d��rMt�w)aInhibit SIGINT handling on a region of code.

    Note that if this is called in a non-main thread, it turns into a no-op.

    Args:
      warn: A callable which takes no arguments, and returns True if the
            previous signal handling should be restored.
    cs,��rt�tj�d��d=��d�dS)NrT)r��SIGINT�append)r���oldsiginthandler�
shouldbail�warnrr�disabledsiginthandlerzsz.uninterruptible.<locals>.disabledsiginthandlerrN)r��	getsignalr��
ValueError�KeyboardInterrupt)rrrrr�uninterruptiblels(�
���r�FTc

Cs�zAd}|durt��}|�|�|��|�d�tjt�t|�|t	|�dt
|||d�}	|dur5||	j�W|dur@|��dSdS|durK|��ww)z1Spawn a command without waiting for it to finish.NrT)rjrvrk�
creationflagsrurlrz)
r�unnamedtempfiler!r6�seekrmrnr�rorw�_creationflagsrUrT)
�scriptrvrjrlrz�ensurestart�record_wait�stdin_bytesrursrrr�runbgcommand�s2


�

��
�rc

s�tjrt�|r|}nt|t�r|g}d�dd�|D��}|dur(d|}d}	nd}	d}d}
z]z7|dur8tj}
nt��}
|
�	|�|
�
�|
�d�|durQtj}|durXtj}tj|d|d|
|||	d	��Wnt
yv|duru|d
��wW|dur�|
dur�t|
t�r�J�|
��n|dur�|
dur�t|
t�r�J�|
��www|s�tj�fdd�d
�}d|_|��dS�j}|dur�||�dSdS)�Spawn a command without waiting for it to finish.


        When `record_wait` is not None, the spawned process will not be fully
        detached and the `record_wait` argument will be called with a the
        `Subprocess.wait` function for the spawned process.  This is mostly
        useful for developers that need to make sure the spawned process
        finished before a certain point. (eg: writing test)� css�|]}t|�VqdSr))�
shellquote)r��xrrrr��s�z"runbgcommandpy3.<locals>.<genexpr>Ns( %s ) &TFr)rjrvrkrurlrz�start_new_session�cs�jSr))rUr�rsrr�<lambda>sz!runbgcommandpy3.<locals>.<lambda>��target)rr�r�r<�bytes�joinrm�DEVNULLrr!r6rrnr��intrT�	threading�Thread�daemon�startrU)
rervrjrlrzrrrrrru�tr�rrr�runbgcommandpy3�sp



�
����
��r&c
stjrt�|durYt����rY|s'�fdd�}tj|d�}	d|	_|	��dSt�	�d�\}
}t�
|�r:t�|�}nt�|�}|dkrW|dkrKt
j}t|d|t�|�f��dSd}d}
z�zR|durgt��|durrttjd	�}
nt��}
|
�|�|
��|
�d�|dur�ttjd
�}|dur�ttjd
�}tj|||d|
||d�}|dur�||j�d}Wn'ty�}z|j
d@}|dkr�d}WYd}~nd}~wty�d}YnwW|
dur�|
��|dur�t�|�dSdS|
dur�|
��|du�rt�|�ww)rNcst��d�dSrD)r��waitpidr�r�rr�_do_wait:sz!runbgcommandpy2.<locals>._do_waitrTrrserror running %r: %s�r�w)rjrvrkrurlrz)rr�r�r��forkr!r"r#r$r'�	WIFEXITED�WEXITSTATUS�WTERMSIGr�EINVALr��strerror�setsidrr�rr!r6rrmrnrU�EnvironmentErrorr�rT�_exit)rervrjrlrzrrrr)r%�_pid�statusr�rurs�exrr(r�runbgcommandpy2s�
��

�	

�����
�r8)r`rar))Nra)NNN)FNNTNN)k�
__future__r�
contextlibrr=r�r�rmr�r!r��i18nrrrrr�rr	r
�utilsr�	importmodr
r�rr�rr�	RawIOBaser�objectr'r>�registerrArBrC�IOBaserKr;ru�bufferrlrz�	winstdoutr�r�r��gethgcmdr��getuser�getpid�
hidewindow�readpipe�	setbinary�setsignalhandlerr�
shellsplitr��sshargsr��setprocnamer�
unblocksignal�isposixrprOrPrhrbrcrxr{ryrr�r�r�r�r�r�r�r�r�r�r�r�r��strfromlocalro�identityrwr�r�r�r�r�r��contextmanagerr�DETACHED_PROCESS�CREATE_NEW_PROCESS_GROUPr
rr&r8rrrr�<module>s 	






�




�
�




&�	
	
&%
!���,
�W
�r