§
    Ètºf±  ã                   ó¾   — 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dS )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                             ¦   «         }t          | ¦  «        |d<   d                     d„ t          | ¦  «        D ¦   «         ¦  «        |d<   t          |¦  «        |d<   |S )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ú:c                 ó   — g | ]}|› d �‘ŒS )z.socket© )Ú.0Úns     ú_/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/python/test/test_systemd.pyú
<listcomp>z$buildEnvironment.<locals>.<listcomp>    s   € Ð(MÐ(MÐ(M¸1¨A¨¨¨Ð(MÐ(MÐ(Mó    ÚLISTEN_FDNAMESÚ
LISTEN_PID)ÚosÚenvironÚcopyÚstrÚjoinÚrange)r   r   Úresults      r   ÚbuildEnvironmentr'      sf   € õ ŒZ�_Š_ÑÔ€FÝ˜u™:œ:€Fˆ<ÑØ"ŸxšxÐ(MÐ(MÅÀeÁÄÐ(MÑ(MÔ(MÑNÔN€FÐÑÝ˜s™8œ8€Fˆ<ÑØ€Mr   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dS )ÚListenFDsTestszV
    Apply tests to L{ListenFDs}, constructed based on an environment dictionary.
    r   é
   )Úmin_sizeÚmax_sizeÚnamesr   Nc                 ó¨  — t          |¦  «        }t          t          t          j        t          j        |z   ¦  «        ¦  «        }t          j        t          t          j        ¦   «         ¦  «        t          |¦  «        d 	                    |¦  «        dœ¦  «        }t          |t          t          |t          |¦  «        ¦  «        ¦  «        ¦  «         dS )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µ9Ô3CÀfÑ3LÑMÔMÑNÔNˆÝÔ'å!¥"¤)¡+¤+Ñ.Ô.Ý! &™kœkØ"%§(¢(¨5¡/¤/ðð ñ
ô 
ˆõ 	�C�¥)¨K½¸u¹¼Ñ"FÔ"FÑGÔGÑHÔHÐHÐHÐHr   c           	      ó(  — |                       t          dt          dt          j        ¦   «         ¦  «        ¦  «         t	          j        ¦   «         }|                      t          t          dd¦  «        ¦  «        | 	                    ¦   «         ¦  «         dS )z§
        If the process environment is not explicitly passed to
        L{ListenFDs.fromEnvironment}, the real process environment dictionary
        is used.
        r!   é   é   é   N)
Úpatchr    r'   r3   r   r2   ÚassertEqualr0   r%   ÚinheritedDescriptors)r5   Úsddaemons     r   Útest_defaultEnvironz"ListenFDsTests.test_defaultEnviron@   sq   € ð 	�
Š
•2�yÕ"2°1µb´i±k´kÑ"BÔ"BÑCÔCÐCÝÔ,Ñ.Ô.ˆØ×Ò��e A u™oœoÑ.Ô.°×0MÒ0MÑ0OÔ0OÑPÔPÐPÐPÐPr   c                 ór  — t          dt          j        ¦   «         ¦  «        }t          j        |¬¦  «        }t          j        |¬¦  «        }|                      t          t          dd¦  «        ¦  «        |                     ¦   «         ¦  «         |                      g |                     ¦   «         ¦  «         dS )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.
        r<   ©r!   é   N)	r'   r    r3   r   r2   r?   r0   r%   r@   )r5   ÚenvÚfirstÚseconds       r   Útest_secondEnvironmentz%ListenFDsTests.test_secondEnvironmentJ   s™   € õ ˜q¥"¤)¡+¤+Ñ.Ô.ˆÝÔ)°#Ð6Ñ6Ô6ˆÝÔ*°3Ð7Ñ7Ô7ˆØ×Ò��e A q™kœkÑ*Ô*¨E×,FÒ,FÑ,HÔ,HÑIÔIÐIØ×Ò˜˜V×8Ò8Ñ:Ô:Ñ;Ô;Ð;Ð;Ð;r   c                 óÈ   — t          dt          j        ¦   «         dz   ¦  «        }t          j        |¬¦  «        }|                      g |                     ¦   «         ¦  «         dS )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.
        r<   r   rD   N©r'   r    r3   r   r2   r?   r@   ©r5   rF   rA   s      r   Útest_mismatchedPIDz!ListenFDsTests.test_mismatchedPIDW   sX   € õ ˜q¥"¤)¡+¤+°¡/Ñ2Ô2ˆÝÔ,°SÐ9Ñ9Ô9ˆØ×Ò˜˜X×:Ò:Ñ<Ô<Ñ=Ô=Ð=Ð=Ð=r   c                 óÈ   — t          dt          j        ¦   «         ¦  «        }|d= t          j        |¬¦  «        }|                      g |                     ¦   «         ¦  «         dS )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.
        r<   r   rD   NrK   rL   s      r   Útest_missingPIDVariablez&ListenFDsTests.test_missingPIDVariablec   s\   € õ ˜q¥"¤)¡+¤+Ñ.Ô.ˆØ�ÐÝÔ,°SÐ9Ñ9Ô9ˆØ×Ò˜˜X×:Ò:Ñ<Ô<Ñ=Ô=Ð=Ð=Ð=r   c                 ó    — t          dd¦  «        }t          j        |¬¦  «        }|                      g |                     ¦   «         ¦  «         dS )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.
        r<   úhello, worldrD   N)r'   r   r2   r?   r@   rL   s      r   Útest_nonIntegerPIDVariablez)ListenFDsTests.test_nonIntegerPIDVariableo   sN   € õ
 ˜q .Ñ1Ô1ˆÝÔ,°SÐ9Ñ9Ô9ˆØ×Ò˜˜X×:Ò:Ñ<Ô<Ñ=Ô=Ð=Ð=Ð=r   c                 óÎ   — t          dt          j        ¦   «         ¦  «        }|d= |d= t          j        |¬¦  «        }|                      g |                     ¦   «         ¦  «         dS )z’
        If the I{LISTEN_FDS} and I{LISTEN_FDNAMES} environment variables
        are not present, no inherited descriptors are reported.
        r<   r   r   rD   NrK   rL   s      r   Útest_missingFDSVariablez&ListenFDsTests.test_missingFDSVariablex   se   € õ
 ˜q¥"¤)¡+¤+Ñ.Ô.ˆØ�ÐØÐ Ð!ÝÔ,°SÐ9Ñ9Ô9ˆØ×Ò˜˜X×:Ò:Ñ<Ô<Ñ=Ô=Ð=Ð=Ð=r   c                 óÌ   — t          dt          j        ¦   «         ¦  «        }d|d<   t          j        |¬¦  «        }|                      g |                     ¦   «         ¦  «         dS )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.
        r<   rQ   r   rD   NrK   rL   s      r   Útest_nonIntegerFDSVariablez)ListenFDsTests.test_nonIntegerFDSVariableƒ   s^   € õ
 ˜q¥"¤)¡+¤+Ñ.Ô.ˆØ*ˆˆLÑÝÔ,°SÐ9Ñ9Ô9ˆØ×Ò˜˜X×:Ò:Ñ<Ô<Ñ=Ô=Ð=Ð=Ð=r   )Ú	min_valueÚ	max_valueT)Úuniquer7   c                 óJ  — t          t          t          |¦  «        ¦  «        }t          ||¦  «        }|                     ¦   «         }t          |t          |¦  «        ¦  «         |                     d¦  «         t          |t          t          |¦  «        ¦  «        ¦  «         dS )zm
        L{ListenFDs.inheritedDescriptors} returns a copy of the inherited
        descriptors list.
        r   N)	r4   Úmapr#   r   r@   r   r   Úappendr   )r5   r7   r-   r8   ÚfdsCopys        r   Útest_inheritedDescriptorsz(ListenFDsTests.test_inheritedDescriptors�   s‹   € õ •c�#˜{Ñ+Ô+Ñ,Ô,ˆÝ˜ UÑ+Ô+ˆØ×*Ò*Ñ,Ô,ˆÝ�K¥¨'Ñ!2Ô!2Ñ3Ô3Ð3Ø�Š�qÑÔÐÝ�K¥¥h¨wÑ&7Ô&7Ñ!8Ô!8Ñ9Ô9Ð9Ð9Ð9r   )rW   )r,   Úexpectedc                 óö   — t          |                     ¦   «         ¦  «        }d„ |D ¦   «         }d„ |D ¦   «         }t          ||¦  «        }t          |                     ¦   «         t          |¦  «        ¦  «         dS )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.
        c                 ó   — g | ]\  }}|‘ŒS r   r   )r   ÚnameÚ_s      r   r   zAListenFDsTests.test_inheritedNamedDescriptors.<locals>.<listcomp>¢   s   € Ð+Ð+Ð+™'˜$ �Ð+Ð+Ð+r   c                 ó   — g | ]\  }}|‘ŒS r   r   )r   rc   Úfds      r   r   zAListenFDsTests.test_inheritedNamedDescriptors.<locals>.<listcomp>£   s   € Ð-Ð-Ð-™e˜a �rÐ-Ð-Ð-r   N)r0   Úitemsr   r   ÚinheritedNamedDescriptorsr   )r5   r_   rf   r-   r7   r8   s         r   Útest_inheritedNamedDescriptorsz-ListenFDsTests.test_inheritedNamedDescriptorsš   sz   € õ �X—^’^Ñ%Ô%Ñ&Ô&ˆØ+Ð+ UÐ+Ñ+Ô+ˆØ-Ð- uÐ-Ñ-Ô-ˆÝ˜ UÑ+Ô+ˆÝ�C×1Ò1Ñ3Ô3µX¸hÑ5GÔ5GÑHÔHÐHÐHÐHr   c                 óR  — t          t          t          |¦  «        ¦  «        }t          ||¦  «        }|                      |                     ¦   «         |                     ¦   «         ¦  «         |                      |                     ¦   «         |                     ¦   «         ¦  «         dS )z€
        Any subsequent calls to C{inheritedDescriptors} and
        C{inheritedNamedDescriptors} return the same list.
        N)r4   r[   r#   r   r?   r@   rg   )r5   r7   r-   rA   s       r   Útest_repeatedzListenFDsTests.test_repeated§   s    € õ •c�#˜{Ñ+Ô+Ñ,Ô,ˆÝ˜[¨%Ñ0Ô0ˆØ×ÒØ×)Ò)Ñ+Ô+¨X×-JÒ-JÑ-LÔ-Lñ	
ô 	
ð 	
ð 	×ÒØ×.Ò.Ñ0Ô0°(×2TÒ2TÑ2VÔ2Vñ	
ô 	
ð 	
ð 	
ð 	
r   )r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   r   r   r#   r9   rB   rI   rM   rO   rR   rT   rV   r   Úintr^   r
   r   rh   rj   r   r   r   r)   r)   %   s7  € € € € € ðð ð €Uˆ5ˆ5Ð'Ð'Ñ)Ô)°AÀÐCÑCÔCÑDÔDðI°X¸c´]ð IÀtð Ið Ið Iñ EÔDðIð*Qð Qð Qð Qð<ð <ð <ð <ð
>ð 
>ð 
>ð 
>ð
>ð 
>ð 
>ð 
>ð>ð >ð >ð >ð	>ð 	>ð 	>ð 	>ð>ð >ð >ð >ð €Uˆ5ˆ5�� A°Ð4Ñ4Ô4¸TÐBÑBÔBÑCÔCð
:°X¸c´]ð 
:Àtð 
:ð 
:ð 
:ñ DÔCð
:ð €Uˆ<ˆ<Ð.Ð.Ñ0Ô0°(°(ÀQÐ2GÑ2GÔ2GÐRTÐUÑUÔUÑVÔVð
I°w¸sÀC¸xÔ7Hð 
IÈTð 
Ið 
Ið 
Iñ WÔVð
Ið €Uˆ5ˆ5�� A°Ð4Ñ4Ô4¸TÐBÑBÔBÑCÔCð
¨°#¬ð 
¸4ð 
ð 
ð 
ñ DÔCð
ð 
ð 
r   r)   )rn   r    Útypingr   r   r   Úhamcrestr   r   r   Ú
hypothesisr	   Úhypothesis.strategiesr
   r   r   Útwisted.python.systemdr   Útwisted.trial.unittestr   Ú
strategiesr   ro   Úobjectr#   r'   r)   r   r   r   ú<module>rx      s,  ððð ð
 
€	€	€	Ø *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *Ð *à 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø Ð Ð Ð Ð Ð Ø ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?Ð ?à ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø 6Ð 6Ð 6Ð 6Ð 6Ð 6Ø .Ð .Ð .Ð .Ð .Ð .ð˜Cð  fð °°c¸3°h´ð ð ð ð ð O
ð O
ð O
ð O
ð O
Ð(ñ O
ô O
ð O
ð O
ð O
r   