U
    
W[  ã                   @   s:   d Z ddlmZmZ dgZddlmZ G dd„ deƒZdS )zƒ
Integration with systemd.

Currently only the minimum APIs necessary for using systemd's socket activation
feature are supported.
é    )ÚdivisionÚabsolute_importÚ	ListenFDs)Úgetpidc                   @   s2   e Zd ZdZdZdd„ Zed
dd„ƒZdd	„ ZdS )r   af  
    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.
    @type _START: C{int}

    @ivar _descriptors: A C{list} of C{int} giving the descriptors which were
        inherited.
    é   c                 C   s
   || _ dS )z
        @param descriptors: The descriptors which will be returned from calls to
            C{inheritedDescriptors}.
        N)Ú_descriptors)ÚselfÚdescriptors© r
   ú8/usr/lib/python3/dist-packages/twisted/python/systemd.pyÚ__init__%   s    zListenFDs.__init__Nc              	   C   s¦   |dkrddl m} |dkr"| j}g }zt|d ƒ}W n ttfk
rN   Y nPX |tƒ kržzt|d ƒ}W n ttfk
r‚   Y nX 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   )ÚenvironZ
LISTEN_PIDZ
LISTEN_FDS)Úosr   Ú_STARTÚintÚKeyErrorÚ
ValueErrorr   Úrange)Úclsr   Ústartr	   ÚpidÚcountr
   r
   r   ÚfromEnvironment-   s"    
zListenFDs.fromEnvironmentc                 C   s
   t | jƒS )z>
        @return: The configured list of descriptors.
        )Úlistr   )r   r
   r
   r   ÚinheritedDescriptorsU   s    zListenFDs.inheritedDescriptors)NN)	Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   Úclassmethodr   r   r
   r
   r
   r   r      s   'N)	r   Z
__future__r   r   Ú__all__r   r   Úobjectr   r
   r
   r
   r   Ú<module>   s   