Ë
    oj!  ã                  óT  — U d Z ddlmZ ddlZddlmZmZmZ ddl	m
Z
 ddlmZmZmZ ddlmZmZ ddlmZ dd	lmZ  G d
„ de«      Z ee«       G d„ d«      «       Z ee«       G d„ d«      «       Z e«       Zded<    G d„ de«      Z G d„ de«      Z G d„ de«      Z G d„ de«      Zy)z
PID file.
é    )ÚannotationsN)ÚgetpidÚkillÚname)ÚTracebackType)ÚAnyÚOptionalÚType)Ú	InterfaceÚimplementer)ÚLogger)ÚFilePathc                  óP   — e Zd ZdZd	d„Zd
d„Zd
d„Zdd„Zdd„Z	 	 	 	 	 	 	 	 dd„Z	y)ÚIPIDFilez5
    Manages a file that remembers a process ID.
    c                  ó   — y)a+  
        Read the process ID stored in this PID file.

        @return: The contained process ID.

        @raise NoPIDFound: If this PID file does not exist.
        @raise EnvironmentError: If this PID file cannot be read.
        @raise ValueError: If this PID file's content is invalid.
        N© r   ó    úE/usr/lib/python3/dist-packages/twisted/application/runner/_pidfile.pyÚreadzIPIDFile.read   ó   � r   c                  ó   — y)zŽ
        Store the PID of the current process in this PID file.

        @raise EnvironmentError: If this PID file cannot be written.
        Nr   r   r   r   ÚwriteRunningPIDzIPIDFile.writeRunningPID%   r   r   c                  ó   — y)zm
        Remove this PID file.

        @raise EnvironmentError: If this PID file cannot be removed.
        Nr   r   r   r   ÚremovezIPIDFile.remove,   r   r   c                  ó   — y)a  
        Determine whether there is a running process corresponding to the PID
        in this PID file.

        @return: True if this PID file contains a PID and a process with that
            PID is currently running; false otherwise.

        @raise EnvironmentError: If this PID file cannot be read.
        @raise InvalidPIDFileError: If this PID file's content is invalid.
        @raise StalePIDFileError: If this PID file's content refers to a PID
            for which there is no corresponding running process.
        Nr   r   r   r   Ú	isRunningzIPIDFile.isRunning3   r   r   c                  ó   — y)zð
        Enter a context using this PIDFile.

        Writes the PID file with the PID of the running process.

        @raise AlreadyRunningError: A process corresponding to the PID in this
            PID file is already running.
        Nr   r   r   r   Ú	__enter__zIPIDFile.__enter__A   r   r   c                 ó   — y)zS
        Exit a context using this PIDFile.

        Removes the PID file.
        Nr   )ÚexcTypeÚexcValueÚ	tracebacks      r   Ú__exit__zIPIDFile.__exit__K   r   r   N©ÚreturnÚint©r%   ÚNone©r%   Úbool)r%   z
'IPIDFile')r    úOptional[Type[BaseException]]r!   úOptional[BaseException]r"   úOptional[TracebackType]r%   zOptional[bool])
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r#   r   r   r   r   r      sI   „ ñó	óóóóð	Ø.ð	à)ð	ð +ð	ð 
ô		r   r   c                  ó’   — e Zd ZdZ e«       Zedd„«       Zdd„Zdd„Z	dd„Z
dd„Zdd„Zdd„Zedd	„«       Zdd
„Z	 	 	 	 	 	 	 	 dd„Zy)ÚPIDFilezÓ
    Concrete implementation of L{IPIDFile}.

    This implementation is presently not supported on non-POSIX platforms.
    Specifically, calling L{PIDFile.isRunning} will raise
    L{NotImplementedError}.
    c                ó:   — t        | «      › d�j                  «       S )z€
        Format a PID file's content.

        @param pid: A process ID.

        @return: Formatted PID file contents.
        ú
)r&   Úencode©Úpids    r   Ú_formatzPIDFile._formatc   s   € ô �c“(�˜2ˆ×%Ñ%Ó'Ð'r   c                ó   — || _         y)zD
        @param filePath: The path to the PID file on disk.
        N)ÚfilePath)Úselfr;   s     r   Ú__init__zPIDFile.__init__n   s   € ð !ˆ�r   c                ó8  — d}	 | j                   j                  «       5 }|D ]  } n d d d «       	 t        |«      S # 1 sw Y   ŒxY w# t        $ r.}|j                  t        j                  k(  rt        d«      ‚‚ d }~ww xY w# t        $ r t        d|›�«      ‚w xY w)Nr   úPID file does not existz#non-integer PID value in PID file: )	r;   ÚopenÚOSErrorÚerrnoÚENOENTÚ
NoPIDFoundr&   Ú
ValueErrorÚInvalidPIDFileError)r<   Ú	pidStringÚfhÚes       r   r   zPIDFile.readt   s«   € Øˆ	ð	Ø—‘×#Ñ#Ó%ð ¨Ø!#ò �IÙð÷ð	Ü�y“>Ð!÷ð ûô ò 	Ø�w‰wœ%Ÿ,™,Ò&Ü Ð!:Ó;Ð;Øûð	ûô ò 	Ü%Ø5°i°]ÐCóð ð	ús6   „A ž	;§A °
B »AÁ A Á	A>Á)A9Á9A>ÂBc                óZ   — | j                   j                  | j                  |¬«      «       y)zš
        Store a PID in this PID file.

        @param pid: A PID to store.

        @raise EnvironmentError: If this PID file cannot be written.
        r7   N)r;   Ú
setContentr9   ©r<   r8   s     r   Ú_writezPIDFile._write†   s!   € ð 	�‰× Ñ  §¡°# Ó!6Õ7r   c                ó6   — | j                  t        «       «       y ©N)rM   r   ©r<   s    r   r   zPIDFile.writeRunningPID�   s   € Ø�‰”F“HÕr   c                ó8   — | j                   j                  «        y rO   )r;   r   rP   s    r   r   zPIDFile.remove“   s   € Ø�‰×ÑÕr   c                óš   — 	 | j                  «       }t        dk(  r| j                  |«      S t	        dt        › �«      ‚# t        $ r Y yw xY w)NFÚposixz isRunning is not implemented on )r   rD   ÚSYSTEM_NAMEÚ_pidIsRunningPOSIXÚNotImplementedErrorrL   s     r   r   zPIDFile.isRunning–   sT   € ð	Ø—)‘)“+ˆCô ˜'Ò!Ø×*Ñ*¨3Ó/Ð/ä%Ð(HÌÈÐ&VÓWÐWøô ò 	Ùð	ús   ‚> ¾	A
Á	A
c                óÖ   — 	 t        | d«       y# t        $ rP}|j                  t        j                  k(  rt	        d«      ‚|j                  t        j
                  k(  rY d}~y‚ d}~ww xY w)a1  
        POSIX implementation for running process check.

        Determine whether there is a running process corresponding to the given
        PID.

        @param pid: The PID to check.

        @return: True if the given PID is currently running; false otherwise.

        @raise EnvironmentError: If this PID file cannot be read.
        @raise InvalidPIDFileError: If this PID file's content is invalid.
        @raise StalePIDFileError: If this PID file's content refers to a PID
            for which there is no corresponding running process.
        r   Tz'PID file refers to non-existing processN)r   rA   rB   ÚESRCHÚStalePIDFileErrorÚEPERM)r8   rI   s     r   rU   zPIDFile._pidIsRunningPOSIX¡   sY   € ð"
	Ü��aŒLð øô ò 	Ø�w‰wœ%Ÿ+™+Ò%Ü'Ð(QÓRÐRØ—‘œEŸK™KÒ'Üàûð	ús   ‚ �	A(˜AA#Á"A#Á#A(c                ó²   — 	 | j                  «       r
t        «       ‚	 | j                  «        | S # t        $ r | j                  j	                  d«       Y Œ8w xY w)Nz&Replacing stale PID file: {log_source})r   ÚAlreadyRunningErrorrY   Ú_logÚinfor   rP   s    r   r   zPIDFile.__enter__¾   sW   € ð	EØ�~‰~ÔÜ)Ó+Ð+ð  ð 	×ÑÔØˆøô !ò 	EØ�I‰I�N‰NÐCÖDð	Eús   ‚/ ¯$AÁAc                ó$   — | j                  «        y rO   )r   ©r<   r    r!   r"   s       r   r#   zPIDFile.__exit__Ç   s   € ð 	�‰ŒØr   N)r8   r&   r%   Úbytes)r;   zFilePath[Any]r%   r(   r$   ©r8   r&   r%   r(   r'   r)   )r8   r&   r%   r*   )r%   z	'PIDFile'©r    r+   r!   r,   r"   r-   r%   r(   )r.   r/   r0   r1   r   r]   Ústaticmethodr9   r=   r   rM   r   r   r   rU   r   r#   r   r   r   r3   r3   W   s…   „ ññ ‹8€Dàò(ó ð(ó!óó$8óóó	Xð òó ðó8ðà.ðð *ðð +ð	ð
 
ôr   r3   c                  ó`   — e Zd ZdZdd„Zdd„Zdd„Zdd„Zdd„Zdd„Z	dd„Z
	 	 	 	 	 	 	 	 dd	„Zy
)ÚNonePIDFilez¤
    PID file implementation that does nothing.

    This is meant to be used as a "active None" object in place of a PID file
    when no PID file is desired.
    c                 ó   — y rO   r   rP   s    r   r=   zNonePIDFile.__init__Ú   s   € Ør   c                ó   — t        d«      ‚)Nr?   )rD   rP   s    r   r   zNonePIDFile.readÝ   s   € ÜÐ2Ó3Ð3r   c                ó6   — t        t        j                  d«      ‚)zä
        Store a PID in this PID file.

        @param pid: A PID to store.

        @raise EnvironmentError: If this PID file cannot be written.

        @note: This implementation always raises an L{EnvironmentError}.
        zOperation not permitted)rA   rB   rZ   rL   s     r   rM   zNonePIDFile._writeà   s   € ô ”e—k‘kÐ#<Ó=Ð=r   c                ó&   — | j                  d«       y )Nr   )rM   rP   s    r   r   zNonePIDFile.writeRunningPIDì   s   € Ø�‰�A�r   c                ó6   — t        t        j                  d«      ‚)NzNo such file or directory)rA   rB   rC   rP   s    r   r   zNonePIDFile.removeï   s   € Ü”e—l‘lÐ$?Ó@Ð@r   c                 ó   — y)NFr   rP   s    r   r   zNonePIDFile.isRunningò   s   € Ør   c                ó   — | S rO   r   rP   s    r   r   zNonePIDFile.__enter__õ   s   € Øˆr   c                 ó   — y rO   r   r`   s       r   r#   zNonePIDFile.__exit__ø   s   € ð r   Nr'   r$   rb   r)   )r%   z'NonePIDFile'rc   )r.   r/   r0   r1   r=   r   rM   r   r   r   r   r#   r   r   r   rf   rf   Ñ   sV   „ ñóó4ó
>óóAóóðà.ðð *ðð +ð	ð
 
ôr   rf   ÚnonePIDFilec                  ó   — e Zd ZdZy)r\   z%
    Process is already running.
    N©r.   r/   r0   r1   r   r   r   r\   r\     ó   „ òr   r\   c                  ó   — e Zd ZdZy)rF   z(
    PID file contents are invalid.
    Nrq   r   r   r   rF   rF   
  rr   r   rF   c                  ó   — e Zd ZdZy)rY   z[
    PID file contents are valid, but there is no process with the referenced
    PID.
    Nrq   r   r   r   rY   rY     s   „ òr   rY   c                  ó   — e Zd ZdZy)rD   z#
    No PID found in PID file.
    Nrq   r   r   r   rD   rD     rr   r   rD   ) r1   Ú
__future__r   rB   Úosr   r   r   rT   Útypesr   Útypingr   r	   r
   Úzope.interfacer   r   Útwisted.loggerr   Útwisted.python.filepathr   r   r3   rf   ro   Ú__annotations__Ú	Exceptionr\   rF   rY   rD   r   r   r   ú<module>r      s¶   ðò
õ #ã ß 0Ñ 0Ý ß &Ñ &ç 1å !Ý ,ô?ˆyô ?ñD ˆXÓ÷vð vó ðvñr ˆXÓ÷,ð ,ó ð,ñ^ $›€ˆXÓ %ô˜)ô ô˜)ô ô˜	ô ô�õ r   