+
    üÐjÃ+  ã                   óÚ   a € R t0 t R t^ RIt^ RIt^ RIt^ RIHt ] ^ k  ^ RIt^ RIH	t	 Rt
^ RIHt  ! R R4      t ! R R	4      t ! R
 R]4      t ! R R]4      tR#   ] d    Rt
 L=i ; i)z;
Tests for POSIX-based L{IReactorProcess} implementations.
N)ÚOptional)Úprocessznon-POSIX platform)ÚTestCasec                   ó<   a € ] tR t^t o RtR tR tR tR tRt	V t
R# )ÚFakeFilez6
A dummy file object which records when it is closed.
c                ó   € Wn         W n        R # ©N)ÚtestcaseÚfd)Úselfr	   r
   s   &&&ÚI/usr/lib/python3/dist-packages/twisted/internet/test/test_posixprocess.pyÚ__init__ÚFakeFile.__init__    s   € Ø ŒØŽó    c                ód   € V P                   P                  P                  V P                  4       R # r   )r	   Ú_filesÚremover
   ©r   s   &r   ÚcloseÚFakeFile.close$   s   € Ø�‰×Ñ×#Ñ# D§G¡GÖ,r   c                ó   € V # r   © r   s   &r   Ú	__enter__ÚFakeFile.__enter__'   s   € Øˆr   c                ó&   € V P                  4        R # 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__Ú__classdictcell__©Ú__classdict__s   @r   r   r      s#   ø‡ € ñòò-ò÷ð r   r   c                   ó4   a € ] tR t^.t o Rt^tR tR tRtV t	R# )Ú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                ó   € Wn         R # r   ©Ú_limit©r   Úlimits   &&r   r   ÚFakeResourceModule.__init__8   s   € ØŽr   c                óF   € WP                   8X  d   ^ V P                  .# ^{R.# )zH
A fake of L{resource.getrlimit} which returns a pre-determined result.
iÈ  )ÚRLIMIT_NOFILEr-   )r   Únos   &&r   Ú	getrlimitÚFakeResourceModule.getrlimit;   s)   € ð ×#Ñ#Ô#Ø�t—{‘{Ð#Ð#Ø�SˆzÐr   r,   N)
r    r!   r"   r#   r$   r2   r   r4   r%   r&   r'   s   @r   r*   r*   .   s    ø‡ € ñð €Mò÷ð r   r*   c                   óˆ   a € ] tR t^Dt o Rt]tRtRtRt	R t
R tR tR tR tR tR	 tR
 tR tR tR tR tR tR tRtV tR# )Ú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                ó   € ^{# )z.
Fake os.getpid, always return the same thing
r   r   s   &r   ÚgetpidÚFDDetectorTests.getpidZ   s   € ñ r   c                ó  € \        \        V P                  4      pV P                  '       d    VRV P	                  4       3,          8X  d   V# V P
                  '       d    VR8X  d   V P                  '       d   V# . RO# \        4       h)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   Úprocfsr9   ÚdevfsÚaccurateDevFDResultsÚOSError)r   ÚargÚaccurates   && r   ÚlistdirÚFDDetectorTests.listdir`   se   € ô ”s˜DŸK™KÓ(ˆØ�;�;ˆ;˜3 =°D·K±K³MÐ3CÕ#CÔDØˆOØ�:�:ˆ:˜# Ô*Ø×(×(Ð(Ø�Ú"Ð"Ü‹iˆr   c           
     óÒ   € \        V \        \        \        R4      4      \        V P                  4      ,
          4      4      pV P                  P                  VP                  4       V# )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                ó,   € R\         P                  R&   R# )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                ó>   € \        V4      \        P                  R&   R# )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.
rU   N)r*   rV   rW   r.   s   &&r   ÚrevealResourceModuleÚ$FDDetectorTests.revealResourceModule„   s   € ô #5°UÓ";Œ�‰�JÓr   c                ó€   € Vf    \         P                  R R# V\         P                  R&   R#   \         d     R# i ; i)z9
Restore the original resource module to L{sys.modules}.
NrU   )rV   rW   ÚKeyError)r   Úvalues   &&r   ÚreplaceResourceModuleÚ%FDDetectorTests.replaceResourceModule�   s>   € ð Š=ðÜ—K‘K 
Ò+ð ',ŒC�K‰K˜
Ó#øô ô Úðús   †. ®=¼=c                ó`  € \         P                  ! 4       V n        V P                  V P                  n        V P                  V P                  n        V P
                  V P                  n        . ROV n        V P                  V P                  \        P                  P                  R4      4       R# )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.
rU   N©é    é   é   )r   Ú_FDDetectorÚdetectorrG   r9   rR   r   Ú
addCleanupr`   rV   rW   Úgetr   s   &r   ÚsetUpÚFDDetectorTests.setUp›   sl   € ô
  ×+Ò+Ó-ˆŒØ $§¡ˆ�‰ÔØ#Ÿ{™{ˆ�‰ÔØ!%§¡ˆ�‰ÔÚˆŒØ�‰˜×2Ñ2´C·K±K·O±OÀJÓ4OÖPr   c                óœ   a € R pR pV 3R lpVVV.S P                   n        S P                  VS P                   P                  4       4       R# )z¡
L{FDDetector._getImplementation} returns the first method from its
C{_implementations} list which returns results which reflect a newly
opened file descriptor.
c                  ó   € \        R 4      h)zThis does not work)Ú
ValueErrorr   r   r   ÚfailWithExceptionÚBFDDetectorTests.test_selectFirstWorking.<locals>.failWithException®   s   € ÜÐ1Ó2Ð2r   c                  ó
   € . RO# ©rd   rc   r   r   r   r   ÚfailWithWrongResultsÚEFDDetectorTests.test_selectFirstWorking.<locals>.failWithWrongResults±   ó   € ÚÐr   c                  ó*   <€ S P                   R ,          # ):NNN)r   r   s   €r   ÚcorrectÚ8FDDetectorTests.test_selectFirstWorking.<locals>.correct´   s   ø€ Ø—;‘;˜q•>Ð!r   N©rh   Ú_implementationsÚassertIsÚ_getImplementation)r   rp   rt   rx   s   f   r   Útest_selectFirstWorkingÚ'FDDetectorTests.test_selectFirstWorking§   sH   ø€ ò	3ò	õ	"ð Ø Øð*
ˆ�‰Ô&ð 	�‰�g˜tŸ}™}×?Ñ?ÓAÖBr   c                óŠ   € R pR pVV.V P                   n        V P                  W P                   P                  4       4       R# )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                  ó
   € . RO# )é   )r‚   é   é	   r   r   r   r   rt   Ú=FDDetectorTests.test_selectLast.<locals>.failWithWrongResultsÆ   rv   r   c                  ó
   € . RO# rs   r   r   r   r   ÚfailWithOtherWrongResultsÚBFDDetectorTests.test_selectLast.<locals>.failWithOtherWrongResultsÉ   rv   r   Nrz   )r   rt   r‡   s   &  r   Útest_selectLastÚFDDetectorTests.test_selectLast¿   s>   € ò	ò	ð !Ø%ð*
ˆ�‰Ô&ð
 	�‰Ð/·±×1QÑ1QÓ1SÖTr   c                ó8  € \         P                  ! 4       pVP                  P                  pVP                  4        VP                  P                  pVP                  4        VP                  P                  pV P	                  W#4       V P                  W44       R# )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   rg   Ú_listOpenFDsr    ÚassertNotEqualÚassertEqual)r   rh   ÚfirstÚsecondÚthirds   &    r   Ú!test_identityOfListOpenFDsChangesÚ1FDDetectorTests.test_identityOfListOpenFDsChangesÓ   sy   € ô ×&Ò&Ó(ˆà×%Ñ%×.Ñ.ˆØ×ÑÔØ×&Ñ&×/Ñ/ˆØ×ÑÔØ×%Ñ%×.Ñ.ˆà×Ñ˜EÔ*Ø×Ñ˜Ö'r   c                óÜ   € RV n         V P                  \        V P                  P                  4       RV n         RV n        V P                  . ROV P                  P	                  4       4       R# )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.
FTNrc   )rB   ÚassertRaisesrD   rh   Ú_devFDImplementationrC   rŽ   r   s   &r   Útest_devFDImplementationÚ(FDDetectorTests.test_devFDImplementationæ   sQ   € ð ˆŒ
Ø×Ñœ' 4§=¡=×#EÑ#EÔFØˆŒ
Ø$)ˆÔ!Ø×Ñš D§M¡M×$FÑ$FÓ$HÖIr   c                óÎ   € RV n         V P                  \        V P                  P                  4       RV n         V P                  . ROV P                  P	                  4       4       R# )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.
FTNrc   )rA   r•   rD   rh   Ú_procFDImplementationrŽ   r   s   &r   Útest_procFDImplementationÚ)FDDetectorTests.test_procFDImplementationò   sI   € ð ˆŒØ×Ñœ' 4§=¡=×#FÑ#FÔGØˆŒØ×Ñš D§M¡M×$GÑ$GÓ$IÖJr   c                ó^  € V P                  R4       V P                  \        \        R4      4      \        V P                  P                  4       4      4       V P                  R4       V P                  \        \        R4      4      \        V P                  P                  4       4      4       R# )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   rJ   N)r[   rŽ   ÚlistrM   rh   Ú_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                ó°   € V P                  4        V P                  \        \        R4      4      \        V P                  P                  4       4      4       R# )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.
rJ   N)rX   rŽ   rž   rM   rh   rŸ   r   s   &r   Útest_fallbackFDImplementationÚ-FDDetectorTests.test_fallbackFDImplementation  s>   € ð 	×ÑÔ!Ø×ÑÜ”�t“Óœt D§M¡M×$KÑ$KÓ$MÓNö	
r   )r   rC   rh   rB   rA   N)r    r!   r"   r#   r$   ÚplatformSkipÚskiprB   rC   rA   r9   rG   rR   rX   r[   r`   rk   r~   r‰   r’   r—   r›   r    r£   r%   r&   r'   s   @r   r7   r7   D   sq   ø‡ € ñð €Dà€EØ Ðà€Fòòòò'ò	<ò
,ò
QòCò0Uò((ò&
Jò	Kò
÷$	
ð 	
r   r7   c                   ó4   a € ] tR tRt o Rt]tR tR tRt	V t
R# )ÚFileDescriptorTestsi  z4
Tests for L{twisted.internet.process._listOpenFDs}
c           	     ó6  € \         P                  ! 4        F)  p \        P                  ! V\        P                  4       K+  	  R#   \         dI   pT P                  \        P                  TP                  RYP                  3,          4        Rp?K}  Rp?ii ; i)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_GETFLrD   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Á=BÂBc                óF  € \        \        P                  4      p\        P                  ! 4       pV P                  VP                  4       V4       \        P                  ! VP                  4       4      pV P                  W1P                  4       8„  R4        VP                  4        V P                  V\        P                  ! 4       4       \        P                  ! V4       V P                  V\        P                  ! 4       4       R#   \        P                  ! T4       i ; i)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   rQ   Ú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'   s   @r   r¨   r¨     s    ø‡ € ñð €Dò÷$)5ð )5r   r¨   c                óV   € V ^8„  d   Qh/ ^ \         9   d   \        \        ,          ;R&   # )rf   r¥   )Ú__conditional_annotations__r   r@   )Úformats   "r   Ú__annotate__rÀ      s"   € ÷ ñ ÷ Ò Œh”s�mÑ òr   )r¾   r$   r¬   r³   rV   Útypingr   rª   Útwisted.internetr   r¥   ÚImportErrorÚtwisted.trial.unittestr   r   r*   r7   r¨   rÀ   )r¾   s   @r   Ú<module>rÅ      sy   øðöó
 Û 	Û 
Ý ã ðÛõ )à€Lå +÷ñ ÷&ñ ô,T
�hô T
ônB5˜(ö B5øðU ô (Ø'‚Lð(ús    A Á	A*Á)A*