Ë
    ojÏ  ã                   ó¨   — 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«      «       Zdedeeef   d	ee   fd
„Zdeeef   d	e	e   fd„Zy)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                   ó¨   — 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	„«       Zdee   fd
„Zdee
ef   fd„Zy)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                 ó  — |€ddl m} |}|€| j                  }t        t	        «       «      |j                  d«      k(  rt        ||«      }t        |«      }ng }d}t        |«      t        |«      k7  r	 | 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.
        r   )r   Ú
LISTEN_PID© )	Úosr   Ú_STARTÚstrr   ÚgetÚ_parseDescriptorsÚ_parseNamesÚlen)Úclsr   r   Ú_environÚdescriptorsÚnamess         ú8/usr/lib/python3/dist-packages/twisted/python/systemd.pyÚfromEnvironmentzListenFDs.fromEnvironment.   s‚   € ð( ˆ?Ý.àˆGØˆ=Ø—J‘JˆEäŒv‹x‹=˜GŸK™K¨Ó5Ò5Ü%6°u¸gÓ%FˆKÜ#.¨wÓ#7‰EàˆKØˆEô ˆu‹:œ˜[Ó)Ò)Ù�r˜2“;Ðá�; Ó&Ð&ó    c                 ó,   — t        | j                  «      S )z6
        @return: The configured descriptors.
        )Úlistr   ©Úselfs    r!   ÚinheritedDescriptorszListenFDs.inheritedDescriptors\   s   € ô �D×%Ñ%Ó&Ð&r#   c                 óT   — t        t        | j                  | j                  «      «      S )zr
        @return: A mapping from the names of configured descriptors to
            their integer values.
        )ÚdictÚzipr   r   r&   s    r!   ÚinheritedNamedDescriptorsz#ListenFDs.inheritedNamedDescriptorsb   s    € ô
 ”C˜Ÿ™ T×%6Ñ%6Ó7Ó8Ð8r#   )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—   … ñð$ ˜3‘-ÓÙ# E›N€FˆH�S‰MÓ*à€Fàð 04Ø#ñ+'à˜' # s (Ñ+Ñ,ð+'ð ˜‰}ð+'ð 
ò	+'ó ð+'ðZ' d¨3¡ió 'ð9¨4°°S°©>ô 9r#   r   r   r   c                 óŽ   — 	 t        |d   «      }t        t        | | |z   «      «      }|d= |d= |S # t        t        f$ r g cY S w xY w)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   )r1   r%   ÚrangeÚKeyErrorÚ
ValueError)r   r   Úcountr   s       r!   r   r   j   s_   € ðÜ�G˜LÑ)Ó*ˆô œ5 ¨°©Ó6Ó7ˆð �LÐ! 7¨<Ð#8ØÐøô# ”jÐ!ò ØŠ	ðús   ‚0 °AÁAc                 óx   — | j                  dd«      }t        |«      dkD  rt        |j                  d«      «      S y)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   r3   Úsplit)r   r    s     r!   r   r   Ž   s7   € ð �K‰KÐ(¨"Ó-€EÜ
ˆ5ƒz�A‚~Ü�U—[‘[ Ó%Ó&Ð&Ør#   N)r0   Ú__all__r   r   Útypingr   r   r   r   r	   Úattrsr
   r   r   r1   r   r   r   r   r#   r!   ú<module>rC      s„   ðñ
ð ˆ-€å ß :Õ :ç !ð ÷Q9ð Q9ó ðQ9ðh!˜Sð !¨7°3¸°8Ñ+<ð !ÀÀcÁó !ðH˜  c Ñ*ð ¨x¸©}ô r#   