o
    ¯b«  ã                   @   s@   d Z dgZddlmZ ddlmZmZmZmZ G d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)ÚIterableÚListÚMappingÚOptionalc                   @   sl   e Zd ZdZdZdee ddf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S )r   aM  
    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.
    é   ÚdescriptorsÚreturnNc                 C   s
   || _ dS )z
        @param descriptors: The descriptors which will be returned from calls to
            C{inheritedDescriptors}.
        N)Ú_descriptors)Úselfr	   © r   ú8/usr/lib/python3/dist-packages/twisted/python/systemd.pyÚ__init__%   s   
zListenFDs.__init__ÚenvironÚstartc              	   C   s¶   |du rddl m} |}|du r| j}g }zt|d ƒ}W n ttfy+   Y | |ƒS w |tƒ krWzt|d ƒ}W n ttfyG   Y | |ƒS w tt||| ƒƒ}|d= |d= | |ƒ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Ú
LISTEN_FDS)	Úosr   Ú_STARTÚintÚKeyErrorÚ
ValueErrorr   ÚlistÚrange)Úclsr   r   Ú_environr	   ÚpidÚcountr   r   r   ÚfromEnvironment,   s,   ô
úzListenFDs.fromEnvironmentc                 C   s
   t | jƒS )z6
        @return: The configured descriptors.
        )r   r   )r   r   r   r   ÚinheritedDescriptorsY   s   
zListenFDs.inheritedDescriptors)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   Úclassmethodr   r   Ústrr   r   r    r   r   r   r   r      s    ýþýü,N)
r$   Ú__all__r   r   Útypingr   r   r   r   r   r   r   r   r   Ú<module>   s
   