ó
    Ö›‘hÃ+  ã                   óÔ   • % S r SSKrSSKrSSKrSSKJr  \\   \S'    SSKrSSK	J
r
  SrSSKJr   " S S	5      r " S
 S5      r " S S\5      r " S S\5      rg! \ a    Sr N;f = f)z;
Tests for POSIX-based L{IReactorProcess} implementations.
é    N)ÚOptionalÚplatformSkip)Úprocessznon-POSIX platform)ÚTestCasec                   ó0   • \ rS rSrSrS rS rS rS rSr	g)	ÚFakeFileé   z6
A dummy file object which records when it is closed.
c                 ó   • Xl         X l        g ©N)ÚtestcaseÚfd)Úselfr   r   s      ÚkC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/internet/test/test_posixprocess.pyÚ__init__ÚFakeFile.__init__    s   € Ø ŒØ�ó    c                 ób   • U R                   R                  R                  U R                  5        g r   )r   Ú_filesÚremover   ©r   s    r   ÚcloseÚFakeFile.close$   s   € Ø�‰×Ñ×#Ñ# D§G¡GÕ,r   c                 ó   • U $ r   © r   s    r   Ú	__enter__ÚFakeFile.__enter__'   s   € Øˆr   c                 ó$   • U R                  5         g r   )r   )r   Úexc_typeÚ	exc_valueÚ	tracebacks       r   Ú__exit__ÚFakeFile.__exit__*   s   € Ø�
‰
�r   )r   r   N)
Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r   r!   Ú__static_attributes__r   r   r   r   r      s   † ñòò-òõr   r   c                   ó(   • \ rS rSrSrSrS rS rSrg)ÚFakeResourceModuleé.   z©
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                 ó   • Xl         g r   ©Ú_limit©r   Úlimits     r   r   ÚFakeResourceModule.__init__8   s   € Ø�r   c                 óD   • XR                   :X  a  SU R                  /$ SS/$ )zH
A fake of L{resource.getrlimit} which returns a pre-determined result.
r   é{   iÈ  )ÚRLIMIT_NOFILEr/   )r   Únos     r   Ú	getrlimitÚFakeResourceModule.getrlimit;   s)   € ð ×#Ñ#Ó#Ø�t—{‘{Ð#Ð#Ø�SˆzÐr   r.   N)	r#   r$   r%   r&   r'   r5   r   r7   r(   r   r   r   r*   r*   .   s   † ñð €Mòõr   r*   c                   ó|   • \ rS rSrSr\rSrSrSr	S r
S rS rS rS rS	 rS
 rS rS rS rS rS rS rS rSrg)ÚFDDetectorTestséD   aÇ  
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                 ó   • g)z.
Fake os.getpid, always return the same thing
r4   r   r   s    r   ÚgetpidÚFDDetectorTests.getpidZ   s   € ð r   c                 óü   • [        [        U R                  5      nU R                  (       a  USU R	                  5       4-  :X  a  U$ U R
                  (       a  US:X  a  U R                  (       a  U$ / SQ$ [        5       e)zl
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   Úprocfsr=   ÚdevfsÚaccurateDevFDResultsÚOSError)r   ÚargÚaccurates      r   ÚlistdirÚFDDetectorTests.listdir`   s^   € ô ”s˜DŸK™KÓ(ˆØ�;�;˜3 =°D·K±K³MÐ3CÑ#CÓDØˆOØ�:�:˜# Ó*Ø×(×(Ø�Ú"Ð"Ü‹iˆr   c           
      óÊ   • [        U [        [        [        S5      5      [        U R                  5      -
  5      5      nU R                  R                  UR                  5        U$ )a  
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   ÚopenfileÚFDDetectorTests.openfileo   sG   € ô �Tœ3œs¤5¨£;Ó/´#°d·k±kÓ2BÑBÓCÓDˆØ�‰×Ñ˜1Ÿ4™4Ô Øˆr   c                 ó*   • S[         R                  S'   g)zX
Make the L{resource} module unimportable for the remainder of the
current test method.
NÚresource)ÚsysÚmodulesr   s    r   ÚhideResourceModuleÚ"FDDetectorTests.hideResourceModule}   s   € ð
 #'Œ�‰�JÒr   c                 ó<   • [        U5      [        R                  S'   g)zã
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.
rY   N)r*   rZ   r[   r0   s     r   ÚrevealResourceModuleÚ$FDDetectorTests.revealResourceModule„   s   € ô #5°UÓ";Œ�‰�JÒr   c                 óv   • Uc   [         R                  S	 gU[         R                  S'   g! [         a     gf = f)z9
Restore the original resource module to L{sys.modules}.
NrY   )rZ   r[   ÚKeyError)r   Úvalues     r   ÚreplaceResourceModuleÚ%FDDetectorTests.replaceResourceModule�   s>   € ð ‰=ðÜ—K‘K 
Ñ+ð ',ŒC�K‰K˜
Ò#øô ó Ùðús   …+ «
8·8c                 ó^  • [         R                  " 5       U l        U R                  U R                  l        U R                  U R                  l        U R
                  U R                  l        / SQU l        U R                  U R                  [        R                  R                  S5      5        g)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,   é   rY   N)r   Ú_FDDetectorÚdetectorrK   r=   rV   r   Ú
addCleanuprd   rZ   r[   Úgetr   s    r   ÚsetUpÚFDDetectorTests.setUp›   sl   € ô
  ×+Ò+Ó-ˆŒØ $§¡ˆ�‰ÔØ#Ÿ{™{ˆ�‰ÔØ!%§¡ˆ�‰ÔÚˆŒØ�‰˜×2Ñ2´C·K±K·O±OÀJÓ4OÕPr   c                 óš   ^ • S nS nU 4S jnUUU/T R                   l        T R                  UT R                   R                  5       5        g)z¡
L{FDDetector._getImplementation} returns the first method from its
C{_implementations} list which returns results which reflect a newly
opened file descriptor.
c                  ó   • [        S5      e)NzThis does not work)Ú
ValueErrorr   r   r   ÚfailWithExceptionÚBFDDetectorTests.test_selectFirstWorking.<locals>.failWithException®   s   € ÜÐ1Ó2Ð2r   c                  ó
   • / SQ$ ©Nrg   r   r   r   r   ÚfailWithWrongResultsÚEFDDetectorTests.test_selectFirstWorking.<locals>.failWithWrongResults±   ó   € ÚÐr   c                  ó"   >• T R                   S S  $ r   )r   r   s   €r   ÚcorrectÚ8FDDetectorTests.test_selectFirstWorking.<locals>.correct´   s   ø€ Ø—;‘;™q�>Ð!r   N©rj   Ú_implementationsÚassertIsÚ_getImplementation)r   rr   rv   rz   s   `   r   Útest_selectFirstWorkingÚ'FDDetectorTests.test_selectFirstWorking§   sH   ø€ ò	3ò	õ	"ð Ø Øð*
ˆ�‰Ô&ð 	�‰�g˜tŸ}™}×?Ñ?ÓAÕBr   c                 óˆ   • S nS nUU/U R                   l        U R                  X R                   R                  5       5        g)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                  ó
   • / SQ$ )N)é   é   é	   r   r   r   r   rv   Ú=FDDetectorTests.test_selectLast.<locals>.failWithWrongResultsÆ   rx   r   c                  ó
   • / SQ$ ru   r   r   r   r   ÚfailWithOtherWrongResultsÚBFDDetectorTests.test_selectLast.<locals>.failWithOtherWrongResultsÉ   rx   r   Nr|   )r   rv   r‰   s      r   Útest_selectLastÚFDDetectorTests.test_selectLast¿   s>   € ò	ò	ð !Ø%ð*
ˆ�‰Ô&ð
 	�‰Ð/·±×1QÑ1QÓ1SÕTr   c                 ó6  • [         R                  " 5       nUR                  R                  nUR                  5         UR                  R                  nUR                  5         UR                  R                  nU R	                  X#5        U R                  X45        g)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   ri   Ú_listOpenFDsr#   ÚassertNotEqualÚassertEqual)r   rj   ÚfirstÚsecondÚthirds        r   Ú!test_identityOfListOpenFDsChangesÚ1FDDetectorTests.test_identityOfListOpenFDsChangesÓ   sy   € ô ×&Ò&Ó(ˆà×%Ñ%×.Ñ.ˆØ×ÑÔØ×&Ñ&×/Ñ/ˆØ×ÑÔØ×%Ñ%×.Ñ.ˆà×Ñ˜EÔ*Ø×Ñ˜Õ'r   c                 óÚ   • SU l         U R                  [        U R                  R                  5        SU l         SU l        U R                  / SQU R                  R	                  5       5        g)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.
FTrg   N)rF   ÚassertRaisesrH   rj   Ú_devFDImplementationrG   r�   r   s    r   Útest_devFDImplementationÚ(FDDetectorTests.test_devFDImplementationæ   sQ   € ð ˆŒ
Ø×Ñœ' 4§=¡=×#EÑ#EÔFØˆŒ
Ø$)ˆÔ!Ø×Ñš D§M¡M×$FÑ$FÓ$HÕIr   c                 óÌ   • SU l         U R                  [        U R                  R                  5        SU l         U R                  / SQU R                  R	                  5       5        g)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.
FTrg   N)rE   r—   rH   rj   Ú_procFDImplementationr�   r   s    r   Útest_procFDImplementationÚ)FDDetectorTests.test_procFDImplementationò   sI   € ð ˆŒØ×Ñœ' 4§=¡=×#FÑ#FÔGØˆŒØ×Ñš D§M¡M×$GÑ$GÓ$IÕJr   c                 ó\  • U R                  S5        U R                  [        [        S5      5      [        U R                  R                  5       5      5        U R                  S5        U R                  [        [        S5      5      [        U R                  R                  5       5      5        g)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   rN   N)r_   r�   ÚlistrQ   rj   Ú_fallbackFDImplementationr   s    r   Útest_resourceFDImplementationÚ-FDDetectorTests.test_resourceFDImplementationý   s~   € ð 	×!Ñ! #Ô&Ø×ÑÜ”�s“Óœd 4§=¡=×#JÑ#JÓ#LÓMô	
ð
 	×!Ñ! $Ô'Ø×ÑÜ”�t“Óœt D§M¡M×$KÑ$KÓ$MÓNõ	
r   c                 ó®   • U R                  5         U R                  [        [        S5      5      [        U R                  R                  5       5      5        g)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.
rN   N)r\   r�   r    rQ   rj   r¡   r   s    r   Útest_fallbackFDImplementationÚ-FDDetectorTests.test_fallbackFDImplementation  s>   € ð 	×ÑÔ!Ø×ÑÜ”�t“Óœt D§M¡M×$KÑ$KÓ$MÓNõ	
r   )r   rG   rj   rF   rE   N)r#   r$   r%   r&   r'   r   ÚskiprF   rG   rE   r=   rK   rV   r\   r_   rd   rm   r€   r‹   r”   r™   r�   r¢   r¥   r(   r   r   r   r:   r:   D   si   † ñð €Dà€EØ Ðà€Fòòòò'ò	<ò
,ò
QòCò0Uò((ò&
Jò	Kò
õ$	
r   r:   c                   ó(   • \ rS rSrSr\rS rS rSr	g)ÚFileDescriptorTestsi  z4
Tests for L{twisted.internet.process._listOpenFDs}
c           	      ó*  • [         R                  " 5        H)  n [        R                  " U[        R                  5        M+     g! [         aD  nU R                  [        R                  UR                  SXR                  4-  5         SnAMw  SnAff = f)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   rŽ   ÚfcntlÚF_GETFLrH   r�   ÚerrnoÚEBADF)r   r   Úerrs      r   Útest_openFDsÚ FileDescriptorTests.test_openFDs"  sr   € ô ×&Ò&Ö(ˆBðÜ—’˜B¤§¡Ö.ò )øô ó Ø× Ñ Ü—K‘KØ—I‘IØHØŸ9™9�oñ&÷ò ûðús   š%AÁ
BÁ9BÂBc                 óD  • [        [        R                  5      n[        R                  " 5       nU R                  UR                  5       U5        [        R                  " UR                  5       5      nU R                  X1R                  5       :„  S5         UR                  5         U R                  U[        R                  " 5       5        [        R                  " U5        U R                  U[        R                  " 5       5        g! [        R                  " U5        f = f)z2
L{_listOpenFDs} lists expected file descriptors.
z>Expected duplicate file descriptor to be greater than originalN)ÚopenÚosÚdevnullr   rŽ   ÚassertInÚfilenoÚdupÚ
assertTruer   ÚassertNotIn)r   rU   Úopenfdsr   s       r   Útest_expectedFDsÚ$FileDescriptorTests.test_expectedFDs4  sÂ   € ô ”—‘ÓˆÜ×&Ò&Ó(ˆØ�‰�a—h‘h“j 'Ô*ô �VŠV�A—H‘H“JÓˆð 	�‰Ø—‘“‰OØLô	
ð
	ð �G‰GŒIØ�M‰M˜"œg×2Ò2Ó4Ô5ô �HŠH�RŒLà×Ñ˜œW×1Ò1Ó3Õ4øô �HŠH�R�Lús   Â5D ÄDr   N)
r#   r$   r%   r&   r'   r   r§   r°   r¼   r(   r   r   r   r©   r©     s   † ñð €Dòõ$)5r   r©   )r'   r­   r´   rZ   Útypingr   rD   Ú__annotations__r«   Útwisted.internetr   r   ÚImportErrorÚtwisted.trial.unittestr   r   r*   r:   r©   r   r   r   Ú<module>rÃ      s   ðòó
 Û 	Û 
Ý à�s‰mÓ ðÛõ )à€Lå +÷ñ ÷&ñ ô,T
�hô T
ônB5˜(õ B5øðU ó (Ø'‚Lð(ús   ŸA ÁA'Á&A'