§
    ÈtºfRF  ã                   ó¾  — d Z ddlmZ ddlmZ 	 ddlZeZn# e$ r dZY nw xY wddlm	Z	 ddl
mZ ddlmZmZ ddlmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZmZmZm Z m!Z! ddl"m#Z# ddl$m%Z% ddl&m'Z'm(Z(  G d„ de j)        ¦  «        Z* G d„ dej+        ¦  «        Z+ G d„ de,¦  «        Z- G d„ de¦  «        Z. G d„ d¦  «        Z/ G d„ de¦  «        Z0dS )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                   ó   — e Zd ZdS )ÚMySiteN)Ú__name__Ú
__module__Ú__qualname__© ó    ú\/var/www/surfInsights/venv3-11/lib/python3.11/site-packages/twisted/web/test/test_distrib.pyr   r   #   s   € € € € € Ø€Dr    r   c                   ó   — e Zd ZdZdZd„ ZdS )ÚPBServerFactoryzÅ
    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                 óZ   — t           j                             | |¦  «        | _        | j        S ©N)r   r#   ÚbuildProtocolÚproto)ÚselfÚaddrs     r!   r&   zPBServerFactory.buildProtocol2   s$   € ÝÔ'×5Ò5°d¸DÑAÔAˆŒ
ØŒzÐr    )r   r   r   Ú__doc__r'   r&   r   r    r!   r#   r#   '   s4   € € € € € ðð ð €Eðð ð ð ð r    r#   c                   ó   — e Zd ZdZdS )ÚArbitraryErrorz%
    An exception for this test.
    N)r   r   r   r*   r   r    r!   r,   r,   7   s   € € € € € ðð ð ð r    r,   c                   ól   — 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„ ZdS )ÚDistribTestsNc                 óâ  ‡— t          j        ¦   «         t          j        ¦   «         gŠ| j        �/| j        j        �#| j        j                             ˆfd„¦  «         n‰d                              d¦  «         | j        �\| j        j        �P| j        j        j                             ˆfd„¦  «         | j        j        j        j	         
                    ¦   «          n‰d                              d¦  «         | j        �,‰                     | j                             ¦   «         ¦  «         | j        �,‰                     | j                             ¦   «         ¦  «         t          j        ‰¦  «        S )z‹
        Clean up all the event sources left behind by either directly by
        test methods or indirectly via some distrib API.
        Nc                  ó:   •— ‰ d                               d ¦  «        S ©Nr   ©Úcallback©Údls   €r!   ú<lambda>z'DistribTests.tearDown.<locals>.<lambda>J   s   ø€ °R¸´U·^²^ÀDÑ5IÔ5I€ r    r   c                  ó:   •— ‰ d                               d ¦  «        S )Né   r2   r4   s   €r!   r6   z'DistribTests.tearDown.<locals>.<lambda>N   s   ø€ ÀÀAÄÇÂÐPTÑAUÔAU€ r    r8   )r   ÚDeferredÚf1r'   ÚnotifyOnDisconnectr3   ÚsubÚ	publisherÚbrokerÚ	transportÚloseConnectionÚport1ÚappendÚstopListeningÚport2ÚgatherResults)r(   r5   s    @r!   ÚtearDownzDistribTests.tearDownC   s:  ø€ õ
 ŒnÑÔ¥¤Ñ 0Ô 0Ð1ˆØŒ7Ð 4¤7¤=Ð#<ØŒGŒM×,Ò,Ð-IÐ-IÐ-IÐ-IÑJÔJÐJÐJàˆqŒE�NŠN˜4Ñ Ô Ð ØŒ8Ð D¤HÔ$6Ð$BØŒHÔÔ%×8Ò8Ð9UÐ9UÐ9UÐ9UÑVÔVÐVØŒHÔÔ%Ô/×>Ò>Ñ@Ô@Ð@Ð@àˆqŒE�NŠN˜4Ñ Ô Ð ØŒ:Ð!Ø�IŠI�d”j×.Ò.Ñ0Ô0Ñ1Ô1Ð1ØŒ:Ð!Ø�IŠI�d”j×.Ò.Ñ0Ô0Ñ1Ô1Ð1ÝÔ" 2Ñ&Ô&Ð&r    c                 óŠ  — t          j        ¦   «         }|                     dt          j        dd¦  «        ¦  «         t          j        |¦  «        }t          t          j	        |¦  «        ¦  «        | _
        t          j        d| j
        ¦  «        | _        t          j        d| j                             ¦   «         j        ¦  «        | _        t          j        ¦   «         }|                     d| j        ¦  «         t%          |¦  «        }t          j        d|¦  «        | _        t)          j        t          ¦  «        }d| j                             ¦   «         j        › d�}|                     d	¦  «        }|                     d
|¦  «        }|                     t(          j        ¦  «         |                     | j        d¦  «         |S )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   ÚResourcePublisherr:   r   Ú	listenTCPrA   ÚResourceSubscriptionÚgetHostÚportr<   r   rD   r   ÚAgentÚencodeÚrequestÚaddCallbackÚreadBodyÚassertEqual)r(   Úr1Úsite1Úr2Úf2ÚagentÚurlÚds           r!   ÚtestDistribzDistribTests.testDistribX   sY  € åÔÑ Ô ˆØ
�Š�H�fœk¨'°<Ñ@Ô@ÑAÔAÐAÝ”˜B‘”ˆÝ!¥'Ô";¸EÑ"BÔ"BÑCÔCˆŒÝÔ& q¨$¬'Ñ2Ô2ˆŒ
ÝÔ/°¸T¼Z×=OÒ=OÑ=QÔ=QÔ=VÑWÔWˆŒÝÔÑ Ô ˆØ
�Š�G˜TœXÑ&Ô&Ð&Ý�B‰ZŒZˆÝÔ& q¨"Ñ-Ô-ˆŒ
Ý”�WÑ%Ô%ˆØH $¤*×"4Ò"4Ñ"6Ô"6Ô";ÐHÐHÐHˆØ�jŠj˜Ñ!Ô!ˆØ�MŠM˜& #Ñ&Ô&ˆØ	�Š•f”oÑ&Ô&Ð&Ø	�Š�dÔ&¨Ñ0Ô0Ð0Øˆr    c                 ó\  — t          j        ¦   «         }|                     d|¦  «         t          j        |¦  «        }t          t          j        |¦  «        ¦  «        x| _        }t          j
        d|d¬¦  «        }|                      |j        ¦  «         |                     ¦   «         }t          j        |j        |j        ¦  «        x| _        }t          j        |¦  «        }t          j
        d|d¬¦  «        }	|                      |	j        ¦  «         |	                     ¦   «         }
|	|
fS )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   rH   )Ú	interface)r   rK   rL   r   rN   r#   r   rO   r:   r   rP   Ú
addCleanuprC   rR   rQ   ÚhostrS   r<   )r(   ÚchildÚdistribRootÚdistribSiteÚdistribFactoryÚdistribPortr)   ÚmainRootÚmainSiteÚmainPortÚmainAddrs              r!   Ú_setupDistribServerz DistribTests._setupDistribServerl   s  € õ Ô'Ñ)Ô)ˆØ×Ò˜X uÑ-Ô-Ð-Ý”k +Ñ.Ô.ˆÝ#2ÝÔ% kÑ2Ô2ñ$
ô $
ð 	
ˆŒ�.õ Ô'¨¨>À[ÐQÑQÔQˆØ�Š˜Ô1Ñ2Ô2Ð2Ø×"Ò"Ñ$Ô$ˆå%Ô:¸4¼9ÀdÄiÑPÔPÐPˆŒ�8Ý”;˜xÑ(Ô(ˆÝÔ$ Q¨¸KÐHÑHÔHˆØ�Š˜Ô.Ñ/Ô/Ð/Ø×#Ò#Ñ%Ô%ˆà˜Ð!Ð!r    c                 ó  — |                       |¦  «        \  }}t          j        t          ¦  «        }d|j        › d|j        › d�}|                     d¦  «        } |j        d|fi |¤Ž}|                     t          j	        ¦  «         |S )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 the result of the request.
        úhttp://ú:ú/childrI   rJ   )
ro   r   rT   r   re   rS   rU   rV   rW   rX   )r(   rf   Úkwargsrm   rn   r^   r_   r`   s           r!   Ú_requestTestzDistribTests._requestTest‡   sŒ   € ð "×5Ò5°eÑ<Ô<Ñˆ�(Ý”�WÑ%Ô%ˆØ=˜œÐ=Ð=¨¬Ð=Ð=Ð=ˆØ�jŠj˜Ñ!Ô!ˆØˆEŒM˜& #Ð0Ð0¨Ð0Ð0ˆØ	�Š•f”oÑ&Ô&Ð&Øˆr    c                 ó  — |                       |¦  «        \  }}d|j        › d|j        › d�}|                     d¦  «        } t	          j        t          ¦  «        j        d|fi |¤Ž}d„ }|                     |¦  «         |S )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.
        rq   rr   rs   rI   rJ   c                 óÀ   ‡ ‡— t          j        ¦   «         Š‰                      ‰¦  «         t          j        ¦   «         x}‰_        |                     ˆˆ fd„¦  «         |S )Nc                 ó   •— ‰‰fS r%   r   )Ú_ÚprotocolÚresponses    €€r!   r6   zGDistribTests._requestAgentTest.<locals>.cbCollectBody.<locals>.<lambda>±   s   ø€  X¨xÐ$8€ r    )r   ÚAccumulatingProtocolÚdeliverBodyr   r9   ÚclosedDeferredrW   )r{   r`   rz   s   ` @r!   ÚcbCollectBodyz5DistribTests._requestAgentTest.<locals>.cbCollectBody­   s_   øø€ Ý$Ô9Ñ;Ô;ˆHØ× Ò  Ñ*Ô*Ð*Ý*/¬.Ñ*:Ô*:Ð:ˆA�Ô'Ø�MŠMÐ8Ð8Ð8Ð8Ð8Ñ9Ô9Ð9ØˆHr    )	ro   re   rS   rU   r   rT   r   rV   rW   )r(   rf   rt   rm   rn   r_   r`   r   s           r!   Ú_requestAgentTestzDistribTests._requestAgentTestš   s—   € ð "×5Ò5°eÑ<Ô<Ñˆ�(à=˜œÐ=Ð=¨¬Ð=Ð=Ð=ˆØ�jŠj˜Ñ!Ô!ˆØ)�FŒL�Ñ!Ô!Ô)¨&°#Ð@Ð@¸Ð@Ð@ˆð	ð 	ð 	ð 	
�Š�mÑ$Ô$Ð$Øˆr    c                 óB  ‡ ‡‡‡‡— i Št          j        ¦   «         Št          j        ‰¦  «         dgŠ G ˆˆfd„dt          j        ¦  «        }ˆˆˆ fd„Š‰                       |¦   «         t          ddgi¦  «        ¬¦  «        }ˆˆˆ fd„}|                     |¦  «         |S )	z†
        The request headers are available on the request object passed to a
        distributed resource's C{render} method.
        Nc                   ó   •— e Zd Zˆ ˆfd„ZdS )ú>DistribTests.test_requestHeaders.<locals>.ReportRequestHeadersc                 ó„   •— |‰d<   ‰                      t          |j                             ¦   «         ¦  «        ¦  «         dS )Nr   r    )ÚupdateÚdictÚrequestHeadersÚgetAllRawHeaders)r(   rV   Úreqr‡   s     €€r!   ÚrenderzEDistribTests.test_requestHeaders.<locals>.ReportRequestHeaders.renderÂ   s<   ø€ Ø ��A‘Ø×%Ò%¥d¨7Ô+A×+RÒ+RÑ+TÔ+TÑ&UÔ&UÑVÔVÐVØ�sr    N©r   r   r   rŠ   )r‰   r‡   s   €€r!   ÚReportRequestHeadersrƒ   Á   s3   ø€ € € € € ðð ð ð ð ð ð ð r    rŒ   c                  óØ   •— d„ ‰D ¦   «         } ‰                      d| ¦  «         ‰                      d| ¦  «         ‰                      ‰d         | ¦  «         t          j        ‰¦  «         d S )Nc                 ó   — g | ]
}|d          ‘ŒS )Ú
log_formatr   )Ú.0Úes     r!   ú
<listcomp>zHDistribTests.test_requestHeaders.<locals>.check_logs.<locals>.<listcomp>È   s   € Ð9Ð9Ð9¨�A�l”OÐ9Ð9Ð9r    zconnected to publisherz3could not connect to distributed web service: {msg}r   )ÚassertInr	   ÚremoveObserver)ÚmsgsÚlogObserverr‰   r(   s    €€€r!   Ú
check_logsz4DistribTests.test_requestHeaders.<locals>.check_logsÇ   sp   ø€ Ø9Ð9¨[Ð9Ñ9Ô9ˆDØ�MŠMÐ2°DÑ9Ô9Ð9Ø�MŠMÐOÐQUÑVÔVÐVØ�MŠM˜#˜aœ& $Ñ'Ô'Ð'ÝÔ-¨kÑ:Ô:Ð:Ð:Ð:r    ÚfooÚbar)Úheadersc                 ó€   •— ‰j         j                             ‰¦  «         ‰                     ‰d         dg¦  «         d S )Ns   Foos   bar)r:   r'   r;   rY   )Úresultr—   r‡   r(   s    €€€r!   ÚcbRequestedz5DistribTests.test_requestHeaders.<locals>.cbRequestedÒ   s>   ø€ ØŒGŒM×,Ò,¨ZÑ8Ô8Ð8Ø×Ò˜^¨FÔ3°f°XÑ>Ô>Ð>Ð>Ð>r    )	r   ÚEventLoggingObserverr	   ÚaddObserverr   rK   ru   r   rW   )r(   rŒ   rV   r�   r—   r–   r‰   r‡   s   `   @@@@r!   Útest_requestHeadersz DistribTests.test_requestHeaders·   s
  øøøøø€ ð
 ˆÝ#Ô8Ñ:Ô:ˆÝÔ& {Ñ3Ô3Ð3Øˆfˆð	ð 	ð 	ð 	ð 	ð 	ð 	ð 	¥8Ô#4ñ 	ô 	ð 	ð	;ð 	;ð 	;ð 	;ð 	;ð 	;ð 	;ð ×#Ò#Ø Ð Ñ"Ô"­G°U¸U¸GÐ4DÑ,EÔ,Eð $ñ 
ô 
ˆð	?ð 	?ð 	?ð 	?ð 	?ð 	?ð 	?ð 	×Ò˜KÑ(Ô(Ð(Øˆr    c                 ó¦   ‡ —  G d„ dt           j        ¦  «        }‰                       |¦   «         ¦  «        }ˆ fd„}|                     |¦  «         |S )z�
        The response code can be set by the request object passed to a
        distributed resource's C{render} method.
        c                   ó   — e Zd Zd„ ZdS )ú>DistribTests.test_requestResponseCode.<locals>.SetResponseCodec                 ó0   — |                      d¦  «         dS )NéÈ   Ú ©ÚsetResponseCode©r(   rV   s     r!   rŠ   zEDistribTests.test_requestResponseCode.<locals>.SetResponseCode.renderà   s   € Ø×'Ò'¨Ñ,Ô,Ð,Ø�rr    Nr‹   r   r    r!   ÚSetResponseCoder£   ß   ó#   € € € € € ðð ð ð ð r    rª   c                 óÎ   •— ‰                      | d         j        d¦  «         ‰                      | d         j        d¦  «         ‰                      | d         j        d¦  «         d S )Nr   r    r8   r¥   s   OK©rY   ÚdataÚcodeÚphrase©rœ   r(   s    €r!   r�   z:DistribTests.test_requestResponseCode.<locals>.cbRequestedæ   s^   ø€ Ø×Ò˜V AœYœ^¨SÑ1Ô1Ð1Ø×Ò˜V AœYœ^¨SÑ1Ô1Ð1Ø×Ò˜V AœYÔ-¨uÑ5Ô5Ð5Ð5Ð5r    ©r   rK   r€   rW   ©r(   rª   rV   r�   s   `   r!   Útest_requestResponseCodez%DistribTests.test_requestResponseCodeÙ   s�   ø€ ð	ð 	ð 	ð 	ð 	�hÔ/ñ 	ô 	ð 	ð
 ×(Ò(¨¨Ñ):Ô):Ñ;Ô;ˆð	6ð 	6ð 	6ð 	6ð 	6ð
 	×Ò˜KÑ(Ô(Ð(Øˆr    c                 ó¦   ‡ —  G d„ dt           j        ¦  «        }‰                       |¦   «         ¦  «        }ˆ fd„}|                     |¦  «         |S )z�
        The response code and message can be set by the request object passed to
        a distributed resource's C{render} method.
        c                   ó   — e Zd Zd„ ZdS )úEDistribTests.test_requestResponseCodeMessage.<locals>.SetResponseCodec                 ó2   — |                      dd¦  «         dS )Nr¥   ó   some-messager¦   r§   r©   s     r!   rŠ   zLDistribTests.test_requestResponseCodeMessage.<locals>.SetResponseCode.renderõ   s   € Ø×'Ò'¨¨_Ñ=Ô=Ð=Ø�rr    Nr‹   r   r    r!   rª   r·   ô   r«   r    rª   c                 óÎ   •— ‰                      | d         j        d¦  «         ‰                      | d         j        d¦  «         ‰                      | d         j        d¦  «         d S )Nr   r    r8   r¥   r¹   r­   r±   s    €r!   r�   zADistribTests.test_requestResponseCodeMessage.<locals>.cbRequestedû   s^   ø€ Ø×Ò˜V AœYœ^¨SÑ1Ô1Ð1Ø×Ò˜V AœYœ^¨SÑ1Ô1Ð1Ø×Ò˜V AœYÔ-¨Ñ?Ô?Ð?Ð?Ð?r    r²   r³   s   `   r!   Útest_requestResponseCodeMessagez,DistribTests.test_requestResponseCodeMessageî   s†   ø€ ð	ð 	ð 	ð 	ð 	�hÔ/ñ 	ô 	ð 	ð
 ×(Ò(¨¨Ñ):Ô):Ñ;Ô;ˆð	@ð 	@ð 	@ð 	@ð 	@ð
 	×Ò˜KÑ(Ô(Ð(Øˆr    c                 ó¼   —  G d„ dt           j        ¦  «        }|                       |¦   «         ¦  «        }|                     | j        dt
          z  dz   ¦  «         |S )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                   ó   — e Zd Zd„ ZdS )ú0DistribTests.test_largeWrite.<locals>.LargeWritec                 ó‚   — |                      dt          z  dz   ¦  «         |                     ¦   «          t          j        S ©Nó   xó   y)Úwriter   Úfinishr   ÚNOT_DONE_YETr©   s     r!   rŠ   z7DistribTests.test_largeWrite.<locals>.LargeWrite.render  s7   € Ø—’˜d¥ZÑ/°$Ñ6Ñ7Ô7Ð7Ø—’Ñ Ô Ð ÝÔ*Ð*r    Nr‹   r   r    r!   Ú
LargeWriter¾   
  s#   € € € € € ð+ð +ð +ð +ð +r    rÆ   rÁ   rÂ   ©r   rK   ru   rW   rY   r   )r(   rÆ   rV   s      r!   Útest_largeWritezDistribTests.test_largeWrite  sr   € ð	+ð 	+ð 	+ð 	+ð 	+�Ô*ñ 	+ô 	+ð 	+ð ×#Ò# J J¡L¤LÑ1Ô1ˆØ×Ò˜DÔ,¨dµZÑ.?À$Ñ.FÑGÔGÐGØˆr    c                 ó¼   —  G d„ dt           j        ¦  «        }|                       |¦   «         ¦  «        }|                     | j        dt
          z  dz   ¦  «         |S )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                   ó   — e Zd Zd„ ZdS )ú2DistribTests.test_largeReturn.<locals>.LargeReturnc                 ó   — dt           z  dz   S rÀ   r   r©   s     r!   rŠ   z9DistribTests.test_largeReturn.<locals>.LargeReturn.render  s   € Ø�jÑ(¨4Ñ/Ð/r    Nr‹   r   r    r!   ÚLargeReturnrË     s#   € € € € € ð0ð 0ð 0ð 0ð 0r    rÍ   rÁ   rÂ   rÇ   )r(   rÍ   rV   s      r!   Útest_largeReturnzDistribTests.test_largeReturn  sr   € ð	0ð 	0ð 	0ð 	0ð 	0�(Ô+ñ 	0ô 	0ð 	0ð ×#Ò# K K¡M¤MÑ2Ô2ˆØ×Ò˜DÔ,¨dµZÑ.?À$Ñ.FÑGÔGÐGØˆr    c                 ól  ‡ ‡— t          t          j        ¦   «         ¦  «        x‰ _        }t	          j        d|¦  «        x‰ _        }t          j        d| 	                    ¦   «         j
        ¦  «        x‰ _        }t          dg¦  «        Št          |‰¦  «        }ˆˆ fd„}|                     |¦  «         |S )zz
        If there is an error issuing the request to the remote publisher, an
        error response is returned.
        r   rH   r    c                 ó(  •— ‰                      ‰j        d¦  «         ‰                     t          j        ¦  «        }‰                      t          |¦  «        d¦  «         g d¢}‰                      d                     |¦  «        g‰j        ¦  «         d S )Niô  r8   )
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    ó   
)rY   ÚresponseCodeÚflushLoggedErrorsr   ÚNoSuchMethodÚlenÚjoinÚwritten)ÚignoredÚerrorsÚexpectedrV   r(   s      €€r!   Ú
cbRenderedz4DistribTests.test_connectionLost.<locals>.cbRendered2  s�   ø€ Ø×Ò˜WÔ1°3Ñ7Ô7Ð7ð ×+Ò+­B¬OÑ<Ô<ˆFØ×Ò�S ™[œ[¨!Ñ,Ô,Ð,ðð ð ˆHð  ×Ò˜eŸjšj¨Ñ2Ô2Ð3°W´_ÑEÔEÐEÐEÐEr    )r#   r   ÚRootr:   r   rP   rA   r   rQ   rR   rS   r<   r   r   rW   )r(   ÚserverFactoryÚ
serverPortÚsubscriptionr`   rÛ   rV   s   `     @r!   Útest_connectionLostz DistribTests.test_connectionLost"  sÅ   øø€ õ #2µ"´'±)´)Ñ"<Ô"<Ð<ˆŒ�-Ý")Ô"3°A°}Ñ"EÔ"EÐEˆŒ
�Zå")Ô">Ø˜×+Ò+Ñ-Ô-Ô2ñ#
ô #
ð 	
ˆŒ�<õ  ˜uÑ%Ô%ˆÝ�L 'Ñ*Ô*ˆð	Fð 	Fð 	Fð 	Fð 	Fð 	Fð2 	
�Š�jÑ!Ô!Ð!Øˆr    c                 óŒ  — t           j                             | t          ¦  «        }t	          j        t          ¦   «         ¦  «        }t          dg¦  «        }t          j	        |¦  «        }| 
                    |¦  «         |                      dt          |¦  «        ¦  «         |                      d|d         d         ¦  «         dS )zQ
        When a request fails, the string form of the failure is logged.
        r    r8   zFailure instancer   r�   N)r   rž   ÚcreateWithCleanupr	   r
   ÚFailurer,   r   r   ÚIssueÚfailedÚassertEqualsrÕ   r“   )r(   r–   ÚfrV   Úissues        r!   Útest_logFailedzDistribTests.test_logFailedN  s¨   € õ $Ô8×JÒJØÕ$ñ
ô 
ˆõ ŒO�NÑ,Ô,Ñ-Ô-ˆÝ ˜uÑ%Ô%ˆÝ”˜gÑ&Ô&ˆØ�Š�Q‰ŒˆØ×Ò˜!�S Ñ-Ô-Ñ.Ô.Ð.Ø�ŠÐ(¨+°a¬.¸Ô*FÑGÔGÐGÐGÐGr    c                 ó¼  — t           j                             | t          ¦  «        }t	          ¦   «         }t          j        |¦  «        }t          j        t          ¦   «         ¦  «        }| 
                    |¦  «         |                      t          ¦  «         |                      dt          |¦  «        ¦  «         |                      |d         d         |¦  «         dS )zf
        When L{twisted.web.distrib.Request}'s fail is called, the failure
        is logged.
        r8   r   Úlog_failureN)r   rž   râ   r	   r,   r
   rã   r   ÚRequestr   ÚfailrÓ   ræ   rÕ   ÚassertIs)r(   r–   Úerrrç   r‰   s        r!   Útest_requestFailzDistribTests.test_requestFail]  sµ   € õ
 $Ô8×JÒJØÕ$ñ
ô 
ˆõ ÑÔˆÝŒO˜CÑ Ô ˆÝŒo�l™nœnÑ-Ô-ˆØ�Š�‰ŒˆØ×Ò�~Ñ.Ô.Ð.Ø×Ò˜!�S Ñ-Ô-Ñ.Ô.Ð.Ø�Š�k !”n ]Ô3°QÑ7Ô7Ð7Ð7Ð7r    )r   r   r   rA   rD   r<   r:   rF   ra   ro   ru   r€   r    r´   r»   rÈ   rÎ   rà   ré   rð   r   r    r!   r.   r.   =   sð   € € € € € Ø€EØ€EØ
€CØ	€Bð'ð 'ð 'ð*ð ð ð("ð "ð "ð6ð ð ð&ð ð ð: ð  ð  ðDð ð ð*ð ð ð*ð ð ð"ð ð ð*ð *ð *ðXHð Hð Hð8ð 8ð 8ð 8ð 8r    r.   c                   ó    — e Zd Zd„ Zd„ Zd„ ZdS )Ú_PasswordDatabasec                 ó   — || _         d S r%   )Ú_users)r(   Úuserss     r!   Ú__init__z_PasswordDatabase.__init__o  s   € ØˆŒˆˆr    c                 ó*   — t          | j        ¦  «        S r%   )Úiterrô   ©r(   s    r!   Úgetpwallz_PasswordDatabase.getpwallr  s   € Ý�D”KÑ Ô Ð r    c                 óR   — | j         D ]}|d         |k    r|c S Œt          ¦   «         ‚r1   )rô   ÚKeyError)r(   ÚusernameÚusers      r!   Úgetpwnamz_PasswordDatabase.getpwnamu  s:   € Ø”Kð 	ð 	ˆDØ�AŒw˜(Ò"Ð"Ø���ð #å‰jŒjÐr    N)r   r   r   rö   rú   rÿ   r   r    r!   rò   rò   n  sA   € € € € € ðð ð ð!ð !ð !ðð ð ð ð r    rò   c                   ó~   — e Zd ZdZd„ Zd„ Zdeddfd„Zd„ Zd	„ Z	d
„ Z
d„ Zd„ Zd„ Z ee d¦  «        d„ ¦   «         ZdS )ÚUserDirectoryTestszj
    Tests for L{UserDirectory}, a resource for listing all user resources
    available on a system.
    c                 ó  — ddddd|                       ¦   «         df| _        dddd	d
|                       ¦   «         df| _        t          | j        | j        g¦  «        | _        t          j        | j        ¦  «        | _        d S )NÚaliceÚxé{   iÈ  zAlice,,,z/bin/shÚbobéê   i7  zBob,,,)Úmktempr  r  rò   Údatabaser   ÚUserDirectoryÚ	directoryrù   s    r!   ÚsetUpzUserDirectoryTests.setUp‚  sn   € Ø˜s C¨¨j¸$¿+º+¹-¼-ÈÐSˆŒ
Ø˜3  S¨(°D·K²K±M´MÀ9ÐMˆŒÝ)¨4¬:°t´xÐ*@ÑAÔAˆŒÝ Ô.¨t¬}Ñ=Ô=ˆŒˆˆr    c                 ój   — |                       t          t          j        | j        ¦  «        ¦  «         dS )zK
        L{UserDirectory} instances provide L{resource.IResource}.
        N)Ú
assertTruer   r   Ú	IResourcer  rù   s    r!   Útest_interfacez!UserDirectoryTests.test_interfaceˆ  s+   € ð 	�Š�¥XÔ%7¸¼ÑHÔHÑIÔIÐIÐIÐIr    ÚnameÚreturnNc              ƒ   óÆ   K  — t          |g¦  «        }| j                             ||¦  «        }t          ||¦  «        }|ƒ d{V —† |                      |j        d¦  «         dS )zr
        Verify that requesting the C{name} child of C{self.directory} results
        in a 404 response.
        Ni”  )r   r  ÚgetChildr   rY   rÒ   )r(   r  rV   rœ   r`   s        r!   Ú_404TestzUserDirectoryTests._404TestŽ  sm   è è € õ
  ˜vÑ&Ô&ˆØ”×(Ò(¨¨wÑ7Ô7ˆÝ�F˜GÑ$Ô$ˆØˆˆˆˆˆˆˆØ×Ò˜Ô-¨sÑ3Ô3Ð3Ð3Ð3r    c              ƒ   ó@   K  — |                       d¦  «        ƒ d{V —† dS )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_getInvalidUserz&UserDirectoryTests.test_getInvalidUser™  ó2   è è € ð �mŠm˜HÑ%Ô%Ð%Ð%Ð%Ð%Ð%Ð%Ð%Ð%Ð%r    c              ƒ   ó@   K  — |                       d¦  «        ƒ d{V —† dS )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_getUserWithoutResourcez.UserDirectoryTests.test_getUserWithoutResource¡  r  r    c                 ól  — t          j        | j        d         ¦  «        }|                     d¦  «        }|                     ¦   «          t          dg¦  «        }| j                             d|¦  «        }|                      |t          j
        ¦  «         |                      |j        |j        ¦  «         dS )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  rf   Úmakedirsr   r  r  ÚassertIsInstancer   ÚFilerY   Úpath)r(   Úhomer  rV   rœ   s        r!   Útest_getPublicHTMLChildz*UserDirectoryTests.test_getPublicHTMLChild©  sœ   € õ Ô  ¤¨"¤Ñ.Ô.ˆØ—j’j Ñ/Ô/ˆØ×ÒÑÔÐÝ ˜wÑ'Ô'ˆØ”×(Ò(¨°Ñ9Ô9ˆØ×Ò˜f¥f¤kÑ2Ô2Ð2Ø×Ò˜œ kÔ&6Ñ7Ô7Ð7Ð7Ð7r    c                 ó¼  — t          j        | j        d         ¦  «        }|                     ¦   «          |                     d¦  «        }t          dg¦  «        }| j                             d|¦  «        }|                      |t          j
        ¦  «         |                      |j        d¦  «         |                      t          |j        ¦  «        |j        ¦  «         dS )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.
        r  ú.twistd-web-pbr  s
   bob.twistdÚunixN)r   r  r  r   rf   r   r  r  r!  r   rQ   rY   re   r   rS   r#  )r(   r$  ÚwebrV   rœ   s        r!   Útest_getDistribChildz'UserDirectoryTests.test_getDistribChild·  s¸   € õ Ô  ¤¨"¤Ñ.Ô.ˆØ�Š‰ŒˆØ�jŠjÐ)Ñ*Ô*ˆÝ ˜wÑ'Ô'ˆØ”×(Ò(¨¸Ñ@Ô@ˆØ×Ò˜f¥gÔ&BÑCÔCÐCØ×Ò˜œ fÑ-Ô-Ð-Ø×Ò� ¤Ñ-Ô-¨s¬xÑ8Ô8Ð8Ð8Ð8r    c                 óŠ   — t          dg¦  «        }d|_        |                      t          j        | j        j        |¦  «         dS )zr
        L{UserDirectory.render} raises L{UnsupportedMethod} in response to a
        non-I{GET} request.
        r¦   ÚPOSTN)r   ÚmethodÚassertRaisesr   ÚUnsupportedMethodr  rŠ   r©   s     r!   Útest_invalidMethodz%UserDirectoryTests.test_invalidMethodÆ  s@   € õ
  ˜tÑ$Ô$ˆØˆŒØ×Ò�&Ô2°D´NÔ4IÈ7ÑSÔSÐSÐSÐSr    c                 óÌ  ‡ ‡— t          j        ‰ j        d         ¦  «                             d¦  «        }|                     ¦   «          t          j        ‰ j        d         ¦  «        }|                     ¦   «          |                     d¦  «                             d¦  «         t          dg¦  «        Št          ‰ j	        ‰¦  «        }ˆˆ fd„}| 
                    |¦  «         |S )z}
        L{UserDirectory} renders a list of links to available user content
        in response to a I{GET} request.
        r  r  r'  r    r¦   c                 óR  •— t          d                     ‰j        ¦  «        ¦  «        }|                     d¦  «        \  }}‰                     |j        j        d¦  «         ‰                     |j                             d¦  «        d¦  «         ‰                     |j        j        j        d¦  «         ‰                     |j        j        d¦  «         ‰                     |j                             d¦  «        d¦  «         ‰                     |j        j        j        d¦  «         d S )	Nr    ÚliÚaÚhrefzalice/zAlice (file)zbob.twistd/zBob (twistd))	r   rÖ   r×   ÚgetElementsByTagNamerY   Ú
firstChildÚtagNameÚgetAttributer®   )rØ   Údocumentr  r  rV   r(   s       €€r!   rÛ   z2UserDirectoryTests.test_render.<locals>.cbRenderedà  sþ   ø€ Ý" 3§8¢8¨G¬OÑ#<Ô#<Ñ=Ô=ˆHð $×8Ò8¸Ñ>Ô>‰LˆU�CØ×Ò˜UÔ-Ô5°sÑ;Ô;Ð;Ø×Ò˜UÔ-×:Ò:¸6ÑBÔBÀHÑMÔMÐMØ×Ò˜UÔ-Ô8Ô=¸~ÑNÔNÐNØ×Ò˜Sœ^Ô3°SÑ9Ô9Ð9Ø×Ò˜Sœ^×8Ò8¸Ñ@Ô@À-ÑPÔPÐPØ×Ò˜Sœ^Ô6Ô;¸^ÑLÔLÐLÐLÐLr    )r   r  r  rf   r   r  Ú
setContentr   r   r  rW   )r(   r  r)  rœ   rÛ   rV   s   `    @r!   Útest_renderzUserDirectoryTests.test_renderÏ  sá   øø€ õ
 Ô'¨¬
°2¬Ñ7Ô7×=Ò=¸mÑLÔLˆØ×ÒÑÔÐÝÔ ¤¨¤Ñ-Ô-ˆØ�Š‰Œˆð 	�	Š	Ð"Ñ#Ô#×.Ò.¨sÑ3Ô3Ð3å ˜tÑ$Ô$ˆÝ˜œ¨Ñ1Ô1ˆð
	Mð 
	Mð 
	Mð 
	Mð 
	Mð 
	Mð 	×Ò˜:Ñ&Ô&Ð&Øˆr    zpwd module requiredc                 ól   — t          j        ¦   «         }|                      |j        t          ¦  «         dS )z„
        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(   r  s     r!   Útest_passwordDatabasez(UserDirectoryTests.test_passwordDatabaseï  s0   € õ Ô)Ñ+Ô+ˆ	Ø×Ò˜Yœ^­SÑ1Ô1Ð1Ð1Ð1r    )r   r   r   r*   r  r  Úbytesr  r  r  r%  r*  r0  r<  r   r@  rA  r   r    r!   r  r  |  sê   € € € € € ðð ð
>ð >ð >ðJð Jð Jð	4 5ð 	4¨Tð 	4ð 	4ð 	4ð 	4ð&ð &ð &ð&ð &ð &ð8ð 8ð 8ð9ð 9ð 9ðTð Tð Tðð ð ð@ €V�ˆGÐ*Ñ+Ô+ð2ð 2ñ ,Ô+ð2ð 2ð 2r    r  )1r*   Úos.pathr   Úxml.dom.minidomr   r@  r?  Ú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   rN   r   r#   Ú	Exceptionr,   r.   rò   r  r   r    r!   ú<module>rT     s§  ððð ð Ð Ð Ð Ð Ð Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'ðØÐÐÐð €C€Cøð ð ð ð Ø
€C€C€Cðøøøð
 Ð Ð Ð Ð Ð à .Ð .Ð .Ð .Ð .Ð .à +Ð +Ð +Ð +Ð +Ð +Ð +Ð +Ø -Ð -Ð -Ð -Ð -Ð -Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø Ð Ð Ð Ð Ð Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø &Ð &Ð &Ð &Ð &Ð &Ø +Ð +Ð +Ð +Ð +Ð +Ø AÐ AÐ AÐ AÐ AÐ AÐ AÐ AÐ AÐ AÐ AÐ AÐ AÐ AØ ,Ð ,Ð ,Ð ,Ð ,Ð ,Ø *Ð *Ð *Ð *Ð *Ð *Ø EÐ EÐ EÐ EÐ EÐ EÐ EÐ Eð	ð 	ð 	ð 	ð 	ˆVŒ[ñ 	ô 	ð 	ðð ð ð ð �bÔ(ñ ô ð ð ð ð ð ð �Yñ ô ð ðn8ð n8ð n8ð n8ð n8�8ñ n8ô n8ð n8ðb	ð ð ð ð ñ ô ð ðz2ð z2ð z2ð z2ð z2˜ñ z2ô z2ð z2ð z2ð z2s   � —! !