o
    ¼>h!  ã                   @  s  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„ deƒZeeƒG dd„ dƒƒZeeƒG dd„ dƒƒZeƒ Zded< G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd„ deƒZdS )z
PID file.
é    )ÚannotationsN)ÚgetpidÚkillÚname)ÚTracebackType)ÚAnyÚOptionalÚType)Ú	InterfaceÚimplementer)ÚLogger)ÚFilePathc                   @  sL   e Zd ZdZddd„Zddd„Zdd	d
„Zddd„Zddd„Zddd„Z	dS ) ÚIPIDFilez5
    Manages a file that remembers a process ID.
    ÚreturnÚintc                   C  ó   dS )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   r   r   úƒ/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/application/runner/_pidfile.pyÚread   ó    zIPIDFile.readÚNonec                   C  r   )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   r   ÚwriteRunningPID%   r   zIPIDFile.writeRunningPIDc                   C  r   )zm
        Remove this PID file.

        @raise EnvironmentError: If this PID file cannot be removed.
        Nr   r   r   r   r   Úremove,   r   zIPIDFile.removeÚboolc                   C  r   )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   r   Ú	isRunning3   r   zIPIDFile.isRunningú
'IPIDFile'c                   C  r   )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   r   Ú	__enter__A   r   zIPIDFile.__enter__ÚexcTypeúOptional[Type[BaseException]]ÚexcValueúOptional[BaseException]Ú	tracebackúOptional[TracebackType]úOptional[bool]c                 C  r   )zS
        Exit a context using this PIDFile.

        Removes the PID file.
        Nr   )r   r   r!   r   r   r   Ú__exit__K   r   zIPIDFile.__exit__N©r   r   ©r   r   ©r   r   )r   r   )r   r   r   r    r!   r"   r   r#   )
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r$   r   r   r   r   r      s    





r   c                   @  s‚   e Zd ZdZeƒ Zed&dd„ƒZd'dd„Zd(dd„Z	d)dd„Z
d*dd„Zd*dd„Zd+dd„Zed,dd„ƒZd-dd„Zd.d#d$„Zd%S )/Ú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}.
    Úpidr   r   Úbytesc                 C  s   t | ƒ› d ¡ S )z€
        Format a PID file's content.

        @param pid: A process ID.

        @return: Formatted PID file contents.
        Ú
)r   Úencode©r-   r   r   r   Ú_formatc   s   	zPIDFile._formatÚfilePathúFilePath[Any]r   c                 C  s
   || _ dS )zD
        @param filePath: The path to the PID file on disk.
        N)r3   )Úselfr3   r   r   r   Ú__init__n   s   
zPIDFile.__init__c              
   C  s”   d}z| j  ¡ }|D ]} W d   ƒ n1 sw   Y  W n ty5 } z|jtjkr0tdƒ‚‚ d }~ww zt|ƒW S  tyI   td|›ƒ‚w )Nó    úPID file does not existz#non-integer PID value in PID file: )	r3   ÚopenÚOSErrorÚerrnoÚENOENTÚ
NoPIDFoundr   Ú
ValueErrorÚInvalidPIDFileError)r5   Ú	pidStringÚfhÚer   r   r   r   t   s*   €þ€€ý
ÿÿzPIDFile.readc                 C  s   | j  | j|d¡ dS )zš
        Store a PID in this PID file.

        @param pid: A PID to store.

        @raise EnvironmentError: If this PID file cannot be written.
        r1   N)r3   Ú
setContentr2   ©r5   r-   r   r   r   Ú_write†   s   zPIDFile._writec                 C  s   |   tƒ ¡ d S ©N)rE   r   ©r5   r   r   r   r      s   zPIDFile.writeRunningPIDc                 C  s   | j  ¡  d S rF   )r3   r   rG   r   r   r   r   “   ó   zPIDFile.remover   c                 C  sB   z|   ¡ }W n
 ty   Y dS w tdkr|  |¡S tdt› ƒ‚)NFÚposixz isRunning is not implemented on )r   r=   ÚSYSTEM_NAMEÚ_pidIsRunningPOSIXÚNotImplementedErrorrD   r   r   r   r   –   s   ÿ
zPIDFile.isRunningc              
   C  sZ   zt | dƒ W dS  ty, } z|jtjkrtdƒ‚|jtjkr'W Y d}~dS ‚ d}~w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   z'PID file refers to non-existing processNT)r   r:   r;   ÚESRCHÚStalePIDFileErrorÚEPERM)r-   rB   r   r   r   rK   ¡   s   	ø€úzPIDFile._pidIsRunningPOSIXú	'PIDFile'c                 C  s>   z	|   ¡ rtƒ ‚W n ty   | j d¡ Y nw |  ¡  | S )Nz&Replacing stale PID file: {log_source})r   ÚAlreadyRunningErrorrN   Ú_logÚinfor   rG   r   r   r   r   ¾   s   ÿÿzPIDFile.__enter__r   r   r   r    r!   r"   c                 C  s   |   ¡  d S rF   )r   ©r5   r   r   r!   r   r   r   r$   Ç   s   zPIDFile.__exit__N)r-   r   r   r.   )r3   r4   r   r   r%   ©r-   r   r   r   r&   r'   )r-   r   r   r   )r   rP   ©r   r   r   r    r!   r"   r   r   )r(   r)   r*   r+   r   rR   Ústaticmethodr2   r6   r   rE   r   r   r   rK   r   r$   r   r   r   r   r,   W   s    








	r,   c                   @  s`   e Zd ZdZddd„Zd dd„Zd!d
d„Zddd„Zddd„Zd"dd„Z	d#dd„Z
d$dd„ZdS )%Ú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.
    r   r   c                 C  ó   d S rF   r   rG   r   r   r   r6   Ú   ó   zNonePIDFile.__init__r   c                 C  s   t dƒ‚)Nr8   )r=   rG   r   r   r   r   Ý   s   zNonePIDFile.readr-   c                 C  ó   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)r:   r;   rO   rD   r   r   r   rE   à   s   
zNonePIDFile._writec                 C  s   |   d¡ d S )Nr   )rE   rG   r   r   r   r   ì   rH   zNonePIDFile.writeRunningPIDc                 C  r[   )NzNo such file or directory)r:   r;   r<   rG   r   r   r   r   ï   s   zNonePIDFile.remover   c                 C  r   )NFr   rG   r   r   r   r   ò   rZ   zNonePIDFile.isRunningú'NonePIDFile'c                 C  s   | S rF   r   rG   r   r   r   r   õ   rZ   zNonePIDFile.__enter__r   r   r   r    r!   r"   c                 C  rY   rF   r   rT   r   r   r   r$   ø   s   zNonePIDFile.__exit__Nr&   r%   rU   r'   )r   r\   rV   )r(   r)   r*   r+   r6   r   rE   r   r   r   r   r$   r   r   r   r   rX   Ñ   s    






rX   ÚnonePIDFilec                   @  ó   e Zd ZdZdS )rQ   z%
    Process is already running.
    N©r(   r)   r*   r+   r   r   r   r   rQ     ó    rQ   c                   @  r^   )r?   z(
    PID file contents are invalid.
    Nr_   r   r   r   r   r?   
  r`   r?   c                   @  r^   )rN   z[
    PID file contents are valid, but there is no process with the referenced
    PID.
    Nr_   r   r   r   r   rN     r`   rN   c                   @  r^   )r=   z#
    No PID found in PID file.
    Nr_   r   r   r   r   r=     r`   r=   ) r+   Ú
__future__r   r;   Úosr   r   r   rJ   Útypesr   Útypingr   r   r	   Úzope.interfacer
   r   Útwisted.loggerr   Útwisted.python.filepathr   r   r,   rX   r]   Ú__annotations__Ú	ExceptionrQ   r?   rN   r=   r   r   r   r   Ú<module>   s&   By/