§
    ÈtºfÃ+  ã                   óô   — U d Z ddlZddlZddlZddlmZ ee         ed<   	 ddlZddl	m
Z
 dZn# e$ r dZY nw xY wddlmZ  G d„ d	¦  «        Z G d
„ d¦  «        Z G d„ de¦  «        Z G d„ de¦  «        ZdS )z;
Tests for POSIX-based L{IReactorProcess} implementations.
é    N)ÚOptionalÚplatformSkip)Úprocessznon-POSIX platform)ÚTestCasec                   ó*   — e Zd ZdZd„ Zd„ Zd„ Zd„ ZdS )ÚFakeFilez>
    A dummy file object which records when it is closed.
    c                 ó"   — || _         || _        d S ©N)ÚtestcaseÚfd)Úselfr   r   s      úf/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/internet/test/test_posixprocess.pyÚ__init__zFakeFile.__init__    s   € Ø ˆŒØˆŒˆˆó    c                 óN   — | j         j                             | j        ¦  «         d S r
   )r   Ú_filesÚremover   ©r   s    r   ÚclosezFakeFile.close$   s#   € ØŒÔ×#Ò# D¤GÑ,Ô,Ð,Ð,Ð,r   c                 ó   — | S r
   © r   s    r   Ú	__enter__zFakeFile.__enter__'   s   € Øˆr   c                 ó.   — |                       ¦   «          d S r
   )r   )r   Úexc_typeÚ	exc_valueÚ	tracebacks       r   Ú__exit__zFakeFile.__exit__*   s   € Ø�
Š
‰Œˆˆˆr   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r   r   r      sZ   € € € € € ðð ðð ð ð-ð -ð -ðð ð ðð ð ð ð r   r   c                   ó"   — e Zd ZdZdZd„ Zd„ ZdS )ÚFakeResourceModulez¹
    Fake version of L{resource} which hard-codes a particular rlimit for maximum
    open files.

    @ivar _limit: The value to return for the hard limit of number of open files.
    é   c                 ó   — || _         d S r
   )Ú_limit©r   Úlimits     r   r   zFakeResourceModule.__init__8   s   € ØˆŒˆˆr   c                 ó2   — || j         k    r	d| j        gS ddgS )zX
        A fake of L{resource.getrlimit} which returns a pre-determined result.
        r   é{   iÈ  )ÚRLIMIT_NOFILEr&   )r   Únos     r   Ú	getrlimitzFakeResourceModule.getrlimit;   s)   € ð �Ô#Ò#Ð#Ø�t”{Ð#Ð#Ø�SˆzÐr   N)r   r   r    r!   r+   r   r-   r   r   r   r#   r#   .   sC   € € € € € ðð ð €Mðð ð ðð ð ð ð r   r#   c                   óv   — e Zd ZdZeZdZdZdZd„ Z	d„ Z
d„ Zd„ Zd„ Zd„ Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ ZdS )ÚFDDetectorTestsaë  
    Tests for _FDDetector class in twisted.internet.process, which detects
    which function to drop in place for the _listOpenFDs method.

    @ivar devfs: A flag indicating whether the filesystem fake will indicate
        that /dev/fd exists.

    @ivar accurateDevFDResults: A flag indicating whether the /dev/fd fake
        returns accurate open file information.

    @ivar procfs: A flag indicating whether the filesystem fake will indicate
        that /proc/<pid>/fd exists.
    Fc                 ó   — dS )z>
        Fake os.getpid, always return the same thing
        r*   r   r   s    r   ÚgetpidzFDDetectorTests.getpidZ   s	   € ð ˆsr   c                 óÐ   — t          t          | j        ¦  «        }| j        r|d|                      ¦   «         fz  k    r|S | j        r|dk    r| j        r|S g d¢S t          ¦   «         ‚)z„
        Fake os.listdir, depending on what mode we're in to simulate behaviour.

        @param arg: the directory to list
        z/proc/%d/fdz/dev/fd)Ú0Ú1Ú2)ÚmapÚstrr   Úprocfsr1   ÚdevfsÚaccurateDevFDResultsÚOSError)r   ÚargÚaccurates      r   ÚlistdirzFDDetectorTests.listdir`   su   € õ •s˜DœKÑ(Ô(ˆØŒ;ð 	˜3 =°D·K²K±M´MÐ3CÑ#CÒDÐDØˆOØŒ:ð 	#˜# Ò*Ð*ØÔ(ð  Ø�Ø"�?�?Ð"Ý‰iŒiˆr   c           
      óÜ   — t          | t          t          t          d¦  «        ¦  «        t          | j        ¦  «        z
  ¦  «        ¦  «        }| j                             |j        ¦  «         |S )aO  
        This is a mock for L{open}.  It keeps track of opened files so extra
        descriptors can be returned from the mock for L{os.listdir} when used on
        one of the list-of-filedescriptors directories.

        A L{FakeFile} is returned which can be closed to remove the new
        descriptor from the open list.
        é   )r   ÚminÚsetÚranger   Úappendr   )r   ÚfnameÚmodeÚfs       r   ÚopenfilezFDDetectorTests.openfileo   sU   € õ �T�3�s¥5¨¡;¤;Ñ/Ô/µ#°d´kÑ2BÔ2BÑBÑCÔCÑDÔDˆØŒ×Ò˜1œ4Ñ Ô Ð Øˆr   c                 ó$   — dt           j        d<   dS )zp
        Make the L{resource} module unimportable for the remainder of the
        current test method.
        NÚresource)ÚsysÚmodulesr   s    r   ÚhideResourceModulez"FDDetectorTests.hideResourceModule}   s   € ð
 #'�Œ�JÑÐÐr   c                 ó>   — t          |¦  «        t          j        d<   dS )a  
        Make a L{FakeResourceModule} instance importable at the L{resource}
        name.

        @param limit: The value which will be returned for the hard limit of
            number of open files by the fake resource module's C{getrlimit}
            function.
        rJ   N)r#   rK   rL   r'   s     r   ÚrevealResourceModulez$FDDetectorTests.revealResourceModule„   s   € õ #5°UÑ";Ô";�Œ�JÑÐÐr   c                 ój   — |€!	 t           j        d= dS # t          $ r Y dS w xY w|t           j        d<   dS )zI
        Restore the original resource module to L{sys.modules}.
        NrJ   )rK   rL   ÚKeyError)r   Úvalues     r   ÚreplaceResourceModulez%FDDetectorTests.replaceResourceModule�   sT   € ð ˆ=ðÝ”K 
Ð+Ð+Ð+øÝð ð ð Ø��ðøøøð ',�CŒK˜
Ñ#Ð#Ð#s   „ “
! !c                 ó  — t          j        ¦   «         | _        | j        | j        _        | j        | j        _        | j        | j        _        g d¢| _        |                      | j        t          j
                             d¦  «        ¦  «         dS )zž
        Set up the tests, giving ourselves a detector object to play with and
        setting up its testable knobs to refer to our mocked versions.
        ©r   r$   é   rJ   N)r   Ú_FDDetectorÚdetectorr>   r1   rH   r   Ú
addCleanuprS   rK   rL   Úgetr   s    r   ÚsetUpzFDDetectorTests.setUp›   sn   € õ
  Ô+Ñ-Ô-ˆŒØ $¤ˆŒÔØ#œ{ˆŒÔØ!%¤ˆŒÔØ�i�iˆŒØ�Š˜Ô2µC´K·O²OÀJÑ4OÔ4OÑPÔPÐPÐPÐPr   c                 ó–   ‡ — d„ }d„ }ˆ fd„}|||g‰ j         _        ‰                      |‰ j                              ¦   «         ¦  «         dS )zÁ
        L{FDDetector._getImplementation} returns the first method from its
        C{_implementations} list which returns results which reflect a newly
        opened file descriptor.
        c                  ó    — t          d¦  «        ‚)NzThis does not work)Ú
ValueErrorr   r   r   ÚfailWithExceptionzBFDDetectorTests.test_selectFirstWorking.<locals>.failWithException®   s   € ÝÐ1Ñ2Ô2Ð2r   c                  ó
   — g d¢S ©NrU   r   r   r   r   ÚfailWithWrongResultszEFDDetectorTests.test_selectFirstWorking.<locals>.failWithWrongResults±   ó   € Ø�9�9Ðr   c                  ó"   •— ‰ j         d d …         S r
   )r   r   s   €r   Úcorrectz8FDDetectorTests.test_selectFirstWorking.<locals>.correct´   s   ø€ Ø”;˜q˜q˜q”>Ð!r   N©rX   Ú_implementationsÚassertIsÚ_getImplementation)r   r_   rb   re   s   `   r   Útest_selectFirstWorkingz'FDDetectorTests.test_selectFirstWorking§   s{   ø€ ð	3ð 	3ð 	3ð	ð 	ð 	ð	"ð 	"ð 	"ð 	"ð 	"ð Ø Øð*
ˆŒÔ&ð 	�Š�g˜tœ}×?Ò?ÑAÔAÑBÔBÐBÐBÐBr   c                 óˆ   — d„ }d„ }||g| j         _        |                      || j                              ¦   «         ¦  «         dS )zâ
        L{FDDetector._getImplementation} returns the last method from its
        C{_implementations} list if none of the implementations manage to return
        results which reflect a newly opened file descriptor.
        c                  ó
   — g d¢S )N)é   é   é	   r   r   r   r   rb   z=FDDetectorTests.test_selectLast.<locals>.failWithWrongResultsÆ   rc   r   c                  ó
   — g d¢S ra   r   r   r   r   ÚfailWithOtherWrongResultszBFDDetectorTests.test_selectLast.<locals>.failWithOtherWrongResultsÉ   rc   r   Nrf   )r   rb   rq   s      r   Útest_selectLastzFDDetectorTests.test_selectLast¿   s_   € ð	ð 	ð 	ð	ð 	ð 	ð !Ø%ð*
ˆŒÔ&ð
 	�ŠÐ/°´×1QÒ1QÑ1SÔ1SÑTÔTÐTÐTÐTr   c                 ó  — t          j        ¦   «         }|j        j        }|                     ¦   «          |j        j        }|                     ¦   «          |j        j        }|                      ||¦  «         |                      ||¦  «         dS )zä
        Check that the identity of _listOpenFDs changes after running
        _listOpenFDs the first time, but not after the second time it's run.

        In other words, check that the monkey patching actually works.
        N)r   rW   Ú_listOpenFDsr   ÚassertNotEqualÚassertEqual)r   rX   ÚfirstÚsecondÚthirds        r   Ú!test_identityOfListOpenFDsChangesz1FDDetectorTests.test_identityOfListOpenFDsChangesÓ   s‰   € õ Ô&Ñ(Ô(ˆàÔ%Ô.ˆØ×ÒÑÔÐØÔ&Ô/ˆØ×ÒÑÔÐØÔ%Ô.ˆà×Ò˜E 6Ñ*Ô*Ð*Ø×Ò˜ Ñ'Ô'Ð'Ð'Ð'r   c                 óØ   — d| _         |                      t          | j        j        ¦  «         d| _         d| _        |                      g d¢| j                             ¦   «         ¦  «         dS )zÈ
        L{_FDDetector._devFDImplementation} raises L{OSError} if there is no
        I{/dev/fd} directory, otherwise it returns the basenames of its children
        interpreted as integers.
        FTrU   N)r9   ÚassertRaisesr;   rX   Ú_devFDImplementationr:   rv   r   s    r   Útest_devFDImplementationz(FDDetectorTests.test_devFDImplementationæ   sc   € ð ˆŒ
Ø×Ò�' 4¤=Ô#EÑFÔFÐFØˆŒ
Ø$)ˆÔ!Ø×Ò˜˜˜ D¤M×$FÒ$FÑ$HÔ$HÑIÔIÐIÐIÐIr   c                 óÊ   — d| _         |                      t          | j        j        ¦  «         d| _         |                      g d¢| j                             ¦   «         ¦  «         dS )zÐ
        L{_FDDetector._procFDImplementation} raises L{OSError} if there is no
        I{/proc/<pid>/fd} directory, otherwise it returns the basenames of its
        children interpreted as integers.
        FTrU   N)r8   r|   r;   rX   Ú_procFDImplementationrv   r   s    r   Útest_procFDImplementationz)FDDetectorTests.test_procFDImplementationò   s[   € ð ˆŒØ×Ò�' 4¤=Ô#FÑGÔGÐGØˆŒØ×Ò˜˜˜ D¤M×$GÒ$GÑ$IÔ$IÑJÔJÐJÐJÐJr   c                 óª  — |                       d¦  «         |                      t          t          d¦  «        ¦  «        t          | j                             ¦   «         ¦  «        ¦  «         |                       d¦  «         |                      t          t          d¦  «        ¦  «        t          | j                             ¦   «         ¦  «        ¦  «         dS )z×
        L{_FDDetector._fallbackFDImplementation} uses the L{resource} module if
        it is available, returning a range of integers from 0 to the
        minimum of C{1024} and the hard I{NOFILE} limit.
        i   i   r@   N)rO   rv   ÚlistrC   rX   Ú_fallbackFDImplementationr   s    r   Útest_resourceFDImplementationz-FDDetectorTests.test_resourceFDImplementationý   sº   € ð 	×!Ò! #Ñ&Ô&Ð&Ø×ÒÝ•�s‘”ÑÔ�d 4¤=×#JÒ#JÑ#LÔ#LÑMÔMñ	
ô 	
ð 	
ð
 	×!Ò! $Ñ'Ô'Ð'Ø×ÒÝ•�t‘”ÑÔ�t D¤M×$KÒ$KÑ$MÔ$MÑNÔNñ	
ô 	
ð 	
ð 	
ð 	
r   c                 óÖ   — |                       ¦   «          |                      t          t          d¦  «        ¦  «        t          | j                             ¦   «         ¦  «        ¦  «         dS )zÔ
        L{_FDDetector._fallbackFDImplementation}, the implementation of last
        resort, succeeds with a fixed range of integers from 0 to 1024 when the
        L{resource} module is not importable.
        r@   N)rM   rv   rƒ   rC   rX   r„   r   s    r   Útest_fallbackFDImplementationz-FDDetectorTests.test_fallbackFDImplementation  sa   € ð 	×ÒÑ!Ô!Ð!Ø×ÒÝ•�t‘”ÑÔ�t D¤M×$KÒ$KÑ$MÔ$MÑNÔNñ	
ô 	
ð 	
ð 	
ð 	
r   N)r   r   r    r!   r   Úskipr9   r:   r8   r1   r>   rH   rM   rO   rS   r[   rj   rr   rz   r~   r�   r…   r‡   r   r   r   r/   r/   D   s  € € € € € ðð ð €Dà€EØ Ðà€Fðð ð ðð ð ðð ð ð'ð 'ð 'ð	<ð 	<ð 	<ð
,ð 
,ð 
,ð
Qð 
Qð 
QðCð Cð Cð0Uð Uð Uð((ð (ð (ð&
Jð 
Jð 
Jð	Kð 	Kð 	Kð
ð 
ð 
ð$	
ð 	
ð 	
ð 	
ð 	
r   r/   c                   ó"   — e Zd ZdZeZd„ Zd„ ZdS )ÚFileDescriptorTestsz<
    Tests for L{twisted.internet.process._listOpenFDs}
    c           	      ó   — t          j        ¦   «         D ]i}	 t          j        |t          j        ¦  «         Œ## t          $ r:}|                      t          j        |j        d||j        fz  ¦  «         Y d}~Œbd}~ww xY wdS )zµ
        File descriptors returned by L{_listOpenFDs} are mostly open.

        This test assumes that zero-legth writes fail with EBADF on closed
        file descriptors.
        z2fcntl(%d, F_GETFL) failed with unexpected errno %dN)r   rt   ÚfcntlÚF_GETFLr;   rv   ÚerrnoÚEBADF)r   r   Úerrs      r   Útest_openFDsz FileDescriptorTests.test_openFDs"  s­   € õ Ô&Ñ(Ô(ð 		ð 		ˆBðÝ”˜B¥¤Ñ.Ô.Ð.Ð.øÝð ð ð Ø× Ò Ý”KØ”IØHØ˜3œ9�oñ&ñô ð ð ð ð ð ð øøøøðøøøð		ð 		s   —7·
A;Á0A6Á6A;c                 ót  — t          t          j        ¦  «        }t          j        ¦   «         }|                      |                     ¦   «         |¦  «         t          j        |                     ¦   «         ¦  «        }|                      ||                     ¦   «         k    d¦  «         	 | 	                    ¦   «          |                      |t          j        ¦   «         ¦  «         t          j	        |¦  «         n# t          j	        |¦  «         w xY w|  
                    |t          j        ¦   «         ¦  «         dS )zB
        L{_listOpenFDs} lists expected file descriptors.
        z>Expected duplicate file descriptor to be greater than originalN)ÚopenÚosÚdevnullr   rt   ÚassertInÚfilenoÚdupÚ
assertTruer   ÚassertNotIn)r   rG   Úopenfdsr   s       r   Útest_expectedFDsz$FileDescriptorTests.test_expectedFDs4  sù   € õ •”ÑÔˆÝÔ&Ñ(Ô(ˆØ�Š�a—h’h‘j”j 'Ñ*Ô*Ð*õ ŒV�A—H’H‘J”JÑÔˆð 	�ŠØ�—’‘”ŠOØLñ	
ô 	
ð 	
ð
	ð �GŠG‰IŒIˆIØ�MŠM˜"�gÔ2Ñ4Ô4Ñ5Ô5Ð5õ ŒH�R‰LŒLˆLˆLø�BŒH�R‰LŒLˆLˆLøøøà×Ò˜�WÔ1Ñ3Ô3Ñ4Ô4Ð4Ð4Ð4s   Â(;C8 Ã8DN)r   r   r    r!   r   rˆ   r‘   rœ   r   r   r   rŠ   rŠ     sC   € € € € € ðð ð €Dðð ð ð$)5ð )5ð )5ð )5ð )5r   rŠ   )r!   rŽ   r”   rK   Útypingr   r7   Ú__annotations__rŒ   Útwisted.internetr   r   ÚImportErrorÚtwisted.trial.unittestr   r   r#   r/   rŠ   r   r   r   ú<module>r¢      sw  ððð ð ð
 €€€Ø 	€	€	€	Ø 
€
€
€
Ø Ð Ð Ð Ð Ð à�sŒmÐ Ð Ñ ðØ€L€L€Lð )Ð(Ð(Ð(Ð(Ð(à€L€Løð ð (ð (ð (Ø'€L€L€Lð(øøøð ,Ð +Ð +Ð +Ð +Ð +ðð ð ð ð ñ ô ð ð&ð ð ð ð ñ ô ð ð,T
ð T
ð T
ð T
ð T
�hñ T
ô T
ð T
ðnB5ð B5ð B5ð B5ð B5˜(ñ B5ô B5ð B5ð B5ð B5s   ¢/ ¯9¸9