ó
    ×›‘hRF  ã                   ó¬  • S r SSKJr  SSKJr   SSKr\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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JrJ r J!r!  SSK"J#r#  SSK$J%r%  SSK&J'r'J(r(   " S S\ RR                  5      r* " S S\RV                  5      r+ " S S\,5      r- " S S\5      r. " S S5      r/ " S S\5      r0g! \ a    Sr N¼f = f)z#
Tests for L{twisted.web.distrib}.
é    )Úabspath)ÚparseStringN)ÚskipIf)ÚverifyObject)ÚdeferÚreactor)ÚglobalLogPublisher)ÚfailureÚfilepath)Úpb©Ú
SIZE_LIMIT)Úproto_helpers)ÚTestCase)ÚclientÚdistribÚresourceÚserverÚstatic)ÚHeaders)Ú_render)ÚDummyChannelÚDummyRequestc                   ó   • \ rS rSrSrg)ÚMySiteé#   © N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__static_attributes__r   ó    ÚaC:\Users\psant\Downloads\Noiseback\school\venv\Lib\site-packages\twisted/web/test/test_distrib.pyr   r   #   s   † Úr#   r   c                   ó"   • \ rS rSrSrSrS rSrg)ÚPBServerFactoryé'   z±
A PB server factory which keeps track of the most recent protocol it
created.

@ivar proto: L{None} or the L{Broker} instance most recently returned
    from C{buildProtocol}.
Nc                 ób   • [         R                  R                  X5      U l        U R                  $ ©N)r   r&   ÚbuildProtocolÚproto)ÚselfÚaddrs     r$   r*   ÚPBServerFactory.buildProtocol2   s$   € Ü×'Ñ'×5Ñ5°dÓAˆŒ
Ø�z‰zÐr#   )r+   )r   r   r    r!   Ú__doc__r+   r*   r"   r   r#   r$   r&   r&   '   s   † ñð €Eõr#   r&   c                   ó   • \ rS rSrSrSrg)ÚArbitraryErroré7   z
An exception for this test.
r   N)r   r   r    r!   r/   r"   r   r#   r$   r1   r1   7   s   † ôr#   r1   c                   ó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S rSrg)ÚDistribTestsé=   Nc                 óh  ^• [         R                  " 5       [         R                  " 5       /mU R                  bA  U R                  R                  b*  U R                  R                  R	                  U4S j5        OTS   R                  S5        U R                  bƒ  U R                  R                  bl  U R                  R                  R                  R	                  U4S j5        U R                  R                  R                  R                  R                  5         OTS   R                  S5        U R                  b)  TR                  U R                  R                  5       5        U R                  b)  TR                  U R                  R                  5       5        [         R                  " T5      $ )zs
Clean up all the event sources left behind by either directly by
test methods or indirectly via some distrib API.
Nc                  ó,   >• T S   R                  S 5      $ ©Nr   ©Úcallback©Údls   €r$   Ú<lambda>Ú'DistribTests.tearDown.<locals>.<lambda>J   s   ø€ °R¸±U·^±^ÀDÔ5Ir#   r   c                  ó,   >• T S   R                  S 5      $ )Né   r9   r;   s   €r$   r=   r>   N   s   ø€ ÀÀAÁÇÁÐPTÔAUr#   r@   )r   ÚDeferredÚf1r+   ÚnotifyOnDisconnectr:   ÚsubÚ	publisherÚbrokerÚ	transportÚloseConnectionÚport1ÚappendÚstopListeningÚport2ÚgatherResults)r,   r<   s    @r$   ÚtearDownÚDistribTests.tearDownC   s  ø€ ô
 �nŠnÓ¤§¢Ó 0Ð1ˆØ�7‰7Ñ 4§7¡7§=¡=Ñ#<Ø�G‰G�M‰M×,Ñ,Ô-IÕJàˆq‰E�N‰N˜4Ô Ø�8‰8Ñ D§H¡H×$6Ñ$6Ñ$BØ�H‰H×Ñ×%Ñ%×8Ñ8Ô9UÔVØ�H‰H×Ñ×%Ñ%×/Ñ/×>Ñ>Õ@àˆq‰E�N‰N˜4Ô Ø�:‰:Ñ!Ø�I‰I�d—j‘j×.Ñ.Ó0Ô1Ø�:‰:Ñ!Ø�I‰I�d—j‘j×.Ñ.Ó0Ô1Ü×"Ò" 2Ó&Ð&r#   c                 óª  • [         R                  " 5       nUR                  S[        R                  " SS5      5        [
        R                  " U5      n[        [        R                  " U5      5      U l
        [        R                  " SU R                  5      U l        [        R                  " SU R                  R                  5       R                   5      U l        [         R                  " 5       nUR                  SU R"                  5        [%        U5      n[        R                  " SU5      U l        [(        R*                  " [        5      nSU R&                  R                  5       R                    S3nUR-                  S	5      nUR/                  S
U5      nUR1                  [(        R2                  5        UR1                  U R4                  S5        U$ )Ns   theres   rootz
text/plainr   ú	127.0.0.1s   herezhttp://127.0.0.1:z/here/thereÚasciió   GET)r   ÚResourceÚputChildr   ÚDatar   ÚSiter&   r   ÚResourcePublisherrB   r   Ú	listenTCPrI   ÚResourceSubscriptionÚgetHostÚportrD   r   rL   r   ÚAgentÚencodeÚrequestÚaddCallbackÚreadBodyÚassertEqual)r,   Úr1Úsite1Úr2Úf2ÚagentÚurlÚds           r$   ÚtestDistribÚDistribTests.testDistribX   s@  € ä×ÒÓ ˆØ
�‰�HœfŸkšk¨'°<Ó@ÔAÜ—’˜B“ˆÜ!¤'×";Ò";¸EÓ"BÓCˆŒÜ×&Ò& q¨$¯'©'Ó2ˆŒ
Ü×/Ò/°¸T¿Z¹Z×=OÑ=OÓ=Q×=VÑ=VÓWˆŒÜ×ÒÓ ˆØ
�‰�G˜TŸX™XÔ&Ü�B‹ZˆÜ×&Ò& q¨"Ó-ˆŒ
Ü—’œWÓ%ˆØ! $§*¡*×"4Ñ"4Ó"6×";Ñ";Ð!<¸KÐHˆØ�j‰j˜Ó!ˆØ�M‰M˜& #Ó&ˆØ	�‰”f—o‘oÔ&Ø	�‰�d×&Ñ&¨Ô0Øˆr#   c                 ób  • [         R                  " 5       nUR                  SU5        [        R                  " U5      n[        [        R                  " U5      5      =U l        n[        R                  " SUSS9nU R                  UR                  5        UR                  5       n[        R                  " UR                  UR                   5      =U l        n[        R                  " U5      n[        R                  " SUSS9n	U R                  U	R                  5        U	R                  5       n
Xš4$ )zÓ
Set up a resource on a distrib site using L{ResourcePublisher}.

@param child: The resource to publish using distrib.

@return: A tuple consisting of the host and port on which to contact
    the created site.
s   childr   rQ   )Ú	interface)r   rT   rU   r   rW   r&   r   rX   rB   r   rY   Ú
addCleanuprK   r[   rZ   Úhostr\   rD   )r,   ÚchildÚdistribRootÚdistribSiteÚdistribFactoryÚdistribPortr-   ÚmainRootÚmainSiteÚmainPortÚmainAddrs              r$   Ú_setupDistribServerÚ DistribTests._setupDistribServerl   só   € ô ×'Ò'Ó)ˆØ×Ñ˜X uÔ-Ü—k’k +Ó.ˆÜ#2Ü×%Ò% kÓ2ó$
ð 	
ˆŒ�.ô ×'Ò'¨¨>À[ÑQˆØ�‰˜×1Ñ1Ô2Ø×"Ñ"Ó$ˆä%×:Ò:¸4¿9¹9ÀdÇiÁiÓPÐPˆŒ�8Ü—;’;˜xÓ(ˆÜ×$Ò$ Q¨¸KÑHˆØ�‰˜×.Ñ.Ô/Ø×#Ñ#Ó%ˆàÐ!Ð!r#   c                 ó"  • U R                  U5      u  p4[        R                  " [        5      nSUR                   SUR
                   S3nUR                  S5      nUR                  " SU40 UD6nUR                  [        R                  5        U$ )ai  
Set up a resource on a distrib site using L{ResourcePublisher} and
then retrieve it from a L{ResourceSubscription} via an HTTP client.

@param child: The resource to publish using distrib.
@param **kwargs: Extra keyword arguments to pass to L{Agent.request} when
    requesting the resource.

@return: A L{Deferred} which fires with the result of the request.
úhttp://Ú:ú/childrR   rS   )
ry   r   r]   r   ro   r\   r^   r_   r`   ra   )r,   rp   Úkwargsrw   rx   rg   rh   ri   s           r$   Ú_requestTestÚDistribTests._requestTest‡   sy   € ð "×5Ñ5°eÓ<ÑˆÜ—’œWÓ%ˆØ˜Ÿ™� a¨¯© °fÐ=ˆØ�j‰j˜Ó!ˆØ�MŠM˜& #Ñ0¨Ñ0ˆØ	�‰”f—o‘oÔ&Øˆr#   c                 ó  • U R                  U5      u  p4SUR                   SUR                   S3nUR                  S5      n[        R
                  " [        5      R                  " SU40 UD6nS nUR                  U5        U$ )aó  
Set up a resource on a distrib site using L{ResourcePublisher} and
then retrieve it from a L{ResourceSubscription} via an HTTP client.

@param child: The resource to publish using distrib.
@param **kwargs: Extra keyword arguments to pass to L{Agent.request} when
    requesting the resource.

@return: A L{Deferred} which fires with a tuple consisting of a
    L{twisted.test.proto_helpers.AccumulatingProtocol} containing the
    body of the response and an L{IResponse} with the response itself.
r|   r}   r~   rR   rS   c                 óº   ^ ^• [         R                  " 5       mT R                  T5        [        R                  " 5       =nTl        UR                  UU 4S j5        U$ )Nc                 ó   >• TT4$ r)   r   )Ú_ÚprotocolÚresponses    €€r$   r=   ÚGDistribTests._requestAgentTest.<locals>.cbCollectBody.<locals>.<lambda>±   s
   ø€  X¨xÑ$8r#   )r   ÚAccumulatingProtocolÚdeliverBodyr   rA   ÚclosedDeferredr`   )r‡   ri   r†   s   ` @r$   ÚcbCollectBodyÚ5DistribTests._requestAgentTest.<locals>.cbCollectBody­   sE   ù€ Ü$×9Ò9Ó;ˆHØ× Ñ  Ô*Ü*/¯.ª.Ó*:Ð:ˆA�Ô'Ø�M‰MÕ8Ô9ØˆHr#   )	ry   ro   r\   r^   r   r]   r   r_   r`   )r,   rp   r   rw   rx   rh   ri   rŒ   s           r$   Ú_requestAgentTestÚDistribTests._requestAgentTestš   sy   € ð "×5Ñ5°eÓ<Ñˆà˜Ÿ™� a¨¯© °fÐ=ˆØ�j‰j˜Ó!ˆÜ�LŠLœÓ!×)Ò)¨&°#Ñ@¸Ñ@ˆò	ð 	
�‰�mÔ$Øˆr#   c                 ó.  ^ ^^^^• 0 m[         R                  " 5       m[        R                  " T5        S/m " UU4S jS[        R
                  5      nUUU 4S jmT R                  U" 5       [        SS/05      S9nUUU 4S jnUR                  U5        U$ )	zn
The request headers are available on the request object passed to a
distributed resource's C{render} method.
Nc                   ó$   >• \ rS rSrU U4S jrSrg)Ú>DistribTests.test_requestHeaders.<locals>.ReportRequestHeaderséÁ   c                 ót   >• UTS'   TR                  [        UR                  R                  5       5      5        g)Nr   r#   )ÚupdateÚdictÚrequestHeadersÚgetAllRawHeaders)r,   r_   Úreqr—   s     €€r$   ÚrenderÚEDistribTests.test_requestHeaders.<locals>.ReportRequestHeaders.renderÂ   s1   ø€ Ø ��A‘Ø×%Ñ%¤d¨7×+AÑ+A×+RÑ+RÓ+TÓ&UÔVØr#   r   N©r   r   r    r!   rš   r"   )r™   r—   s   €€r$   ÚReportRequestHeadersr’   Á   s   ø† ÷ñ r#   r�   c                  óÖ   >• T V s/ s H  o S   PM	     nn TR                  SU5        TR                  SU5        TR                  TS   U5        [        R                  " T5        g s  sn f )NÚ
log_formatzconnected to publisherz3could not connect to distributed web service: {msg}r   )ÚassertInr	   ÚremoveObserver)ÚeÚmsgsÚlogObserverr™   r,   s     €€€r$   Ú
check_logsÚ4DistribTests.test_requestHeaders.<locals>.check_logsÇ   s]   ø€ Ù-8Ó9ª[¨�l”O©[ˆDÐ9Ø�M‰MÐ2°DÔ9Ø�M‰MÐOÐQUÔVØ�M‰M˜#˜a™& $Ô'Ü×-Ò-¨kÕ:ùò	 :s   †A&ÚfooÚbar)Úheadersc                 ó|   >• TR                   R                  R                  T5        TR                  TS   S/5        g )Ns   Foos   bar)rB   r+   rC   rb   )Úresultr¥   r—   r,   s    €€€r$   ÚcbRequestedÚ5DistribTests.test_requestHeaders.<locals>.cbRequestedÒ   s0   ø€ Ø�G‰G�M‰M×,Ñ,¨ZÔ8Ø×Ñ˜^¨FÑ3°f°XÕ>r#   )	r   ÚEventLoggingObserverr	   ÚaddObserverr   rT   r€   r   r`   )r,   r�   r_   r¬   r¥   r¤   r™   r—   s   `   @@@@r$   Útest_requestHeadersÚ DistribTests.test_requestHeaders·   sŽ   ü€ ð
 ˆÜ#×8Ò8Ó:ˆÜ×&Ò& {Ô3Øˆfˆ÷	ð 	¤8×#4Ñ#4ô 	÷	;ð ×#Ñ#Ù Ó"¬G°U¸U¸GÐ4DÓ,Eð $ð 
ˆ÷	?ð 	×Ñ˜KÔ(Øˆr#   c                 ó”   ^ •  " S S[         R                  5      nT R                  U" 5       5      nU 4S jnUR                  U5        U$ )zi
The response code can be set by the request object passed to a
distributed resource's C{render} method.
c                   ó   • \ rS rSrS rSrg)Ú>DistribTests.test_requestResponseCode.<locals>.SetResponseCodeéß   c                 ó&   • UR                  S5        g)NéÈ   Ú ©ÚsetResponseCode©r,   r_   s     r$   rš   ÚEDistribTests.test_requestResponseCode.<locals>.SetResponseCode.renderà   s   € Ø×'Ñ'¨Ô,Ør#   r   Nrœ   r   r#   r$   ÚSetResponseCoder´   ß   ó   † õr#   r½   c                 óÀ   >• TR                  U S   R                  S5        TR                  U S   R                  S5        TR                  U S   R                  S5        g )Nr   r#   r@   r·   s   OK©rb   ÚdataÚcodeÚphrase©r«   r,   s    €r$   r¬   Ú:DistribTests.test_requestResponseCode.<locals>.cbRequestedæ   sM   ø€ Ø×Ñ˜V A™YŸ^™^¨SÔ1Ø×Ñ˜V A™YŸ^™^¨SÔ1Ø×Ñ˜V A™Y×-Ñ-¨uÕ5r#   ©r   rT   rŽ   r`   ©r,   r½   r_   r¬   s   `   r$   Útest_requestResponseCodeÚ%DistribTests.test_requestResponseCodeÙ   sD   ø€ ô	œh×/Ñ/ô 	ð
 ×(Ñ(©Ó):Ó;ˆõ	6ð
 	×Ñ˜KÔ(Øˆr#   c                 ó”   ^ •  " S S[         R                  5      nT R                  U" 5       5      nU 4S jnUR                  U5        U$ )zu
The response code and message can be set by the request object passed to
a distributed resource's C{render} method.
c                   ó   • \ rS rSrS rSrg)ÚEDistribTests.test_requestResponseCodeMessage.<locals>.SetResponseCodeéô   c                 ó(   • UR                  SS5        g)Nr·   ó   some-messager¸   r¹   r»   s     r$   rš   ÚLDistribTests.test_requestResponseCodeMessage.<locals>.SetResponseCode.renderõ   s   € Ø×'Ñ'¨¨_Ô=Ør#   r   Nrœ   r   r#   r$   r½   rÌ   ô   r¾   r#   r½   c                 óÀ   >• TR                  U S   R                  S5        TR                  U S   R                  S5        TR                  U S   R                  S5        g )Nr   r#   r@   r·   rÏ   rÀ   rÄ   s    €r$   r¬   ÚADistribTests.test_requestResponseCodeMessage.<locals>.cbRequestedû   sM   ø€ Ø×Ñ˜V A™YŸ^™^¨SÔ1Ø×Ñ˜V A™YŸ^™^¨SÔ1Ø×Ñ˜V A™Y×-Ñ-¨Õ?r#   rÆ   rÇ   s   `   r$   Útest_requestResponseCodeMessageÚ,DistribTests.test_requestResponseCodeMessageî   sE   ø€ ô	œh×/Ñ/ô 	ð
 ×(Ñ(©Ó):Ó;ˆõ	@ð
 	×Ñ˜KÔ(Øˆr#   c                 ó°   •  " S S[         R                  5      nU R                  U" 5       5      nUR                  U R                  S[
        -  S-   5        U$ )z¾
If a string longer than the Banana size limit is passed to the
L{distrib.Request} passed to the remote resource, it is broken into
smaller strings to be transported over the PB connection.
c                   ó   • \ rS rSrS rSrg)Ú0DistribTests.test_largeWrite.<locals>.LargeWritei
  c                 óx   • UR                  S[        -  S-   5        UR                  5         [        R                  $ ©Nó   xó   y)Úwriter   Úfinishr   ÚNOT_DONE_YETr»   s     r$   rš   Ú7DistribTests.test_largeWrite.<locals>.LargeWrite.render  s.   € Ø—‘˜d¤ZÑ/°$Ñ6Ô7Ø—‘Ô Ü×*Ñ*Ð*r#   r   Nrœ   r   r#   r$   Ú
LargeWriter×   
  s   † õ+r#   rà   rÚ   rÛ   ©r   rT   r€   r`   rb   r   )r,   rà   r_   s      r$   Útest_largeWriteÚDistribTests.test_largeWrite  sM   € ô	+œ×*Ñ*ô 	+ð ×#Ñ#¡J£LÓ1ˆØ×Ñ˜D×,Ñ,¨d´ZÑ.?À$Ñ.FÔGØˆr#   c                 ó°   •  " S S[         R                  5      nU R                  U" 5       5      nUR                  U R                  S[
        -  S-   5        U$ )zˆ
Like L{test_largeWrite}, but for the case where C{render} returns a
long string rather than explicitly passing it to L{Request.write}.
c                   ó   • \ rS rSrS rSrg)Ú2DistribTests.test_largeReturn.<locals>.LargeReturni  c                 ó   • S[         -  S-   $ rÙ   r   r»   s     r$   rš   Ú9DistribTests.test_largeReturn.<locals>.LargeReturn.render  s   € ØœjÑ(¨4Ñ/Ð/r#   r   Nrœ   r   r#   r$   ÚLargeReturnræ     s   † õ0r#   ré   rÚ   rÛ   rá   )r,   ré   r_   s      r$   Útest_largeReturnÚDistribTests.test_largeReturn  sM   € ô	0œ(×+Ñ+ô 	0ð ×#Ñ#¡K£MÓ2ˆØ×Ñ˜D×,Ñ,¨d´ZÑ.?À$Ñ.FÔGØˆr#   c                 ó\  ^ ^• [        [        R                  " 5       5      =T l        n[        R
                  " SU5      =T l        n[        R                  " SUR                  5       R                  5      =T l        n[        S/5      m[        UT5      nUU 4S jnUR                  U5        U$ )zb
If there is an error issuing the request to the remote publisher, an
error response is returned.
r   rQ   r#   c                 ó  >• TR                  TR                  S5        TR                  [        R                  5      nTR                  [        U5      S5        / SQnTR                  SR                  U5      /TR                  5        g )Niô  r@   )
r#   s   <html>s:     <head><title>500 - Server Connection Lost</title></head>s     <body>s#       <h1>Server Connection Lost</h1>s¦       <p>Connection to distributed server lost:<pre>[Failure instance: Traceback from remote host -- twisted.spread.flavors.NoSuchMethod: No such method: remote_requests   ]</pre></p>s	     </body>s   </html>r#   ó   
)rb   ÚresponseCodeÚflushLoggedErrorsr   ÚNoSuchMethodÚlenÚjoinÚwritten)ÚignoredÚerrorsÚexpectedr_   r,   s      €€r$   Ú
cbRenderedÚ4DistribTests.test_connectionLost.<locals>.cbRendered2  sl   ø€ Ø×Ñ˜W×1Ñ1°3Ô7ð ×+Ñ+¬B¯O©OÓ<ˆFØ×ÑœS ›[¨!Ô,òˆHð  ×Ñ˜eŸj™j¨Ó2Ð3°W·_±_ÕEr#   )r&   r   ÚRootrB   r   rY   rI   r   rZ   r[   r\   rD   r   r   r`   )r,   ÚserverFactoryÚ
serverPortÚsubscriptionri   rø   r_   s   `     @r$   Útest_connectionLostÚ DistribTests.test_connectionLost"  s•   ù€ ô #2´"·'²'³)Ó"<Ð<ˆŒ�-Ü")×"3Ò"3°A°}Ó"EÐEˆŒ
�Zä")×">Ò">Ø˜×+Ñ+Ó-×2Ñ2ó#
ð 	
ˆŒ�<ô  ˜uÓ%ˆÜ�L 'Ó*ˆö	Fð2 	
�‰�jÔ!Øˆr#   c                 óT  • [         R                  R                  U [        5      n[        R
                  " [        5       5      n[        S/5      n[        R                  " U5      nUR                  U5        U R                  S[        U5      5        U R                  SUS   S   5        g)zA
When a request fails, the string form of the failure is logged.
r#   r@   zFailure instancer   rŸ   N)r   r®   ÚcreateWithCleanupr	   r
   ÚFailurer1   r   r   ÚIssueÚfailedÚassertEqualsrò   r    )r,   r¤   Úfr_   Úissues        r$   Útest_logFailedÚDistribTests.test_logFailedN  s…   € ô $×8Ñ8×JÑJØÔ$ó
ˆô �OŠOœNÓ,Ó-ˆÜ ˜uÓ%ˆÜ—’˜gÓ&ˆØ�‰�QŒØ×Ñ˜!œS Ó-Ô.Ø�‰Ð(¨+°a©.¸Ñ*FÕGr#   c                 óz  • [         R                  R                  U [        5      n[	        5       n[
        R                  " U5      n[        R                  " [        5       5      nUR                  U5        U R                  [        5        U R                  S[        U5      5        U R                  US   S   U5        g)zN
When L{twisted.web.distrib.Request}'s fail is called, the failure
is logged.
r@   r   Úlog_failureN)r   r®   r  r	   r1   r
   r  r   ÚRequestr   Úfailrð   r  rò   ÚassertIs)r,   r¤   Úerrr  r™   s        r$   Útest_requestFailÚDistribTests.test_requestFail]  s�   € ô
 $×8Ñ8×JÑJØÔ$ó
ˆô ÓˆÜ�OŠO˜CÓ ˆÜ�oŠoœl›nÓ-ˆØ�‰�ŒØ×Ñœ~Ô.Ø×Ñ˜!œS Ó-Ô.Ø�‰�k !‘n ]Ñ3°QÕ7r#   )rB   rI   rL   rD   )r   r   r    r!   rI   rL   rD   rB   rN   rj   ry   r€   rŽ   r°   rÈ   rÓ   râ   rê   rþ   r  r  r"   r   r#   r$   r4   r4   =   sZ   † Ø€EØ€EØ
€CØ	€Bò'ò*ò("ò6ò&ò: òDò*ò*ò"ò*òXHõ8r#   r4   c                   ó&   • \ rS rSrS rS rS rSrg)Ú_PasswordDatabasein  c                 ó   • Xl         g r)   ©Ú_users)r,   Úuserss     r$   Ú__init__Ú_PasswordDatabase.__init__o  s   € Ø�r#   c                 ó,   • [        U R                  5      $ r)   )Úiterr  ©r,   s    r$   ÚgetpwallÚ_PasswordDatabase.getpwallr  s   € Ü�D—K‘KÓ Ð r#   c                 óV   • U R                    H  nUS   U:X  d  M  Us  $    [        5       er8   )r  ÚKeyError)r,   ÚusernameÚusers      r$   ÚgetpwnamÚ_PasswordDatabase.getpwnamu  s+   € Ø—K”KˆDØ�A‰w˜(Õ"Ø’ñ  ô ‹jÐr#   r  N)r   r   r    r!   r  r  r#  r"   r   r#   r$   r  r  n  s   † òò!õr#   r  c                   ó‚   • \ rS rSrSrS rS rS\SS4S jrS	 r	S
 r
S rS rS rS r\" \(       + S5      S 5       rSrg)ÚUserDirectoryTestsi|  z^
Tests for L{UserDirectory}, a resource for listing all user resources
available on a system.
c                 ó
  • SSSSSU R                  5       S4U l        SSSS	S
U R                  5       S4U l        [        U R                  U R                  /5      U l        [
        R                  " U R                  5      U l        g )NÚaliceÚxé{   iÈ  zAlice,,,z/bin/shÚbobéê   i7  zBob,,,)Úmktempr(  r+  r  Údatabaser   ÚUserDirectoryÚ	directoryr  s    r$   ÚsetUpÚUserDirectoryTests.setUp‚  si   € Ø˜s C¨¨j¸$¿+¹+»-ÈÐSˆŒ
Ø˜3  S¨(°D·K±K³MÀ9ÐMˆŒÜ)¨4¯:©:°t·x±xÐ*@ÓAˆŒÜ ×.Ò.¨t¯}©}Ó=ˆ�r#   c                 ój   • U R                  [        [        R                  U R                  5      5        g)z;
L{UserDirectory} instances provide L{resource.IResource}.
N)Ú
assertTruer   r   Ú	IResourcer0  r  s    r$   Útest_interfaceÚ!UserDirectoryTests.test_interfaceˆ  s!   € ð 	�‰œ¤X×%7Ñ%7¸¿¹ÓHÕIr#   ÚnameÚreturnNc              ƒ   óÀ   #   • [        U/5      nU R                  R                  X5      n[        X25      nUI Sh  v•N   U R	                  UR
                  S5        g N!7f)zZ
Verify that requesting the C{name} child of C{self.directory} results
in a 404 response.
Ni”  )r   r0  ÚgetChildr   rb   rï   )r,   r8  r_   r«   ri   s        r$   Ú_404TestÚUserDirectoryTests._404TestŽ  sS   é € ô
  ˜vÓ&ˆØ—‘×(Ñ(¨Ó7ˆÜ�FÓ$ˆØ�ˆØ×Ñ˜×-Ñ-¨sÕ3ñ 	ùs   ‚8AºA»"Ac              ƒ   óB   #   • U R                  S5      I Sh  v•N   g N7f)z�
L{UserDirectory.getChild} returns a resource which renders a 404
response when passed a string which does not correspond to any known
user.
s   carolN©r<  r  s    r$   Útest_getInvalidUserÚ&UserDirectoryTests.test_getInvalidUser™  ó   é € ð �m‰m˜HÓ%×%Ó%ùó   ‚—˜c              ƒ   óB   #   • U R                  S5      I Sh  v•N   g N7f)z¾
L{UserDirectory.getChild} returns a resource which renders a 404
response when passed a string which corresponds to a known user who has
neither a user directory nor a user distrib socket.
s   aliceNr?  r  s    r$   Útest_getUserWithoutResourceÚ.UserDirectoryTests.test_getUserWithoutResource¡  rB  rC  c                 óh  • [         R                  " U R                  S   5      nUR                  S5      nUR	                  5         [        S/5      nU R                  R                  SU5      nU R                  U[        R                  5        U R                  UR                  UR                  5        g)z™
L{UserDirectory.getChild} returns a L{static.File} instance when passed
the name of a user with a home directory containing a I{public_html}
directory.
éþÿÿÿÚpublic_htmlr+  s   bobN)r   ÚFilePathr+  rp   Úmakedirsr   r0  r;  ÚassertIsInstancer   ÚFilerb   Úpath)r,   ÚhomerI  r_   r«   s        r$   Útest_getPublicHTMLChildÚ*UserDirectoryTests.test_getPublicHTMLChild©  s†   € ô × Ò  §¡¨"¡Ó.ˆØ—j‘j Ó/ˆØ×ÑÔÜ ˜wÓ'ˆØ—‘×(Ñ(¨°Ó9ˆØ×Ñ˜f¤f§k¡kÔ2Ø×Ñ˜Ÿ™ k×&6Ñ&6Õ7r#   c                 ó²  • [         R                  " U R                  S   5      nUR                  5         UR	                  S5      n[        S/5      nU R                  R                  SU5      nU R                  U[        R                  5        U R                  UR                  S5        U R                  [        UR                  5      UR                  5        g)zÀ
L{UserDirectory.getChild} returns a L{ResourceSubscription} instance
when passed the name of a user suffixed with C{".twistd"} who has a
home directory containing a I{.twistd-web-pb} socket.
rH  ú.twistd-web-pbr+  s
   bob.twistdÚunixN)r   rJ  r+  rK  rp   r   r0  r;  rL  r   rZ   rb   ro   r   r\   rN  )r,   rO  Úwebr_   r«   s        r$   Útest_getDistribChildÚ'UserDirectoryTests.test_getDistribChild·  s�   € ô × Ò  §¡¨"¡Ó.ˆØ�‰ŒØ�j‰jÐ)Ó*ˆÜ ˜wÓ'ˆØ—‘×(Ñ(¨¸Ó@ˆØ×Ñ˜f¤g×&BÑ&BÔCØ×Ñ˜Ÿ™ fÔ-Ø×Ñœ §¡Ó-¨s¯x©xÕ8r#   c                 ó”   • [        S/5      nSUl        U R                  [        R                  U R
                  R                  U5        g)zZ
L{UserDirectory.render} raises L{UnsupportedMethod} in response to a
non-I{GET} request.
r¸   ÚPOSTN)r   ÚmethodÚassertRaisesr   ÚUnsupportedMethodr0  rš   r»   s     r$   Útest_invalidMethodÚ%UserDirectoryTests.test_invalidMethodÆ  s9   € ô
  ˜tÓ$ˆØˆŒØ×Ñœ&×2Ñ2°D·N±N×4IÑ4IÈ7ÕSr#   c                 ó¨  ^ ^• [         R                  " T R                  S   5      R                  S5      nUR	                  5         [         R                  " T R
                  S   5      nUR	                  5         UR                  S5      R                  S5        [        S/5      m[        T R                  T5      nUU 4S jnUR                  U5        U$ )ze
L{UserDirectory} renders a list of links to available user content
in response to a I{GET} request.
rH  rI  rS  r#   r¸   c                 óx  >• [        SR                  TR                  5      5      nUR                  S5      u  p#TR	                  UR
                  R                  S5        TR	                  UR
                  R                  S5      S5        TR	                  UR
                  R
                  R                  S5        TR	                  UR
                  R                  S5        TR	                  UR
                  R                  S5      S5        TR	                  UR
                  R
                  R                  S5        g )	Nr#   ÚliÚaÚhrefzalice/zAlice (file)zbob.twistd/zBob (twistd))	r   ró   rô   ÚgetElementsByTagNamerb   Ú
firstChildÚtagNameÚgetAttributerÁ   )rõ   Údocumentr(  r+  r_   r,   s       €€r$   rø   Ú2UserDirectoryTests.test_render.<locals>.cbRenderedà  sæ   ø€ Ü" 3§8¡8¨G¯O©OÓ#<Ó=ˆHð $×8Ñ8¸Ó>‰LˆUØ×Ñ˜U×-Ñ-×5Ñ5°sÔ;Ø×Ñ˜U×-Ñ-×:Ñ:¸6ÓBÀHÔMØ×Ñ˜U×-Ñ-×8Ñ8×=Ñ=¸~ÔNØ×Ñ˜SŸ^™^×3Ñ3°SÔ9Ø×Ñ˜SŸ^™^×8Ñ8¸Ó@À-ÔPØ×Ñ˜SŸ^™^×6Ñ6×;Ñ;¸^ÕLr#   )r   rJ  r(  rp   rK  r+  Ú
setContentr   r   r0  r`   )r,   rI  rU  r«   rø   r_   s   `    @r$   Útest_renderÚUserDirectoryTests.test_renderÏ  s¦   ù€ ô
 ×'Ò'¨¯
©
°2©Ó7×=Ñ=¸mÓLˆØ×ÑÔÜ×Ò §¡¨¡Ó-ˆØ�‰Œð 	�	‰	Ð"Ó#×.Ñ.¨sÔ3ä ˜tÓ$ˆÜ˜Ÿ™¨Ó1ˆö
	Mð 	×Ñ˜:Ô&Øˆr#   zpwd module requiredc                 ón   • [         R                  " 5       nU R                  UR                  [        5        g)zl
If L{UserDirectory} is instantiated with no arguments, it uses the
L{pwd} module as its password database.
N)r   r/  ÚassertIdenticalÚ_pwdÚpwd)r,   r0  s     r$   Útest_passwordDatabaseÚ(UserDirectoryTests.test_passwordDatabaseï  s&   € ô ×)Ò)Ó+ˆ	Ø×Ñ˜YŸ^™^¬SÕ1r#   )r(  r+  r.  r0  )r   r   r    r!   r/   r1  r6  Úbytesr<  r@  rE  rP  rV  r]  rk  r   rp  rq  r"   r   r#   r$   r&  r&  |  sc   † ñò
>òJð	4 5ð 	4¨Tô 	4ò&ò&ò8ò9òTòñ@ �ŒGÐ*Ó+ñ2ó ,ó2r#   r&  )1r/   Úos.pathr   Úxml.dom.minidomr   rp  ro  ÚImportErrorÚunittestr   Úzope.interface.verifyr   Útwisted.internetr   r   Útwisted.loggerr	   Útwisted.pythonr
   r   Útwisted.spreadr   Útwisted.spread.bananar   Útwisted.testr   Útwisted.trial.unittestr   Útwisted.webr   r   r   r   r   Útwisted.web.http_headersr   Útwisted.web.test._utilr   Útwisted.web.test.requesthelperr   r   rW   r   r&   Ú	Exceptionr1   r4   r  r&  r   r#   r$   Ú<module>r…     s·   ðñõ Ý 'ðÛð €Cå å .ç +Ý -ß ,Ý Ý ,Ý &Ý +ß AÕ AÝ ,Ý *ß Eô	ˆV�[‰[ô 	ô�b×(Ñ(ô ô �Yô ôn8�8ô n8÷b	ñ ôz2˜õ z2øð_ ó Ø
‚Cðús   �C ÃCÃC