ó
    ×›‘hp/  ã                  ó^  • S r SSKJr  SSKrSSKrSSKJr  SSKJr  SSK	J
r
Jr  SSKJrJr  SSKJr  SS	KJr  SS
KJr  SSKJr  SSKJr  SSKJr  SSKJr  SSKJrJr  SSK J!r!  SSK"J#r#  SSK$J%r%J&r&  SSK'J(r(J)r)J*r*J+r+  SSK,J-r-  SSK.J/r/  SSK0J1r1  \2" 5       r3 " S S\5      r4 " S S\5      r5g)z
Tests for L{twisted.web.tap}.
é    )ÚannotationsN)Úcast)ÚskipIf)Ú	endpointsÚreactor)ÚIReactorCoreÚIReactorUNIX)ÚFilePath)ÚrequireModule)Ú
ThreadPool)Ú
UsageError)ÚPBServerFactory)ÚTestCase)Údemo)ÚResourcePublisherÚUserDirectory)ÚPythonScript)ÚSite)ÚDataÚFile)ÚOptionsÚ_AddHeadersResourceÚmakePersonalServerFactoryÚmakeService)ÚDummyRequest)Ú	CGIScript)ÚWSGIResourcec                  óö  • \ rS rSrSrSS jrSS jr\" \R                  " \
5      (       + S5      SS j5       rSS jrSS jrSS	 jrSS
 jr\" \R                  " \
5      (       + S5      SS j5       r\" \R                  " \
5      (       + S5      SS j5       rSS jrSS jrSS jrSS jr\" \" S5      SLS5      SS j5       r\" \" S5      SL S5      SS j5       rSS jrSS jrSS jrSS jrSS jrSrg)ÚServiceTestsé(   z<
Tests for the service creation APIs in L{twisted.web.tap}.
c                ó²   • [        U R                  5       5      nUR                  5         [        5       nUR	                  SUR
                  /5        US   nX4$ )aK  
Helper for the I{--path} tests which creates a directory and creates
an L{Options} object which uses that directory as its static
filesystem root.

@return: A two-tuple of a L{FilePath} referring to the directory and
    the value associated with the C{'root'} key in the L{Options}
    instance after parsing a I{--path} option.
ú--pathÚroot)r
   ÚmktempÚmakedirsr   ÚparseOptionsÚpath)Úselfr'   Úoptionsr#   s       Ú]C:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/web/test/test_tap.pyÚ_pathOptionÚServiceTests._pathOption-   sL   € ô ˜Ÿ™›Ó&ˆØ�‰ŒÜ“)ˆØ×Ñ˜h¨¯	©	Ð2Ô3Ø�v‰ˆØˆzÐó    c                ó    • U R                  5       u  pU R                  U[        5        U R                  UR                  UR                  5        g)zr
The I{--path} option causes L{Options} to create a root resource
which serves responses from the specified path.
N)r+   ÚassertIsInstancer   ÚassertEqualr'   ©r(   r'   r#   s      r*   Ú	test_pathÚServiceTests.test_path>   s<   € ð
 ×%Ñ%Ó'‰
ˆØ×Ñ˜d¤DÔ)Ø×Ñ˜Ÿ™ D§I¡IÕ.r-   z0The reactor does not support UNIX domain socketsc                ó  • [        U R                  5       5      nUR                  5         U R                  5       n[        5       nUR	                  SSU-   SUR
                  /5        [        U5      nUR                  5         U R                  UR                  5        U R                  UR                  S   R                  R                  [        5        U R                  UR                  S   R                  R                  R
                  UR
                  5        U R!                  ["        R
                  R%                  U5      5        U R!                  [&        R(                  " ["        R&                  " U5      R*                  5      5        g)z�
The I{--path} option to L{makeService} causes it to return a service
which will listen on the server address given by the I{--port} option.
ú--portúunix:r"   r   N)r
   r$   r%   r   r&   r'   r   ÚstartServiceÚ
addCleanupÚstopServicer/   ÚservicesÚfactoryÚresourcer   r0   Ú
assertTrueÚosÚexistsÚstatÚS_ISSOCKÚst_mode)r(   r'   Úportr)   Úservices        r*   Útest_pathServerÚServiceTests.test_pathServerG   s
  € ô ˜Ÿ™›Ó&ˆØ�‰ŒØ�{‰{‹}ˆÜ“)ˆØ×Ñ˜h¨°$©¸À$Ç)Á)ÐLÔMÜ˜gÓ&ˆØ×ÑÔØ�‰˜×+Ñ+Ô,Ø×Ñ˜g×.Ñ.¨qÑ1×9Ñ9×BÑBÄDÔIØ×Ñ˜×)Ñ)¨!Ñ,×4Ñ4×=Ñ=×BÑBÀDÇIÁIÔNØ�‰œŸ™Ÿ™ tÓ,Ô-Ø�‰œŸš¤b§g¢g¨d£m×&;Ñ&;Ó<Õ=r-   c                ó´   • U R                  5       u  pUR                  S5      R                  S5        U R                  UR	                  SS5      [
        5        g)z
The I{--path} option creates a root resource which serves a
L{CGIScript} instance for any child with the C{".cgi"} extension.
zfoo.cgir-   N)r+   ÚchildÚ
setContentr/   ÚgetChildr   r1   s      r*   Útest_cgiProcessorÚServiceTests.test_cgiProcessor]   sF   € ð
 ×%Ñ%Ó'‰
ˆØ�
‰
�9Ó×(Ñ(¨Ô-Ø×Ñ˜dŸm™m¨I°tÓ<¼iÕHr-   c                ó´   • U R                  5       u  pUR                  S5      R                  S5        U R                  UR	                  SS5      [
        5        g)z‚
The I{--path} option creates a root resource which serves a
L{PythonScript} instance for any child with the C{".epy"} extension.
zfoo.epyr-   N)r+   rH   rI   r/   rJ   r   r1   s      r*   Útest_epyProcessorÚServiceTests.test_epyProcessorf   sF   € ð
 ×%Ñ%Ó'‰
ˆØ�
‰
�9Ó×(Ñ(¨Ô-Ø×Ñ˜dŸm™m¨I°tÓ<¼lÕKr-   c                ó(  • U R                  5       u  pUR                  S5      R                  S5        UR                  SS5      nU R	                  U[
        5        U R                  UR                  S5        U R                  UR                  S5        g)zš
The I{--path} option creates a root resource which serves the
C{resource} global defined by the Python source in any child with
the C{".rpy"} extension.
zfoo.rpysN   from twisted.web.static import Data
resource = Data('content', 'major/minor')
NÚcontentzmajor/minor)	r+   rH   rI   rJ   r/   r   r0   ÚdataÚtype)r(   r'   r#   rH   s       r*   Útest_rpyProcessorÚServiceTests.test_rpyProcessoro   sz   € ð ×%Ñ%Ó'‰
ˆØ�
‰
�9Ó×(Ñ(ð;ô	
ð —‘˜i¨Ó.ˆØ×Ñ˜e¤TÔ*Ø×Ñ˜Ÿ™ YÔ/Ø×Ñ˜Ÿ™ ]Õ3r-   c                óü   • [        [        SS5      5      n[        U5      nU R                  U[        5        U R                  UR
                  [        5        U R                  UR
                  R                  U5        g)zo
L{makePersonalServerFactory} returns a PB server factory which has
as its root object a L{ResourcePublisher}.
s   foo barz
text/plainN)	r   r   r   r/   r   r#   r   ÚassertIdenticalÚsite)r(   rX   ÚserverFactorys      r*   Útest_makePersonalServerFactoryÚ+ServiceTests.test_makePersonalServerFactory   sb   € ô ”D˜ \Ó2Ó3ˆÜ1°$Ó7ˆØ×Ñ˜m¬_Ô=Ø×Ñ˜m×0Ñ0Ô2CÔDØ×Ñ˜]×/Ñ/×4Ñ4°dÕ;r-   c                ó´  • U R                  5       n[        5       nUR                  SSU-   S/5        [        U5      nUR	                  5         U R                  UR                  5        U R                  [        R                  R                  U5      5        U R                  [        R                  " [        R                  " U5      R                  5      5        g)z‘
The I{--personal} option to L{makeService} causes it to return a
service which will listen on the server address given by the I{--port}
option.
r5   r6   ú
--personalN)r$   r   r&   r   r7   r8   r9   r=   r>   r'   r?   r@   rA   rB   )r(   rC   r)   rD   s       r*   Útest_personalServerÚ ServiceTests.test_personalServerŒ   s“   € ð �{‰{‹}ˆÜ“)ˆØ×Ñ˜h¨°$©¸ÐEÔFÜ˜gÓ&ˆØ×ÑÔØ�‰˜×+Ñ+Ô,Ø�‰œŸ™Ÿ™ tÓ,Ô-Ø�‰œŸš¤b§g¢g¨d£m×&;Ñ&;Ó<Õ=r-   c                ó  • [        5       nUR                  S/5        [        R                  R	                  [        R                  R                  S[        R                  5      5      nU R                  US   S   SU 35        g)z¦
If the I{--port} option not specified but the I{--personal} option is,
L{Options} defaults the port to C{UserDirectory.userSocketName} in the
user's home directory.
r]   Ú~Úportsr   r6   N)	r   r&   r>   r'   Ú
expanduserÚjoinr   ÚuserSocketNamer0   )r(   r)   r'   s      r*   Útest_defaultPersonalPathÚ%ServiceTests.test_defaultPersonalPathŸ   sd   € ô “)ˆØ×Ñ˜l˜^Ô,Ü�w‰w×!Ñ!¤"§'¡'§,¡,¨s´M×4PÑ4PÓ"QÓRˆØ×Ñ˜ Ñ)¨!Ñ,°°d°V¨nÕ=r-   c                óš   • [        5       nUR                  / 5        U R                  [        R                  " US   S   S5      SS S5        g)zT
If the I{--port} option is not specified, L{Options} defaults the port
to C{8080}.
rb   r   Né   )ÚTCP)i�  N)r   r&   r0   r   Ú_parseServer©r(   r)   s     r*   Útest_defaultPortÚServiceTests.test_defaultPort®   sK   € ô
 “)ˆØ×Ñ˜RÔ Ø×ÑÜ×"Ò" 7¨7Ñ#3°AÑ#6¸Ó=¸b¸qÐAÐCXõ	
r-   c                óž   • [        5       nUR                  / SQ5        U R                  SUS   S   5        U R                  SUS   S   5        g)zA
If the I{--http} option is given twice, there are two listeners
)ú--listenztcp:8001rp   ztcp:8002Ú8001rb   r   Ú8002é   N©r   r&   ÚassertInrl   s     r*   Útest_twoPortsÚServiceTests.test_twoPorts¹   sJ   € ô “)ˆØ×ÑÒMÔNØ�‰�f˜g gÑ.¨qÑ1Ô2Ø�‰�f˜g gÑ.¨qÑ1Õ2r-   c                ó  • [        5       nUR                  S[        S-   /5        US   nU R                  U[        5        U R                  UR                  [        5        U R                  [        UR                  [        5      5        U R                  UR                  [        5        U R                  UR                  R                  5        [        [         [        5      R#                  S5        U R                  UR                  R                  5        U R                  UR                  R$                  5        [        [         [        5      R#                  S5        U R                  UR                  R$                  5        g)z¡
The I{--wsgi} option takes the fully-qualifed Python name of a WSGI
application object and creates a L{WSGIResource} at the root which
serves that application.
ú--wsgiz.applicationr#   ÚstartupÚshutdownN)r   r&   Ú__name__r=   r   rW   Ú_reactorr   Ú
isinstanceÚ_threadpoolr   Ú_applicationÚapplicationÚassertFalseÚstartedr   r   ÚfireSystemEventÚjoined)r(   r)   r#   s      r*   Ú	test_wsgiÚServiceTests.test_wsgiÂ   s  € ô “)ˆØ×Ñ˜h¬°>Ñ(AÐBÔCØ�v‰ˆØ�‰˜œlÔ+Ø×Ñ˜TŸ]™]¬GÔ4Ø�‰œ
 4×#3Ñ#3´ZÓ@ÔAØ×Ñ˜T×.Ñ.´Ô<ð 	×Ñ˜×)Ñ)×1Ñ1Ô2ÜŒ\œ7Ó#×3Ñ3°IÔ>Ø�‰˜×(Ñ(×0Ñ0Ô1Ø×Ñ˜×)Ñ)×0Ñ0Ô1ÜŒ\œ7Ó#×3Ñ3°JÔ?Ø�‰˜×(Ñ(×/Ñ/Õ0r-   c                óÀ   • [        5       n[        S-   S4 HE  nU R                  [        UR                  SU/5      nU R                  [        U5      SU< 35        MG     g)zV
If I{--wsgi} is given an invalid name, L{Options.parseOptions}
raises L{UsageError}.
z.nosuchthingzfoo.ry   zNo such WSGI application: N)r   r|   ÚassertRaisesr   r&   r0   Ústr)r(   r)   ÚnameÚexcs       r*   Útest_invalidApplicationÚ$ServiceTests.test_invalidApplicationØ   s[   € ô
 “)ˆÜ Ñ.°Ó7ˆDØ×#Ñ#¤J°×0DÑ0DÀxÐQUÐFVÓWˆCØ×ÑœS ›XÐ)CÀDÁ8Ð'LÖMò 8r-   zOpenSSL.SSLNzSSL module is available.c                óš   • [        5       nU R                  [        UR                  S/5      nU R	                  SUR
                  S   5        g)zX
An L{UsageError} is raised when C{https} is requested but there is no
support for SSL.
ú--https=443zSSL support not installedr   N)r   r‰   r   r&   r0   Úargs)r(   r)   Ú	exceptions      r*   Útest_HTTPSFailureOnMissingSSLÚ*ServiceTests.test_HTTPSFailureOnMissingSSLâ   sA   € ô “)ˆà×%Ñ%¤j°'×2FÑ2FÈÈÓXˆ	à×ÑÐ4°i·n±nÀQÑ6GÕHr-   zSSL module is not available.c                óœ   • [        5       nUR                  S/5        U R                  SUS   S   5        U R                  SUS   S   5        g)z=
When SSL support is present, it accepts the --https option.
r�   Ússlrb   r   Ú443Nrt   rl   s     r*   Ú test_HTTPSAcceptedOnAvailableSSLÚ-ServiceTests.test_HTTPSAcceptedOnAvailableSSLî   sK   € ô
 “)ˆà×Ñ˜m˜_Ô-à�‰�e˜W WÑ-¨aÑ0Ô1Ø�‰�e˜W WÑ-¨aÑ0Õ1r-   c                ól   • [        5       nUR                  / SQ5        U R                  US   SS/5        g)z5
When --add-header is specific, the value is parsed.
©ú--add-headerzK1: V1rœ   zK2: V2ÚextraHeaders©ÚK1ÚV1©ÚK2ÚV2N)r   r&   r0   rl   s     r*   Útest_add_header_parsingÚ$ServiceTests.test_add_header_parsingú   s4   € ô “)ˆØ×ÑÒQÔRØ×Ñ˜ Ñ0°<ÀÐ2NÕOr-   c                óV  • [        5       nUR                  / SQ5        [        U5      nUR                  S   R                  R
                  nU R                  U[        5        U R                  UR                  SS/5        U R                  UR                  [        R                  5        g)zR
When --add-header is specified, the resource is a composition that adds
headers.
r›   r   rž   r¡   N)r   r&   r   r:   r;   r<   r/   r   r0   Ú_headersÚ_originalResourcer   ÚTest)r(   r)   rD   r<   s       r*   Útest_add_header_resourceÚ%ServiceTests.test_add_header_resource  s†   € ô
 “)ˆØ×ÑÒQÔRÜ˜gÓ&ˆØ×#Ñ# AÑ&×.Ñ.×7Ñ7ˆØ×Ñ˜hÔ(;Ô<Ø×Ñ˜×*Ñ*¨\¸<Ð,HÔIØ×Ñ˜h×8Ñ8¼$¿)¹)ÕDr-   c                ó(  • [        5       nUR                  S/5        [        U5        U R                  U R                  /5      nU R                  US   S   [        5        U R                  US   S   S5        U R                  [        U5      S5        g)z'
Passing --notracebacks is deprecated.
z--notracebacksr   ÚcategoryÚmessagez/--notracebacks was deprecated in Twisted 19.7.0rs   N)r   r&   r   ÚflushWarningsÚtest_noTracebacksDeprecationr0   ÚDeprecationWarningÚlen)r(   r)   Úwarningss      r*   r°   Ú)ServiceTests.test_noTracebacksDeprecation  s‹   € ô “)ˆØ×ÑÐ.Ð/Ô0Ü�GÔà×%Ñ% t×'HÑ'HÐ&IÓJˆØ×Ñ˜ !™ ZÑ0Ô2DÔEØ×ÑØ�Q‰K˜	Ñ"Ð$Uô	
ð 	×Ñœ˜X›¨Õ*r-   c                ó¶   • [        5       nUR                  S/5        [        U5      nU R                  UR                  S   R
                  R                  5        g)zU
Passing --display-tracebacks will enable traceback rendering on the
generated Site.
z--display-tracebacksr   N)r   r&   r   r=   r:   r;   ÚdisplayTracebacks©r(   r)   rD   s      r*   Útest_displayTracebacksÚ#ServiceTests.test_displayTracebacks  sJ   € ô
 “)ˆØ×ÑÐ4Ð5Ô6Ü˜gÓ&ˆØ�‰˜×(Ñ(¨Ñ+×3Ñ3×EÑEÕFr-   c                ó´   • [        5       nUR                  / 5        [        U5      nU R                  UR                  S   R
                  R                  5        g)z\
Not passing --display-tracebacks will leave traceback rendering on the
generated Site off.
r   N)r   r&   r   r‚   r:   r;   r¶   r·   s      r*   Útest_displayTracebacksNotGivenÚ+ServiceTests.test_displayTracebacksNotGiven(  sH   € ô
 “)ˆØ×Ñ˜RÔ Ü˜gÓ&ˆØ×Ñ˜×)Ñ)¨!Ñ,×4Ñ4×FÑFÕGr-   © )Úreturnztuple[FilePath[str], File]©r¾   ÚNone)r|   Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r+   r2   r   r	   Ú
providedByr   rE   rK   rN   rT   rZ   r^   rf   rm   rv   r†   r�   r   r“   r˜   r¤   rª   r°   r¸   r»   Ú__static_attributes__r½   r-   r*   r   r   (   s0  † ñôô"/ñ Ø×#Ò# GÓ,Ô,Ø:óó>ó	ð>ô$IôLô4ô <ñ Ø×#Ò# GÓ,Ô,Ø:óó>ó	ð>ñ Ø×#Ò# GÓ,Ô,Ø:óó	>ó	ð	>ô	
ô3ô1ô,Nñ ‰M˜-Ó(°Ð4Ð6PÓQó	Ió Rð	Iñ ‰M˜-Ó(¨DÐ0Ð2PÓQó	2ó Rð	2ôPôEô+ôG÷Hr-   r   c                  ó   • \ rS rSrSS jrSrg)ÚAddHeadersResourceTestsi3  c                ó2  • [        [        R                  " 5       / SQ5      n[        / 5      nUR	                  SU5        U R                  UR                  R                  S5      SS/5        U R                  UR                  R                  S5      S/5        g)	zK
When getChildWithDefault is invoked, it adds the headers to the
response.
)rž   r¡   )rŸ   ÚV3Ú rŸ   r    rÊ   r¢   r£   N)r   r   r©   r   ÚgetChildWithDefaultr0   ÚresponseHeadersÚgetRawHeaders)r(   r<   Úrequests      r*   Útest_getChildWithDefaultÚ0AddHeadersResourceTests.test_getChildWithDefault4  s~   € ô
 'Ü�IŠI‹KÒCó
ˆô ˜rÓ"ˆØ×$Ñ$ R¨Ô1Ø×Ñ˜×0Ñ0×>Ñ>¸tÓDÀtÈTÀlÔSØ×Ñ˜×0Ñ0×>Ñ>¸tÓDÀtÀfÕMr-   r½   Nr¿   )r|   rÁ   rÂ   rÃ   rÐ   rÆ   r½   r-   r*   rÈ   rÈ   3  s   † ÷Nr-   rÈ   )6rÄ   Ú
__future__r   r>   r@   Útypingr   Úunittestr   Útwisted.internetr   r   Útwisted.internet.interfacesr   r	   Útwisted.python.filepathr
   Útwisted.python.reflectr   Útwisted.python.threadpoolr   Útwisted.python.usager   Útwisted.spread.pbr   Útwisted.trial.unittestr   Útwisted.webr   Útwisted.web.distribr   r   Útwisted.web.scriptr   Útwisted.web.serverr   Útwisted.web.staticr   r   Útwisted.web.tapr   r   r   r   Útwisted.web.test.requesthelperr   Útwisted.web.twcgir   Útwisted.web.wsgir   Úobjectr�   r   rÈ   r½   r-   r*   Ú<module>rç      s}   ðñõ #ã 	Û Ý Ý ç /ß BÝ ,Ý 0Ý 0Ý +Ý -Ý +Ý ß @Ý +Ý #ß )÷ó õ 8Ý 'Ý )á‹h€ôHH�8ô HHôVN˜hõ Nr-   