HEX
Server: Apache
System: Linux scp1.abinfocom.com 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User: confeduphaar (1010)
PHP: 8.1.33
Disabled: exec,passthru,shell_exec,system
Upload Files
File: //lib/python3/dist-packages/twisted/application/runner/__pycache__/_pidfile.cpython-38.pyc
U


W[S�@s�dZddlZddlmZmZmZddlmZm	Z	ddl
mZGdd�de�Ze	e�Gdd	�d	e
��Ze	e�Gd
d�de
��Ze�ZGdd
�d
e�ZGdd�de�ZGdd�de�ZGdd�de�ZdS)z
PID file.
�N)�getpid�kill�name)�	Interface�implementer)�Loggerc@s@eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dS)�IPIDFilez5
    Manages a file that remembers a process ID.
    cCsdS)aB
        Read the process ID stored in this PID file.

        @return: The contained process ID.
        @rtype: L{int}

        @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	�E/usr/lib/python3/dist-packages/twisted/application/runner/_pidfile.py�readsz
IPIDFile.readcCsdS)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$szIPIDFile.writeRunningPIDcCsdS)zm
        Remove this PID file.

        @raise EnvironmentError: If this PID file cannot be removed.
        Nr	r	r	r	r
�remove,szIPIDFile.removecCsdS)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.
        @rtype: L{bool}

        @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
�	isRunning4szIPIDFile.isRunningcCsdS)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__DszIPIDFile.__enter__cCsdS)zS
        Exit a context using this PIDFile.

        Removes the PID file.
        Nr	)�excType�excValue�	tracebackr	r	r
�__exit__OszIPIDFile.__exit__N)
�__name__�
__module__�__qualname__�__doc__rrr
rrrr	r	r	r
rs
rc@sneZdZdZe�Zedd��Zdd�Zdd�Z	dd	�Z
d
d�Zdd
�Zdd�Z
edd��Zdd�Zdd�ZdS)�PIDFilez�
    Concrete implementation of L{IPIDFile} based on C{IFilePath}.

    This implementation is presently not supported on non-POSIX platforms.
    Specifically, calling L{PIDFile.isRunning} will raise
    L{NotImplementedError}.
    cCsd�t|���d�S)z�
        Format a PID file's content.

        @param pid: A process ID.
        @type pid: int

        @return: Formatted PID file contents.
        @rtype: L{bytes}
        z{}
zutf-8)�format�int�encode��pidr	r	r
�_formateszPIDFile._formatcCs
||_dS)zi
        @param filePath: The path to the PID file on disk.
        @type filePath: L{IFilePath}
        N)�filePath)�selfrr	r	r
�__init__sszPIDFile.__init__c
Cs�d}z(|j���}|D]}q qW5QRXWn8tk
rd}z|jtjkrRtd���W5d}~XYnXz
t|�WStk
r�td�	|���YnXdS)N��PID file does not existz'non-integer PID value in PID file: {!r})
r�open�OSError�errno�ENOENT�
NoPIDFoundr�
ValueError�InvalidPIDFileErrorr)r Z	pidStringZfh�er	r	r
r{s
�zPIDFile.readcCs|j�|j|d��dS)z�
        Store a PID in this PID file.

        @param pid: A PID to store.
        @type pid: L{int}

        @raise EnvironmentError: If this PID file cannot be written.
        rN)rZ
setContentr�r rr	r	r
�_write�s	zPIDFile._writecCs|�t��dS�N)r-r�r r	r	r
r�szPIDFile.writeRunningPIDcCs|j��dSr.)rr
r/r	r	r
r
�szPIDFile.removecCsHz|��}Wntk
r"YdSXtdkr6|�|�Std�t���dS)NF�posixz"isRunning is not implemented on {})rr(�SYSTEM_NAME�_pidIsRunningPOSIX�NotImplementedErrorrr,r	r	r
r�s
�zPIDFile.isRunningc
Cshzt|d�WnPtk
r^}z2|jtjkr6td��n|jtjkrLWY�
dS�W5d}~XYnXdSdS)a"
        POSIX implementation for running process check.

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

        @return: True if the given PID is currently running; false otherwise.
        @rtype: L{bool}

        @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.
        rz'PID file refers to non-existing processTN)rr%r&ZESRCH�StalePIDFileError�EPERM)rr+r	r	r
r2�s�
zPIDFile._pidIsRunningPOSIXcCs@z|��rt��Wn tk
r2|j�d�YnX|��|S)Nz&Replacing stale PID file: {log_source})r�AlreadyRunningErrorr4�_log�inforr/r	r	r
r�s
zPIDFile.__enter__cCs|��dSr.)r
�r rrrr	r	r
r�szPIDFile.__exit__N)rrrrrr7�staticmethodrr!rr-rr
rr2rrr	r	r	r
rXs



rc@sPeZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�ZdS)�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.
    cCsdSr.r	r/r	r	r
r!�szNonePIDFile.__init__cCstd��dS)Nr#)r(r/r	r	r
r�szNonePIDFile.readcCsttjd��dS)z�
        Store a PID in this PID file.

        @param pid: A PID to store.
        @type pid: L{int}

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

        @note: This implementation always raises an L{EnvironmentError}.
        zOperation not permittedN)r%r&r5r,r	r	r
r-�szNonePIDFile._writecCs|�d�dS)Nr)r-r/r	r	r
r�szNonePIDFile.writeRunningPIDcCsttjd��dS)NzNo such file or directory)r%r&r'r/r	r	r
r
szNonePIDFile.removecCsdS)NFr	r/r	r	r
rszNonePIDFile.isRunningcCs|Sr.r	r/r	r	r
r	szNonePIDFile.__enter__cCsdSr.r	r9r	r	r
r
szNonePIDFile.__exit__N)rrrrr!rr-rr
rrrr	r	r	r
r;�sr;c@seZdZdZdS)r6z%
    Process is already running.
    N�rrrrr	r	r	r
r6sr6c@seZdZdZdS)r*z(
    PID file contents are invalid.
    Nr<r	r	r	r
r*sr*c@seZdZdZdS)r4z[
    PID file contents are valid, but there is no process with the referenced
    PID.
    Nr<r	r	r	r
r4$sr4c@seZdZdZdS)r(z#
    No PID found in PID file.
    Nr<r	r	r	r
r(,sr()rr&�osrrrr1Zzope.interfacerrZtwisted.loggerrr�objectrr;ZnonePIDFile�	Exceptionr6r*r4r(r	r	r	r
�<module>sF3