%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /usr/lib/python3/dist-packages/twisted/spread/test/__pycache__/
Upload File :
Create Path :
Current File : //usr/lib/python3/dist-packages/twisted/spread/test/__pycache__/test_pb.cpython-312.pyc

�

Ϫ�f6���"�dZddlZddlZddlZddlZddlZddlmZddlm	Z
ddlmZddl
mZmZddlmZmZmZddlmZmZdd	lmZmZmZmZdd
lmZmZmZddl m!Z!ddl"m#Z#dd
l$m%Z%ddl&m'Z'm(Z(ddl)m*Z*ddl+m,Z,m-Z-m.Z.m/Z/ddl0m1Z1Gd�de-jd�Z3Gd�de-jh�Z5eejl�Gd�d��Z7Gd�d�Z8d�Z9Gd�d�Z:Gd�de#�Z;d�d�Z<Gd �d!e-jz�Z>Gd"�d#e-jz�Z?Gd$�d%e-j��ZAGd&�d'e-j��ZCe-j�eAeC�Gd(�d)e-j��ZEd*�ZFe-j�eEeF�Gd+�d,e-jz�ZHGd-�d.e-j��ZJGd/�d0e-jz�ZKGd1�d2e-j��ZLGd3�d4e-j��ZNe-j�eLeN�Gd5�d6e-j��ZOe-j�eJeO�Gd7�d8e-jz�ZPGd9�d:e-jz�ZQGd;�d<e-jz�ZRGd=�d>e-jz�ZSGd?�d@e-j�e-j��ZTe-j�eTeT�GdA�dBe-j�e-j��ZUe-j�eUeU�GdC�dDe-j�e-j��ZVe-j�eVeV�GdE�dFe-j��ZXGdG�dHe-j��ZYGdI�dJe1j��Z[GdK�dLe-j��Z]GdM�dNe1j��Z_GdO�dPe1j��Z`dQZadabdacdR�ZdGdS�dTe-jz�ZeGdU�dVe-jz�ZfGdW�dXe1j��ZgGdY�dZe.j��ZiGd[�d\e.j��ZkGd]�d^e-jz�Zle-j�eiek�Gd_�d`e1j��ZmGda�dben�ZoGdc�dde-j��ZpGde�dfe-jz�ZqGdg�dhe/j��Zsee-j��Gdi�dje-jh��ZuGdk�dl�ZvGdm�dne-jd�ZwGdo�dpev�ZxGdq�dre1j��ZyGds�dte1j��Zzee-j��Gdu�dv��Z{Gdw�dxe1j��Z|Gdy�dze�Z}ee}�Gd{�d|��Z~Gd}�d~e1j��ZGd�d�e1j��Z�y)�z�
Tests for Perspective Broker module.

TODO: update protocol level tests to use new connection API, leaving
only specific tests for old API.
�N)�deque)�BytesIO)�Dict)�	Interface�implementer)�checkers�credentials�portal)�UnauthorizedLogin�UnhandledCredentials)�address�main�protocol�reactor)�Deferred�
gatherResults�succeed)�ConnectionRefusedError)�_FakeConnector)�WrappingFactory)�failure�log)�	iterbytes)�jelly�pb�publish�util)�unittestc��eZdZd�Zy)�Dummyc�&�t|t�ryy)Nzhello world!zgoodbye, cruel world!)�
isinstance�DummyPerspective��self�users  �=/usr/lib/python3/dist-packages/twisted/spread/test/test_pb.py�view_doNothingzDummy.view_doNothing(s���d�,�-�!�*�N)�__name__�
__module__�__qualname__r(�r)r'r r 's��+r)r c��eZdZdZd�Zy)r#zE
    An L{IPerspective} avatar which will be used in some tests.
    c��t�S�N)r �r%s r'�perspective_getDummyViewPointz.DummyPerspective.perspective_getDummyViewPoint4s	���w�r)N)r*r+r,�__doc__r2r-r)r'r#r#/s���r)r#c��eZdZd�Zy)�
DummyRealmc�X�|D]%}|tjus�|t|�d�fcSy)Nc��yr0r-r-r)r'�<lambda>z*DummyRealm.requestAvatar.<locals>.<lambda>=��r))r�IPerspectiver#)r%�avatarId�mind�
interfaces�ifaces     r'�
requestAvatarzDummyRealm.requestAvatar:s2���	G�E�����'��.�x�8�,�F�F�	Gr)N)r*r+r,r?r-r)r'r5r58s��Gr)r5c�(�eZdZdZd�Zd�Zd�Zd�Zy)�IOPumpz�
    Utility to pump data between clients and servers for protocol testing.

    Perhaps this is a utility worthy of being in protocol.py?
    c�<�||_||_||_||_yr0)�client�server�clientIO�serverIO)r%rCrDrErFs     r'�__init__zIOPump.__init__Gs�������� ��
� ��
r)c���d|_tj�dz}|jsH|j�r7tj�|kDry|js|j�r�5yyyy)z�
        Pump until there is no more input or output or until L{stop} is called.
        This does not run any timers, so don't use it with any code that calls
        reactor.callLater.
        F�N)�_stop�time�pump)r%�timeouts  r'�flushzIOPump.flushMsQ����
��)�)�+��/���*�*������y�y�{�W�$���*�*�����*��*r)c��d|_y)zd
        Stop a running L{flush} operation, even if data remains to be
        transferred.
        TN)rJr1s r'�stopzIOPump.stopZs��
��
r)c���|jjd�|jjd�|jj�}|jj�}|jjd�|jjd�|jj	�|jj	�|j
jj�|jjj�t|�D]}|jj|��t|�D]}|j
j|��|s|ryy)zX
        Move data back and forth.

        Returns whether any data was moved.
        r�)rE�seekrF�read�truncaterC�	transport�_checkProducerrDr�dataReceived)r%�cData�sData�bytes    r'rLzIOPump.pumpas��	
�
�
���1���
�
���1���
�
�"�"�$���
�
�"�"�$���
�
���1���
�
���1���
�
��� ��
�
��� ������,�,�.������,�,�.��e�$�	+�D��K�K�$�$�T�*�	+��e�$�	+�D��K�K�$�$�T�*�	+��E��r)N)r*r+r,r3rGrNrPrLr-r)r'rArA@s���!���r)rAc����d}�j|�}|j|�}t�}t�}|jtj|��|jtj|��t||||�}d�}	�fd�}
|j
|	|�|j
|	|�|j
|
�|j�|||fS)al
    Create a server and a client and connect the two with an
    L{IOPump}.

    @param test: the test case where the client and server will be
        used.
    @type test: L{twisted.trial.unittest.TestCase}

    @param clientFactory: The factory that creates the client object.
    @type clientFactory: L{twisted.spread.pb.PBClientFactory}

    @param serverFactory: The factory that creates the server object.
    @type serverFactory: L{twisted.spread.pb.PBServerFactory}

    @return: a 3-tuple of (client, server, pump)
    @rtype: (L{twisted.spread.pb.Broker}, L{twisted.spread.pb.Broker},
        L{IOPump})
    )�	127.0.0.1c��|js3|jtjtj
��yyr0)�disconnected�connectionLostr�Failurer�CONNECTION_DONE)�brokers r'�maybeDisconnectz/connectServerAndClient.<locals>.maybeDisconnect�s-���"�"��!�!�'�/�/�$�2F�2F�"G�H�#r)c�n���jdtjtj���y)N)�	connector�reason)�clientConnectionLostrrarrb)�
clientFactorys�r'�disconnectClientFactoryz7connectServerAndClient.<locals>.disconnectClientFactory�s,���
	�*�*��7�?�?�4�3G�3G�#H�	+�	
r))�
buildProtocol�StringIO�makeConnectionr�FileWrapperrA�
addCleanuprL)�testri�
serverFactory�addr�clientBroker�serverBroker�clientTransport�serverTransportrLrdrjs `         r'�connectServerAndClientrw{s����&�D� �.�.�t�4�L� �.�.�t�4�L��j�O��j�O����� 4� 4�_� E�F����� 4� 4�_� E�F��,��o��O�D�I�
�	�O�O�O�\�2��O�O�O�\�2��O�O�+�,��I�I�K���t�+�+r)c�"�eZdZdZd�Zd�Zd�Zy)�_ReconnectingFakeConnectorStatez�
    Manages connection notifications for a
    L{_ReconnectingFakeConnector} instance.

    @ivar notifications: pending L{Deferreds} that will fire when the
        L{_ReconnectingFakeConnector}'s connect method is called
    c�"�t�|_yr0)r�
notificationsr1s r'rGz(_ReconnectingFakeConnectorState.__init__�s��"�W��r)c�P�t�}|jj|�|S)z�
        Connection notification.

        @return: A L{Deferred} that fires when this instance's
            L{twisted.internet.interfaces.IConnector.connect} method
            is called.
        @rtype: L{Deferred}
        )rr{�
appendleft)r%�notifiers  r'�notifyOnConnectz/_ReconnectingFakeConnectorState.notifyOnConnect�s$���:�����%�%�h�/��r)c��|jr7|jj�j|�|jr�6yy)z1
        Fire all pending notifications.
        N)r{�pop�callbackr1s r'�	notifyAllz)_ReconnectingFakeConnectorState.notifyAll�s5��� � ����"�"�$�-�-�d�3�� � r)N)r*r+r,r3rGrr�r-r)r'ryry�s���%��4r)ryc�,��eZdZdZ�fd�Z�fd�Z�xZS)�_ReconnectingFakeConnectorzc
    A fake L{IConnector} that can fire L{Deferred}s when its
    C{connect} method is called.
    c�2��t�|�|�||_y)a
        @param address: An L{IAddress} provider that represents this
            connector's destination.
        @type address: An L{IAddress} provider.

        @param state: The state instance
        @type state: L{_ReconnectingFakeConnectorState}
        N)�superrG�_state)r%r
�state�	__class__s   �r'rGz#_ReconnectingFakeConnector.__init__�s���	����!���r)c�V��t�|��|jj�y)zM
        A C{connect} implementation that calls C{reconnectCallback}
        N)r��connectr�r�)r%r�s �r'r�z"_ReconnectingFakeConnector.connect�s���	���������r))r*r+r,r3rGr��
__classcell__)r�s@r'r�r��s����

� � r)r�c���|xs
t�}tjd��}tjtj||g��}tj�}t|||�S)z�
    Connect a client and server L{Broker} together with an L{IOPump}

    @param realm: realm to use, defaulting to a L{DummyRealm}

    @returns: a 3-tuple (client, server, pump).
    �guest)�guest)	r5r�'InMemoryUsernamePasswordDatabaseDontUser�PBServerFactoryr
�Portal�PBClientFactoryrw)rp�realm�checkerrqris     r'�connectedServerAndClientr��sZ��
�!�Z�\�E��>�>�X�N�G��&�&�v�}�}�U�W�I�'F�G�M��&�&�(�M�!�$�
�}�E�Er)c��eZdZd�Zd�Zy)�SimpleRemotec��||_|dzS�NrR)�arg�r%r�s  r'�remote_thunkzSimpleRemote.remote_thunk��������Q�w�r)c��t��r0)�	Exceptionr�s  r'�remote_knuthzSimpleRemote.remote_knuth�s
���k�r)N)r*r+r,r�r�r-r)r'r�r��s���r)r�c��eZdZd�Zy)�NestedRemotec��t�Sr0)r�r1s r'�remote_getSimplezNestedRemote.remote_getSimples
���~�r)N)r*r+r,r�r-r)r'r�r�s��r)r�c��eZdZd�Zy)�
SimpleCopyc�4�d|_ddi|_dg|_y�NrR�Hello�Worldrp��x�y�zr1s r'rGzSimpleCopy.__init__�������7�#������r)N�r*r+r,rGr-r)r'r�r����r)r�c��eZdZy)�SimpleLocalCopyN�r*r+r,r-r)r'r�r�
���r)r�c�0�eZdZUdZiZeedfed<d�Zy)�SimpleFactoryCopyz]
    @cvar allIDs: hold every created instances of this class.
    @type allIDs: C{dict}
    �allIDsc�8�||_|tj|<yr0)�idr�r�)r%r�s  r'rGzSimpleFactoryCopy.__init__s�����'+�� � ��$r)N)	r*r+r,r3r�r�int�__annotations__rGr-r)r'r�r�s#���
.0�F�D��)�)�*�/�,r)r�c��|jdd�}|�tdt|�����|tjvrtdtj����tj|}|std��|S)zl
    Factory of L{SimpleFactoryCopy}, getting a created instance given the
    C{id} found in C{state}.
    r�Nz&factory copy state has no 'id' member zfactory class has no ID: z&factory method found no object with id)�get�RuntimeError�reprr�r�)r��stateId�insts   r'�createFactoryCopyr�!s~��
�i�i��d�#�G����C�D��K�=�Q�R�R��'�.�.�.��6�7H�7O�7O�6P�Q�R�R��#�#�G�,�D���C�D�D��Kr)c��eZdZd�Zd�Zy)�
NestedCopyc��t�Sr0)r�r1s r'�remote_getCopyzNestedCopy.remote_getCopy5s
���|�r)c��t|�Sr0)r�)r%�values  r'�remote_getFactoryzNestedCopy.remote_getFactory8s
�� ��'�'r)N)r*r+r,r�r�r-r)r'r�r�4s���(r)r�c��eZdZd�Zy)�SimpleCachec�4�d|_ddi|_dg|_yr�r�r1s r'�	__init___zSimpleCache.__init___=r�r)N)r*r+r,r�r-r)r'r�r�<r�r)r�c��eZdZd�Zd�Zy)�NestedComplicatedCachec�"�t�|_yr0)�VeryVeryComplicatedCacheable�cr1s r'rGzNestedComplicatedCache.__init__Ds��-�/��r)c��|jSr0)r�r1s r'�remote_getCachez&NestedComplicatedCache.remote_getCacheGs���v�v�
r)N)r*r+r,rGr�r-r)r'r�r�Cs��0�r)r�c�$�eZdZd�Zd�Zd�Zd�Zy)r�c�.�d|_d|_d|_y)NrR���r�r��foor1s r'rGz%VeryVeryComplicatedCacheable.__init__Ls����������r)c�J�d|_|jjdd�y)N�r�)r��observer�
callRemoter1s r'�setFoo4z$VeryVeryComplicatedCacheable.setFoo4Qs������
�
� � ���*r)c�X�||_|j|j|jd�S)Nr�)r�r�r�r��r%�perspectiver�s   r'�getStateToCacheAndObserveForz9VeryVeryComplicatedCacheable.getStateToCacheAndObserveForUs"�� ��
��V�V�$�&�&����:�:r)c�~�tjd�|jd�||jk(rd|_yy)Nzstopped observing�end)r�msgr�r�r�s   r'�stoppedObservingz-VeryVeryComplicatedCacheable.stoppedObservingYs5�����#�$����E�"��t�}�}�$� �D�M�%r)N)r*r+r,rGr�r�r�r-r)r'r�r�Ks���
+�;�!r)r�c��eZdZd�Zd�Zy)�RatherBaroqueCachec��||_yr0�r�)r%�newFoos  r'�observe_foozRatherBaroqueCache.observe_fooas	����r)c�.�tjd�y)Nzthe end of things)rr�r1s r'�observe_endzRatherBaroqueCache.observe_endds�����#�$r)N)r*r+r,r�r�r-r)r'r�r�`s���%r)r�c�$�eZdZd�Zd�Zd�Zd�Zy)�SimpleLocalCachec�:�|jj|�yr0)�__dict__�update)r%r�s  r'�setCopyableStatez!SimpleLocalCache.setCopyableStatels���
�
���U�#r)c��|jSr0)�checkr1s r'�checkMethodzSimpleLocalCache.checkMethodo����z�z�r)c��|Sr0r-r1s r'�	checkSelfzSimpleLocalCache.checkSelfrs���r)c��yr�r-r1s r'r�zSimpleLocalCache.checkus��r)N)r*r+r,r�r�r�r�r-r)r'r�r�ks��$���r)r�c��eZdZd�Zd�Zd�Zy)�NestedCachec�"�t�|_yr0)r�r�r1s r'rGzNestedCache.__init__}s�����r)c�2�|j|jgSr0�r�r1s r'r�zNestedCache.remote_getCache�s���������r)c��|j|uSr0r�r%�caches  r'�remote_putCachezNestedCache.remote_putCache�s���v�v���r)N)r*r+r,rGr�rr-r)r'rr|s��� �r)rc�$�eZdZd�Zd�Zd�Zd�Zy)�
Observablec��g|_yr0)�	observersr1s r'rGzObservable.__init__�s	����r)c�:�|jj|�yr0)r�append�r%�obss  r'�remote_observezObservable.remote_observe���������c�"r)c�:�|jj|�yr0)r�removers  r'�remote_unobservezObservable.remote_unobserve�rr)c�L�|jD]}|jd||��y)N�notify)rr�)r%�objr�s   r'rzObservable.notify�s'�����	5�H�����$��4�	5r)N)r*r+r,rGrrrr-r)r'r
r
�s���#�#�5r)r
c�$�eZdZd�Zd�Zd�Zd�Zy)�DeferredRemotec��d|_y)Nr��runr1s r'rGzDeferredRemote.__init__�s	����r)c��||_|dzSr�rr�s  r'�runMezDeferredRemote.runMe�r�r)c��Jd��)Nzshouldn't have been run!r-r�s  r'�	dontRunMezDeferredRemote.dontRunMe�s
��,�,�,�qr)c�t�t�}|j|j|j�||_|S)zo
        Return a L{Deferred} to be fired on client side. When fired,
        C{self.runMe} is called.
        )r�addCallbacksrr!�d)r%r$s  r'�remote_doItLaterzDeferredRemote.remote_doItLater�s-��

�J��	���t�z�z�4�>�>�2�����r)N)r*r+r,rGrr!r%r-r)r'rr�s����-�r)rc��eZdZdZdZd�Zy)�ObserverrNc�^�||_|jdz|_|jd|�y)NrR�	unobserve)r�notifiedr�)r%�otherrs   r'�
remote_notifyzObserver.remote_notify�s)������
�
��)��
�
����d�+r))r*r+r,r*rr,r-r)r'r'r'�s���H�
�C�,r)r'c��eZdZd�Zy)�NewStyleCopyc��||_yr0)�s)r%r0s  r'rGzNewStyleCopy.__init__�s	����r)Nr�r-r)r'r.r.�s��r)r.c�$�eZdZdZdZdZd�Zd�Zy)�
NewStyleCopy2rrRc�p�txjdz
c_tj|�}d|_|S)NrRr�)r2�	allocated�object�__new__r�)r%r�s  r'r6zNewStyleCopy2.__new__�s-�����1�$���~�~�d�#����
��r)c�6�txjdz
c_yr�)r2�initializedr1s r'rGzNewStyleCopy2.__init__�s���!�!�Q�&�!r)N)r*r+r,r4r8r�r6rGr-r)r'r2r2�s���I��K�
�E��'r)r2c��eZdZd�Zy)�NewStyleCacheCopyc��|jSr0)r�r�s   r'r�z.NewStyleCacheCopy.getStateToCacheAndObserveFor�s���}�}�r)N)r*r+r,r�r-r)r'r:r:�s��r)r:c��eZdZd�Zd�Zy)�Echoerc��|Sr0r-�r%�sts  r'�remote_echozEchoer.remote_echo�s���	r)c�
�||fSr0r-)r%r@�kws   r'�remote_echoWithKeywordszEchoer.remote_echoWithKeywords�s���B�x�r)N)r*r+r,rArDr-r)r'r=r=�s���r)r=c��eZdZd�Zd�Zy)�CachedReturnerc��||_yr0�rrs  r'rGzCachedReturner.__init__�s	����
r)c��|jSr0rHr?s  r'�remote_giveMeCachez!CachedReturner.remote_giveMeCache�r�r)N)r*r+r,rGrJr-r)r'rFrF�s���r)rFc�*�eZdZd�Zd�Zd�Zd�Zd�Zy)�
NewStyleTestsc��tjt��|_tj�}t|||j��\}|_|_|j|j��|_
y)zY
        Create a pb server using L{Echoer} protocol and connect a client to it.
        )rprirqN)rr�r=rqr�rwrDrL�successResultOf�
getRootObject�ref)r%rirCs   r'�setUpzNewStyleTests.setUp�sf�� �/�/���9����*�*�,�
�)?��]�$�BT�BT�*
�&����T�Y��'�'�
�(C�(C�(E�F��r)c�F�dt_dt_dt_y)zp
        Close client and server connections, reset values of L{NewStyleCopy2}
        class variables.
        rrRN)r2r4r8r�r1s r'�tearDownzNewStyleTests.tearDown�s��
#$�
��$%�
�!��
�r)c����td���jjd��}�jj	���fd�}|j|�|S)zY
        Create a new style object, send it over the wire, and check the result.
        r��echoc����j|t��j|jd��j	|�u�y)Nr�)�assertIsInstancer.�assertEqualr0�assertFalse��res�origr%s ��r'�cbz'NewStyleTests.test_newStyle.<locals>.cbs9����!�!�#�|�4����S�U�U�G�,����S�D�[�)r)�r.rPr�rLrN�addCallback�r%r$r]r\s`  @r'�
test_newStylezNewStyleTests.test_newStyle�sK����G�$���H�H�����-���	�	����	*�
	
�
�
�b���r)c�8���t���jtjd��jtjd��jjd��}�jj���fd�}|j|�|S)zN
        Send a new style object and check the number of allocations.
        rRrUc����j|t��j|jd��jtjd��jtj
d��j
|��y)Nr�r�rR)rWr2rXr�r4r8�assertIsNotrZs ��r'r]z$NewStyleTests.test_alloc.<locals>.cbsc����!�!�#�}�5����S�Y�Y��*����]�4�4�a�8����]�6�6��:����S�$�'r))	r2rXr4r8rPr�rLrNr_r`s`  @r'�
test_alloczNewStyleTests.test_alloc
st����������0�0�!�4�����2�2�A�6��H�H�����-���	�	����	(�	
�
�
�b���r)c����td���jjd�dd��}�jj	���fd�}|j|�|S)zo
        Create a new style object with keywords,
        send it over the wire, and check the result.
        �value1�echoWithKeywords�one�two��keyword1�keyword2c�.���j|t��j|dt��j|dt��j	|dj
d��j
|d���j	|dddd��y)NrrRrgrirjrk)rW�tupler.�dictrXr0rdrZs ��r'r]z3NewStyleTests.test_newStyleWithKeywords.<locals>.cb.s�����!�!�#�u�-��!�!�#�a�&�,�7��!�!�#�a�&�$�/����S��V�X�X�x�0����S��V�T�*����S��V�%�U�%K�Lr)r^r`s`  @r'�test_newStyleWithKeywordsz'NewStyleTests.test_newStyleWithKeywords#sZ���
�H�%���H�H�����u�u�
 �
��	
�	�	����	M�	
�
�
�b���r)N)r*r+r,rQrSrarerqr-r)r'rLrL�s��	G� �� �,r)rLc� �eZdZdZdZd�Zd�Zy)�ConnectionNotifyServerFactoryaj
    A server factory which stores the last connection and fires a
    L{Deferred} on connection made. This factory can handle only one
    client connection.

    @ivar protocolInstance: the last protocol instance.
    @type protocolInstance: C{pb.Broker}

    @ivar connectionMade: the deferred fired upon connection.
    @type connectionMade: C{Deferred}
    Nc�b�tjj||�t�|_y)z)
        Initialize the factory.
        N)rr�rGr�connectionMade)r%�roots  r'rGz&ConnectionNotifyServerFactory.__init__Is$��	���#�#�D�$�/�&�j��r)c�b�||_|jdc}|_|�|jd�yy)zF
        Store the protocol and fire the connection deferred.
        N)�protocolInstancerur�)r%rr$s   r'�clientConnectionMadez2ConnectionNotifyServerFactory.clientConnectionMadePs7��!)���!%�!4�!4�d���4���=�
�J�J�t��r))r*r+r,r3rxrGryr-r)r'rsrs:s��
���)�r)rsc��eZdZd�Zd�Zd�Zy)�NewStyleCachedTestsc����t��_d�j_tjdtt
�j����_tj�}tjd�jj�j|��fd�}|j�j|�}�jjj }t#||g�S)zi
        Create a pb server using L{CachedReturner} protocol and connect a
        client to it.
        r�r�	localhostc���|�_yr0)rP)rPr%s �r'�gotRootz*NewStyleCachedTests.setUp.<locals>.gotRooths
����D�Hr))r:r\r0r�	listenTCPrsrFrDrr��
connectTCP�getHost�portrOr_�factoryrur)r%rir�d1�d2s`    r'rQzNewStyleCachedTests.setUp[s����
&�'��	���	�	���'�'�
�,�^�D�I�I�-F�G�
����*�*�,�
����;����(;�(;�(=�(B�(B�M�R�	��
(�
(�
*�
6�
6�w�
?��
�[�[�
 �
 �
/�
/���b�"�X�&�&r)c��|jjjjj	�|j
jjj	�|jj�S)z6
        Close client and server connections.
        )rDr�rxrV�loseConnectionrPrc�
stopListeningr1s r'rSzNewStyleCachedTests.tearDownosS��	
�����,�,�6�6�E�E�G������!�!�0�0�2��{�{�(�(�*�*r)c����jjd�j�}�fd�}|j|d�|j|d�|S)z�
        A new-style cacheable object can be retrieved and re-retrieved over a
        single connection.  The value of an attribute of the cacheable can be
        accessed on the receiving side.
        �giveMeCachec����j|t��jd|j��j	�j
|�|r-|�_�jjd�j
�Sy)Nr�r�)	rWr:rXr0rdr\r[rPr�)r[�againr%s  �r'r]z2NewStyleCachedTests.test_newStyleCache.<locals>.cbsh����!�!�#�'8�9����W�c�e�e�,����T�Y�Y��,������x�x�*�*�=�$�)�)�D�D�r)TF)rPr�r\r_)r%r$r]s`  r'�test_newStyleCachez&NewStyleCachedTests.test_newStyleCachewsH���
�H�H���
�t�y�y�9��	E�	
�
�
�b�$��	�
�
�b�%� ��r)N)r*r+r,rQrSr�r-r)r'r{r{Zs��'�(+�r)r{c�v�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zy)�BrokerTestsNc�N�	tjd�y#t$rYywxYw)N�None-None-TESTING.pub)�os�unlink�OSErrorr1s r'rSzBrokerTests.tearDown�s&��	��I�I�-�.���	��	�s��	$�$c�,�|jd|���y)Nz&This should cause a return value, not ��fail)r%�errors  r'�
thunkErrorBadzBrokerTests.thunkErrorBad�s���	�	�:�5�'�B�Cr)c��||_yr0)�thunkResult�r%�results  r'�thunkResultGoodzBrokerTests.thunkResultGood�s
��!��r)c��yr0r-)r%�tbs  r'�thunkErrorGoodzBrokerTests.thunkErrorGood����r)c�,�|jd|���y)Nz This should cause an error, not r�r�s  r'�thunkResultBadzBrokerTests.thunkResultBad�s���	�	�4�V�H�=�>r)c��t|��\}}}Gd�dtj�}Gd�dtj�}|jd|��|j	d�}|�}|�}|jd||�|j
�|j
�|j
�|j|j|d�|j|jd�|jd��y)	N�rpc��eZdZd�Zy)�%BrokerTests.test_reference.<locals>.Xc��||_yr0)�caughtr�s  r'�remote_catchz2BrokerTests.test_reference.<locals>.X.remote_catch�s	��!��r)N)r*r+r,r�r-r)r'�Xr��s��
"r)r�c��eZdZd�Zy)�%BrokerTests.test_reference.<locals>.Yc�(�|jd|�y)N�catch�r��r%�a�bs   r'�remote_throwz2BrokerTests.test_reference.<locals>.Y.remote_throw�s�����W�a�(r)N)r*r+r,r�r-r)r'�Yr��s��
)r)r�r��throwzX should have caught Z)r�r�
Referenceable�setNameForLocal�
remoteForNamer�rL�assertIsr�rX�remoteMethod)	r%r�r0rLr�r�r�r�r�s	         r'�test_referencezBrokerTests.test_reference�s���-�4�8�
��1�d�	"�� � �	"�	)�� � �	)�	
���#�q�s�#�
�O�O�C� ��
�C��
�C��	���W�a��#��	�	���	�	���	�	���
�
�a�h�h��#;�<�	
�������0�!�.�.��2I�Jr)c��t|��\}}}||f||ffD]�\}}t�}|jd|�|jd�}d|_|jd|jdz
�j
|j|j�|j�|j�|j|j|jd���y)Nr�r���thunkrRzresult wasn't received.)r�r�r�r��expectedThunkResultr�r#r�r�rLrXr�)r%r�r0rLr�r�r��bars        r'�test_resultzBrokerTests.test_result�s���-�4�8�
��1�d���F�Q��F�N�	�D�A�q��.�C�
���e�S�)��/�/�%�(�C�'(�D�$��N�N�7�D�$<�$<�q�$@�A�N�N��$�$�d�&8�&8�
�
�I�I�K��I�I�K����� � �$�":�":�<U�
�	r)c��||_yr0)�nestedRemoter�s  r'�refcountResultzBrokerTests.refcountResult�s
��"��r)c
�v�g}g}t|��\}}}t�}|jd|�|jd�}t	t
jdz�D]u}|jjs|jjrnG|jd�j|j|j�|j��wt
jdz
}	|j|jjd�|jt|�|	d|	�dt|����y)	Nr�r��
�	getSimplerRztransport was not closedz	expected z got )r�r�r�r��ranger�MAX_BROKER_REFSrV�closedr�r#rrL�
assertTruerX�len)
r%�l�er�r0rLr�r��igno�expecteds
          r'�test_tooManyRefszBrokerTests.test_tooManyRefs�s�������-�4�8�
��1�d��n��	���%��%�
�O�O�E�"���"�,�,�r�1�2�	�D��{�{�!�!�Q�[�[�%7�%7��
�L�L��%�2�2�1�8�8�Q�X�X�F��I�I�K�		�
�%�%��)��������*�*�,F�G�����Q���Y�x�j��c�!�f�X�+N�Or)c��t|��\}}}t�}|jd|�|jd�}|j	d�j|j|j�|j�|j�|j|jjd�|j|jjdd�|j|jjdd�y)	Nr�r��getCopyrRr�r�rrp)r�r�r�r�r�r#r�r�rLrXr�r�r�r�)r%r�r0rLr�r�s      r'�	test_copyzBrokerTests.test_copy�s���-�4�8�
��1�d��l��	���%��%�
�O�O�E�"��	���Y��,�,�T�-A�-A�4�CU�CU�V��	�	���	�	������)�)�+�+�Q�/�����)�)�+�+�G�4�g�>�����)�)�+�+�A�.��7r)c��t|��\}}}t�}t�}|jd|�|j	d�}|jd|�|j
�|jd�|j
�|j
�|jd�|j
�|j
�|j|jd�|j|jdd�y)Nr�r��observerRr�z
didn't notifyznotified too much)r�r
r'r�r�r�rLr�assertIsNotNonerrX)r%r�r0rLr�r��ras       r'�test_observezBrokerTests.test_observe�s���-�4�8�
��1�d�
�L���J��	���#�q�!�
�_�_�S�
!��
�
�
�i��#��	�	��	������	�	���	�	��	������	�	���	�	�����Q�U�U�O�4��������#6�7r)c�j�t|��\}}}t�}|jd|�|jd�}|j	�|j	�g}|jd�j
|j�|j	�|j	�|j|jd�|jjd�|j|jdd�|j	�|j	�|j|ddd	�y)
Nr�r$�	doItLaterzDeferred method run too early.rIzDeferred method run too late.r�zIncorrect result.)
r�rr�r�rLr�r_rrYrr$r�rX)r%r�r0rLr$r��resultss       r'�
test_deferzBrokerTests.test_defers���-�4�8�
��1�d����	���#�q�!�
�O�O�C� ���	�	���	�	����	���[�!�-�-�g�n�n�=��	�	���	�	�������� @�A�	�����Q���������#B�C��	�	���	�	��������Q�(;�<r)c�v�t|��\}}}t�}|jd|�|jd�}|j	d�j|j|j�|j�|j�|jj}|j||j�|`	tjdk\rtj �|j�|j�|j�|j#||j�y)Nr�r�r��)r�r�r�r�r�r#r�r�rLr��luid�assertIn�localObjects�sys�
hexversion�gc�collect�assertNotIn)r%r�r0rLr�r��rluids       r'�
test_refcountzBrokerTests.test_refcounts���-�4�8�
��1�d��n��	���%��%��o�o�e�$�����{�#�0�0�����!3�!3�	
�
	
�	�	���	�	���!�!�&�&���
�
�e�Q�^�^�,����>�>�Y�&��J�J�L��	�	���	�	���	�	���������/r)c�*�t|��\}}}t�}t�}|j}|j	d|�|j	d|�|jd�}|jd�}g}	|j
d�j|	j�j|	j�|j
d�j|	j�j|	j�g}
|j
d�j|
j�|j
d�j|
j�|j�|j|
djd�|j|
djd�|j|
djd�|j�|j�|j|
djd	�|jt!|	�d�|	dd}|j#|j%�j&|d
�|j#|j)�|d�g}|j
d|�j|j�|j�|j+|d�|j|j-d�|j-d��|j.}
|
dj.}|j1|
|j2d
�~	~|j�~
~|j�t4j6dk\rt9j:�|j�|j=|
|j2d�|j=|
|j>d�|j=||j2d�|j=||j>d�|jA|jBd�y)Nr�r�xxx�getCacherrRr�r�r�zpotential refcounting issuez!other potential refcounting issue�putCachezremote cache doesn't have itr�zServer still had it after GCzClient still had it after GCz!Server still had complex after GCz!Client still had complex after GCzobserver was not removed)"r�rr�r�r�r�r�r_r�
addErrbackrNrXr�r�r�r�r��assertIdenticalr��__self__r�r�r�r�r��remotelyCachedObjectsr�r�r�r�r��locallyCachedObjects�assertIsNoner�)r%r�r0rLr�obj2�vcc�o2�o3�coll�complex�cp�col2r��baroqueLuids               r'�
test_cachezBrokerTests.test_cache4s!��-�4�8�
��1�d��m��%�'���f�f��	���%��%�	���%��&�
�_�_�U�
#��
�_�_�U�
#����
�
�
�j�!�-�-�d�k�k�:�E�E�d�k�k�R�
�
�
�j�!�-�-�d�k�k�:�E�E�d�k�k�R���
�
�
�j�!�-�-�g�n�n�=�
�
�
�j�!�-�-�g�n�n�=��
�
����������q�)���������q�)����������+����
��
�
�����������+�����T��A�&�
�!�W�Q�Z������N�N��%�%�r�+H�	
�	
���R�\�\�^�R�1T�U���
�
�
�j�"�%�1�1�$�+�+�>��
�
������Q�� ��������4�b�o�o�j�6Q�R��w�w���a�j�o�o���
�
�d�A�3�3�5S�T����
�
�����
�
���>�>�Y�&��J�J�L��
�
������q�6�6�8V�W�����q�5�5�7U�V������0�0�2U�	
�	
�����/�/�1T�	
�	
���#�,�,�(B�Cr)c��	tjd�t|��\}}}t	�}|jd|�|j
d�}g}|jd�j|j|j�|j�|j�}|j|jd�|j|jd�|j|j d�|j|j"d�t|��\}}}|jd|�|j
d�}|jd�j|j|j�|j�|j�}|j|j"d�y#t$rY���wxYw)Nr�r�r��getPubrRr)r�r�r�r��GetPublisherr�r�r�r#rr�rNr�rX�activateCalled�isActivated�yayIGotPublished�_wasCleanWhenLoaded)r%r�r0rLr�r��accumrs        r'�test_publishablezBrokerTests.test_publishablevsl��	��I�I�-�.�.�4�8�
��1�d��n��	���%��%��o�o�e�$�������x� �-�-�e�l�l�D�<N�<N�O��
�
���i�i�k������+�+�Q�/�������!�,�����-�-�q�1�����0�0�!�4�-�4�8�
��1�d�	���%��%��o�o�e�$�����x� �-�-�e�l�l�D�<N�<N�O��
�
���i�i�k������0�0�!�4��/�	��	�s�G�	G
�G
c�&�|j|_yr0)r�r�)r%�vals  r'�gotCopyzBrokerTests.gotCopy�s���6�6��r)c��t|��\}}}d}t�}|jd|�|jd�}|j	d|�j|j|j�|j�|j�|j�|j|j|d|j���y)Nr��cr��
getFactoryz!ID not correct on factory object )r�r�r�r�r�r#r
r�rLrXr�)r%r�r0rL�IDrr�s       r'�test_factoryCopyzBrokerTests.test_factoryCopy�s���-�4�8�
��1�d�
���l��	���%��%�
�O�O�E�"��	���\�2�&�3�3�D�L�L�$�BU�BU�V��	�	���	�	���	�	���������/��0@�0@�/A�B�	
r))r*r+r,r�rSr�r�r�r�r�r�r�r�r�r�r�r�rr
r
rr-r)r'r�r��sb���K��D�"�
�?�K�0�(#�P� 
8�8�(=�$0�8@D�D5�8"�
r)r�s�helloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldhelloworldc��|a|ayr0)�callbackArgs�callbackKeyword)�argsrCs  r'�finishedCallbackr�s���L��Or)c��eZdZd�Zd�Zy)�	Pagerizerc�0�|||c|_|_|_yr0)r�rrC)r%r�rrCs    r'rGzPagerizer.__init__�s��,4�d�B�)��
�t�y�$�'r)c��tj|td|jg|j��i|j
��dx|_|_y)N�d)r�StringPager�	bigStringr�rrC�r%�	collectors  r'�remote_getPageszPagerizer.remote_getPages�sE������y�#�t�}�}�	
�7;�y�y�	
�DH�G�G�	
�#�"��	�D�Gr)N)r*r+r,rGr!r-r)r'rr�s��?�#r)rc��eZdZdZd�Zd�Zy)�
FilePagerizerNc�>�||_|||c|_|_|_yr0)�filenamer�rrC)r%r%r�rrCs     r'rGzFilePagerizer.__init__�s�� ��
�,4�d�B�)��
�t�y�$�'r)c���tj|t|jd�|jg|j
��i|j��|_dx|_|_y)N�rb)r�	FilePager�openr%r�rrC�pagerrs  r'r!zFilePagerizer.remote_getPages�sP���^�^��t�D�M�M�4�0�$�-�-�
�BF�)�)�
�OS�w�w�
��
�#�"��	�D�Gr))r*r+r,r*rGr!r-r)r'r#r#�s���E�?�#r)r#c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�PagingTestsz0
    Test pb objects sending data by pages.
    c��|j�|_t|jd�5}|jt�ddd�y#1swYyxYw)z?
        Create a file used to test L{util.FilePager}.
        �wbN)�mktempr%r)�writer)r%�fs  r'rQzPagingTests.setUp�sB�����
��
�
�$�-�-��
&�	�!�
�G�G�I��	�	�	�s�A�Ac���t|��\}}}|jdttdd���|j	d�}g}tj|d�j|j�|s|j�|s�|jdj|d�td	�|jtd
d�|jtddid�y
)zg
        Test L{util.StringPager}, passing a callback to fire when all pages
        are sent.
        r�r��hellor��r��getPagesr)r�'Pages received not equal to pages sent!)r3�Completed callback not invokedr�N)r�r�rrr�r�getAllPagesr_rrLrX�joinrrr�r%r�r0rLr�r�s      r'�test_pagingWithCallbackz#PagingTests.test_pagingWithCallback�s���
.�4�8�
��1�d�	���%��+;�W�B�!O�P�
�O�O�E�"��������J�'�3�3�A�H�H�=���I�I�K������H�H�Q�q�T�N�I�'P�	
�	
����z�3S�T�����g�r�]�,L�	
r)c�Z�t|��\}}}|jdtd��|jd�}g}t	j
|d�j
|j�|s|j�|s�|jdj|d�td�y)z>
        Test L{util.StringPager} without a callback.
        r�r�Nr5r)rr6)r�r�rr�rr8r_rrLrXr9rr:s      r'�test_pagingWithoutCallbackz&PagingTests.test_pagingWithoutCallback�s���.�4�8�
��1�d�	���%��4��1�
�O�O�E�"��������J�'�3�3�A�H�H�=���I�I�K������H�H�Q�q�T�N�I�'P�	
r)c���|j�}t|d�j�t|��\}}}t	|d�}|jd|�|j
d�}g}tj|d�j|j�d}|s"|dkDr|j�|dz}|s|dkDr�|s|jd	�|jd
j|d�d
d�y)z@
        Test L{util.FilePager}, sending an empty file.
        �wr�Nr�r5r�rrRzgetAllPages timed outr)r6)r/r)�closer�r#r�r�rr8r_rrLr�rXr9)	r%�
filenameEmptyr�r0rL�	pagerizerr�r��ttls	         r'�test_emptyFilePagingz PagingTests.test_emptyFilePaging�s������
�
��]�C� �&�&�(�-�4�8�
��1�d�!�-��6�	�	���%��+�
�O�O�E�"��������J�'�3�3�A�H�H�=�����a���I�I�K��1�H�C���a����I�I�-�.�������!�A�$���.W�Xr)c�.�t|��\}}}t|jtdd��}|j	d|�|jd�}g}t
j|d�j|j�|s|j�|s�|jdj|d�td	�|jtd
d�|jtddid�|j|j j"g�y
)z�
        Test L{util.FilePager}, passing a callback to fire when all pages
        are sent, and verify that the pager doesn't keep chunks in memory.
        r��frodo�	r4r�r5r)rr6)rFr7r�N)r�r#r%rr�r�rr8r_rrLrXr9rrrr*�chunks�r%r�r0rLrBr�r�s       r'�test_filePagingWithCallbackz'PagingTests.test_filePagingWithCallbacks���
.�4�8�
��1�d�!�$�-�-�1A�7�RS�T�	�	���%��+�
�O�O�E�"��������J�'�3�3�A�H�H�=���I�I�K������H�H�Q�q�T�N�I�'P�	
�	
����z�3S�T�����g�q�\�+K�	
�	
������/�/��4r)c��t|��\}}}t|jd�}|jd|�|j	d�}g}tj|d�j|j�|s|j�|s�|jdj|d�td�|j|jjg�y)z<
        Test L{util.FilePager} without a callback.
        r�Nr�r5r)rr6)r�r#r%r�r�rr8r_rrLrXr9rr*rHrIs       r'�test_filePagingWithoutCallbackz*PagingTests.test_filePagingWithoutCallback%s���.�4�8�
��1�d�!�$�-�-��6�	�	���%��+�
�O�O�E�"��������J�'�3�3�A�H�H�=���I�I�K������H�H�Q�q�T�N�I�'P�	
�	
������/�/��4r)N)
r*r+r,r3rQr;r=rDrJrLr-r)r'r,r,�s&����
�(

�Y�(5�,5r)r,c��eZdZd�Zy)�DumbPublishablec�
�ddiS)NrrRr-r1s r'�getStateToPublishz!DumbPublishable.getStateToPublish8s
��"�A�&�&r)N)r*r+r,rPr-r)r'rNrN7s��'r)rNc��eZdZd�Zy)�DumbPubc��d|_yr�)rr1s r'�	activatedzDumbPub.activated=s
����r)N)r*r+r,rTr-r)r'rRrR<s�� r)rRc��eZdZd�Zd�Zy)rc�$�td�|_y)N�TESTING)rN�pubr1s r'rGzGetPublisher.__init__Bs��"�9�-��r)c��|jSr0)rXr1s r'�
remote_getPubzGetPublisher.remote_getPubEs���x�x�r)N)r*r+r,rGrZr-r)r'rrAs��.�r)rc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�DisconnectionTestsz'
    Test disconnection callbacks.
    c��td|����)NzI shouldn't have been called: �r�)r%rs  r'r�zDisconnectionTests.errorQs���;�D�6�B�C�Cr)c��d|_y)z.
        Called on broker disconnect.
        rRN)�gotCallbackr1s r'�gotDisconnectedz"DisconnectionTests.gotDisconnectedTs����r)c�J�|j||j�d|_y)z7
        Called on RemoteReference disconnect.
        rRN)rX�remoteObject�objectCallback�r%�os  r'�objectDisconnectedz%DisconnectionTests.objectDisconnectedZs"��	
����D�-�-�.���r)c�Z�t|��\}}}|j�|jdt��|j	d�}g}|jdt
��j|j�|j�|jt|�d�y)Nr�rf�
setBadCopyrR)r�rLr��
BadCopySetr�r��BadCopyabler�rrNrXr�)r%r�r0rL�gr�s      r'�test_badSerializationz(DisconnectionTests.test_badSerializationas|��-�4�8�
��1�d��	�	��	���#�z�|�,�
�O�O�C� ����	���\�;�=�1�<�<�Q�X�X�F��
�
������Q���#r)c���t|��\}}}|j�|jdt��|j	d�}|j�|j�|j�|j|j�|j|j|j�|j|j�|j|j|j�|j|j�|j|j|j�|j|j|j�|j|j�|j|j|j�|j|j|j�|j|j�|j|j�||_|j!t#j$t&j(��|j+|j,�|j+|j.�y)Nr�rf)r�rLr�r�r��notifyOnDisconnectr�r��disconnects�dontNotifyOnDisconnectr��
_disconnected�disconnectCallbacksrargrcr`rrarrbr�r`rd)r%r�r0rL�rs     r'�test_disconnectionz%DisconnectionTests.test_disconnectionks���-�4�8�
��1�d��	�	��	���#�|�~�.�
�O�O�C� ���	�	���	�	���	�	��	
���T�Z�Z�(��
�
�d�j�j�!�-�-�0�	� � ����,�������Q�]�]�3�	���T�Z�Z�(��
�
�a�o�o�q�}�}�5��
�
�d�j�j�!�"7�"7�8�	� � ����,�������!�-�-�8�������Q�%:�%:�;�	
���T�1�1�2�	���T�4�4�5����	
�������)=�)=�>�?�����(�(�)�����+�+�,r)N)	r*r+r,r3r�rargrmrur-r)r'r\r\Ls!���D�� �$�!-r)r\c��eZdZy)�FreakOutNr�r-r)r'rwrw�r�r)rwc��eZdZd�Zy)rkc��t��r0)rw)r%�ps  r'�getStateToCopyForzBadCopyable.getStateToCopyFor�s
���j�r)N)r*r+r,r{r-r)r'rkrk�s��r)rkc��eZdZd�Zy)rjc��yr0r-)r%�bcs  r'�remote_setBadCopyzBadCopySet.remote_setBadCopy�s��r)N)r*r+r,rr-r)r'rjrj�s��r)rjc�$�eZdZdZd�Zdd�Zd�Zy)�LocalRemoteTestrc��|dzSr�r-)r%r�s  r'�	sync_add1zLocalRemoteTest.sync_add1�����1�u�r)c��||zSr0r-)r%r�r�s   r'�	async_addzLocalRemoteTest.async_add�r�r)c��t��r0r^r1s r'�
async_failzLocalRemoteTest.async_fail�s
���n�r)N)rrR)r*r+r,�reportAllTracebacksr�r�r�r-r)r'r�r��s������r)r�c�6�eZdZdZdxZZd�Zd�Zd�Zd�Z	d�Z
y)	�
MyPerspectivez�
    @ivar loggedIn: set to C{True} when the avatar is logged in.
    @type loggedIn: C{bool}

    @ivar loggedOut: set to C{True} when the avatar is logged out.
    @type loggedOut: C{bool}
    Fc��||_yr0�r;�r%r;s  r'rGzMyPerspective.__init__�s	�� ��
r)c��|jS)zT
        Return the avatar identifier which was used to access this avatar.
        r�r1s r'�perspective_getAvatarIdz%MyPerspective.perspective_getAvatarId�s���}�}�r)c��t�Sr0)�MyViewr1s r'�perspective_getViewPointz&MyPerspective.perspective_getViewPoint�s	���x�r)c��||zS)z�
        Add the given objects and return the result.  This is a method
        unavailable on L{Echoer}, so it can only be invoked by authenticated
        users who received their avatar from L{TestRealm}.
        r-r�s   r'�perspective_addzMyPerspective.perspective_add�s
���1�u�r)c��d|_y�NT��	loggedOutr1s r'�logoutzMyPerspective.logout��	����r)N)r*r+r,r3�loggedInr�rGr�r�r�r�r-r)r'r�r��s,���!� �H�y�!����r)r�c��eZdZdZeZdZd�Zy)�	TestRealma�
    A realm which repeatedly gives out a single instance of L{MyPerspective}
    for non-anonymous logins and which gives out a new instance of L{Echoer}
    for each anonymous login.

    @ivar lastPerspective: The L{MyPerspective} most recently created and
        returned from C{requestAvatar}.

    @ivar perspectiveFactory: A one-argument callable which will be used to
        create avatars to be returned from C{requestAvatar}.
    Nc�F�|tjk(sJ�|dk(sJ�|tjurtjt	�d�fS|j|�|_d|j_tj|j|jjfS)z�
        Verify that the mind and interface supplied have the expected values
        (this should really be done somewhere else, like inside a test method)
        and return an avatar appropriate for the given identifier.
        �BRAINS!c��yr0r-r-r)r'r8z)TestRealm.requestAvatar.<locals>.<lambda>�r9r)T)	rr:r�	ANONYMOUSr=�perspectiveFactory�lastPerspectiver�r�)r%r;r<�	interfaces    r'r?zTestRealm.requestAvatar�s����B�O�O�+�+�+��y� � � ��x�)�)�)��?�?�F�H�l�:�:�#'�#:�#:�8�#D�D� �,0�D� � �)��O�O�T�%9�%9�4�;O�;O�;V�;V�W�Wr))r*r+r,r3r�r�r�r?r-r)r'r�r��s��
�'���O�
Xr)r�c��eZdZd�Zy)r�c�"�t|t�Sr0)r"r�r$s  r'�
view_checkzMyView.view_check�s���$�
�.�.r)N)r*r+r,r�r-r)r'r�r��s��/r)r�c��eZdZdZd�Zd�Zy)�
LeakyRealmz]
    A realm which hangs onto a reference to the mind object in its logout
    function.
    c��||_y)z�
        Create a L{LeakyRealm}.

        @param mindEater: a callable that will be called with the C{mind}
        object when it is available
        N)�
_mindEater)r%�	mindEaters  r'rGzLeakyRealm.__init__�s��$��r)c�x���|j��|j|��tj���fd�fS)Nc�(����j�fSr0)r�)r<�persps��r'r8z*LeakyRealm.requestAvatar.<locals>.<lambda>s����u�|�|�~�0F�r))r�r�rr:)r%r;r<r�r�s  ` @r'r?zLeakyRealm.requestAvatars1���������'�'��1������(F�G�Gr)N)r*r+r,r3rGr?r-r)r'r�r��s���
$�Hr)r�c��eZdZdZd�Zy)�NewCredLeakTestsz/
    Tests to try to trigger memory leaks.
    c�����	�d�_�fd�}t�t|���\}�	�g�|jd�}|j	dd�}d�}|j|����	fd�}|j|��j
��j�d	g�tj��j�j��y)
z�
        The server does not leak a reference when the client disconnects
        suddenly, even if the cred logout function forms a reference cycle with
        the perspective.
        Nc�:��tj|��_yr0)�weakrefrP�mindRef)r<r%s �r'�
setMindRefz4NewCredLeakTests.test_logoutLeak.<locals>.setMindRefs���"�;�;�t�,�D�Lr))rpr�rv�loginr�c�n�|\}}t�}|jdtj|d�|�S)N�respondr�)r�r�rr�)r��	challenge�
challengerr<s    r'�
cbResponsez4NewCredLeakTests.test_logoutLeak.<locals>.cbResponse$s8��$%�!�I�z��>�D��(�(��2�:�:�i��:�D��
r)c����j��jd��jtjtd���y)NrR�boom)rPrr`rrar�)�_�connectionBrokenrLrts ���r'r`z8NewCredLeakTests.test_logoutLeak.<locals>.connectionLost-s6����I�I�K��#�#�A�&��'�'�����V�8L�(M�Nr)rR)r�r�r�r�r�r_rNrXr�r�r�)
r%r�rsrvr$r�r`r�rLrts
`      @@@r'�test_logoutLeakz NewCredLeakTests.test_logoutLeaks�������	-�,D��Z�
�3�,
�(��l�D�
���)�)�&�1���O�O�G�X�.��	�	
�
�
�j�!�	O�
	
�
�
�n�%�	
�
�
�����)�A�3�/�
	�
�
�����$�,�,�.�)r)N)r*r+r,r3r�r-r)r'r�r�	s���.*r)r�c��eZdZdZd�Zdd�Zejej�fd�Z
d�Zd�Zd�Z
d	�Zd
�Zd�Zd�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�NewCredTestsz=
    Tests related to the L{twisted.cred} support in PB.
    c���t�|_tj|j�|_t	|j�|_t
j�|_y)z�
        Create a portal with no checkers and wrap it around a simple test
        realm.  Set up a PB server on a TCP port which serves perspectives
        using that portal.
        N)	r�r�r
r�rsrqrr�rir1s r'rQzNewCredTests.setUpDsC���[��
��m�m�D�J�J�/���:�4�;�;�G����/�/�1��r)Nc�P�t||j|j�\|_|_|_t
�|_ttjddd�|j�|_|jj�j|j�y)a�
        Connect a client obtained from C{clientFactory} and a server
        obtained from the current server factory via an L{IOPump},
        then assign them to the appropriate instance variables

        @ivar clientFactory: the broker client factory
        @ivar clientFactory: L{pb.PBClientFactory} instance

        @ivar client: the client broker
        @type client: L{pb.Broker}

        @ivar server: the server broker
        @type server: L{pb.Broker}

        @ivar pump: the IOPump connecting the client and server
        @type pump: L{IOPump}

        @ivar connector: A connector whose connect method recreates
            the above instance variables
        @type connector: L{twisted.internet.base.IConnector}
        �TCPr]i�N)rwrirqrCrDrLry�connectorStater�r
�IPv4Addressrfrr_�establishClientAndServer)r%�_ignoreds  r'r�z%NewCredTests.establishClientAndServerOs���,/E��$�$�$�d�&8�&8�/
�+���T�[�$�)�>�?���3�����{�D�9�4�;N�;N�
���	
���+�+�-�9�9�$�:W�:W�Xr)c���|j|jjj�|jj	|�|j
j
|j|�y)a�
        Asserts that the client broker's transport was closed and then
        mimics the event loop by calling the broker's connectionLost
        callback with C{reason}, followed by C{self.clientFactory}'s
        C{clientConnectionLost}

        @param reason: (optional) the reason to pass to the client
            broker's connectionLost callback
        @type reason: L{Failure}
        N)r�rCrVr�r`rirhrf)r%rgs  r'�completeClientLostConnectionz)NewCredTests.completeClientLostConnectionosN��	
������-�-�4�4�5�	
���"�"�6�*����/�/�����Gr)c����j��jj�}�fd�}�fd�}|j|�|j|�|S)z�
        Assert that L{PBClientFactory.getRootObject}'s Deferred fires with
        a L{RemoteReference}, and that disconnecting it runs its
        disconnection callbacks.
        c�H���j|tj�|Sr0)rWr�RemoteReference)�rootObjr%s �r'�
gotRootObjectz6NewCredTests.test_getRootObject.<locals>.gotRootObject�s����!�!�'�2�+=�+=�>��Nr)c���t�}|j|j��jj	��j�|Sr0)rror�ri�
disconnectr�)r��disconnectedDeferredr%s  �r'r�z3NewCredTests.test_getRootObject.<locals>.disconnect�sD���#+�:� ��&�&�';�'D�'D�E����)�)�+��-�-�/�'�'r)�r�rirOr_)r%�rootObjDeferredr�r�s`   r'�test_getRootObjectzNewCredTests.test_getRootObject�sS���	
�%�%�'��,�,�:�:�<��	�	(�	�#�#�M�2��#�#�J�/��r)c����j��jj�}�fd�}|j|�S)z�
        Test that when a connection is lost, calling a method on a
        RemoteReference obtained from it raises L{DeadReferenceError}.
        c�����t�}�j|j���fd�}|j|��jj��j
�|S)Nc�\���jtj�jd�y)N�method)�assertRaisesr�DeadReferenceErrorr�)�ignr�r%s ��r'�lostConnectionzSNewCredTests.test_deadReferenceError.<locals>.gotRootObject.<locals>.lostConnection�s!����!�!�"�"7�"7��9K�9K�X�Vr))rror�r_rir�r�)r�r�r�r%s`  �r'r�z;NewCredTests.test_deadReferenceError.<locals>.gotRootObject�sZ���#+�:� ��&�&�';�'D�'D�E�
W�
!�,�,�^�<����)�)�+��-�-�/�'�'r)r�)r%r�r�s`  r'�test_deadReferenceErrorz$NewCredTests.test_deadReferenceError�s=���
	
�%�%�'��,�,�:�:�<��	(��*�*�=�9�9r)c����Gd�dtj�}|��_�j��jj	�}�fd�}|j|�S)z�
        Test that if the L{reconnecting} flag is passed with a True value then
        a remote call made from a disconnection notification callback gets a
        result successfully.
        c��eZdZdZd�Zy)�=NewCredTests.test_clientConnectionLost.<locals>.ReconnectOnceFc��|j}d|_tjj||||�}|r|j	�|Sr�)�reconnectedAlreadyrr�rhr�)r%rfrg�reconnectingr�s     r'rhzRNewCredTests.test_clientConnectionLost.<locals>.ReconnectOnce.clientConnectionLost�sM��#'�#:�#:�:��*.��'��+�+�@�@��)�V�\��� ��%�%�'��
r)N)r*r+r,r�rhr-r)r'�
ReconnectOncer��s
��!&��
r)r�c����j|tj�t�}|j	|j
��jj��j��fd�}|j|�S)Nc�d���jj�}�fd�}|j|�S)Nc�����j|tj�t�}|j	|j
��jj��j�|Sr0)	rWrr�rror�rir�r�)�anotherRootObjr$r%s  �r'�gotAnotherRootObjectzqNewCredTests.test_clientConnectionLost.<locals>.gotRootObject.<locals>.disconnected.<locals>.gotAnotherRootObject�sU����)�)�.�"�:L�:L�M� �
�A�"�5�5�a�j�j�A��&�&�1�1�3��5�5�7��Hr))rirOr_)r�r$r�r%s   �r'r_zSNewCredTests.test_clientConnectionLost.<locals>.gotRootObject.<locals>.disconnected�s.����&�&�4�4�6����}�}�%9�:�:r))
rWrr�rror�rir�r�r_)r�r$r_r%s   �r'r�z=NewCredTests.test_clientConnectionLost.<locals>.gotRootObject�sf����!�!�'�2�+=�+=�>��
�A��&�&�q�z�z�2����)�)�+��-�-�/�
;��=�=��.�.r))rr�rir�rOr_)r%r�r�r�s`   r'�test_clientConnectionLostz&NewCredTests.test_clientConnectionLost�sY���	�B�.�.�	�+�_����%�%�'��,�,�:�:�<��	/�0�*�*�=�9�9r)c��|j�|jjd�}|jt	j
t
���|jtjtj��y)z�
        Test that if a Broker loses its connection without receiving any bytes,
        it doesn't raise any exceptions or log any errors.
        )r]i90N)r�rqrkrmrrnrlr`rrarrb)r%�serverProtos  r'�test_immediateClosez NewCredTests.test_immediateClose�s_��
	
�%�%�'��(�(�6�6�7K�L���"�"�8�#7�#7��
�#C�D��"�"�7�?�?�4�3G�3G�#H�Ir)c��tj�}|jtjdd��}|jdt
jtd���|j|t�S)z�
        L{PBClientFactory.login} returns a L{Deferred} which is errbacked
        with the L{ConnectionRefusedError} if the underlying connection is
        refused.
        �foo�barNz!Test simulated refused connection)
rr�r�r	�UsernamePassword�clientConnectionFailedrrar�
assertFailure)r%ri�
loginDeferreds   r'�test_loginConnectionRefusedz(NewCredTests.test_loginConnectionRefused�sp���*�*�,�
�%�+�+��(�(���8�
�
�	�,�,���O�O�&�'J�K�
�	
��!�!�-�1G�H�Hr)c�<����jjtjd���t	j
dd�}d}t
���jj||�}��fd�}�fd�}|j|�|j|��fd�}|j|��j��jj�tj��jj��jd�|S)	z�
        Test that login can be performed with IUsernamePassword credentials and
        that when the connection is dropped the avatar is logged out.
        �pass�r&�userr�c����j�jjj��j	|t
j��Sr0)r�r�r�r�rWrr�)r��loginCompletedr%s ��r'�cbLoginz.NewCredTests.test_loginLogout.<locals>.cbLogins;����O�O�D�J�J�6�6�?�?�@��!�!�+�r�/A�/A�B�!�!r)c�Z���jj��j�yr0)rir�r���ignoredr%s �r'�cbDisconnectz3NewCredTests.test_loginLogout.<locals>.cbDisconnects!������)�)�+��-�-�/r)c�d���j�jjj�yr0)r�r�r�r�rs �r'�cbLogoutz/NewCredTests.test_loginLogout.<locals>.cbLogout&s����O�O�D�J�J�6�6�@�@�Ar)N)r
�registerCheckerrr�r	r�rrir�r_r�rLrNr�r�r�)r%�credsr<r$rrrr�s`      @r'�test_loginLogoutzNewCredTests.test_loginLogouts����
	
���#�#��<�<�'�J�	
��,�,�W�g�>����!������$�$�U�D�1��	"�
	0�	
�
�
�g��	�
�
�l�#�	B�	
�
�
�h���%�%�'��	�	����	�
�
���	�	��������%��r)c�<���t��G�fd�dtj�}|�j_�j
j
tjd����jjtjdd�d�}�fd�}|j|��fd�}|j|��j��jj!�t#j$��jj!�|S)	z�
        If a L{RemoteReference} to an L{IPerspective} avatar is decrefed and
        there remain no other references to the avatar on the server, the
        avatar is garbage collected and the logout method called.
        c�"��eZdZdZd�Z�fd�Zy)�=NewCredTests.test_logoutAfterDecref.<locals>.EventPerspectivezQ
            An avatar which fires a Deferred when it is logged out.
            c��yr0r-r�s  r'rGzFNewCredTests.test_logoutAfterDecref.<locals>.EventPerspective.__init__Cs��r)c�(���jd�yr0)r�)r%r�s �r'r�zDNewCredTests.test_logoutAfterDecref.<locals>.EventPerspective.logoutFs����"�"�4�(r)N)r*r+r,r3rGr�r�s�r'�EventPerspectiver>s���
�
�
)r)rr�r�r�r�c����Sr0r-)�avatarr�s �r'�
cbLoggedInz7NewCredTests.test_logoutAfterDecref.<locals>.cbLoggedInSs����r)c�f���j�jjji�yr0)rXrqrx�
_localCleanuprs �r'�cbLoggedOutz8NewCredTests.test_logoutAfterDecref.<locals>.cbLoggedOutZs(���
���T�/�/�@�@�N�N�PR�Sr))rr�Avatarr�r�r
rrr�rir�r	r�r_r�rLrNr�r�)r%rr$rrr�s`    @r'�test_logoutAfterDecrefz#NewCredTests.test_logoutAfterDecref6s�����J�	�		)�r�y�y�		)�)9��
�
�%����#�#��<�<��H�	
�
���$�$��(�(���8�)�
��	�
	
�
�
�j�!�	T�
	
�
�
�k�"��%�%�'�	
�	�	����	�
�
���	�	�����r)c�����jjtjdd����jjt
jdd�d�}�jjt
jdd�d�}t||g�}d�}|j|��fd�}|j|��j��jj�|S)	z�
        Two different correct login attempts can be made on the same root
        object at the same time and produce two different resulting avatars.
        r�squux)r��bazr�r��bazc�b�|\}}t|jd�|jd�g�S)N�getAvatarId)rr�)r��first�seconds   r'rz5NewCredTests.test_concurrentLogin.<locals>.cbLoggedIn}s6��$�O�U�F� ��!�!�-�0�&�2C�2C�M�2R�S��
r)c�X��|\}}�j|d��j|d�y)Nr�r)rX)r�rrr%s   �r'�cbAvatarIdsz6NewCredTests.test_concurrentLogin.<locals>.cbAvatarIds�s,����M�E�6����U�F�+����V�V�,r))
r
rrr�rir�r	r�rr_r�rLrN)r%�
firstLogin�secondLoginr$rr s`     r'�test_concurrentLoginz!NewCredTests.test_concurrentLoginls����
	
���#�#��<�<��W�U�	
��'�'�-�-��(�(���8�)�
�
��(�(�.�.��(�(���9�9�
��
�:�{�3�4��	�	
�
�
�j�!�	-�
	
�
�
�k�"��%�%�'��	�	�����r)c����jjtjd����jjt
jdd��}�jjt
jdd��}�j|t��j|t�t||g�}�fd�}|j|��j��jj�|S)zz
        Test that a login attempt with an invalid user or invalid password
        fails in the appropriate way.
        r�r�s
nosuchuserr�s	wrongpassc�f���jt�}�jt|�d�y)Nr�)�flushLoggedErrorsrrXr���ignore�errorsr%s  �r'�cleanupz;NewCredTests.test_badUsernamePasswordLogin.<locals>.cleanup�s(����+�+�,=�>�F����S��[�!�,r))r
rrr�rir�r	r�r�rrr_r�rLrN)r%r!r"r$r*s`    r'�test_badUsernamePasswordLoginz*NewCredTests.test_badUsernamePasswordLogin�s����
	
���#�#��<�<�'�J�	
��'�'�-�-��(�(���@�
�
��(�(�.�.��(�(��,�?�
��	
���:�'8�9����;�(9�:��:�{�3�4��	-�	
�
�
�g���%�%�'��	�	�����r)c�p�|jjtj��|jjt
j�d�}d�}|j|�|j|jd�|j�|jj�|S)z�
        Verify that a PB server using a portal configured with a checker which
        allows IAnonymous credentials can be logged into using IAnonymous
        credentials.
        r�c�&�|jdd�S�NrU�{r��r�s r'rz4NewCredTests.test_anonymousLogin.<locals>.cbLoggedIn�����)�)�&�#�6�6r)r/)
r
rr�AllowAnonymousAccessrir�r	�	Anonymousr_rXr�rLrN)r%r$rs   r'�test_anonymousLoginz NewCredTests.test_anonymousLogin�s���	
���#�#�H�$A�$A�$C�D����$�$�[�%:�%:�%<�i�H��	7�	
�
�
�j�!�	�
�
�d�&�&��,��%�%�'��	�	�����r)c�n���jjtjd����jjt
j�d�}�j|t��fd�}|j|��j��jj�|S)zg
        Verify that without an anonymous checker set up, anonymous login is
        rejected.
        �passr�r�c�f���jt�}�jt|�d�yr�)r&rrXr�r's  �r'r*z=NewCredTests.test_anonymousLoginNotPermitted.<locals>.cleanup�s(����+�+�,@�A�F����S��[�!�,r))r
rrr�rir�r	r3r�rr_r�rLrN)r%r$r*s`  r'�test_anonymousLoginNotPermittedz,NewCredTests.test_anonymousLoginNotPermitted�s����
	
���#�#��<�<�&�I�	
�
���$�$�[�%:�%:�%<�i�H�����1�2�3�	-�	
�
�
�g���%�%�'��	�	�����r)c���|jjtj��|jjtjd���|j
j
tj�d�}d�}|j|�|j|jd�|j�|jj�|S)z�
        Like L{test_anonymousLogin} but against a portal with a checker for
        both IAnonymous and IUsernamePassword.
        r�r�r�c�&�|jdd�Sr.r�r0s r'rzENewCredTests.test_anonymousLoginWithMultipleCheckers.<locals>.cbLogin�r1r)r/)r
rrr2r�rir�r	r3r_rXr�rLrN�r%r$rs   r'�'test_anonymousLoginWithMultipleCheckersz4NewCredTests.test_anonymousLoginWithMultipleCheckers�s���
	
���#�#�H�$A�$A�$C�D����#�#��<�<�'�J�	
�
���$�$�[�%:�%:�%<�i�H��	7�	
�
�
�g��	�
�
�d�&�&��,��%�%�'��	�	�����r)c���|jjtj��|jjtjd���|j
j
tjdd�d�}d�}|j|�|j|jd�|j�|jj�|S)z�
        Like L{test_anonymousLoginWithMultipleCheckers} but check that
        username/password authentication works.
        r�r�r�r�c�(�|jddd�S)N�addr�r�r0s r'rzINewCredTests.test_authenticatedLoginWithMultipleCheckers.<locals>.cbLogin�s���)�)�%��b�9�9r)r/)r
rrr2r�rir�r	r�r_rXr�rLrNr;s   r'�+test_authenticatedLoginWithMultipleCheckersz8NewCredTests.test_authenticatedLoginWithMultipleCheckers�s���
	
���#�#�H�$A�$A�$C�D����#�#��<�<�'�J�	
�
���$�$��(�(��'�:�I�
��	:�	
�
�
�g��	�
�
�d�&�&��,��%�%�'��	�	�����r)c��|jjtjd���|jjt
jdd�d�}d�}|j|�d�}|j|�|j|j�|j�|jj�|S)zb
        Verify that a viewpoint can be retrieved after authenticating with
        cred.
        r�r�r�r�c�$�|jd�S)N�getViewPointr�r0s r'rz'NewCredTests.test_view.<locals>.cbLogins���)�)�.�9�9r)c�$�|jd�S)Nr�r�)�	viewpoints r'�cbViewz&NewCredTests.test_view.<locals>.cbViews���'�'��0�0r))
r
rrr�rir�r	r�r_r�r�rLrN)r%r$rrGs    r'�	test_viewzNewCredTests.test_view
s���
	
���#�#��<�<�'�J�	
�
���$�$��(�(��'�:�I�
��	:�	
�
�
�g��	1�	
�
�
�f��	�
�
�d�o�o�&��%�%�'��	�	�����r)r0)r*r+r,r3rQr�rrarrbr�r�r�r�r�r�r	rr#r+r4r8r<rArHr-r)r'r�r�?s{���	2�Y�B%�W�_�_�T�%9�%9�:�H�(�6:�01:�fJ�I�$/�b4�l#�J�>�(�,�.�2r)r�c��eZdZd�Zd�Zd�Zy)�NonSubclassingPerspectivec��yr0r-r�s  r'rGz"NonSubclassingPerspective.__init__*r�r)c�r�|j||�}|j||�}|j|||f�Sr0)�unserialize�	serialize)r%rc�messager�kwargss     r'�perspectiveMessageReceivedz4NonSubclassingPerspective.perspectiveMessageReceived.s>���!�!�$��-���#�#�F�D�1������$�� 7�8�8r)c��d|_yr�r�r1s r'r�z NonSubclassingPerspective.logout4r�r)N)r*r+r,rGrQr�r-r)r'rJrJ(s��
�9�r)rJc��eZdZdZd�Zd�Zy)�NSPTestsz
    Tests for authentication against a realm where the L{IPerspective}
    implementation is not a subclass of L{Avatar}.
    c��t�|_t|j_t	j
|j�|_t
j�|_|jjdd�|jj|j�ttj|j��|_tj d|jd��|_|j%|j"j&�|j"j)�j"|_y)Nr�r�rr])r�)r�r�rJr�r
r�rr�r��addUserrrrr�r�rr�r�ror�r��portnor1s r'rQzNSPTests.setUp>s����[��
�(A��
�
�%��m�m�D�J�J�/����G�G�I��������W�g�.����#�#�D�L�L�1�&�r�'9�'9�$�+�+�'F�G����%�%�a�����M��	�����	�	�/�/�0��i�i�'�'�)�.�.��r)c�T���tj���jtjdd�d�}tjd�j��|jd��|j�jdddd	if���fd
�}|j|�|S)z�
        An L{IPerspective} implementation which does not subclass
        L{Avatar} can expose remote methods for the client to call.
        r�r�r�r]c�*�|jddd��S)N�ANYTHING�herer)r�r�)rzs r'r8z#NSPTests.test_NSP.<locals>.<lambda>Rs�����Z��U�� K�r)rZ)r[r�rc����j��jjD]}|jj	��yr0)r�r��	protocolsrVr�)rrzr�r%s  ��r'r*z"NSPTests.test_NSP.<locals>.cleanupUs8������ ��\�\�+�+�
-�����*�*�,�
-r))
rr�r�r	r�rr�rWr_rX)r%r$r*r�s`  @r'�test_NSPzNSPTests.test_NSPJs����
�$�$�&���M�M�+�6�6�w��H�)�T�����;����W�=�	�
�
�K�L�	�
�
�d�&�&��Y����(O�P�	-�
	
�
�
�g���r)N)r*r+r,r3rQr^r-r)r'rTrT8s���

/�r)rTc��eZdZdZd�Zd�Zy)�
IForwardedzA
    Interface used for testing L{util.LocalAsyncForwarder}.
    c��y)z,
        Simple synchronous method.
        Nr-r-r)r'�	forwardMezIForwarded.forwardMecr9r)c��y)z-
        Simple asynchronous method.
        Nr-r-r)r'�forwardDeferredzIForwarded.forwardDeferredhr9r)N)r*r+r,r3rbrdr-r)r'r`r`^s����
r)r`c�*�eZdZdZdZdZd�Zd�Zd�Zy)�	Forwardedz�
    Test implementation of L{IForwarded}.

    @ivar forwarded: set if C{forwardMe} is called.
    @type forwarded: C{bool}
    @ivar unforwarded: set if C{dontForwardMe} is called.
    @type unforwarded: C{bool}
    Fc��d|_y)z6
        Set a local flag to test afterwards.
        TN)�	forwardedr1s r'rbzForwarded.forwardMe|s����r)c��d|_y)zv
        Set a local flag to test afterwards. This should not be called as it's
        not in the interface.
        TN)�unforwardedr1s r'�
dontForwardMezForwarded.dontForwardMe�s��
 ��r)c��td�S)z0
        Asynchronously return C{True}.
        T)rr1s r'rdzForwarded.forwardDeferred�s���t�}�r)N)	r*r+r,r3rhrjrbrkrdr-r)r'rfrfns"����I��K�� �r)rfc�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�SpreadUtilTestsz+
    Tests for L{twisted.spread.util}.
    c�\�t�}|j|jdd�d�y)zk
        Call a synchronous method of a L{util.LocalAsRemote} object and check
        the result.
        �add1r�r�N)r�rXr�res  r'�	test_synczSpreadUtilTests.test_sync�s'��

���������f�a�0�!�4r)c��t�}t�}|jddd��}|j|t�|j	|j
d�|S)zm
        Call an asynchronous method of a L{util.LocalAsRemote} object and check
        the result.
        r?r�r�)r�r�)r�r�rWrr_rX)r%rfr$s   r'�
test_asynczSpreadUtilTests.test_async�sQ��

������
�L�L���Q�L�'�����a��*�	�
�
�d�&�&��*��r)c�r��t�}|jd�}�fd�}|j�fd�|�|S)zG
        Test an asynchronous failure on a remote method call.
        r�c�p���j|tj�|jt�yr0)rWrra�trapr�)r1r%s �r'�ebz*SpreadUtilTests.test_asyncFail.<locals>.eb�s#����!�!�!�W�_�_�5�
�F�F�<� r)c�&���jd�S)Nzsupposed to failr�)r[r%s �r'r8z0SpreadUtilTests.test_asyncFail.<locals>.<lambda>�s���4�9�9�-?�#@�r))r�r�r#)r%rfr$rws`   r'�test_asyncFailzSpreadUtilTests.test_asyncFail�s6���
���
�L�L�� ��	!�	
���@�"�E��r)c�j�t�}|jd�}|j|d�d�y)zM
        Test the C{remoteMethod} facility of L{util.LocalAsRemote}.
        rpr�r�N)r�r�rX)r%rf�ms   r'�test_remoteMethodz!SpreadUtilTests.test_remoteMethod�s.��
���
�N�N�6�"������1��q�!r)c��t�}tj|t�}|j	d�|j|j�|j	d�|j|j�|j	d�}g}|j|j�|j|dd�y)ze
        Test a call to L{util.LocalAsyncForwarder} using L{Forwarded} local
        object.
        rbrkrdrrRN)rfr�LocalAsyncForwarderr`r�r�rhrYrjr_rrX)r%r1�lf�rrr�s     r'�test_localAsyncForwarderz(SpreadUtilTests.test_localAsyncForwarder�s���

�K��
�
%�
%�a��
4��
�
�
�k�"�������$�
�
�
�o�&�������'�
�]�]�,�
-����
���q�x�x� �����1��q�!r)N)	r*r+r,r3rqrsryr|r�r-r)r'rnrn�s ���5�
��"�"r)rnc�(�eZdZdZd�Zd�Zd�Zd�Zy)�PBWithSecurityOptionsTestsz&
    Test security customization.
    c��tj�}|jd�}|j|jt
j�y)zl
        By default, client broker should use C{jelly.globalSecurity} as
        security settings.
        N)rr�rkr��securityr�globalSecurity�r%r�rcs   r'�!test_clientDefaultSecurityOptionsz<PBWithSecurityOptionsTests.test_clientDefaultSecurityOptions�s:��
�$�$�&���&�&�t�,���
�
�f�o�o�u�';�';�<r)c��tjt��}|jd�}|j	|j
tj�y)zl
        By default, server broker should use C{jelly.globalSecurity} as
        security settings.
        N)rr�r=rkr�r�rr�r�s   r'�!test_serverDefaultSecurityOptionsz<PBWithSecurityOptionsTests.test_serverDefaultSecurityOptions�s>��
�$�$�V�X�.���&�&�t�,���
�
�f�o�o�u�';�';�<r)c��tj�}tj|��}|j	d�}|j|j|�y)zs
        Check that the security settings are passed from the client factory to
        the broker object.
        �r�N)r�SecurityOptionsrr�rkr�r��r%r�r�rcs    r'� test_clientSecurityCustomizationz;PBWithSecurityOptionsTests.test_clientSecurityCustomization�sD��
�(�(�*���$�$�h�7���&�&�t�,���
�
�f�o�o�x�0r)c���tj�}tjt	�|��}|jd�}|j
|j|�y)zs
        Check that the security settings are passed from the server factory to
        the broker object.
        r�N)rr�rr�r=rkr�r�r�s    r'� test_serverSecurityCustomizationz;PBWithSecurityOptionsTests.test_serverSecurityCustomization�sH��
�(�(�*���$�$�V�X��A���&�&�t�,���
�
�f�o�o�x�0r)N)r*r+r,r3r�r�r�r�r-r)r'r�r��s���=�=�1�1r)r�r0)�r3r�r�r�rKr��collectionsr�iorrl�typingr�zope.interfacerr�twisted.credrr	r
�twisted.cred.errorrr�twisted.internetr
rrr�twisted.internet.deferrrr�twisted.internet.errorr�twisted.internet.testingr�twisted.protocols.policiesr�twisted.pythonrr�twisted.python.compatr�twisted.spreadrrrr�
twisted.trialr�Viewabler rr#�IRealmr5rArwryr�r�r�r�r��Copyabler��
RemoteCopyr��setUnjellyableForClassr�r��setUnjellyableFactoryForClassr��	Cacheabler�r�r��RemoteCacher�r�rr
rr'r.r2r:�Rootr=rF�SynchronousTestCaserLr�rs�TestCaser{r�rrrrrr#r,�PublishablerN�RemotePublishedrRrr\r�rwrkrj�
LocalAsRemoter�r:r�r�r�r�r�r�rJrTr`rfrnr�r-r)r'�<module>r�s���
�	�
����"��1�6�6�F�=�=�C�C�9�3�6�'�+�3�3�"�+�B�K�K�+��r�y�y��
�V�]�]��G�G��G�8�8�v0,�f4�4�B �� �4F��2�#�#���2�#�#��
�����	�b�m�m�	�����*�o�6�
,����
,�
� !�� � �!2�4E�F�(��!�!�(��"�,�,���R�-�-��!�2�<�<�!�*%����%�����6�8J�K��r�~�~������+�'7�8��"�"�"��5��!�!�5��R�%�%��,,�r���,��2�;�;��
�
��
����,��5�'�B�K�K����'�����-��7�����b�n�n��
����+�->�?��R�W�W���R�W�W��O�H�0�0�O�d�B�$6�$6��@4�(�+�+�4�nR
�(�#�#�R
�j
�	������#�� � �#�#�B�$�$�#�i5�(�#�#�i5�X'�g�)�)�'�
 �g�%�%� �
�2�#�#������/�7�3�@-��*�*�@-�F	�y�	��"�+�+��
��!�!��

�d�(�(�
�
�R�_�_�� �B�I�I� �� �FX�X�B/�R�[�[�/�
H��H�*3*�x�(�(�3*�lf�8�$�$�f�R
�R�_�_������#�x� � �#�L
��
� 
�Z������B="�h�'�'�="�@)1��!2�!2�)1r)

Zerion Mini Shell 1.0