o
    ¼>hÏ  ã                   @   s˜   d Z dgZddlmZ ddlmZmZmZmZm	Z	 ddl
mZmZ eG dd„ dƒƒZdedeeef d	ee fd
d„Zdeeef d	e	e fdd„ZdS )zƒ
Integration with systemd.

Currently only the minimum APIs necessary for using systemd's socket activation
feature are supported.
Ú	ListenFDsé    )Úgetpid)ÚDictÚListÚMappingÚOptionalÚSequence)ÚFactoryÚdefinec                   @   sŽ   e Zd ZU dZee ed< eeƒZ	ee
 ed< dZe		ddeee
e
f  dee dd fd	d
„ƒZdee fdd„Zdee
ef fdd„ZdS )r   aº  
    L{ListenFDs} provides access to file descriptors inherited from systemd.

    Typically L{ListenFDs.fromEnvironment} should be used to construct a new
    instance of L{ListenFDs}.

    @cvar _START: File descriptors inherited from systemd are always
        consecutively numbered, with a fixed lowest "starting" descriptor.  This
        gives the default starting descriptor.  Since this must agree with the
        value systemd is using, it typically should not be overridden.

    @ivar _descriptors: A C{list} of C{int} giving the descriptors which were
        inherited.

    @ivar _names: A L{Sequence} of C{str} giving the names of the descriptors
        which were inherited.
    Ú_descriptorsÚ_namesé   NÚenvironÚstartÚreturnc                 C   sz   |du rddl m} |}|du r| j}ttƒ ƒ| d¡kr't||ƒ}t|ƒ}ng }d}t|ƒt|ƒkr8| g dƒS | ||ƒS )a¶  
        @param environ: A dictionary-like object to inspect to discover
            inherited descriptors.  By default, L{None}, indicating that the
            real process environment should be inspected.  The default is
            suitable for typical usage.

        @param start: An integer giving the lowest value of an inherited
            descriptor systemd will give us.  By default, L{None}, indicating
            the known correct (that is, in agreement with systemd) value will be
            used.  The default is suitable for typical usage.

        @return: A new instance of C{cls} which can be used to look up the
            descriptors which have been inherited.
        Nr   )r   Ú
LISTEN_PID© )	Úosr   Ú_STARTÚstrr   ÚgetÚ_parseDescriptorsÚ_parseNamesÚlen)Úclsr   r   Ú_environÚdescriptorsÚnamesr   r   úv/var/www/vedio/testing/chatpythonscript.ninositsolution.com/env/lib/python3.10/site-packages/twisted/python/systemd.pyÚfromEnvironment.   s   

	

zListenFDs.fromEnvironmentc                 C   s
   t | jƒS )z6
        @return: The configured descriptors.
        )Úlistr   ©Úselfr   r   r   ÚinheritedDescriptors\   s   
zListenFDs.inheritedDescriptorsc                 C   s   t t| j| jƒƒS )zr
        @return: A mapping from the names of configured descriptors to
            their integer values.
        )ÚdictÚzipr   r   r!   r   r   r   ÚinheritedNamedDescriptorsb   s   z#ListenFDs.inheritedNamedDescriptors)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   ÚintÚ__annotations__r	   Útupler   r   r   Úclassmethodr   r   r   r   r#   r   r&   r   r   r   r   r      s"   
 ýþýü-r   r   r   c              	   C   sN   zt |d ƒ}W n ttfy   g  Y S w tt| | | ƒƒ}|d= |d= |S )a  
    Parse the I{LISTEN_FDS} environment variable supplied by systemd.

    @param start: systemd provides only a count of the number of descriptors
        that have been inherited.  This is the integer value of the first
        inherited descriptor.  Subsequent inherited descriptors are numbered
        counting up from here.  See L{ListenFDs._START}.

    @param environ: The environment variable mapping in which to look for the
        value to parse.

    @return: The integer values of the inherited file descriptors, in order.
    Ú
LISTEN_FDSr   )r+   ÚKeyErrorÚ
ValueErrorr    Úrange)r   r   Úcountr   r   r   r   r   j   s   ÿr   c                 C   s*   |   dd¡}t|ƒdkrt| d¡ƒS dS )zö
    Parse the I{LISTEN_FDNAMES} environment variable supplied by systemd.

    @param environ: The environment variable mapping in which to look for the
        value to parse.

    @return: The names of the inherited descriptors, in order.
    ÚLISTEN_FDNAMESÚ r   ú:r   )r   r   r-   Úsplit)r   r   r   r   r   r   Ž   s   	r   N)r*   Ú__all__r   r   Útypingr   r   r   r   r   Úattrsr	   r
   r   r+   r   r   r   r   r   r   r   Ú<module>   s   "T"$