Ë
    „ÇVh±  ã                   ó°   — d Z ddlZddlmZmZmZ ddlmZmZm	Z	 ddl
mZ ddlmZmZmZ ddlmZ ddlmZ d	d
lmZ dededeeef   fd„Z G d„ de«      Zy)z&
Tests for L{twisted.python.systemd}.
é    N)ÚDictÚMappingÚSequence)Úassert_thatÚequal_toÚnot_)Úgiven)ÚdictionariesÚintegersÚlists)Ú	ListenFDs)ÚSynchronousTestCaseé   )ÚsystemdDescriptorNamesÚcountÚpidÚreturnc                 óà   — t         j                  j                  «       }t        | «      |d<   dj	                  t        | «      D cg c]  }|› d‘Œ	 c}«      |d<   t        |«      |d<   |S c c}w )a+  
    @param count: The number of file descriptors to indicate as inherited.

    @param pid: The pid of the inheriting process to indicate.

    @return: A copy of the current process environment with the I{systemd}
        file descriptor inheritance-related environment variables added to it.
    Ú
LISTEN_FDSú:z.socketÚLISTEN_FDNAMESÚ
LISTEN_PID)ÚosÚenvironÚcopyÚstrÚjoinÚrange)r   r   ÚresultÚns       úP/home/dcms/DCMS/lib/python3.12/site-packages/twisted/python/test/test_systemd.pyÚbuildEnvironmentr"      sd   € ô Z‰Z_‰_Ó€FÜ˜u›:€Fˆ<ÑØ"Ÿx™xÄÀeÃÖ(M¸1¨A¨3¨gªÒ(MÓN€FÐÑÜ˜s›8€Fˆ<ÑØ€Mùò )Ns   ÁA+c                   ó‚  — e Zd ZdZ e e e«       dd¬«      «      dee   ddfd„«       Z	dd	„Z
dd
„Zdd„Zdd„Zdd„Zdd„Zdd„Z e e edd¬«      d¬«      «      dee   ddfd„«       Z e e e«        ed¬«      d¬«      «      deeef   ddfd„«       Z e e edd¬«      d¬«      «      dee   ddfd„«       Zy)ÚListenFDsTestszV
    Apply tests to L{ListenFDs}, constructed based on an environment dictionary.
    r   é
   )Úmin_sizeÚmax_sizeÚnamesr   Nc                 ój  — t        |«      }t        t        t        j                  t        j                  |z   «      «      }t        j
                  t        t        j                  «       «      t        |«      dj                  |«      dœ«      }t        |t        t        |t        |«      «      «      «       y)a  
        The L{ListenFDs} and L{ListenFDs.fromEnvironment} constructors are
        equivalent for their respective representations of the same
        information.

        @param names: The names of the file descriptors to represent as
            inherited in the test environment given to the parser.  The number
            of descriptors represented will equal the length of this list.
        r   )r   r   r   N)ÚlenÚlistr   r   Ú_STARTÚfromEnvironmentr   r   Úgetpidr   r   r   Útuple)Úselfr(   ÚnumFDsÚdescriptorsÚfdss        r!   Útest_fromEnvironmentEquivalencez.ListenFDsTests.test_fromEnvironmentEquivalence*   s€   € ô U“ˆÜœ5¤×!1Ñ!1´9×3CÑ3CÀfÑ3LÓMÓNˆÜ×'Ñ'ä!¤"§)¡)£+Ó.Ü! &›kØ"%§(¡(¨5£/ñó
ˆô 	Cœ¤)¨K¼¸u»Ó"FÓGÕHó    c           	      óø   — | j                  t        dt        dt        j                  «       «      «       t	        j
                  «       }| j                  t        t        dd«      «      |j                  «       «       y)z§
        If the process environment is not explicitly passed to
        L{ListenFDs.fromEnvironment}, the real process environment dictionary
        is used.
        r   é   é   é   N)
Úpatchr   r"   r.   r   r-   ÚassertEqualr+   r   ÚinheritedDescriptors)r0   Úsddaemons     r!   Útest_defaultEnvironz"ListenFDsTests.test_defaultEnviron@   sT   € ð 	
‰
”2yÔ"2°1´b·i±i³kÓ"BÔCÜ×,Ñ,Ó.ˆØ×Ñœœe A u›oÓ.°×0MÑ0MÓ0OÕPr5   c                 ó>  — t        dt        j                  «       «      }t        j                  |¬«      }t        j                  |¬«      }| j                  t        t        dd«      «      |j                  «       «       | j                  g |j                  «       «       y)a  
        L{ListenFDs.fromEnvironment} removes information about the
        inherited file descriptors from the environment mapping so that the
        same inherited file descriptors cannot be handled repeatedly from
        multiple L{ListenFDs} instances.
        r8   ©r   é   N)	r"   r   r.   r   r-   r;   r+   r   r<   )r0   ÚenvÚfirstÚseconds       r!   Útest_secondEnvironmentz%ListenFDsTests.test_secondEnvironmentJ   ss   € ô ˜q¤"§)¡)£+Ó.ˆÜ×)Ñ)°#Ô6ˆÜ×*Ñ*°3Ô7ˆØ×Ñœœe A q›kÓ*¨E×,FÑ,FÓ,HÔIØ×Ñ˜˜V×8Ñ8Ó:Õ;r5   c                 ó²   — t        dt        j                  «       dz   «      }t        j                  |¬«      }| j                  g |j                  «       «       y)aV  
        If the current process PID does not match the PID in the
        environment then the systemd variables in the environment were set for
        a different process (perhaps our parent) and the inherited descriptors
        are not intended for this process so L{ListenFDs.inheritedDescriptors}
        returns an empty list.
        r8   r   r@   N©r"   r   r.   r   r-   r;   r<   ©r0   rB   r=   s      r!   Útest_mismatchedPIDz!ListenFDsTests.test_mismatchedPIDW   sC   € ô ˜q¤"§)¡)£+°¡/Ó2ˆÜ×,Ñ,°SÔ9ˆØ×Ñ˜˜X×:Ñ:Ó<Õ=r5   c                 ó²   — t        dt        j                  «       «      }|d= t        j                  |¬«      }| j                  g |j                  «       «       y)zù
        If the I{LISTEN_PID} environment variable is not present then
        there is no clear indication that any file descriptors were inherited
        by this process so L{ListenFDs.inheritedDescriptors} returns an empty
        list.
        r8   r   r@   NrG   rH   s      r!   Útest_missingPIDVariablez&ListenFDsTests.test_missingPIDVariablec   sG   € ô ˜q¤"§)¡)£+Ó.ˆØÐÜ×,Ñ,°SÔ9ˆØ×Ñ˜˜X×:Ñ:Ó<Õ=r5   c                 óˆ   — t        dd«      }t        j                  |¬«      }| j                  g |j	                  «       «       y)z¢
        If the I{LISTEN_PID} environment variable is set to a string that cannot
        be parsed as an integer, no inherited descriptors are reported.
        r8   úhello, worldr@   N)r"   r   r-   r;   r<   rH   s      r!   Útest_nonIntegerPIDVariablez)ListenFDsTests.test_nonIntegerPIDVariableo   s9   € ô
 ˜q .Ó1ˆÜ×,Ñ,°SÔ9ˆØ×Ñ˜˜X×:Ñ:Ó<Õ=r5   c                 ó¸   — t        dt        j                  «       «      }|d= |d= t        j                  |¬«      }| j                  g |j                  «       «       y)z’
        If the I{LISTEN_FDS} and I{LISTEN_FDNAMES} environment variables
        are not present, no inherited descriptors are reported.
        r8   r   r   r@   NrG   rH   s      r!   Útest_missingFDSVariablez&ListenFDsTests.test_missingFDSVariablex   sP   € ô
 ˜q¤"§)¡)£+Ó.ˆØÐØÐ Ð!Ü×,Ñ,°SÔ9ˆØ×Ñ˜˜X×:Ñ:Ó<Õ=r5   c                 ó¶   — t        dt        j                  «       «      }d|d<   t        j                  |¬«      }| j                  g |j                  «       «       y)z¢
        If the I{LISTEN_FDS} environment variable is set to a string that cannot
        be parsed as an integer, no inherited descriptors are reported.
        r8   rM   r   r@   NrG   rH   s      r!   Útest_nonIntegerFDSVariablez)ListenFDsTests.test_nonIntegerFDSVariableƒ   sI   € ô
 ˜q¤"§)¡)£+Ó.ˆØ*ˆˆLÑÜ×,Ñ,°SÔ9ˆØ×Ñ˜˜X×:Ñ:Ó<Õ=r5   )Ú	min_valueÚ	max_valueT)Úuniquer2   c                 óö   — t        t        t        |«      «      }t        ||«      }|j	                  «       }t        |t        |«      «       |j                  d«       t        |t        t        |«      «      «       y)zm
        L{ListenFDs.inheritedDescriptors} returns a copy of the inherited
        descriptors list.
        r   N)	r/   Úmapr   r   r<   r   r   Úappendr   )r0   r2   r(   r3   ÚfdsCopys        r!   Útest_inheritedDescriptorsz(ListenFDsTests.test_inheritedDescriptors   s^   € ô ”cœ#˜{Ó+Ó,ˆÜ˜ UÓ+ˆØ×*Ñ*Ó,ˆÜK¤¨'Ó!2Ô3Ø‰qÔÜK¤¤h¨wÓ&7Ó!8Õ9r5   )rS   )r'   Úexpectedc                 óü   — t        |j                  «       «      }|D cg c]  \  }}|‘Œ	 }}}|D cg c]  \  }}|‘Œ	 }}}t        ||«      }t        |j	                  «       t        |«      «       yc c}}w c c}}w )zÛ
        L{ListenFDs.inheritedNamedDescriptors} returns a mapping from the
        descriptor names to their integer values, with items formed by
        pairwise combination of the input descriptors and names.
        N)r+   Úitemsr   r   ÚinheritedNamedDescriptorsr   )	r0   r[   r]   ÚnameÚ_r(   Úfdr2   r3   s	            r!   Útest_inheritedNamedDescriptorsz-ListenFDsTests.test_inheritedNamedDescriptorsš   so   € ô X—^‘^Ó%Ó&ˆØ%*×+™'˜$ ’Ð+ˆÑ+Ø',×-™e˜a ’rÐ-ˆÑ-Ü˜ UÓ+ˆÜC×1Ñ1Ó3´X¸hÓ5GÕHùó ,ùÛ-s
   ŸA2³A8c                 ó  — t        t        t        |«      «      }t        ||«      }| j	                  |j                  «       |j                  «       «       | j	                  |j                  «       |j                  «       «       y)z€
        Any subsequent calls to C{inheritedDescriptors} and
        C{inheritedNamedDescriptors} return the same list.
        N)r/   rW   r   r   r;   r<   r^   )r0   r2   r(   r=   s       r!   Útest_repeatedzListenFDsTests.test_repeated§   sm   € ô ”cœ#˜{Ó+Ó,ˆÜ˜[¨%Ó0ˆØ×ÑØ×)Ñ)Ó+¨X×-JÑ-JÓ-Lô	
ð 	×ÑØ×.Ñ.Ó0°(×2TÑ2TÓ2Võ	
r5   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r   r4   r>   rE   rI   rK   rN   rP   rR   r   ÚintrZ   r
   r   rb   rd   © r5   r!   r$   r$   %   s$  „ ññ ‰5Ñ'Ó)°AÀÔCÓDðI°X¸c±]ð IÀtò Ió EðIó*Qó<ó
>ó
>ó>ó	>ó>ñ ‰5‘ A°Ô4¸TÔBÓCð
:°X¸c±]ð 
:Àtò 
:ó Dð
:ñ ‰<Ñ.Ó0±(ÀQÔ2GÐRTÔUÓVð
I°w¸sÀC¸xÑ7Hð 
IÈTò 
Ió Wð
Iñ ‰5‘ A°Ô4¸TÔBÓCð
¨°#©ð 
¸4ò 
ó Dñ
r5   r$   )rh   r   Útypingr   r   r   Úhamcrestr   r   r   Ú
hypothesisr	   Úhypothesis.strategiesr
   r   r   Útwisted.python.systemdr   Útwisted.trial.unittestr   Ú
strategiesr   ri   Úobjectr   r"   r$   rj   r5   r!   ú<module>rs      s^   ðñó
 
ß *Ñ *ç 0Ñ 0Ý ß ?Ñ ?å ,Ý 6Ý .ð˜Cð  fð °°c¸3°h±ó ô O
Ð(õ O
r5   