
    \d                         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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                       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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                 D   |ddl m} |}|| j        }t          t	                                |                    d          k    r t          ||          }t          |          }ng }d}t          |          t          |          k    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.
        Nr   )r   
LISTEN_PID )	osr   _STARTstrr   get_parseDescriptors_parseNameslen)clsr   r   _environdescriptorsnamess         6lib/python3.11/site-packages/twisted/python/systemd.pyfromEnvironmentzListenFDs.fromEnvironment.   s    ( ?......G=JEvxx==GKK5555%6ug%F%FK#.w#7#7EEKE u::[))))3r2;;s;&&&    c                 *    t          | j                  S )z6
        @return: The configured descriptors.
        )listr   selfs    r!   inheritedDescriptorszListenFDs.inheritedDescriptors\   s     D%&&&r#   c                 P    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778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-#GENNFHSM***F 04#+' +''#s(+,+' }+' 
	+' +' +' [+'Z'd3i ' ' ' '94S> 9 9 9 9 9 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   sx    GL)** 56677 L!7<#8# j!   			s   ? AAc                     |                      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   r3   split)r   r    s     r!   r   r      sF     KK("--E
5zzA~~U[[%%&&&2r#   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 Q9 Q9 Q9 Q9 Q9h!S !738+< !c ! ! ! !Hc* x}      r#   