%PDF- %PDF-
Mini Shell

Mini Shell

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

�

Ϫ�f)����dZddlZddlZddlmZmZmZmZddlm	Z	ddl
mZddlm
Z
mZddlmZmZmZmZmZmZddlmZdd	lmZdd
lmZddlmZddlmZdd
l m!Z!	ddlm"Z#e#jHsdZ"ne#Z"	e"�dZ&ndZ&ejNjQe�sdZ)ndZ)ejTjVZ,Gd�dejZ�Z.Gd�dej^�Z0Gd�de1�Z2Gd�de1�Z3Gd�de1�Z4Gd�dejj�Z6Gd�dejn�Z8Gd�d e8�Z9Gd!�d"ejn�Z:Gd#�d$ejn�Z;Gd%�d&ejn�Z<Gd'�d(ejn�Z=Gd)�d*ejn�Z>Gd+�d,ejn�Z?Gd-�d.ejn�Z@Gd/�d0ejn�ZAGd1�d2ej��ZCGd3�d4ej��ZEd5ZFGd6�d7e1�ZGGd8�d9ej^�ZHGd:�d;eH�ZIGd<�d=eI�ZJGd>�d?eI�ZKGd@�dAeI�ZLe0e0fdB�ZMGdC�dDejZ�ZNGdE�dFej^�ZOGdG�dHe!�ZPGdI�dJe!�ZQGdK�dL�ZRGdM�dN�ZSGdO�dPe!�ZTGdQ�dRejn�ZUGdS�dTej��ZWGdU�dVeW�ZXGdW�dXeX�ZYGdY�dZej^�ZZGd[�d\e!�Z[d]Z\d^Z]Gd_�d`e!�Z^Gda�dbe!�Z_Gdc�dd�Z`Gde�df�ZaGdg�dhea�ZbGdi�djea�ZcGdk�dlea�ZdGdm�dneH�Zee	e&do�e	e)dp�Gdq�dre!���ZfGds�dte!�ZgGdu�dve1�ZhGdw�dxe1�ZiGdy�dzejn�ZjGd{�d|ej�ZkGd}�d~ej�ZlGd�d�ej^�ZmGd��d�ej^�ZnGd��d�ej^�ZoGd��d�e!�Zpd��ZqGd��d��Zrd��Zsd��Zte"�et�Zue	e&do�e	e)dp�Gd��d�ere!���ZvGd��d�eI�Zwe	e&do�e	e)dp�Gd��d�ere!���Zxe	e&do�e	e)dp�Gd��d�ere!���ZyGd��d�ejj�ZzGd��d�ejn�Z{Gd��d�ejn�Z|Gd��d�ej^�Z}ed��Z~ed��ZGd��d�ee~ef�Z�Gd��d�e{�Z�Gd��d�e!�Z�Gd��d��Z�Gd��d�e!e��Z�Gd��d�e!e��Z�Gd��d�e!e��Z�Gd��d�e!e��Z�Gd��d�e!e��Z�Gd��d�e!�Z�Gd��d�e!�Z�Gd��d�e!e��Z�Gd��d�e!�Z�ee�j�Gd��d���Z�e
e�je��e
e�je��Gd��d�e!�Z�Gd��d�e!�Z�Gd��d�e!�Z�Gd��d�e!�Z�y#e%$rdZ"Y���wxYw)�z%
Tests for L{twisted.protocols.amp}.
�N)�ClassVar�Dict�Type�TypeVar)�skipIf)�implementer)�verifyClass�verifyObject)�address�defer�error�
interfaces�protocol�reactor)�StringTransport)�amp)�filepath)�Failure)�iosim)�TestCase��sslTFc�8�eZdZdZdZd�Zd�Zd�Zd�Zde	fd�Z
y	)
�	TestProtoz�
    A trivial protocol for use in testing where a L{Protocol} is expected.

    @ivar instanceId: the id of this instance
    @ivar onConnLost: deferred that will fired when the connection is lost
    @ivar dataToSend: data to send on the protocol
    rc���t|t�sJt|���||_||_t
j|_t
jdzt
_y)N�)�
isinstance�bytes�repr�
onConnLost�
dataToSendr�
instanceCount�
instanceId)�selfr r!s   �7/usr/lib/python3/dist-packages/twisted/test/test_amp.py�__init__zTestProto.__init__=sJ���*�e�,�>�d�:�.>�>�,�$���$���#�1�1���"+�"9�"9�A�"=�	��c�\�g|_|jj|j�y�N)�data�	transport�writer!�r$s r%�connectionMadezTestProto.connectionMadeDs����	������T�_�_�-r'c�:�|jj|�yr))r*�append)r$rs  r%�dataReceivedzTestProto.dataReceivedHs���	�	����r'c�N�|jj|j�yr))r �callbackr*�r$�reasons  r%�connectionLostzTestProto.connectionLostKs����� � ����+r'�returnc�"�d|jfzS)z�
        Custom repr for testing to avoid coupling amp tests with repr from
        L{Protocol}

        Returns a string which contains a unique identifier that can be looked
        up using the instanceId property::

            <TestProto #3>
        z<TestProto #%d>)r#r-s r%�__repr__zTestProto.__repr__Ns��!�D�O�O�#5�5�5r'N)�__name__�
__module__�__qualname__�__doc__r"r&r.r1r6�strr9�r'r%rr2s.����M�>�.� �,�
6�#�
6r'rc��eZdZd�Zd�Zy)�SimpleSymmetricProtocolc�(�|jd|��S�N�hello��hello)�callRemoteString�r$�texts  r%�	sendHelloz!SimpleSymmetricProtocol.sendHello\s���$�$�X�T�$�:�:r'c�4�tj|d��SrC�r�Box�r$�boxs  r%�	amp_HELLOz!SimpleSymmetricProtocol.amp_HELLO_s���w�w�S��]�+�+r'N)r:r;r<rJrPr?r'r%rArA[s��;�,r'rAc��eZdZdZy)�UnfriendlyGreeting�!Greeting was insufficiently kind.N�r:r;r<r=r?r'r%rRrRc���+r'rRc��eZdZdZy)�DeathThreatrSNrTr?r'r%rWrWgrUr'rWc��eZdZdZy)�UnknownProtocolz&Asked to switch to the wrong protocol.NrTr?r'r%rYrYks��0r'rYc��eZdZd�Zd�Zd�Zy)�
TransportPeerc��y)Nr'r?)r$�d�name�protos    r%�retrievezTransportPeer.retrievers��r'c�6�|jj�Sr))r+�getPeer)r$�
notAStringr_s   r%�fromStringProtozTransportPeer.fromStringProtous�����&�&�(�(r'c��yr)r?)r$r^�strings�objectsr_s     r%�toBoxzTransportPeer.toBoxxs��r'N)r:r;r<r`rdrhr?r'r%r[r[os���)�r'r[c
��eZdZUdZdej
�fdejd��fdejd��fded��fdej
d��fdej
d��fd	ej
d��fgZ	dej
�fdejd��fgZ
ed
iZe
eeeefed<ediZe
eeeefed
<y)�HellorD�optionalT��optional�print�from�	mixedCase�dash-arg�underscore_arg�
UNFRIENDLY�errorssDEAD�fatalErrorsN)r:r;r<�commandNamer�String�Boolean�Unicoder[�	arguments�responserRrtrrr�	Exceptionr�__annotations__rWrur?r'r%rjrj|s����K�
�:�3�:�:�<� �	�k�c�k�k�4�0�1�	�;�3�;�;��-�.�	�-��.�/�	�z�s�z�z�4�0�1�	�j�c�j�j�$�/�0�	�J�C�J�J��5�6��I��:�3�:�:�<�(�8�[�S�[�[�$�5O�*P�Q�H�6H�-�5X�F�H�T�$�y�/�5�0�1�2�X�;F��:P�K��$�t�I���5�6�7�Pr'rjc�(�eZdZejZdZy)�
NoAnswerHelloFN)r:r;r<rjrv�requiresAnswerr?r'r%rr�s���#�#�K��Nr'rc��eZdZdZdej
�fdejd��fdejd��fded��fdej
d��fgZ	dej
�fdejd��fgZ
ediZy	)
�FutureHellorDrkTrlrnrosbonusrsN)
r:r;r<rvrrwrxryr[rzr{rRrtr?r'r%r�r��s����K�
�:�3�:�:�<� �	�k�c�k�k�4�0�1�	�;�3�;�;��-�.�	�-��.�/�	�:�3�:�:�t�,�-�	�I��:�3�:�:�<�(�8�[�S�[�[�$�5O�*P�Q�H� �-�
0�Fr'r�c��eZdZdZy)�WTFz+
    An example of an invalid command.
    NrTr?r'r%r�r�����r'r�c��eZdZdZdZy)�BrokenReturnz[An example of a perfectly good command, but the handler is going to return
    None...
    s
broken_returnN)r:r;r<r=rvr?r'r%r�r��s���#�Kr'r�c�L�eZdZdej�fgZejZy)�GoodbyesgoodbyeN)r:r;r<rrwr{�QuitBox�responseTyper?r'r%r�r��s ���Z�S�Z�Z�\�*�+�H��;�;�Lr'r�c��eZdZdZy)�WaitForeverswait_foreverN)r:r;r<rvr?r'r%r�r��s��!�Kr'r�c��eZdZdZdej
�fgZdejdej
�fg�fgZy)�GetListsgetlistslength�body�xN)	r:r;r<rvr�Integerrz�AmpListr{r?r'r%r�r��sD���K��[�S�[�[�]�+�,�I��+�#�+�+��k�c�k�k�m�'<�&=�>�?�@�Hr'r�c��eZdZdZdej
�fdejdej
�fgd��fgZdej
�fgZy)	�DontRejectMesdontrejectmes	magicWordslist�nameTrlsresponseN)	r:r;r<rvrryr�rzr{r?r'r%r�r��sZ��!�K�	�{�s�{�{�}�%�	�+�#�+�+�������7�8�4�H�I��I��k�c�k�k�m�,�-�Hr'r�c�4�eZdZdej�fgZy)�SecuredPingspingedN)r:r;r<rrxr{r?r'r%r�r��s���K�C�K�K�M�*�+�Hr'r�c�@�eZdZdZdej
�fgZediZy)�TestSwitchProtosSwitch-Protor�sUNKNOWNN)	r:r;r<rvrrwrzrYrtr?r'r%r�r��s,��!�K�
�*�#�*�*�,���I��z�
*�Fr'r�c�"�eZdZd�Zd�ZdZd�Zy)�SingleUseFactoryc�4�||_||j_yr))r_�factory)r$r_s  r%r&zSingleUseFactory.__init__�s����
�!��
�
�r'c�.�|jdc}|_|Sr))r_)r$�addr�ps   r%�
buildProtocolzSingleUseFactory.buildProtocol�s���
�
�D�
��4�:��r'Nc��||_yr))�reasonFailed�r$�	connectorr5s   r%�clientConnectionFailedz'SingleUseFactory.clientConnectionFailed�s
��"���r')r:r;r<r&r�r�r�r?r'r%r�r��s��"���L�r'r�sgwebol nargoc��eZdZy)�ThingIDontUnderstandErrorN)r:r;r<r?r'r%r�r��s��r'r�c�>�eZdZdZd�Zd�Zeje�y)�FactoryNotifierNc��|j�N||j_t|jd�r&|jjj	d�yyy)N�onMade)r��theProto�hasattrr�r3r-s r%r.zFactoryNotifier.connectionMade�sH���<�<�#�$(�D�L�L�!��t�|�|�X�.����#�#�,�,�T�2�/�$r'c�b�ddlm}|j|j�st	d��ddiS)Nr)�
ISSLTransportz+only send secure pings over secure channels�pingedT)�twisted.internet.interfacesr��
providedByr+rW)r$r�s  r%�emitpongzFactoryNotifier.emitpong�s.��=��'�'����7��K�L�L��$��r')r:r;r<r�r.r�r��	responderr?r'r%r�r��s!���G�3� ����(�#r'r�c�V�eZdZdZdd�Zd�Zd�ZdZ					dd�Ze	je�d�Zeje�dd�Z
eje
�d	�Zeje�d
�Zeje�dd�Zd�Zeje�d
�Zeje�y)�SimpleSymmetricCommandProtocolNc�P�tjj|�||_yr))r�AMPr&r )r$r s  r%r&z'SimpleSymmetricCommandProtocol.__init__
s���������$��r'c�0�|jt|��S)NrE��
callRemoterjrHs  r%rJz(SimpleSymmetricCommandProtocol.sendHellos�����u�D��1�1r'c�2�|jt||��S)N�rF�Printr�)r$rI�translations   r%�sendUnicodeHelloz/SimpleSymmetricCommandProtocol.sendUnicodeHellos�����u�D���D�Dr'Fc�"�||jj�k(sJ�|tk(r
t��|j	d�rtd��|dk(rt
d��t|��}|�|jt|���d|_	|S)Nsfuck�Don't be a dick.�die�aieeeeeeeeerE)r�T)
r+rb�THING_I_DONT_UNDERSTANDr��
startswithrRrW�dict�update�greeted)	r$rF�Fromrmr��	mixedCase�dash_arg�underscore_arg�results	         r%�cmdHelloz'SimpleSymmetricCommandProtocol.cmdHellos����t�~�~�-�-�/�/�/�/��+�+�+�-�-����G�$�$�%7�8�8��F�?��m�,�,��E�"�����M�M�$�U�+�,�����
r'c�&�dtd��g|ziS)N�bodyr)�x�r�)r$�lengths  r%�
cmdGetlistz)SimpleSymmetricCommandProtocol.cmdGetlist/s�������f�,�-�-r'c�:�|�d}nd|ddz}t|��S)N�list omittedz%s acceptedrr^)r{r�)r$�	magicWord�listr{s    r%�okiwontz&SimpleSymmetricCommandProtocol.okiwont4s)���<�%�H�$��Q����8�H��X�&�&r'c�L�tj�|_|jSr))r�Deferred�waitingr-s r%�	waitforitz(SimpleSymmetricCommandProtocol.waitforit=s���~�~�'����|�|�r'c��td��S)N�everyone)�goodbyer�r-s r%�saybyez%SimpleSymmetricCommandProtocol.saybyeCs
���K�(�(r'c���|rd}nd}t|jt��|jtt��|��j
�fd��S)Nsno-proto�
test-proto)r^c����Sr)r?)�ignr�s �r%�<lambda>zESimpleSymmetricCommandProtocol.switchToTestProtocol.<locals>.<lambda>Ps���!�r')rr �SWITCH_CLIENT_DATAr�r�r��addCallback)r$�failr^r�s   @r%�switchToTestProtocolz3SimpleSymmetricCommandProtocol.switchToTestProtocolHsN�����D� �D��d�o�o�'9�:������-�a�0�t��
�
�+�m�
$�	%r'c�V�|dk(rt|jt�St|���Nr�)rr �SWITCH_SERVER_DATArY�r$r^s  r%�switchitz'SimpleSymmetricCommandProtocol.switchitRs'���=� ��T�_�_�.@�A�A��d�#�#r'c��yr)r?r-s r%�	donothingz(SimpleSymmetricCommandProtocol.donothingY���r'r)�NNNNN)F)r:r;r<�
maybeLaterr&rJr�r�r�rjr�r�r�r�r�r�r�r�r�r�r�r�r�r�r?r'r%r�r�s����J�%�2�E��G�������.
�O�O�H��.����j�!�'����7�#�����)�$�)����f��%�$�
���h�'�����9�%r'r�c�4�eZdZd�Zeje�y)� DeferredSymmetricCommandProtocolc��|dk(rDt|jt�|_t	j
�|_|jSyr�)rr r��maybeLaterProtorr�r�r�s  r%r�z)DeferredSymmetricCommandProtocol.switchit`s;���=� �#,�T�_�_�>P�#Q�D� �#�n�n�.�D�O��?�?�"�!r'N)r:r;r<r�r�r�r?r'r%r�r�_s��#����h�'r'r�c�@�eZdZ					dd�Zeje�y)�BadNoAnswerCommandProtocolNc��y)zQ
        This responder does nothing and forgets to return a dictionary.
        Nr?�r$rFr�rmr�r�r�r�s        r%�badResponderz'BadNoAnswerCommandProtocol.badResponderj��r'r�)r:r;r<rrr�r?r'r%r�r�is(��
���������L�)r'r�c�@�eZdZ					dd�Zeje�y)�NoAnswerCommandProtocolNc� �t|dz��S)Ns	-noanswerrEr�r�s        r%�goodNoAnswerResponderz-NoAnswerCommandProtocol.goodNoAnswerResponder|s���%�,�.�/�/r'r�)r:r;r<rrr�r?r'r%rr{s)��
�����
0����1�2r'rc�6�tj||g|��i|��S)z)Returns a 3-tuple: (client, server, pump))r�connectedServerAndClient)�ServerClass�ClientClass�a�kws    r%rr�s!���)�)�+�{�M�Q�M�"�M�Mr'c��eZdZdZd�Zy)�TotallyDumbProtocolr'c�.�|xj|z
c_yr))�buf�r$r*s  r%r1z TotallyDumbProtocol.dataReceived�s�����D��r'N)r:r;r<rr1r?r'r%r
r
�s��

�C�r'r
c��eZdZd�Zd�Zy)�
LiteralAmpc��g|_yr))�boxesr-s r%r&zLiteralAmp.__init__�s	����
r'c�:�|jj|�yr)�rr0rNs  r%�ampBoxReceivedzLiteralAmp.ampBoxReceived�s���
�
���#��r'N)r:r;r<r&rr?r'r%rr�s���r'rc�"�eZdZdZd�Zd�Zd�Zy)�AmpBoxTestszm
    Test a few essential properties of AMP boxes, mostly with respect to
    serialization correctness.
    c��tjd��}|jt|j	��t
�y)z8
        Make sure that strs serialize to strs.
        svalue��keyN)r�AmpBox�assertEqual�type�	serializer�r$r
s  r%�test_serializeStrzAmpBoxTests.test_serializeStr�s-��
�J�J�8�$������a�k�k�m�,�e�4r'c�r�tjdiddi��}|jt|j�y)zX
        Verify that TypeError is raised when trying to serialize Unicode keys.
        r�valueNr?�rr�assertRaises�	TypeErrorr r!s  r%�test_serializeUnicodeKeyRaisesz*AmpBoxTests.test_serializeUnicodeKeyRaises�s.��
�J�J�*�%��)�*�����)�Q�[�[�1r'c�p�tjd��}|jt|j�y)zb
        Verify that TypeError is raised when trying to serialize Unicode
        values.
        r$rNr%r!s  r%� test_serializeUnicodeValueRaisesz,AmpBoxTests.test_serializeUnicodeValueRaises�s&��

�J�J�7�#�����)�Q�[�[�1r'N)r:r;r<r=r"r(r*r?r'r%rr�s���
5�2�2r'rc�$�eZdZd�Zd�Zd�Zd�Zy)�ParsingTestsc��tj�}|j|jd��|j	|jd��|jt|jd�|jt|jd�|jt|jd�|j|jd�d�|j|jd�d�y)	ze
        Verify that the Boolean parser parses 'True' and 'False', but nothing
        else.
        sTruesFalsesninjastruesTRUETFN)	rrx�
assertTrue�
fromString�assertFalser&r'r�toString)r$�bs  r%�test_booleanValueszParsingTests.test_booleanValues�s���

�K�K�M��������W�-�.�������h�/�0����)�Q�\�\�8�<����)�Q�\�\�7�;����)�Q�\�\�7�;�������D�)�7�3�������E�*�H�5r'c��tj|j��}tj�}|j|�}|j
|�}|j||�|j||�y)zL
        Verify the 'Path' argument can parse and emit a file path.
        N)	r�FilePath�mktempr�Pathr1r/�assertIsNotr)r$�fpr��s�vs     r%�test_pathValueRoundTripz$ParsingTests.test_pathValueRoundTrip�s_���
�
�t�{�{�}�
-���H�H�J��
�J�J�r�N��
�L�L��O������Q������Q�r'c��tj�}|jtj|jtj
��S)zk
        Test that empty boxes raise an error; they aren't supposed to be sent
        on purpose.
        )rr�r&�NoEmptyBoxesrrMr!s  r%�test_sillyEmptyThingz!ParsingTests.test_sillyEmptyThing�s6��

�G�G�I��� � ��!1�!1�1�3C�3C�S�W�W�Y�O�Or'c
�z�ttt��\}}}d}d}d}d}d}d}	d}
|g||
g||g||g||||g|||g||||	g|
||gg}|D]p}tj�}
|
j	t|��|
j
|�|j�|j|jd	|
��ry
)zq
        Verify that various kinds of data make it through the encode/parse
        round-trip unharmed.
        )r	r)�simplestest)sceqs: )scrteststest
)slftestshello
)snewlinestest
one
two)snewline2stest
one
 two)r�sblah

testtest���N)
rrrrMr�r��_sendTo�flushrr)r$�cr:r��SIMPLE�CE�CR�LF�NEWLINE�NEWLINE2�BODYTEST�testData�test�jbs              r%�test_ParsingRoundTripz"ParsingTests.test_ParsingRoundTrip�s���
+�"�
�
���1�a�&��
��
#��
$��5��8��5���H�
�X��
�R�L�
�R�L�
�R��R� �
��R�L�
�W�b�(�+�
�v�w�'�	
���	.�D�����B��I�I�d�4�j�!��J�J�q�M�
�G�G�I����Q�W�W�R�[�"�-�	.r'N)r:r;r<r3r<r?rPr?r'r%r,r,�s��6�	 �P�!.r'r,c��eZdZdZd�Zd�Zy)�FakeLocatorzZ
    This is a fake implementation of the interface implied by
    L{CommandLocator}.
    c��i|_y)zN
        Remember the given keyword arguments as a set of responders.
        N��commandsr-s r%r&zFakeLocator.__init__s����
r'c� �|j|S)zz
        Look up and return a function passed as a keyword argument of the given
        name to the constructor.
        rT)r$rvs  r%�locateResponderzFakeLocator.locateResponders��
�}�}�[�)�)r'N)r:r;r<r=r&rWr?r'r%rRrRs���
�*r'rRc�(�eZdZdZd�Zd�Zd�Zd�Zy)�
FakeSenderz\
    This is a fake implementation of the 'box sender' interface implied by
    L{AMP}.
    c�.�g|_g|_d|_y)zn
        Create a fake sender and initialize the list of received boxes and
        unhandled errors.
        rN)�	sentBoxes�unhandledErrors�expectedErrorsr-s r%r&zFakeSender.__init__s��
���!�����r'c�.�|xjdz
c_y)zB
        Expect one error, so that the test doesn't fail.
        rN)r]r-s r%�expectErrorzFakeSender.expectError(s��	
���q� �r'c�:�|jj|�y)z6
        Accept a box, but don't do anything.
        N)r[r0rNs  r%�sendBoxzFakeSender.sendBox.s��	
�����c�"r'c��|xjdzc_|jdkr|j�y|jj|�y)zW
        Deal with failures by instantly re-raising them for easier debugging.
        rrN)r]�raiseExceptionr\r0)r$�failures  r%�unhandledErrorzFakeSender.unhandledError4sC��	
���q� ������"��"�"�$�� � �'�'��0r'N)r:r;r<r=r&r_rarer?r'r%rYrYs���
 �!�#�1r'rYc�@�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zy
)�CommandDispatchTestsa�
    The AMP CommandDispatcher class dispatches converts AMP boxes into commands
    and responses using Command.responder decorator.

    Note: Originally, AMP's factoring was such that many tests for this
    functionality are now implemented as full round-trip tests in L{AMPTests}.
    Future tests should be written at this level instead, to ensure API
    compatibility and to provide more granular, readable units of test
    coverage.
    c���t�|_t�|_t	j
|j�|_|jj|j�y)z-
        Create a dispatcher to use.
        N)rR�locatorrY�senderr�
BoxDispatcher�
dispatcher�startReceivingBoxesr-s r%�setUpzCommandDispatchTests.setUpKsB��#�}��� �l����+�+�D�L�L�9������+�+�D�K�K�8r'c����g��fd�}tjddd��}||jjd<|jj|�|j
�|g�y)z�
        L{CommandDispatcher.ampBoxReceived} should locate the appropriate
        command in its responder lookup, based on the '_ask' key.
        c�T���j|�tjddi�S)NrFr�)r0rrM)rO�receiveds �r%�thunkz4CommandDispatchTests.test_receivedAsk.<locals>.thunk[s#����O�O�C� ��7�7�G�Y�/�0�0r'rF�test-command-id�world��_command�_askrFN)rrMrirUrlrr)r$rr�inputrqs   @r%�test_receivedAskz%CommandDispatchTests.test_receivedAskTs\���
��	1�����/@��P��).������g�&����&�&�u�-�����E�7�+r'c�Z�td�}|jj�|jj	t|��|j
t|jj�d�|j
|jjdj|�y)zy
        L{CommandDispatcher} should relay its unhandled errors in responding to
        boxes to its boxSender.
        zsomething went wrong, oh norrN)
�RuntimeErrorrjr_rlrerr�lenr\r$)r$�errs  r%�test_sendUnhandledErrorz,CommandDispatchTests.test_sendUnhandledErrordsy��
�8�9�������!����&�&�w�s�|�4�����T�[�[�8�8�9�1�=�������4�4�Q�7�=�=�s�Cr'c���td���fd�}||jjd<tjddd��}|j
j
�|jj|�|jt|j
j�d�|j|j
jdj��y	)
zp
        Errors during serialization ought to be relayed to the sender's
        unhandledError method.
        zsomething undefined went wrongc�H��G�fd�dtj�}|�S)Nc���eZdZ�fd�Zy)�WCommandDispatchTests.test_unhandledSerializationError.<locals>.thunk.<locals>.BrokenBoxc�����r)r?)r$r_r}s  �r%rCz_CommandDispatchTests.test_unhandledSerializationError.<locals>.thunk.<locals>.BrokenBox._sendToxs����Ir'N)r:r;r<rC)r}s�r%�	BrokenBoxr�ws���r'r�rL)r�r�r}s  �r%rrzDCommandDispatchTests.test_unhandledSerializationError.<locals>.thunkvs���
�C�G�G�
��;�r'rFrsrtrurrN)
r{rirUrrMrjr_rlrrr|r\r$)r$rrrxr}s   @r%� test_unhandledSerializationErrorz5CommandDispatchTests.test_unhandledSerializationErroros����
�;�<��	�*/������g�&�����/@��P�������!����&�&�u�-�����T�[�[�8�8�9�1�=�������4�4�Q�7�=�=�s�Cr'c��|jjtd��}|j|jj
t
jddd��g�g}|j|j�|j|g�|jjt
jdddd���|j|tdd	�
�g�y)a[
        L{CommandDispatcher.callRemote} should emit a properly formatted '_ask'
        box to its boxSender and record an outstanding L{Deferred}.  When a
        corresponding '_answer' packet is received, the L{Deferred} should be
        fired, and the results translated via the given L{Command}'s response
        de-serialization.
        �worldrErD�1ru�yay�ignored�rDrns_answer�ignoredr�N)rlr�rjrrjr[rrr�r0rr�)r$�D�answerss   r%�test_callRemotez$CommandDispatchTests.test_callRemote�s���
�O�O�&�&�u�H�&�=������K�K�!�!�
�Z�Z���H�
E�F�	
���	�
�
�g�n�n�%�����"�%����&�&��J�J�&�J�D�Q�R�	
�	
����4�f�I�#F�"G�Hr'c�0�g}|j|j�|jdt|jj
��|j
|jj
djt�|jdg|�y)z�
        Verify that C{callResult} completes with a L{None} result and that an
        unhandled error has been logged.
        rrN)	�addBothr0rr|rjr\�assertIsInstancer$�ZeroDivisionError)r$�
callResult�finalResults   r%�_localCallbackErrorLoggingTestz3CommandDispatchTests._localCallbackErrorLoggingTest�st��
�����;�-�-�.�����C���� ;� ;�<�=����d�k�k�9�9�!�<�B�B�DU�V����$���-r'c�$�|jj�|jjtd��}|jd��|jj
tjdddd���|j|�y)	z�
        If the last callback on the L{Deferred} returned by C{callRemote} (added
        by application code calling C{callRemote}) fails, the failure is passed
        to the sender's C{unhandledError} method.
        r�rEc��ddzS�Nrrr?�r�s r%r�zVCommandDispatchTests.test_callRemoteSuccessLocalCallbackErrorLogging.<locals>.<lambda>�s
��a�1�f�r'r�r�r�r�N)
rjr_rlr�rjr�rrrr��r$r�s  r%�/test_callRemoteSuccessLocalCallbackErrorLoggingzDCommandDispatchTests.test_callRemoteSuccessLocalCallbackErrorLogging�sq��	
�����!��_�_�/�/��X�/�F�
����4�5����&�&��J�J�&�J�D�Q�R�	
�	
�+�+�J�7r'c�$�|jj�|jjtd��}|jd��|jj
tjdddd���|j|�y)	z�
        Like L{test_callRemoteSuccessLocalCallbackErrorLogging}, but for the
        case where the L{Deferred} returned by C{callRemote} fails.
        r�rEc��ddzSr�r?r�s r%r�zTCommandDispatchTests.test_callRemoteErrorLocalCallbackErrorLogging.<locals>.<lambda>�s
��Q�!�V�r'r�sbugssstuff)�_error�_error_code�_error_descriptionN)
rjr_rlr�rj�
addErrbackrrrr�r�s  r%�-test_callRemoteErrorLocalCallbackErrorLoggingzBCommandDispatchTests.test_callRemoteErrorLocalCallbackErrorLogging�sx��
	
�����!��_�_�/�/��X�/�F�
����3�4����&�&��J�J�#�$+�+3��
�	
�	
�+�+�J�7r'N)r:r;r<r=rnryr~r�r�r�r�r�r?r'r%rgrg?s2��	�9�,� 	D�D�*I�*.�8�"8r'rgc��eZdZdZdZdej�fdej�fgZdej�fgZ	y)�SimpleGreetingzN
    A very simple greeting command that uses a few basic argument types.
    rAsgreetingscookies
cookieplusN)
r:r;r<r=rvrryr�rzr{r?r'r%r�r��sG����K��{�s�{�{�}�-�	�;�3�;�;�=�/I�J�I������
�.�/�Hr'r�c�>�eZdZdZd�Zd�Zeje�Zy)�TestLocatorzI
    A locator which implements a responder to the 'simple' command.
    c��g|_yr))�	greetingsr-s r%r&zTestLocator.__init__�s	����r'c�Z�|jj||f�t|dz��S�N���
cookieplus�r�r0r��r$�greeting�cookies   r%�greetingResponderzTestLocator.greetingResponder��(�������x��0�1��v��z�*�*r'N)r:r;r<r=r&r�r�r�r?r'r%r�r��s%����+�'�0�0�1B�C�r'r�c�8�eZdZdZd�Zej
e�Zy)�OverridingLocatorzJ
    A locator which overrides the responder to the 'simple' command.
    c�Z�|jj||f�t|dz��S)zV
        Return a different cookieplus than L{TestLocator.greetingResponder}.
        �r�r�r�s   r%r�z#OverridingLocator.greetingResponder�s*��	
�����x��0�1��v��z�*�*r'N)r:r;r<r=r�r�r�r?r'r%r�r��s ���+�'�0�0�1B�C�r'r�c��eZdZdZy)�InheritingLocatorzN
    This locator should inherit the responder from L{OverridingLocator}.
    NrTr?r'r%r�r��r�r'r�c�L��eZdZd�Z�fd�Zd�Zeje�Z�xZS)�OverrideLocatorAMPc��tjj|�t�|_d|ji|_g|_y�Nscustom)rr�r&�object�customResponder�expectationsr�r-s r%r&zOverrideLocatorAMP.__init__�s8���������%�x���&��(<�(<�=�����r'c�`��||jvr|j|}|St�|�	|�S)zB
        Override the deprecated lookupFunction function.
        )r��super�lookupFunction)r$r^r��	__class__s   �r%r�z!OverrideLocatorAMP.lookupFunctions8����4�$�$�$��&�&�t�,�F��M��7�)�$�/�/r'c�Z�|jj||f�t|dz��Sr�r�r�s   r%r�z$OverrideLocatorAMP.greetingResponder
r�r')	r:r;r<r&r�r�r�r��
__classcell__)r�s@r%r�r��s&����0�+�'�0�0�1B�C�r'r�c�4�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	y)	�CommandLocatorTestsz�
    The CommandLocator should enable users to specify responders to commands as
    functions that take structured objects, annotated with metadata.
    c����|�}|jd�}|tjdd���}��fd�}|j|�S)z�
        Check that a locator of type C{locatorClass} finds a responder
        for command named I{simple} and that the found responder answers
        with the C{expected} result to a C{SimpleGreeting<"ni hao", 5>}
        command.
        rA�ni hao�5�r�r�c�Z���j|tjd�fz���y)Ns%dr��rrr)�values�expectedr$s ��r%�donez6CommandLocatorTests._checkSimpleGreeting.<locals>.done%s#������V�S�Z�Z�5�H�;�;N�%O�Pr')rWrrMr�)r$�locatorClassr�ri�responderCallabler�r�s` `    r%�_checkSimpleGreetingz(CommandLocatorTests._checkSimpleGreetingsK����.��#�3�3�I�>��"�3�7�7�I�d�#K�L��	Q��!�!�$�'�'r'c�.�|jtd�S)z�
        A method on a L{CommandLocator} subclass decorated with a L{Command}
        subclass's L{responder} decorator should be returned from
        locateResponder, wrapped in logic to serialize and deserialize its
        arguments.
        �)r�r�r-s r%�test_responderDecoratorz+CommandLocatorTests.test_responderDecorator*s���(�(��a�8�8r'c�.�|jtd�S)z�
        L{CommandLocator} subclasses can override a responder inherited from
        a base class by using the L{Command.responder} decorator to register
        a new responder method.
        �	)r�r�r-s r%�test_responderOverridingz,CommandLocatorTests.test_responderOverriding3s���(�(�):�A�>�>r'c�.�|jtd�S)z�
        Responder lookup follows the same rules as normal method lookup
        rules, particularly with respect to inheritance.
        r�)r�r�r-s r%�test_responderInheritancez-CommandLocatorTests.test_responderInheritance;s��
�(�(�):�A�>�>r'c�4���t���jtdt�fd��}�j	�j
|��jtdt�fd��}|t
jdd���}�fd�}|j|�S)a0
        Subclasses which override locateResponder under its old name,
        lookupFunction, should have the override invoked instead.  (This tests
        an AMP subclass, because in the version of the code that could invoke
        this deprecated code path, there was no L{CommandLocator}.)
        z-Override locateResponder, not lookupFunction.c�&���jd�Sr��rW�ris�r%r�zKCommandLocatorTests.test_lookupFunctionDeprecatedOverride.<locals>.<lambda>N����G�+�+�I�6�r'c�&���jd�S�NrAr�r�s�r%r�zKCommandLocatorTests.test_lookupFunctionDeprecatedOverride.<locals>.<lambda>Vr�r'r�r�r�c�R���j|tjd���y�N�8r�r��r�r$s �r%r�zGCommandLocatorTests.test_lookupFunctionDeprecatedOverride.<locals>.doneZ�������V�S�Z�Z�4�%@�Ar')	r��assertWarns�PendingDeprecationWarning�__file__rr�rrMr�)r$�customResponderObject�normalResponderObjectr�r�ris`    @r%�%test_lookupFunctionDeprecatedOverridez9CommandLocatorTests.test_lookupFunctionDeprecatedOverrideBs����%�&�� $� 0� 0�%�;��6�	!
��	
����0�0�2G�H� $� 0� 0�%�;��6�	!
��'�s�w�w�	�$�'O�P��	B��!�!�$�'�'r'c����t���jtdt�fd��}|t	j
dd���}�fd�}|j
|�S)z�
        Invoking locateResponder under its old name, lookupFunction, should
        emit a deprecation warning, but do the same thing.
        z)Call locateResponder, not lookupFunction.c�&���jd�Sr�)r�r�s�r%r�zICommandLocatorTests.test_lookupFunctionDeprecatedInvoke.<locals>.<lambda>is���G�*�*�9�5�r'r�r�r�c�R���j|tjd���yr�r�r�s �r%r�zECommandLocatorTests.test_lookupFunctionDeprecatedInvoke.<locals>.donemr�r')r�r�r�r�rrMr�)r$r�r�r�ris`   @r%�#test_lookupFunctionDeprecatedInvokez7CommandLocatorTests.test_lookupFunctionDeprecatedInvoke_sY���
�-�� �,�,�%�7��5�	
��#�3�7�7�I�d�#K�L��	B��!�!�$�'�'r'N)
r:r;r<r=r�r�r�r�r�r�r?r'r%r�r�s%���
(� 9�?�?�(�:(r'r�sSuccess!sNo, really.  Success.c��eZdZdZd�Zd�Zd�ZdZd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�BinaryProtocolTestsz�
    Tests for L{amp.BinaryBoxProtocol}.

    @ivar _boxSender: After C{startReceivingBoxes} is called, the L{IBoxSender}
        which was passed to it.
    c� �g|_g|_y)zz
        Keep track of all boxes received by this test in its capacity as an
        L{IBoxReceiver} implementor.
        N)rr*r-s r%rnzBinaryProtocolTests.setUps��
��
���	r'c��||_y)zm
        Implement L{IBoxReceiver.startReceivingBoxes} to just remember the
        value passed in.
        N)�
_boxSender�r$rjs  r%rmz'BinaryProtocolTests.startReceivingBoxes�s��
!��r'c�:�|jj|�y)z5
        A box was received by the protocol.
        NrrNs  r%rz"BinaryProtocolTests.ampBoxReceived�s��	
�
�
���#�r'Nc��||_y)zD
        Record the reason that we stopped receiving boxes.
        N)�
stopReasonr4s  r%�stopReceivingBoxesz&BinaryProtocolTests.stopReceivingBoxes�s��!��r'c��y)Nzno peerr?r-s r%rbzBinaryProtocolTests.getPeer����r'c��y)Nzno hostr?r-s r%�getHostzBinaryProtocolTests.getHost�r�r'c�f�|j|t�|jj|�yr))r�rr*r0rs  r%r,zBinaryProtocolTests.write�s$�����d�E�*��	�	����r'c��tj|�}|jd�|j|j|�y)z�
        When L{amp.BinaryBoxProtocol} is connected to a transport, it calls
        C{startReceivingBoxes} on its L{IBoxReceiver} with itself as the
        L{IBoxSender} parameter.
        N)r�BinaryBoxProtocol�makeConnection�assertIsr��r$rs  r%�test_startReceivingBoxesz,BinaryProtocolTests.test_startReceivingBoxes�s6���(�(��.�������%��
�
�d�o�o�x�0r'c���Gd�d�}t�}tj|��}|j|�|j	|j�d�y)z�
        The L{IBoxReceiver} which is started when L{amp.BinaryBoxProtocol} is
        connected to a transport can call C{sendBox} on the L{IBoxSender}
        passed to it before C{startReceivingBoxes} returns and have that box
        sent.
        c��eZdZd�Zy)�[BinaryProtocolTests.test_sendBoxInStartReceivingBoxes.<locals>.SynchronouslySendingReceiverc�P�|jtjddi��y)N�foo�bar)rarrMr�s  r%rmzoBinaryProtocolTests.test_sendBoxInStartReceivingBoxes.<locals>.SynchronouslySendingReceiver.startReceivingBoxes�s�����s�w�w���'7�8�9r'N)r:r;r<rmr?r'r%�SynchronouslySendingReceiverr�s��
:r'rsfoobarN)rrrrrr$)r$rr+rs    r%�!test_sendBoxInStartReceivingBoxesz5BinaryProtocolTests.test_sendBoxInStartReceivingBoxes�sR��	:�	:�$�%�	��(�(�)E�)G�H������	�*�������*�,M�Nr'c��tj|�}|jd�|jd�|jd�|j|jtj
d��g�y)z�
        When a binary box protocol receives:
            * a key
            * a value
            * an empty string
        it should emit a box and send it to its boxReceiver.
        rDr�r'rEN)rr�stringReceivedrrrr!s  r%�test_receiveBoxStateMachinez/BinaryProtocolTests.test_receiveBoxStateMachine�s^��
�!�!�$�'��	����"�	����"�	�����������c�j�j�x�&@�%A�Br'c��t�}tj|�}|j|�|jd�|j|j�y)z�
        L{amp.BinaryBoxProtocol} drops its connection if the length prefix for
        the first a key it receives is larger than 255.
        �N)rrrrr1r.�
disconnecting�r$r+rs   r%�$test_firstBoxFirstKeyExcessiveLengthz8BinaryProtocolTests.test_firstBoxFirstKeyExcessiveLength�sN��
$�%�	��(�(��.������	�*�����k�*����	�/�/�0r'c��t�}tj|�}|j|�|jd�|j|j�|jd�|j|j�y)z�
        L{amp.BinaryBoxProtocol} drops its connection if the length prefix for
        a subsequent key in the first box it receives is larger than 255.
        skvrN�rrrrr1r0rr.rs   r%�)test_firstBoxSubsequentKeyExcessiveLengthz=BinaryProtocolTests.test_firstBoxSubsequentKeyExcessiveLength�ss��
$�%�	��(�(��.������	�*�����3�4�����0�0�1�����k�*����	�/�/�0r'c��t�}tj|�}|j|�|jd�|j|j�|jd�|j|j�y)z�
        L{amp.BinaryBoxProtocol} drops its connection if the length prefix for
        the first key in a subsequent box it receives is larger than 255.
        skvrNrrs   r%�)test_subsequentBoxFirstKeyExcessiveLengthz=BinaryProtocolTests.test_subsequentBoxFirstKeyExcessiveLength�ss��
$�%�	��(�(��.������	�*�����;�<�����0�0�1�����k�*����	�/�/�0r'c��tj|�}|jt��|jd�|j
t
tjd���|jjtj�|j|jjj�|j|jjj �|j#|jjj�|j#|jjj$�y)z�
        If L{amp.BinaryBoxProtocol} disconnects because it received a key
        length prefix which was too large, the L{IBoxReceiver}'s
        C{stopReceivingBoxes} method is called with a L{TooLong} failure.
        rzsimulated connection doneN)rrrrr1r6rr
�ConnectionDoner��trap�TooLongr.r$�isKeyr0�isLocal�assertIsNone�keyNamers  r%�test_excessiveKeyFailurez,BinaryProtocolTests.test_excessiveKeyFailure�s����(�(��.������� 1�2�����k�*������E�(�(�)D�E�F�	
�	
�����S�[�[�)�������-�-�3�3�4�������.�.�6�6�7����$�/�/�/�/�5�5�6����$�/�/�/�/�7�7�8r'c�@�t�}tj|�}|j|�|jtt
d���|jdt|jt���|j|j�y)z~
        L{amp.BinaryBoxProtocol.unhandledError} logs the failure passed to it
        and disconnects its transport.
        �
Fake errorrN)rrrrrerr{rr|�flushLoggedErrorsr.rrs   r%� test_unhandledErrorWithTransportz4BinaryProtocolTests.test_unhandledErrorWithTransportsx��
$�%�	��(�(��.������	�*�������\�(B� C�D�����C�� 6� 6�|� D�E�F����	�/�/�0r'c�N�tj|�}|jt��|jtt
d���|jttd���|jdt|jt���y)z�
        L{amp.BinaryBoxProtocol.unhandledError} completes without error when
        there is no associated transport.
        �	Simulatedr(rN)rrrrr6rr|rer{rr|r)rs  r%�#test_unhandledErrorWithoutTransportz7BinaryProtocolTests.test_unhandledErrorWithoutTransports{��
�(�(��.������� 1�2������	�+�(>� ?�@�������\�(B� C�D�����C�� 6� 6�|� D�E�Fr'c��tj|�}|jtjddd��j	��|j|jtjddd��g�y)z�
        When a binary box protocol receives the serialized form of an AMP box,
        it should emit a similar box to its boxReceiver.
        �	valueTestsanotherValue)�testKeys
anotherKeyN)rrr1rMr rrr!s  r%�test_receiveBoxDataz'BinaryProtocolTests.test_receiveBoxDatasf��

�!�!�$�'��	����G�G�)�/�J�
��i�k�	
�
	
����J�J�
�W�W�,��O�
P�Q�	
r'c�x�d}d|z}t�}tj|�}|j|�|jtj
d|i�j
��|j|jtj
d|i�g�|j|j�y)z�
        An L{amp.BinaryBoxProtocol} can receive serialized AMP boxes with
        values of up to (2 ** 16 - 1) bytes.
        i��r��kN)rrrrr1rMr rrr0r)r$r�r$r+rs     r%�test_receiveLongerBoxDataz-BinaryProtocolTests.test_receiveLongerBoxData.s���
���v�
��#�%�	��(�(��.������	�*�����c�g�g�s�E�l�3�=�=�?�@�������c�g�g�s�E�l�&;�%<�=�����0�0�1r'c�6�tj|�}|j|�tjddd��}|j|�|j	|�|jdj
|j�|j��y)z�
        When a binary box protocol sends a box, it should emit the serialized
        bytes of that box to its transport.
        r/rD)r0ssomeDatar'N)	rrrrMrar�joinr*r )r$r
�aBoxs   r%�test_sendBoxz BinaryProtocolTests.test_sendBox<sr��

�!�!�$�'��	������w�w�L�x�H�I��	�����	�	�	�$��������$�)�)�,�d�n�n�.>�?r'c���tj|�}|j|�tt	��}|j|�|j
|j|�y)z�
        When a binary box protocol loses its connection, it should notify its
        box receiver that it has stopped receiving boxes.
        N)rrrrr{r6rr�)r$r
�connectionFailures   r%�#test_connectionLostStopSendingBoxesz7BinaryProtocolTests.test_connectionLostStopSendingBoxesHsQ��

�!�!�$�'��	�����#�L�N�3��	���*�+��
�
�d�o�o�'8�9r'c�����tdd��|�G���fd�d�}tj|���tjddd��}�j	|�|j�dz}�j
|�|j�j|�|jd	j�j�d�|j|jdg��j
d
�|jd	j�j�d�|jtj�j|�y)z�
        L{BinaryBoxProtocol} has the capacity to switch to a different protocol
        on a box boundary.  When a protocol is in the process of switching, it
        cannot receive traffic.
        N�
outgoing datac�&��eZdZdZd�Z���fd�Zy)�@BinaryProtocolTests.test_protocolSwitch.<locals>.SwitchyReceiverFc��yr)r?r�s  r%rmzTBinaryProtocolTests.test_protocolSwitch.<locals>.SwitchyReceiver.startReceivingBoxes_s��r'c����j|jd�d|_�j��j��y)NzShould only receive one box!T)r0�switched�_lockForSwitch�	_switchTo)r$rOr
�
otherProtorNs  ���r%rzOBinaryProtocolTests.test_protocolSwitch.<locals>.SwitchyReceiver.ampBoxReceivedbs7���� � ����0N�O� $��
�� � �"����J�'r'N)r:r;r<rBrmr)r
rErNs���r%�SwitchyReceiverr?\s����H�
�
(r'rFslots�data)sincludesofsHello, world!r's	more datasHello, world!more data)rrrrMrr r1rr+rr6r*r&�ProtocolSwitchedra)r$rF�	anyOldBox�moreThanOneBoxr
rErNs    @@@r%�test_protocolSwitchz'BinaryProtocolTests.test_protocolSwitchSs	����t�%5�6�
���
	(�
	(�
�!�!�/�"3�4���G�G���A�B�	�	�����#�,�,�.�1I�I��	���~�&��
�
�j�*�*�D�1�������*�/�/�2�4L�M�������%5�$6�7�	���|�$�������*�/�/�2�4U�V����#�.�.��	�	�9�Er'c���tj|�}|j|�tdd�}|j	|�|j|jg�y)z�
        After switching to a different protocol, if no extra bytes beyond
        the switch box were delivered, an empty string is not passed to the
        switched protocol's C{dataReceived} method.
        Nr')rrrrrDrr*)r$r
rEs   r%�test_protocolSwitchEmptyBufferz2BinaryProtocolTests.test_protocolSwitchEmptyBufferwsN��
�!�!�$�'��	������t�S�)�
�	���J��������"�-r'c�V�tj|�}|j|�tjddi�}|j	�|jtj|j|�|j�|j|�|jdj|j�|j��|j	�tdd�}|j|�|jtj|j�y)a8
        In order to make sure the protocol never gets any invalid data sent
        into the middle of a box, it must be locked for switching before it is
        switched.  It can only be unlocked if the switch failed, and attempting
        to send a box while it is locked should raise an exception.
        ssomerGr'Nr=)rrrrMrCr&rHra�_unlockFromSwitchrr6r*r rrD)r$r
�	sampleBoxrEs    r%� test_protocolSwitchInvalidStatesz4BinaryProtocolTests.test_protocolSwitchInvalidStates�s���
�!�!�$�'��	������G�G�W�g�.�/�	�	�������#�.�.��	�	�9�E�	����	�	�	�)��������$�)�)�,�i�.A�.A�.C�D�	�����t�%5�6�
�	���J�����#�.�.��0C�0C�Dr'c�R�Gd�dtj�}|�}tj|�}|j	|�|j�|j
|�tt��}|j|�|j|j|�y)zo
        When the protocol is switched, it should notify its nested protocol of
        disconnection.
        c��eZdZdZd�Zy)�DBinaryProtocolTests.test_protocolSwitchLoseConnection.<locals>.LoserNc��||_yr)�r5r4s  r%r6zSBinaryProtocolTests.test_protocolSwitchLoseConnection.<locals>.Loser.connectionLost��	��$��r')r:r;r<r5r6r?r'r%�LoserrT�����F�
%r'rXN)r�ProtocolrrrrCrDrr{r6rr5)r$rX�connectionLoserr
r:s     r%�!test_protocolSwitchLoseConnectionz5BinaryProtocolTests.test_protocolSwitchLoseConnection�s���	%�H�%�%�	%� �'���!�!�$�'��	�����	����	���O�$�#�L�N�3��	���*�+�����/�/�1B�Cr'c�^�Gd�d�}tj|�}tj�}|�}|j	|�|j�|j
||�tt��}|j|�|j|j|�y)z~
        When the protocol is switched, it should notify its nested client
        protocol factory of disconnection.
        c��eZdZdZd�Zy)�PBinaryProtocolTests.test_protocolSwitchLoseClientConnection.<locals>.ClientLoserNc��||_yr)rVr�s   r%�clientConnectionLostzeBinaryProtocolTests.test_protocolSwitchLoseClientConnection.<locals>.ClientLoser.clientConnectionLost�rWr')r:r;r<r5rar?r'r%�ClientLoserr_�rYr'rbN)rrrrZrrCrDrr{r6rr5)r$rbr
r[�clientLoserr:s      r%�'test_protocolSwitchLoseClientConnectionz;BinaryProtocolTests.test_protocolSwitchLoseClientConnection�s���	%�	%�
�!�!�$�'��"�+�+�-��!�m��	�����	����	���O�[�1�#�L�N�3��	���*�+�����+�+�->�?r')r:r;r<r=rnrmrr�r�rbrr,rrrrrrr&r*r-r1r4r8r;rKrMrQr\rdr?r'r%r�r�ws�����!���J�!����1�O�"C�	1�1�1�9�$
1�	G�
� 2�
@�	:�"F�H
.�E�(D�*@r'r�c��eZdZd�Zd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zeed
�d��Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Zd�Z d�Z!d�Z"e#d d fd!�Z$d"�Z%e#fd#�Z&d$�Z'd%�Z(d&�Z)d'�Z*d(�Z+y))*�AMPTestsc��tjtjftjtjftj
tjftj
tjftjtjftjtjftj
tjffD],\}}|j|j|�|�d|�d���.y)z~
        The classes in the amp module ought to implement the interfaces that
        are declared for their benefit.
        z does not implements(�)N)r�
IBoxSenderr�IBoxReceiverrk�IResponderLocator�CommandLocator�SimpleStringLocatorr�r.�
implementedBy)r$�	interface�implementations   r%�test_interfaceDeclarationsz#AMPTests.test_interfaceDeclarations�s����^�^�S�2�2�3�
�
�
�s�0�0�1�
�
"�
"�C�$6�$6�7�
�
"�
"�C�$;�$;�<�
�^�^�S�W�W�%�
�
�
�s�w�w�'�
�
"�
"�C�G�G�,�*
�	�%�I�~�
�O�O��'�'��7�!�"�"7�	�{�!�D�
�	r'c���t�\}}}g}d}|j|�j|j�|j	�|j|dd|�y)z�
        Verify that a simple command can be sent and its response received with
        the simple low-level string-based API.
        r�rrDN�rrJr�r0rDr�r$rEr:r��L�HELLOs      r%�test_helloWorldzAMPTests.test_helloWorld��X��
+�,���1�a�����	���E��&�&�q�x�x�0�	���	�����1��h���/r'c���t�\}}}g}d}|j|�j|j�|j	�|j|dd|�y)z}
        Verify that mixed-case, underscored and dashed arguments are mapped to
        their python names properly.
        r�rrDNrsrts      r%�test_wireFormatRoundTripz!AMPTests.test_wireFormatRoundTrip�rxr'c��ttt��\}}}g}d}d}|j||�j|j�|j�|j
|dd|�|j
|dd|�y)zK
        Verify that unicode arguments can be encoded and decoded.
        �rr	r�uworሴldrrFr�N)rr�r�r�r0rDr)r$rEr:r�rurv�
HELLO_UNICODEs       r%�test_helloWorldUnicodezAMPTests.test_helloWorldUnicode�s���+�6�6�
���1�a�
����%�
�	���5�-�0�<�<�Q�X�X�F�	���	�����1��g���.�����1��g��
�6r'c�h�t�\}}}|jdd��}|j|�y)zm
        L{BoxDispatcher.callRemoteString} returns L{None} if C{requiresAnswer}
        is C{False}.
        �WTFF)r�N)rrGr$)r$rEr:r��rets     r%�(test_callRemoteStringRequiresAnswerFalsez1AMPTests.test_callRemoteStringRequiresAnswerFalse�s5��
+�,���1�a�� � ��� �>�����#�r'c��t�\}}}g}d�}|jd�j|�j|j�|j�|j
|j�d�d}|j|�j|j�|j�|j
|dd|�y)z�
        Verify that unknown commands using low-level APIs will be rejected with an
        error, but will NOT terminate the connection.
        c�B�|jtj�y�z:
            You can't propagate the error...
            �OK�r r�UnhandledCommand��es r%�clearAndAddz4AMPTests.test_unknownCommandLow.<locals>.clearAndAdd���
�F�F�3�'�'�(�r'r�r�r�rrDN)	rrGr�r�r0rDr�poprJ�r$rEr:r�rur�rvs       r%�test_unknownCommandLowzAMPTests.test_unknownCommandLows���
+�,���1�a���	�	
���6�"�-�-�k�:�F�F�q�x�x�P�	���	��������$�'���	���E��&�&�q�x�x�0�	���	�����1��h���/r'c��t�\}}}g}d�}|jt�j|�j	|j
�|j
�|j|j�d�d}|j|�j	|j
�|j
�|j|dd|�y)z�
        Verify that unknown commands using high-level APIs will be rejected with an
        error, but will NOT terminate the connection.
        c�B�|jtj�yr�r�r�s r%r�z5AMPTests.test_unknownCommandHigh.<locals>.clearAndAdd'r�r'r�r�rrDN)
rr�r�r�r�r0rDrr�rJr�s       r%�test_unknownCommandHighz AMPTests.test_unknownCommandHighs���
+�,���1�a���	�	
���S��$�$�[�1�=�=�a�h�h�G�	���	��������$�'���	���E��&�&�q�x�x�0�	���	�����1��h���/r'c�D�g}t�jtjtj
���j
|j�|djtj�|jdt|dj��y)a
        It can be very confusing if you write some code which responds to a
        command, but gets the return value wrong.  Most commonly you end up
        returning None instead of a dictionary.

        Verify that if that happens, the framework logs a useful error.
        )rvr�NoneN)
r��dispatchCommandrrr�rvr�r0r �BadLocalReturn�failUnlessInrr$)r$rus  r%�test_brokenReturnValuezAMPTests.test_brokenReturnValue6sm��
��&�(�8�8��J�J�� 8� 8�9�	
�
�*�Q�X�X�
�	�!��	�	�#�$�$�%����&�$�q��t�z�z�"2�3r'c���ttt��\}}}g}d}|jt|d��j	|j
�|j
�|j|dd|�y)z�
        Verify that unknown arguments are ignored, and not passed to a Python
        function which can't accept them.
        r|r�sI'm not in the book!)rF�bonusrrFN)rr�r�r�r�r0rDrrts      r%�test_unknownArgumentzAMPTests.test_unknownArgumentEsn��
+�6�6�
���1�a�
����	����u�,C�	�	
�
�+�a�h�h�
�	���	�����1��g���.r'c	��|jtttjd���t
�|jtttj���t
�|jtttj���t
�|jdttj���y)zS
        Verify that the various Box objects repr properly, for debugging.
        r
rN)	rrrr�
_SwitchBoxr>r�r�assertInr-s r%�test_simpleReprszAMPTests.test_simpleReprsWs���	
����d�3�>�>�#�#6�7�8�#�>�����d�3�;�;�=�1�2�C�8�����d�3�:�:�<�0�1�3�7��
�
�h��S�Z�Z�\� 2�3r'c��tdd�}tj�}||_|j	t|�d|jt|�fz�y)zQ
        Verify that L{AMP} objects output their innerProtocol when set.
        Nr=z#<AMP inner <TestProto #%d> at 0x%x>)rrr��
innerProtocolrrr#�id)r$rEr
s   r%�test_innerProtocolInReprz!AMPTests.test_innerProtocolInRepr`sO���t�%5�6�
��G�G�I��$��������G�1�Z�5J�5J�B�q�E�4R�R�	
r'c�~�tj�}|jt|�dt	|�d�d��y)zh
        Verify that L{AMP} objects do not output 'inner' when no innerProtocol
        is set.
        z
<AMP at 0xr��>N)rr�rrr�r!s  r%�test_innerProtocolNotInReprz$AMPTests.test_innerProtocolNotInReprms2��

�G�G�I������a��J�r�!�u�Q�i�q�"9�:r'�SSL not availablec�x�|jtttj���t
�y)z;
        L{amp._TLSBox.__repr__} returns a string.
        N)rrrr�_TLSBoxr>r-s r%�test_simpleSSLReprzAMPTests.test_simpleSSLReprus$��
	
����d�3�;�;�=�1�2�C�8r'c�
�t�\}}}d}|jtj|jdfi|di��}|j|j�|j|j�|j|j�|j|j|jd��|jtt|��t!|��|jdt!|��y)zl
        Verify that a key that is too long will immediately raise a synchronous
        exception.
        �HHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHsHelloshi�asciirN)rr&rr!rGr.r"r#r$r%rr$�encoder�r>r|r�r$rEr:r�r��tls      r%�test_keyTooLongzAMPTests.test_keyTooLong|s���
+�,���1�a���
�T�
�
�s�{�{�A�,>�,>��
W�Q�PU�J�
W��������!�����
�
�#����"�*�*�%�������1�8�8�G�#4�5��
�
�c�#�a�&�k�4��8�,��
�
�e�T�"�X�&r'c�B�t�\}}}ddz}|jtj|j|�}|j�|j
|j�|j|j�|j|jd�|j|j|�|jtt!|��t#|��|jdt#|��|jdt#|��y)zs
        Verify that attempting to send value longer than 64k will immediately
        raise an exception.
        �HirDr$rFN)rr&rr!rJrDr0r"r.r#rr%�failUnlessIdenticalr$r�r>r|rr�s      r%�test_valueTooLongzAMPTests.test_valueTooLong�s���
+�,���1�a��J���
�
�
�s�{�{�A�K�K��
;��	���	�������"�����
�
�#�������X�.�� � ����1�-��
�
�c�#�a�&�k�4��8�,��
�
�g�t�B�x�(��
�
�g�t�B�x�(r'c���ttt��\}}}g}d}|j|�j|j�|j�|j
|dd|�y)z�
        Verify that a simple command can be sent and its response received with
        the high-level value parsing API.
        r|r�rrFN)rr�rJr�r0rDrrts      r%�test_helloWorldCommandzAMPTests.test_helloWorldCommand�sb��
+�6�6�
���1�a�
����	���E��&�&�q�x�x�0�	���	�����1��g���.r'c�2�g}ttt��\}}}d}|j|�j|j�|j�|dj
t�|jt|dj�d�y)z�
        Verify that if a known error type is raised and handled, it will be
        properly relayed to the other end of the connection and translated into
        an exception, and no error will be logged.
        r|�fuck yourr�N)rr�rJr�r0rDr rRrr>r$�r$rurEr:r�rvs      r%�test_helloErrorHandlingz AMPTests.test_helloErrorHandling�sx��
��*�6�6�
���1�a���	���E��%�%�a�h�h�/�	���	�	�!��	�	�$�%�����Q�q�T�Z�Z��*<�=r'c���g}ttt��\}}}d}|j|�j|j�|j�|j
�jt�|j|�j|j�|j�|j
�jtj�y)a

        Verify that if a known, fatal error type is raised and handled, it will
        be properly relayed to the other end of the connection and translated
        into an exception, no error will be logged, and the connection will be
        terminated.
        r|r�N)rr�rJr�r0rDr�r rWr
rr�s      r%�test_helloFatalErrorHandlingz%AMPTests.test_helloFatalErrorHandling�s���
��*�6�6�
���1�a���	���E��%�%�a�h�h�/�	���	�	������[�!�	���E��%�%�a�h�h�/�	���	�	������U�)�)�*r'c��g}ttt��\}}}t}|j|�j	|j
�|j
�|j�}|jtj�|j|�j	|j
�|j�}|jtj�|j|jt��y)z�
        Verify that if an unknown error type is raised, it will be relayed to
        the other end of the connection and translated into an exception, it
        will be logged, and then the connection will be dropped.
        r|N)rr�r�rJr�r0rDr�r r�UnknownRemoteErrorr
rr.r)r�)r$rurEr:r�rv�ure�cls        r%�test_helloNoErrorHandlingz"AMPTests.test_helloNoErrorHandling�s���
��*�6�6�
���1�a�(��	���E��%�%�a�h�h�/�	���	��e�e�g������'�'�(�	���E��%�%�a�h�h�/�
�U�U�W��
����$�$�%�����.�.�/H�I�Jr'c���ttt��\}}}g}|jt�j	|j
�|j
�|j|g�|jj�|j
�|j�jtj�|jji�|jS)z�
        Verify that a command that does not get answered until after the
        connection terminates will not cause any errors.
        r|)rr�r�r�r�r0rDrr+�loseConnectionr�r r
rr�r3�r$rEr:r�rus     r%�test_lateAnswerzAMPTests.test_lateAnswer�s���
+�6�6�
���1�a�
��	���[�!�,�,�Q�X�X�6�	���	�����B��	���"�"�$�	���	�	������U�)�)�*�	�	�	���2���y�y�r'c��ttt��\}}}d}|jt|��|j	�|j|j�y)zG
        Verify that a command that requires no answer is run.
        r|r�rEN)rr�r�rrDr.r�)r$rEr:r�rvs     r%�test_requiresNoAnswerzAMPTests.test_requiresNoAnswer�sJ��+�6�6�
���1�a���	���]�%��0�	���	�����	�	�"r'c��g}ttt��\}}}d}|jt|��|j	�|j|j
tj��d}|jt|��j|j�|j	�|j�jtj�|j!|j"�y)z]
        Verify that commands sent after a failed no-answer request do not complete.
        r|r�rEr�N)rr�r�rrDr.r)r�RemoteAmpErrorrjr�r0r�r r
rr0r�r�s      r%�test_requiresNoAnswerFailz"AMPTests.test_requiresNoAnswerFails���
��*�6�6�
���1�a���	���]�%��0�	���	�����.�.�s�/A�/A�B�C���	���U�%��(�3�3�A�H�H�=�	���	�	������U�)�)�*�������#r'c���ttt��\}}}|jj�|j	�|jtd��}|j|d�y)zv
        No-answer commands sent after the connection has been torn down do not
        return a L{Deferred}.
        r|r�rEN)rr�r+r�rDr�rr)r$rEr:r�r�s     r%�test_requiresNoAnswerAfterFailz'AMPTests.test_requiresNoAnswerAfterFailsU��
+�6�6�
���1�a�	
���"�"�$�	���	����m�:��>���
�
�f�d�#r'c��ttt��\}}}|jtd��|j�|j
tj�}|jt|�d�y)a+
        Verify that responders of requiresAnswer=False commands have to return
        a dictionary anyway.

        (requiresAnswer is a hint from the _client_ - the server may be called
        upon to answer commands in any case, if the client wants to know when
        they complete.)
        r|rDrErN)rr�r�r�rrDr)rr�rr|)r$rEr:r��les     r%�test_noAnswerResponderBadAnswerz(AMPTests.test_noAnswerResponderBadAnswer)s_��+�2�6�
���1�a�	
���]�(��3�	���	�
�
#�
#�C�$6�$6�
7������R��!�$r'c�,�ttt��\}}}g}|jtd��j|j�|j�|jt|�d�|j|tdd��g�y)z�
        Verify that responders with requiresAnswer=False will actually respond
        if the client sets requiresAnswer=True.  In other words, verify that
        requiresAnswer is a hint honored only by the client.
        r|sHello!rErsHello!-noanswerNr�)rrr�r�rjr�r0rDrr|r�r�s     r%�$test_noAnswerResponderAskedForAnswerz-AMPTests.test_noAnswerResponderAskedForAnswer;s{��+�/�6�
���1�a�
��	���U�)��,�8�8����B�	���	�����Q���#����
��-�T�:�;�	
r'c�(�ttt��\}}}g}|jtd��j	|j
�|j
�|j�jd�}|j|ddigdz�y)zN
        Test encoding of an argument that uses the AmpList encoding.
        r|�
)r�r�r�rN)
rr�r�r�r�r0rDr��getr)r$rEr:r�rur�s      r%�test_ampListCommandzAMPTests.test_ampListCommandMsw��+�6�6�
���1�a�
��	���W�R��(�4�4�Q�X�X�>�	���	�������V�$������3��(��b��1r'c��ttt��\}}}g}|jtd��j	|j
�|j
�|j�jd�}|j|d�y)z�
        Sending a command with an omitted AmpList argument that is
        designated as optional does not raise an InvalidSignature error.
        r|�please)r�r{r�N�
rr�r�r�r�r0rDr�r�r�r$rEr:r�rur{s      r%�test_optionalAmpListOmittedz$AMPTests.test_optionalAmpListOmitted[sm��
+�6�6�
���1�a�
��	���\�X��6�B�B�1�8�8�L�	���	��5�5�7�;�;�z�*������>�2r'c�$�ttt��\}}}g}|jtdddig��j	|j
�|j
�|j�jd�}|j|d�y)	zV
        Sanity check that optional AmpList arguments are processed normally.
        r|r�r^�foo)r�r�r{zfoo acceptedNr�r�s      r%�test_optionalAmpListPresentz$AMPTests.test_optionalAmpListPresentjs{��+�6�6�
���1�a�
��	����H�V�U�O�3D�	�	
�
�+�a�h�h�
�	���	��5�5�7�;�;�z�*������>�2r'c�L�|jtjt�y)z~
        Verify that if we pass an invalid argument list (omitting an argument),
        an exception will be raised.
        N)r&r�InvalidSignaturerjr-s r%�test_failEarlyOnArgSendingz#AMPTests.test_failEarlyOnArgSendingzs��
	
���#�.�.��6r'c�V�����tj�}t|��tj�}t|��t�fd��fd���\�}}��fd�}�j	�j|�|j
��j�j�y)z�
        As a debugging aid, a protocol system should raise a
        L{ProtocolSwitched} exception when asked to switch a protocol that is
        already switched.
        c����Sr)r?��serverProtos�r%r�z4AMPTests.test_doubleProtocolSwitch.<locals>.<lambda>������r'c����Sr)r?��clientProtos�r%r�z4AMPTests.test_doubleProtocolSwitch.<locals>.<lambda>������r'r|c�h���jtj�j�d�_y�NT)r&rrHr��
testSucceeded)r�rEr$s ��r%rBz4AMPTests.test_doubleProtocolSwitch.<locals>.switched�s'������c�2�2�A�4J�4J�K�!%�D�r'N)	rr�r�rr�r�rDr.r�)	r$�serverDeferred�clientDeferredr:r�rBrEr�r�s	`     @@@r%�test_doubleProtocolSwitchz"AMPTests.test_doubleProtocolSwitch�s�������)��4�^�D�����)��4�^�D��*�+�9L�
���1�a�	&�	
��� �,�,�X�6�	���	�����*�*�+r'Fc���
���
��d�_tj��
|�
��tj��|���t�fd��fd���\}}}|r0g}|j	t
�j
|j�|j�}|r+�jtj|jd��fd��
�
��
fd�}	|j|	�|j��j�5�jj!�j"�|j�|r]|r0|j$j'tj(d	d
��n|j$j!i�|j�|j*j-�|j��j/�j�y)z�
        Verify that it is possible to switch to another protocol mid-connection and
        send data to it successfully.
        Fc����Sr)r?r�s�r%r�z.AMPTests.test_protocolSwitch.<locals>.<lambda>�r�r'c����Sr)r?r�s�r%r�z.AMPTests.test_protocolSwitch.<locals>.<lambda>�r�r'r|r�c���|\\}}\}}�j|��j|��jdj|�t��jdj|�t�d�_y)Nr'T)r.rr6r�r�r�)�info�
serverSuccess�
serverData�
clientSuccess�
clientDatar$s     �r%�cbConnsLostz1AMPTests.test_protocolSwitch.<locals>.cbConnsLost�sk���IM�F�
(�m�Z�*E�=�*��O�O�M�*��O�O�M�*����S�X�X�j�1�3E�F����S�X�X�j�1�3E�F�!%�D�r'c�P��tj��g�j��Sr))r�DeferredListr�)r_r�r�r�s ���r%�cbSwitchz.AMPTests.test_protocolSwitch.<locals>.cbSwitch�s)����%�%�~�~�&F�G�S�S���
r'NsSPURIOUSz,Here's some traffic in the form of an error.)r�rr�rr�r�r�r0r�r&rrHrJr�rDr�r3r�r��errbackr�r+r�r.)r$�switcher�spuriousTraffic�
spuriousErrorrEr:r��wfdr�switchDeferredr�r�r�r�r�r�s`         @@@@@r%rKzAMPTests.test_protocolSwitch�si���#������)���~�.�����)���~�.��*�+�9L�
���1�a���D�
�L�L��%�0�0����=��/�/�1������c�2�2�A�K�K��J�	&�	�
	�"�"�8�,�	���	��!�!�-��"�"�+�+�K�,G�,G�H�
�G�G�I����	�	�!�!��&�&�#�%S����	�	�"�"�2�&�
�G�G�I�	���"�"�$�	���	�����*�*�+r'c�.�|jt��S)z�
        Verify that protocol-switching even works if the value returned from
        the command that does the switch is deferred.
        )r�)rKr�r-s r%�test_protocolSwitchDeferredz$AMPTests.test_protocolSwitchDeferred�s��
�'�'�1Q�'�R�Rr'c�d��	�d|_tj�}||��	tj�}||��t�	fd��fd���\}}}g}|j	d��j|j�|j�|j�jt�|j|j�|jd�j|j�|j�|j|j�dd�y	)
z�
        Verify that if we try to switch protocols and it fails, the connection
        stays up and we can go back to speaking AMP.
        Fc����Sr)r?r�s�r%r�z2AMPTests.test_protocolSwitchFail.<locals>.<lambda>�r�r'c����Sr)r?r�s�r%r�z2AMPTests.test_protocolSwitchFail.<locals>.<lambda>�r�r'r|T)r�r�rFN)r�rr�rr�r�r0rDr�r rYr0rJr�r)
r$r�r�r�rEr:r�rur�r�s
        @@r%�test_protocolSwitchFailz AMPTests.test_protocolSwitchFail�s����
#������)���~�.�����)���~�.��*�+�9L�
���1�a�
��	���D��)�4�4�Q�X�X�>�	���	�	������_�%�����+�+�,�	
���H��)�)�!�(�(�3�	���	���������)�8�4r'c�&�|jd��S)zs
        Verify that attempts to send traffic after a switch will not corrupt
        the nested protocol.
        T)r�rKr-s r%�test_trafficAfterSwitchz AMPTests.test_trafficAfterSwitch�s��
�'�'��'�=�=r'c�(�|jdd��S)zh
        Returning an error after a protocol switch should record the underlying
        error.
        T)rrrr-s r%�test_errorAfterSwitchzAMPTests.test_errorAfterSwitch�s��
�'�'��D�'�Q�Qr'c�l�ttt��\}}}g}d}d}|j|�j|j�|j�|j
|j�d|�|jt�j|j�|j�|j
|j�d|�|j|�j|j�|j�jtj�y)zt
        Verify that commands with a responseType of QuitBox will in fact
        terminate the connection.
        r|r�r�rFr�N)rr�rJr�r0rDrr�r�r�r�r r
r)r$rEr:r�rurv�GOODBYEs       r%�test_quitBoxQuitszAMPTests.test_quitBoxQuitss���
+�6�6�
���1�a�

������	���E��&�&�q�x�x�0�	���	���������)�5�1�	���W��)�)�!�(�(�3�	���	���������+�W�5�	���E��%�%�a�h�h�/�	������U�)�)�*r'c��t�\}}}g}|j|_|jtdddd��|j�|j
t|�d�dtjfdd	d
dfD])\}}|j
|dj|�|��+|djd
�|j
|di�y)z�
        Verify that the command dictionaries for a callRemoteN look correct
        after being serialized and parsed.
        �
hello test�mixed case arg testr��y�rFr�r�r�r�_command)rDr)rpr)rqr�)rrrrB�_askN)
rr0rr�rjrDrr|rvr�)r$rEr:r�rur3r;s       r%�test_basicLiteralEmitzAMPTests.test_basicLiteralEmits���
+�,���1�a����8�8���	�����,���	�	
�	
���	�����Q���#�
�%�+�+�,�%�2��%�
�	.�D�A�q�
���Q�r�U�Y�Y�q�\�1�-�	.�	
�"��	�	�'������2���#r'c
����g�G�fd�dtj�}t|��\}}}|jtdddd��j�j�|j�|jt��d	�|j�d
dtdddd|jj�dd�
�f�|j�dtdd���y)z�
        Verify that a call similar to basicLiteralEmit's is handled properly with
        high-level quoting and passing to Python methods, and that argument
        names are correctly handled.
        c�:��eZdZ�fd�Zeje�y)�:AMPTests.test_basicStructuredEmit.<locals>.StructuredHelloc�B���j||f�td��S)N�aaarE)r0r�)r$r
r3rus   �r%�hz<AMPTests.test_basicStructuredEmit.<locals>.StructuredHello.h=s������!�Q�� ��&�)�)r'N)r:r;r<rrjr�)rus�r%�StructuredHellor<s���
*�
�O�O�A�r'r )rrrr�rr�rr?N)rFr�r�r�r�r�rmrr)r�rF)
rr�rr�rjr�r0rDrr|r�r+rb)r$r rEr:r�rus     @r%�test_basicStructuredEmitz!AMPTests.test_basicStructuredEmit4s����
��	�c�g�g�	�+��G���1�a�	�����,���	�	
��+�a�h�h�
�	���	�����Q���#����
�a�D���'�4�!�#'����,�,�.��!��
�	
�$	
����1��t�$�f�=�>r'N),r:r;r<rqrwrzr~r�r�r�r�r�r�r�r�r�skipSSLr�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rKrr	rrrrr"r?r'r%rfrf�s����&
0�
0�7� �0�.0�.
4�/�$4�
�;��G�(�)�9�*�9�
'�)�"
/�>�"+�(K�,�(#�$�($�%�$
�$2�
3�3� 7�,�00���	;,�zS�0N�5�2>�R�+�,$�8+?r'rfc��eZdZd�Zy)�!PretendRemoteCertificateAuthorityc��yr�r?r-s r%�checkIsPretendRemotez6PretendRemoteCertificateAuthority.checkIsPretendRemotecr�r'N)r:r;r<r'r?r'r%r%r%bs��r'r%c��eZdZdZd�Zd�Zy)�	IOSimCertrc��|Sr)r?)r$r�s  r%�optionszIOSimCert.optionsjs���r'c�:�||usJ�|xjdz
c_y)a
        This isn't a real certificate, and wouldn't work on a real socket, but
        iosim specifies a different API so that we don't have to do any crypto
        math to demonstrate that the right functions get called in the right
        places.
        rT��verifyCount�r$�	otherCerts  r%�iosimVerifyzIOSimCert.iosimVerifyms&���D� � � ����A���r'N)r:r;r<r.r+r1r?r'r%r)r)gs���K��	r'r)c��eZdZd�Zy)�OKCertc�*�|j�sJ�|Sr))r')r$r�s  r%r+zOKCert.optionszs���%�%�'�'�'��r'N)r:r;r<r+r?r'r%r3r3ys��r'r3c��eZdZd�Zy)�
GrumpyCertc�.�|xjdz
c_y)NrFr-r/s  r%r1zGrumpyCert.iosimVerify�s�����A���r'N)r:r;r<r1r?r'r%r6r6s��r'r6c��eZdZd�Zd�Zy)�
DroppyCertc��||_yr))�toDrop)r$r;s  r%r&zDroppyCert.__init__�s	����r'c�b�|xjdz
c_|jj�y)NrT)r.r;r�r/s  r%r1zDroppyCert.iosimVerify�s&�����A������"�"�$�r'N)r:r;r<r&r1r?r'r%r9r9�s���r'r9c�R�eZdZdZd�Zd�Zejje�y)�SecurableProtoNc��t�gSr))r%r-s r%�
verifyFactoryzSecurableProto.verifyFactory�s��1�3�4�4r'c�\�|j�}|j�}t||��S)N��tls_localCertificate�tls_verifyAuthorities)�certFactoryr@r�)r$�cert�verifys   r%�
getTLSVarszSecurableProto.getTLSVars�s+�����!���#�#�%����V�L�Lr')	r:r;r<r�r@rHr�StartTLSr�r?r'r%r>r>�s&���G�5�M�
�L�L���:�&r'r>r�z2This test case requires SSL support in the reactorc�$�eZdZd�Zd�Zd�Zd�Zy)�TLSTestsc���ttt��\}}}t���fd�|_|j	t
j�t�g��g}|j	t�j|j�|j�|j�jd�g}|j	t�j|j�|j�|j|dddi�y)	z�
        Verify that starting TLS and succeeding at handshaking sends all the
        notifications to all the right places.
        r|c����Sr)r?��okcs�r%r�z+TLSTests.test_startingTLS.<locals>.<lambda>�����#�r'rBr!rr�TN)rr>r3rEr�rrIr%r�r�r0rDrr.)r$�cli�svrr�rurOs     @r%�test_startingTLSzTLSTests.test_startingTLS�s����
/�&�N�
���S�!��h��%�������L�L�!$�#D�#F�"G�	�	
�
�����{�#�/�/����9�	���	�������!�,������{�#�/�/����9�	���	�����1���$�/�0r'c�n��ttt��\}}}t���fd�|_|j	t
j�t�g��|j�d|_	|jt
j|jt
j�t�g��y)zz
        Verify that the protocol will complain if we attempt to renegotiate TLS,
        which we don't support.
        r|c����Sr)r?rNs�r%r�z1TLSTests.test_startTooManyTimes.<locals>.<lambda>�rPr'rBTN)rr>r3rEr�rrIr%rD�noPeerCertificater&�
OnlyOneTLS�r$rQrRr�rOs    @r%�test_startTooManyTimeszTLSTests.test_startTooManyTimes�s����
/�&�N�
���S�!��h��%�������L�L�!$�#D�#F�"G�	�	
�
	
���	� $�������N�N��N�N��L�L�!$�#D�#F�"G�	�	
r'c���t��ttt��\}}}�fd�|_|j	t
j���|j�|j�jd�|j	t�}|j�|j|tj�y)z�
        Verify that starting TLS and failing on both sides at handshaking sends
        notifications to all the right places and terminates the connection.
        r|c����Sr)r?)�badCerts�r%r�z1TLSTests.test_negotiationFailed.<locals>.<lambda>�s���'�r'�rCr!N)r6rr>rEr�rrIrDrr.r��
assertFailurer�NativeOpenSSLError)r$rQrRr�r]r\s     @r%�test_negotiationFailedzTLSTests.test_negotiationFailed�s�����,��.�&�N�
���S�!�*������s�|�|�'��B�	���	�����,�,�a�0��N�N�;�'��	���	����1�e�6�6�7r'c���ttt��\}}}t|j���fd�|_|jtj���|j�|j�jd�|jt�}|j�|j|tj�y)z�
        Verify that starting TLS and failing by way of a lost connection
        notices that it is probably an SSL problem.
        r|c����Sr)r?)�
droppyCerts�r%r�z:TLSTests.test_negotiationFailedByClosing.<locals>.<lambda>�s���*�r'r]r!N)rr>r9r+rEr�rrIrDrr.r�r^r
�PeerVerifyError)r$rQrRr�r]rcs     @r%�test_negotiationFailedByClosingz(TLSTests.test_negotiationFailedByClosing�s����/�&�N�
���S�!� ��
�
�.�
�,������s�|�|�*��E�	���	�����/�/��3��N�N�;�'��	���	�	
���1�e�3�3�4r'N)r:r;r<rSrYr`rer?r'r%rKrK�s��1�:
�68�,5r'rKc�(�eZdZdZd�Zd�Zd�Zd�Zy)�TLSNotAvailableTestszP
    Tests what happened when ssl is not available in current installation.
    c�D�tj|_dt_y)z%
        Disable ssl in amp.
        N)rrr-s r%rnzTLSNotAvailableTests.setUp
s���7�7�����r'c�.�|jt_y)z%
        Restore ssl module.
        N)rrr-s r%�tearDownzTLSNotAvailableTests.tearDowns���(�(��r'c����ttt��\}}}t���fd�|_|j	|jtj�t�g��t�S)zg
        Check that callRemote raises an exception when called with a
        L{amp.StartTLS}.
        r|c����Sr)r?rNs�r%r�z;TLSNotAvailableTests.test_callRemoteError.<locals>.<lambda>$rPr'rB)
rr>r3rEr^r�rrIr%r{rXs    @r%�test_callRemoteErrorz)TLSNotAvailableTests.test_callRemoteErrorsf���
/�&�N�
���S�!��h��%����!�!��N�N����%(�'H�'J�&K�
�
�

�

�	
r'c�&��t�}t���fd�|_tj�}d|d<d|d<g}|j
|_|jt��|j|�|j|dddd�g�y	)
z|
        When a client with SSL enabled talks to a server without SSL, it
        should return a meaningful error.
        c����Sr)r?rNs�r%r�z@TLSNotAvailableTests.test_messageReceivedError.<locals>.<lambda>6rPr'sStartTLSrr�rs	TLS_ERRORsTLS not available)r�r�r�N)r>r3rErrMr0rarrrr)r$rRrOrrOs    @r%�test_messageReceivedErrorz.TLSNotAvailableTests.test_messageReceivedError/s����
����h��%����g�g�i��&��K����G�����l�l������?�,�-����3������%1�#�+?��
�		
r'N)r:r;r<r=rnrjrmrpr?r'r%rgrgs�����
�*
r'rgc��eZdZdZy)�InheritedErrorz2
    This error is used to check inheritance.
    NrTr?r'r%rrrrJr�r'rrc��eZdZdZy)�OtherInheritedErrorz<
    This is a distinct error for checking inheritance.
    NrTr?r'r%rtrtPr�r'rtc�:�eZdZUdZediZeeee	e
fed<y)�BaseCommandz:
    This provides a command that will be subclassed.
    sINHERITED_ERRORrtN)r:r;r<r=rrrtrrrr|rr}r?r'r%rvrvVs0���
	�*�6�F�H�T�$�y�/�5�0�1�2�r'rvc��eZdZdZy)�InheritedCommandz`
    This is a command which subclasses another command but does not override
    anything.
    NrTr?r'r%rxrx`s��r'rxc�b�eZdZUdZdej
�fgZediZe	e
eee
fed<y)�AddErrorsCommandz]
    This is a command which subclasses another command but adds errors to the
    list.
    sothersOTHER_INHERITED_ERRORrtN)r:r;r<r=rrxrzrtrtrrrr|rr}r?r'r%rzrzgsE���
�K�C�K�K�M�*�+�I��5�6�F�H�T�$�y�/�5�0�1�2�r'rzc�8�eZdZdZd�Zej
e�y)�NormalCommandProtocolz�
    This is a protocol which responds to L{BaseCommand}, and is used to test
    that inheritance does not interfere with the normal handling of errors.
    c��t��r)�rrr-s r%�respzNormalCommandProtocol.respy�����r'N)r:r;r<r=rrvr�r?r'r%r|r|ss���
����$�r'r|c�8�eZdZdZd�Zej
e�y)�InheritedCommandProtocolz�
    This is a protocol which responds to L{InheritedCommand}, and is used to
    test that inherited commands inherit their bases' errors if they do not
    respond to any of their own.
    c��t��r)r~r-s r%rzInheritedCommandProtocol.resp�r�r'N)r:r;r<r=rrxr�r?r'r%r�r�s�������t�$r'r�c�8�eZdZdZd�Zej
e�y)�AddedCommandProtocolz�
    This is a protocol which responds to L{AddErrorsCommand}, and is used to
    test that inherited commands can add their own new types of errors, but
    still respond in the same way to their parents types of errors.
    c�.�|r
t��t��r))rtrr)r$�others  r%rzAddedCommandProtocol.resp�s���%�'�'� �"�"r'N)r:r;r<r=rrzr�r?r'r%r�r��s���#����t�$r'r�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�CommandInheritanceTestszM
    These tests verify that commands inherit error conditions properly.
    c��t||��\}}}|j|fi|��}|j||�}	|j�|	S)z~
        Check that the appropriate kind of error is raised when a given command
        is sent to a given protocol.
        r|)rr��failUnlessFailurerD)
r$r}r_�cmdrrEr:r�r]�d2s
          r%�
errorCheckz"CommandInheritanceTests.errorCheck�sK��
+�u�%�P���1�a��A�L�L��#��#��
�
#�
#�A�s�
+��	���	��	r'c�@�|jttt�S)zx
        Verify that errors specified in a superclass are respected normally
        even if it has subclasses.
        )r�rrr|rvr-s r%�test_basicErrorPropagationz2CommandInheritanceTests.test_basicErrorPropagation�s��
���~�/D�k�R�Rr'c�@�|jttt�S)zp
        Verify that errors specified in a superclass command are propagated to
        its subclasses.
        )r�rrr�rxr-s r%�test_inheritedErrorPropagationz6CommandInheritanceTests.test_inheritedErrorPropagation�s��
����4�6F�
�	
r'c�D�|jtttd��S)z�
        Verify that new errors specified in a subclass of an existing command
        are honored even if the superclass defines some errors.
        T�r�)r�rtr�rzr-s r%�test_inheritedErrorAdditionz3CommandInheritanceTests.test_inheritedErrorAddition�s%��
����!5�7G�t��
�	
r'c�D�|jtttd��S)z�
        Verify that errors specified in a command's superclass are respected
        even if that command defines new errors itself.
        Fr�)r�rrr�rzr-s r%�test_additionWithOriginalErrorz6CommandInheritanceTests.test_additionWithOriginalError�s%��
����0�2B�%��
�	
r'N)	r:r;r<r=r�r�r�r�r�r?r'r%r�r��s!���	�S�
�
�
r'r�c��|jtjtj�|`|j	|�yr))r r
�ConnectionLostrr6)r}r_s  r%�_loseAndPassr��s0���H�H�U�
!�
!�5�#7�#7�8�
��	����r'c��eZdZdZd�Zd�Zy)�LiveFireBasez4
    Utility for connected reactor-using tests.
    c�x��ddlm}tj��_�j
�j_tj��_�j�j_tj��j_tj��j_|jd�j��_
�j�jj�|j d�jj#�j$�j��_�j�j&j(��fd�}tj*�jj�jjg�}|j-|�S)zB
        Create an amp server and connect a client to it.
        r)rz	127.0.0.1c�r���jj�_�jj�_yr))�
clientFactoryr�rQ�
serverFactoryrR)�rlstr$s �r%�	getProtosz%LiveFireBase.setUp.<locals>.getProtos�s)����)�)�2�2�D�H��)�)�2�2�D�Hr')�twisted.internetrr�
ServerFactoryr�r��
ClientFactoryr�r�rr�r��	listenTCP�
serverPort�
addCleanup�
stopListening�
connectTCPr�port�
clientConn�
disconnectr�r�)r$rr��dls`   r%rnzLiveFireBase.setUp�s=���	-�%�3�3�5���&*�&6�&6����#�%�3�3�5���&*�&6�&6����#�$)�N�N�$4����!�$)�N�N�$4����!�+�'�+�+�A�t�/A�/A�B���������5�5�6�,�'�,�,�����0�0�2�7�7��9K�9K�
���	
������2�2�3�	3��
�
��!3�!3�!:�!:�D�<N�<N�<U�<U� V�
W���~�~�i�(�(r'c�l�g}|j|jfD]s}|j��tj�jt|�}|j|_|jj�|j|��utj|�jd��S)zn
        Cleanup client and server connections, and check the error got at
        C{connectionLost}.
        c�.�|jjSr))r$�
subFailure)�firsts r%r�z'LiveFireBase.tearDown.<locals>.<lambda>	s��u�{�{�?U�?U�r')rQrRr+rr�r�r�r�r6r�r0�
gatherResults)r$ru�connr]s    r%rjzLiveFireBase.tearDown�s���

���H�H�d�h�h�&�	�D��~�~�)��N�N�$�/�/��d�C��&'�i�i��#����-�-�/������
	��"�"�1�%�0�0�1U�V�Vr'N)r:r;r<r=rnrjr?r'r%r�r��s���)�4
Wr'r�c�|�ddl}|jj|dz�|jj�y)Nr�
)�sys�stdoutr,rD)r�r�s  r%�showr�	s+����J�J���Q��X���J�J���r'c���ddlm}|jd��}|jj	�}|j|�}|j
||d�d�}|j|�}|S)Nrr�shared)�CNc��yr�r?)�dns r%r�z tempSelfSigned.<locals>.<lambda>	rr'i��)r�r�DN�KeyPair�generate�certificateRequest�signCertificateRequest�newCertificate)r�sharedDNr�cr�sscrdrFs      r%�tempSelfSignedr�	sb��$��v�v��v�"�H�

�+�+�
�
�
 �C�	�	�	��	)�B��&�&�x��_�g�N�E����e�$�D��Kr'c��eZdZeZeZd�Zy)�LiveFireTLSTestsc�����t��fd��j_�fd��j_��fd�}�jjtj��g��j|�S)aH
        Using real, live TLS, actually negotiate a connection.

        This also looks at the 'peerCertificate' attribute's correctness, since
        that's actually loaded using OpenSSL calls, but the main purpose is to
        make sure that we didn't miss anything obvious in iosim about TLS
        negotiations.
        c�
���gSr)r?�rFs�r%r�z9LiveFireTLSTests.test_liveFireCustomTLS.<locals>.<lambda>-	s	���$��r'c����Sr)r?r�s�r%r�z9LiveFireTLSTests.test_liveFireCustomTLS.<locals>.<lambda>.	s���t�r'c�����j����fd�}�jjt�j	|�S)Nc����j��jjj���j��jjj���j��j
jj���j��j
jj��yr))rrQ�hostCertificate�digest�peerCertificaterR)�rslt2r$r�s ��r%r�zHLiveFireTLSTests.test_liveFireCustomTLS.<locals>.secured.<locals>.pinged4	s����
� � ��D�H�H�$<�$<�$C�$C�$E�F�� � ��D�H�H�$<�$<�$C�$C�$E�F�� � ��D�H�H�$<�$<�$C�$C�$E�F�� � ��D�H�H�$<�$<�$C�$C�$E�Fr')r�rQr�r�r�)�rsltr�r�rFr$s  @��r%�securedz8LiveFireTLSTests.test_liveFireCustomTLS.<locals>.secured1	s6������
�A�
G��8�8�&�&�{�3�?�?��G�Gr'rB)	�tempcertrRr@rErQr�rrIr�)r$r�rFs` @r%�test_liveFireCustomTLSz'LiveFireTLSTests.test_liveFireCustomTLS!	s]�����!/�����+�����
	H��x�x�"�"��L�L�t�D�6�#�
�
�+�g�
�	r'N)r:r;r<r>r�r�r�r?r'r%r�r�	s��!�K� �K�!r'r�c�L�eZdZdZd�Zejje�y)�SlightlySmartTLSz_
    Specific implementation of server side protocol with different
    management of TLS.
    c�"�tt��S)zS
        @return: the global C{tempcert} certificate as local certificate.
        r])r�r�r-s r%rHzSlightlySmartTLS.getTLSVarsK	s����2�2r'N)r:r;r<r=rHrrIr�r?r'r%r�r�E	s ���
3��L�L���:�&r'r�c��eZdZeZeZd�Zy)�PlainVanillaLiveFireTestsc�~���fd�}�jjtj�j	|�S)z�
        Verify that out of the box, we can start TLS to at least encrypt the
        connection, even if we don't have any certificates to use.
        c�B���jjt�Sr)�rQr�r��r�r$s �r%r�zBPlainVanillaLiveFireTests.test_liveFireDefaultTLS.<locals>.secured`	�����8�8�&�&�{�3�3r')rQr�rrIr��r$r�s` r%�test_liveFireDefaultTLSz1PlainVanillaLiveFireTests.test_liveFireDefaultTLSZ	s.���	4��x�x�"�"�3�<�<�0�<�<�W�E�Er'N)r:r;r<r�r�r�r�r?r'r%r�r�T	s��1�K�0�K�	Fr'r�c��eZdZeZeZd�Zy)�WithServerTLSVerificationTestsc����fd�}�jjtjtg��j|�S)zO
        Verify that anonymous clients can verify server certificates.
        c�B���jjt�Sr)r�r�s �r%r�zMWithServerTLSVerificationTests.test_anonymousVerifyingClient.<locals>.securedq	r�r')rD)rQr�rrIr�r�r�s` r%�test_anonymousVerifyingClientz<WithServerTLSVerificationTests.test_anonymousVerifyingClientl	s;���
	4��x�x�"�"��L�L��
�#�
�
�+�g�
�	r'N)r:r;r<r�r�r�r�r�r?r'r%r�r�f	s��1�K�"�K�
r'r�c��eZdZdZd�Zd�Zy)�ProtocolIncludingArgumentz�
    An L{amp.Argument} which encodes its parser and serializer
    arguments *including the protocol* into its parsed and serialized
    forms.
    c�
�||fS)z�
        Don't decode anything; just return all possible information.

        @return: A two-tuple of the input string and the protocol.
        r?)r$�stringrs   r%rdz)ProtocolIncludingArgument.fromStringProto�	s����!�!r'c�V�dt|�t|�fz}|jd�S)z�
        Encode identifying information about L{object} and protocol
        into a string for later verification.

        @type obj: L{object}
        @type protocol: L{amp.AMP}
        �%d:%dr�)r�r�)r$�objr�idents    r%�
toStringProtoz'ProtocolIncludingArgument.toStringProto�	s*���2�c�7�B�x�L�1�1���|�|�G�$�$r'N)r:r;r<r=rdr�r?r'r%r�r�y	s���"�	%r'r�c�8�eZdZdZde�fgZde�fgZy)�ProtocolIncludingCommandzf
    A command that has argument and response schemas which use
    L{ProtocolIncludingArgument}.
    �weirdN)r:r;r<r=r�rzr{r?r'r%r�r��	s+���
�5�7�8�9�I��4�6�7�8�Hr'r�c�@�eZdZdZed��Zed��Zed��Zy)�MagicSchemaCommandza
    A command which overrides L{parseResponse}, L{parseArguments}, and
    L{makeResponse}.
    c��||f|_|S)z�
        Don't do any parsing, just jam the input strings and protocol
        onto the C{protocol.parseResponseArguments} attribute as a
        two-tuple. Return the original strings.
        )�parseResponseArguments)r$rfrs   r%�
parseResponsez MagicSchemaCommand.parseResponse�	���,3�H�*=��'��r'c��||f|_|S)z�
        Don't do any parsing, just jam the input strings and protocol
        onto the C{protocol.parseArgumentsArguments} attribute as a
        two-tuple. Return the original strings.
        )�parseArgumentsArguments)�clsrfrs   r%�parseArgumentsz!MagicSchemaCommand.parseArguments�	s��-4�X�+>��(��r'c��||f|_|S)z�
        Don't do any serializing, just jam the input strings and protocol
        onto the C{protocol.makeArgumentsArguments} attribute as a
        two-tuple. Return the original strings.
        )�makeArgumentsArguments)r�rgrs   r%�
makeArgumentsz MagicSchemaCommand.makeArguments�	r�r'N)r:r;r<r=�classmethodr�r�rr?r'r%r�r��	sC���
�����������r'r�c�:�eZdZdZd�Zej
d��y)�NoNetworkProtocola�
    An L{amp.AMP} subclass which overrides private methods to avoid
    testing the network. It also provides a responder for
    L{MagicSchemaCommand} that does nothing, so that tests can test
    aspects of the interaction of L{amp.Command}s and L{amp.AMP}.

    @ivar parseArgumentsArguments: Arguments that have been passed to any
    L{MagicSchemaCommand}, if L{MagicSchemaCommand} has been handled by
    this protocol.

    @ivar parseResponseArguments: Responses that have been returned from a
    L{MagicSchemaCommand}, if L{MagicSchemaCommand} has been handled by
    this protocol.

    @ivar makeArgumentsArguments: Arguments that have been serialized by any
    L{MagicSchemaCommand}, if L{MagicSchemaCommand} has been handled by
    this protocol.
    c�,�tj|�S)zJ
        Return a Deferred which fires with the original strings.
        )r�succeed)r$rvrfr�s    r%�_sendBoxCommandz!NoNetworkProtocol._sendBoxCommand�	s���}�}�W�%�%r'c��iSr)r?)r:�weirds  r%r�zNoNetworkProtocol.<lambda>�	s��"�r'N)r:r;r<r=rr�r�r?r'r%rr�	s���&&�� � �!4�5r'r�_KT�_VTc��eZdZdZy)�MyBoxz!
    A unique dict subclass.
    NrTr?r'r%rr�	r�r'rc��eZdZdZeZy)�0ProtocolIncludingCommandWithDifferentCommandTypezN
    A L{ProtocolIncludingCommand} subclass whose commandType is L{MyBox}
    N)r:r;r<r=r�commandTyper?r'r%rr�	s����Kr'rc�|�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Zd�Zd�Zy)�CommandTestsz7
    Tests for L{amp.Argument} and L{amp.Command}.
    c�z�|jttjtj���y)zE
        L{Argument} instances provide L{amp.IArgumentType}.
        N)r.r
r�
IArgumentType�Argumentr-s r%�test_argumentInterfacez#CommandTests.test_argumentInterface�	s#��	
����S�%6�%6�����G�Hr'c�x�t�}d}d|i}|jtj||�d||fi�y)z�
        There should be a class method of Command which accepts a
        mapping of argument names to serialized forms and returns a
        similar mapping whose values have been parsed via the
        Command's response schema.
        �whateverr�r
N)r�rr�r��r$rr�rfs    r%�test_parseResponsezCommandTests.test_parseResponse�	sE���8�����V�$�����$�2�2�7�H�E�
�v�x�(�)�	
r'c�����t��d��jt���}���fd�}|j|�|S)z�
        Making a remote call on a L{amp.Command} subclass which
        overrides the C{parseResponse} method should call that
        C{parseResponse} method to get the response.
        sweeoo�r
c�F���j�jd�i�f�y�Nr
)rr�)r��clientr$�thingys ���r%�gotResponsezCCommandTests.test_callRemoteCallsParseResponse.<locals>.gotResponse
s$������V�:�:�g�v�=N�PV�<W�Xr')rr�r�r�)r$r{r"r r!s`  @@r%�!test_callRemoteCallsParseResponsez.CommandTests.test_callRemoteCallsParseResponse
sC���#�$�����$�$�%7�v�$�F��	Y�	���[�)��r'c�x�t�}d}d|i}|jtj||�d||fi�y)z�
        There should be a class method of L{amp.Command} which accepts
        a mapping of argument names to serialized forms and returns a
        similar mapping whose values have been parsed via the
        command's argument schema.
        rr�r
N)r�rr�r�rs    r%�test_parseArgumentsz CommandTests.test_parseArguments
sE���8�����V�$�����$�3�3�G�X�F�
�v�x�(�)�	
r'c������t���jtj�}t	��|t����}|j
���fd��|S)z�
        Making a remote call on a L{amp.Command} subclass which
        overrides the C{parseArguments} method should call that
        C{parseArguments} method to get the arguments.
        rc�D���j�jd�i�f�Sr)rr�)r��argumentrr$s ���r%r�z@CommandTests.test_responderCallsParseArguments.<locals>.<lambda>6
s'����(�(��0�0�G�X�3F��2Q��r')rrWr�rvr�r�r�)r$r�r{r(rs`  @@r%�!test_responderCallsParseArgumentsz.CommandTests.test_responderCallsParseArguments+
sV���%�&��,�H�,�,�-?�-K�-K�L�	��8���T��1�2�����
�	
�
�r'c���t�}t�}d|i}dt|�t|�fz}|jtj	||�d|jd�i�y)z�
        There should be a class method of L{amp.Command} which accepts
        a mapping of argument names to objects and returns a similar
        mapping whose values have been serialized via the command's
        argument schema.
        r
r�r�r�N)r�r�rr�rr�)r$rr(rgr�s     r%�test_makeArgumentszCommandTests.test_makeArguments<
sb���8���8���H�%���2�h�<��H��6�6�����$�2�2�7�H�E�
�u�|�|�G�,�-�	
r'c��t�}ddi}tj||�}|jt	|�t
�y)z�
        L{amp.Command.makeArguments}'s return type should be the type
        of the result of L{amp.Command.commandType}.
        r
rN)r�rrrrr)r$rrgr�s    r%�!test_makeArgumentsUsesCommandTypez.CommandTests.test_makeArgumentsUsesCommandTypeL
s>��
�8���K�(��A�O�O��X�
��	
�
�
�d�6�l�E�*r'c�����t��t���jt���}���fd�}|j	|�|S)z�
        Making a remote call on a L{amp.Command} subclass which
        overrides the C{makeArguments} method should call that
        C{makeArguments} method to get the response.
        rc�F���j�jd�i�f�yr)rr)r�r(r r$s ���r%r"zCCommandTests.test_callRemoteCallsMakeArguments.<locals>.gotResponsec
s&�������-�-��(�0C�V�/L�
r')rr�r�r�r�)r$r{r"r(r s`  @@r%�!test_callRemoteCallsMakeArgumentsz.CommandTests.test_callRemoteCallsMakeArgumentsY
sD���#�$���8���$�$�%7�x�$�H��	�
	���[�)��r'c	��|jtjtjtdt
���d�y)z�
        L{Command.makeArguments} raises L{amp.InvalidSignature} if the objects
        dictionary passed to it includes a key which does not correspond to the
        Python identifier for a defined argument.
        rF)rF�
bogusArgumentN)r&rr�rjrr�r�r-s r%�test_extraArgumentsDisallowedz*CommandTests.test_extraArgumentsDisallowedk
s3��	
���� � �����w�f�h�7��		
r'c
�~�|jtjtjtdddiddi��d�y)a�
        If a command argument conflicts with a Python keyword, the
        untransformed argument name is not allowed as a key in the dictionary
        passed to L{Command.makeArguments}.  If it is supplied,
        L{amp.InvalidSignature} is raised.

        This may be a pointless implementation restriction which may be lifted.
        The current behavior is tested to verify that such arguments are not
        silently dropped on the floor (the previous behavior).
        rF�required�printzprint valueNr?)r&rr�rjrr�r-s r%�test_wireSpellingDisallowedz(CommandTests.test_wireSpellingDisallowedx
s<��	
���� � �����>�z�>�g�}�%=�>��		
r'c�n�Gd�dtj�}|jd|j�y)zj
        A L{Command} subclass without a defined C{commandName} that's
        not a byte string.
        c��eZdZdZy)�PCommandTests.test_commandNameDefaultsToClassNameAsByteString.<locals>.NewCommandz(
            A new command.
            NrTr?r'r%�
NewCommandr:�
s��
r'r;s
NewCommandN)r�Commandrrv�r$r;s  r%�/test_commandNameDefaultsToClassNameAsByteStringz<CommandTests.test_commandNameDefaultsToClassNameAsByteString�
s*��	����	�
	
����
�(>�(>�?r'c��|jttdtjfddi�}|jt
|�d�y)zq
        A L{Command} subclass cannot be defined with a C{commandName} that's
        not a byte string.
        r;rv�FOOz2^Command names must be byte strings, got: u?'FOO'$N�r&r'rrr<�assertRegexr>�r$r
s  r%�!test_commandNameMustBeAByteStringz.CommandTests.test_commandNameMustBeAByteString�
sD��
�!�!��t�\�C�K�K�>�M�5�;Q�
��	
�����J�L�	
r'c��|jttdtjfddgi�}|jt
|�d�y)zS
        A L{Command} subclass's C{arguments} must have byte string names.
        r;rz�r�Nz3^Argument names must be byte strings, got: u?'foo'$NrArCs  r%�/test_commandArgumentsMustBeNamedWithByteStringsz<CommandTests.test_commandArgumentsMustBeNamedWithByteStrings�
sJ���!�!����
�[�[�N�
�=�/�*�
��	
�����J�M�	
r'c��|jttdtjfddgi�}|jt
|�d�y)zR
        A L{Command} subclass's C{response} must have byte string names.
        r;r{rFz3^Response names must be byte strings, got: u?'foo'$NrArCs  r%�.test_commandResponseMustBeNamedWithByteStringsz;CommandTests.test_commandResponseMustBeNamedWithByteStrings�
sF���!�!��t�\�C�K�K�>�J���;X�
��	
�����J�M�	
r'c�z�Gd�dtj�}|jtdi|j�y)zN
        A L{Command} subclass's C{errors} is coerced into a C{dict}.
        c��eZdZedfgZy)�DCommandTests.test_commandErrorsIsConvertedToDict.<locals>.NewCommand�ZDEN)r:r;r<r�rtr?r'r%r;rL�
s��(�&�1�2�Fr'r;rMN)rr<rr�rtr=s  r%�#test_commandErrorsIsConvertedToDictz0CommandTests.test_commandErrorsIsConvertedToDict�
s0��
	3����	3�	
���+�V�4�j�6G�6G�Hr'c	��|jttdtjfdt
dfgi�}|j
t|�d�y)zX
        A L{Command} subclass's C{errors} must map exceptions to byte strings.
        r;rtr�z0^Error names must be byte strings, got: u?'foo'$N�r&r'rrr<r�rBr>rCs  r%�5test_commandErrorsMustUseBytesForOnWireRepresentationzBCommandTests.test_commandErrorsMustUseBytesForOnWireRepresentation�
sN���!�!����
�[�[�N�
�*�E�2�3�4�
��	
����U��%W�Xr'c�z�Gd�dtj�}|jtdi|j�y)zS
        A L{Command} subclass's C{fatalErrors} is coerced into a C{dict}.
        c��eZdZedfgZy)�ICommandTests.test_commandFatalErrorsIsConvertedToDict.<locals>.NewCommandrMN)r:r;r<r�rur?r'r%r;rT�
s��-�v�6�7�Kr'r;rMN)rr<rr�rur=s  r%�(test_commandFatalErrorsIsConvertedToDictz5CommandTests.test_commandFatalErrorsIsConvertedToDict�
s0��
	8����	8�	
���+�V�4�j�6L�6L�Mr'c	��|jttdtjfdt
dfgi�}|j
t|�d�y)ze
        A L{Command} subclass's C{fatalErrors} must map exceptions to byte
        strings.
        r;rur�z6^Fatal error names must be byte strings, got: u?'foo'$NrPrCs  r%�:test_commandFatalErrorsMustUseBytesForOnWireRepresentationzGCommandTests.test_commandFatalErrorsMustUseBytesForOnWireRepresentation�
sQ��
�!�!����
�[�[�N�
�/��7�8�9�
��	
�����J�S�	
r'N)r:r;r<r=rrr#r%r)r+r-r0r3r7r>rDrGrIrNrQrUrWr?r'r%rr�	sf���I�

�� 

��"
� +��$
�
�$@�

�

�	
�I�Y�N�
r'rc��eZdZdZd�Zd�Zy)�ListOfTestsMixina�
    Base class for testing L{ListOf}, a parameterized zero-or-more argument
    type.

    @ivar elementType: Subclasses should set this to an L{Argument}
        instance.  The tests will make a L{ListOf} using this.

    @ivar strings: Subclasses should set this to a dictionary mapping some
        number of keys -- as BYTE strings -- to the correct serialized form
        for some example values. These should agree with what L{elementType}
        produces/accepts.

    @ivar objects: Subclasses should set this to a dictionary with the same
        keys as C{strings} -- as NATIVE strings -- and with values which are
        the lists which should serialize to the values in the C{strings}
        dictionary.
    c�:�tj|j�}tj�}|jD]=}|j|j
d�||jj�d��?|j||j�y)a�
        L{ListOf.toBox} extracts the list of objects from the C{objects}
        dictionary passed to it, using the C{name} key also passed to it,
        serializes each of the elements in that list using the L{Argument}
        instance previously passed to its initializer, combines the serialized
        results, and inserts the result into the C{strings} dictionary using
        the same C{name} key.
        r�N)
r�ListOf�elementTyperrgrhr��copyrrf)r$�
stringListrfrs    r%�
test_toBoxzListOfTestsMixin.test_toBoxsw���Z�Z�� 0� 0�1�
��*�*�,���<�<�	V�C����S�Z�Z��0�'�4�<�<�;L�;L�;N�PT�U�	V�����$�,�,�/r'c��tj|j�}i}|jD].}|j	||jj�|d��0|j
||j�y)�X
        L{ListOf.fromBox} reverses the operation performed by L{ListOf.toBox}.
        N)rr[r\rf�fromBoxr]rrg)r$r^rgrs    r%�test_fromBoxzListOfTestsMixin.test_fromBoxsg���Z�Z�� 0� 0�1�
����<�<�	H�C����s�D�L�L�$5�$5�$7��$�G�	H�����$�,�,�/r'N)r:r;r<r=r_rcr?r'r%rYrY�
s���$
0�0r'rYc�P�eZdZdZej
�Zdddd�Zgdggd�d�Zy	)
�ListOfStringsTestsz:
    Tests for L{ListOf} combined with L{amp.String}.
    r'�foosbarbazquux��empty�single�multipler
)rsbazsquux��empty�single�multipleN)	r:r;r<r=rrwr\rfrgr?r'r%reres9����#�*�*�,�K��!�:��G��v�h�<U�V�Gr'rec�n�eZdZdZej
�ZddzZddddefzdd�Zgd	ggd
�egdgd�Z	y
)�ListOfIntegersTestsz;
    Tests for L{ListOf} combined with L{amp.Integer}.
    l
�����]OS�t7s�
Xg�&}r's10s120500st%ds-1)rhrirjshugesnegativer�)r�i�rB)rlrmrn�huge�negativeN)
r:r;r<r=rr�r\rrrfrgr?r'r%rprp,sg����#�+�+�-�K�	C�
D�	E�	�� �6��$��(�"��G���$� ����D��Gr'rpc�P�eZdZdZej
�Zdddd�Zgdggd�d�Zy	)
�ListOfUnicodeTestsz;
    Tests for L{ListOf} combined with L{amp.Unicode}.
    r'rfs☃Helloworldrgr�)u☃rjrtrkN)	r:r;r<r=rryr\rfrgr?r'r%ruruIs<����#�+�+�-�K��!�F��G���'�5��Gr'ruc��eZdZdZej
�Zdddddej
d�j�jd�zd	zej
d
�j�jd�zd�Z
gej
d�gej
d
�ej
d�gej
d�ej
d�ej
d�ej
d�ej
d�ej
d�gej
d�ej
d
�gd�Zy)�ListOfDecimalTestsz;
    Tests for L{ListOf} combined with L{amp.Decimal}.
    r's1.1sInfinity	-InfinitysC3.141E+5
0.000031413.141E-7	-3.141E+5-0.00003141	-3.141E-7s�0e6r�sz1.5E-9)rhrisextremes	scientistsengineerz1.1�Infinityz	-Infinityz3.141E5z3.141e-5z3.141E-7z-3.141e5z	-3.141E-5z	-3.141e-7)rlrm�extreme�	scientist�engineerN)r:r;r<r=r�Decimalr\�decimal�
to_eng_stringr�rfrgr?r'r%rwrw]sI����#�+�+�-�K��!�8�A�
��g�o�o�e�$�2�2�4�;�;�G�D�
E��
��g�o�o�h�'�5�5�7�>�>�w�G�
H��G��"�7�?�?�5�)�*��G�O�O�J�'��G�O�O�K�(�
�
�G�O�O�I�&��G�O�O�J�'��G�O�O�J�'��G�O�O�J�'��G�O�O�K�(��G�O�O�K�(�

�
�G�O�O�E�"��G�O�O�H�%�
�'�Gr'rwc���eZdZdZej
�ZddiZdej
d�ej
d�ej
d�ej
d�giZ	d	�Z
y
)�ListOfDecimalNanTestszS
    Tests for L{ListOf} combined with L{amp.Decimal} for not-a-number values.
    snansNaN-NaNsNaN-sNaN�nan�NaNz-NaN�sNaNz-sNaNc��d�}d�}d�}tj|j�}i}|jD].}|j	||jj�|d��0|d}|j
||d�xr||d��|j
||d�xr||d��|j
||d�xr||d��|j
||d	�xr||d	��y)
rac�:�dt|�vxr
dt|�vS)Nr�r��r>�r~s r%�is_qnanz3ListOfDecimalNanTests.test_fromBox.<locals>.is_qnan�s���C��L�(�G�V�3�w�<�-G�Gr'c��dt|�vS)Nr�r�r�s r%�is_snanz3ListOfDecimalNanTests.test_fromBox.<locals>.is_snan�s���S��\�)�)r'c��dt|�vS)N�-r�r�s r%�	is_signedz5ListOfDecimalNanTests.test_fromBox.<locals>.is_signed�s���#�g�,�&�&r'Nr�rrr!r�)rr[r\rfrbr]r.)r$r�r�r�r^rgr�ns        r%rcz"ListOfDecimalNanTests.test_fromBox�s���	H�	*�	'��Z�Z�� 0� 0�1�
����<�<�	H�C����s�D�L�L�$5�$5�$7��$�G�	H��E�N�������!��
�=�i��!��o�*=�>������!��
�9�)�A�a�D�/�:������!��
�=�i��!��o�*=�>������!��
�9�)�A�a�D�/�:r'N)r:r;r<r=rr}r\rfr~rgrcr?r'r%r�r��ss����#�+�+�-�K�	�C��G�
	��G�O�O�E�"��G�O�O�F�#��G�O�O�F�#��G�O�O�G�$�	
��G�;r'r�c��eZdZdZd�Zy)�DecimalTestsz#
    Tests for L{amp.Decimal}.
    c���tj�}|jt|jd�|jt|jd�|jt|jd�y)z�
        L{amp.Decimal.toString} raises L{ValueError} if passed an object which
        is not an instance of C{decimal.Decimal}.
        �1.234�X9��v��?��N)rr}r&�
ValueErrorr1�r$r(s  r%�test_nonDecimalzDecimalTests.test_nonDecimal�sW��
�;�;�=�����*�h�&7�&7��A����*�h�&7�&7��?����*�h�&7�&7��>r'N)r:r;r<r=r�r?r'r%r�r��s���?r'r�c��eZdZdZd�Zd�Zy)�
FloatTestsz!
    Tests for L{amp.Float}.
    c���tj�}|jt|jd�|jt|jd�|jt|jd�y)zq
        L{amp.Float.toString} raises L{ValueError} if passed an object which
        is not a L{float}.
        r��1.234r�N)r�Floatr&r�r1r�s  r%�
test_nonFloatzFloatTests.test_nonFloat�sW��
�9�9�;�����*�h�&7�&7��A����*�h�&7�&7��B����*�h�&7�&7��>r'c�n�tj�}|j|jd�d�y)zY
        L{amp.Float.toString} returns a bytestring when it is given a L{float}.
        r�r�N)rr�rr1r�s  r%�
test_floatzFloatTests.test_float�s*���9�9�;������*�*�5�1�8�<r'N)r:r;r<r=r�r�r?r'r%r�r��s���?�=r'r�c��eZdZdZej
�Zdddddd�Zejdd	d
dddej��ejdd	d
ddde
d
dd���gejdd	d
ddde
d
dd���gejdd	d
ddde
d
dd���gejdd	d
ddde
ddd���gejdd	d
ddde
d
dd���ejdd	d
ddde
ddd���gd�Zy)�ListOfDateTimeTestsz<
    Tests for L{ListOf} combined with L{amp.DateTime}.
    sD 2010-12-25T00:00:00.000000-00:00 2010-12-25T00:00:00.000000-00:00s" 2010-12-25T00:00:00.000000+01:00s" 2010-12-25T00:00:00.000000+03:30s" 2010-12-25T00:00:00.000000-05:00sD 2010-12-25T00:00:00.000000+03:19 2010-12-25T00:00:00.000000-06:59)s	christmasschristmas in euschristmas in iranschristmas in nycsprevious tests����r)�tzinfo�+rr��r�����;)�	christmaszchristmas in euzchristmas in iranzchristmas in nyczprevious testsN)r:r;r<r=r�DateTimer\rf�datetime�utc�tzrgr?r'r%r�r��sR����#�,�,�.�K�4�G�I�H�4�
�G�
�H���d�B��A�q�!�C�G�G�D��H���d�B��A�q�!�B�s�A�q�M�J�
�

�H���d�B��A�q�!�B�s�A�q�M�J�
�
�H���d�B��A�q�!�B�s�A�r�N�K�
�
�H���d�B��A�q�!�B�s�A�q�M�J�
�
�H���d�B��A�q�!�B�s�A�r�N�K��H���d�B��A�q�!�B�s�A�r�N�K�
��Gr'r�c�.�eZdZdZd�Zd�Zd�Zd�Zd�Zy)�ListOfOptionalTestszo
    Tests to ensure L{ListOf} AMP arguments can be omitted from AMP commands
    via the 'optional' flag.
    c���tjtj��}|jt|j
dtj�ddid�y)zn
        L{ListOf.toBox} raises C{TypeError} when passed a value of L{None}
        for the argument.
        �omitted�omittedN)rr[r�r&r'rhr�r$r^s  r%�1test_requiredArgumentWithNoneValueRaisesTypeErrorzEListOfOptionalTests.test_requiredArgumentWithNoneValueRaisesTypeErrorsI��
�Z�Z����
�.�
����������J�J�L�
����
	
r'c���tjtj�d��}tj�}|j	d|ddid�|j|i�y)z�
        L{ListOf.toBox} silently omits serializing any argument with a
        value of L{None} that is designated as optional for the protocol.
        Trlr�N)rr[r�rrhr)r$r^rfs   r%�)test_optionalArgumentWithNoneValueOmittedz=ListOfOptionalTests.test_optionalArgumentWithNoneValueOmitted sN��
�Z�Z����
��=�
��*�*�,������W�z�4�.@�$�G�����"�%r'c���tjtj��}|jt|j
dtj�ddid�y)z|
        L{ListOf.toBox} raises C{KeyError} if the argument's key is not
        present in the objects dictionary.
        �ommited�someOtherKeyrN)rr[r�r&�KeyErrorrhrr�s  r%�1test_requiredArgumentWithKeyMissingRaisesKeyErrorzEListOfOptionalTests.test_requiredArgumentWithKeyMissingRaisesKeyError*sI��
�Z�Z����
�.�
����������J�J�L�
�Q���
	
r'c��tjtj�d��}|jdtj�ddid�y)z�
        L{ListOf.toBox} silently omits serializing any argument designated
        as optional whose key is not present in the objects dictionary.
        Trlr�ssomeOtherKeyrN)rr[r�rhrr�s  r%�*test_optionalArgumentWithKeyMissingOmittedz>ListOfOptionalTests.test_optionalArgumentWithKeyMissingOmitted9s9��
�Z�Z����
��=�
�����S�Z�Z�\�O�Q�3G��Nr'c��tjtj�d��}i}|jdi|d�|j	|ddi�y)z�
        L{ListOf.fromBox} correctly reverses the operation performed by
        L{ListOf.toBox} for optional arguments.
        Trlr�Nr�)rr[r�rbr)r$r^rgs   r%�.test_omittedOptionalArgumentDeserializesAsNonezBListOfOptionalTests.test_omittedOptionalArgumentDeserializesAsNoneAsH��
�Z�Z����
��=�
������:�r�7�D�9�����9�d�"3�4r'N)	r:r;r<r=r�r�r�r�r�r?r'r%r�r�s!���


�&�

�O�5r'r�c�:�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
y	)
�UNIXStringTransportar
    An in-memory implementation of L{interfaces.IUNIXTransport} which collects
    all data given to it for later inspection.

    @ivar _queue: A C{list} of the data which has been given to this transport,
        eg via C{write} or C{sendFileDescriptor}.  Elements are two-tuples of a
        string (identifying the destination of the data) and the data itself.
    c� �||_g|_y)zp
        @param descriptorFuzz: An offset to apply to descriptors.
        @type descriptorFuzz: C{int}
        N)�_fuzz�_queue)r$�descriptorFuzzs  r%r&zUNIXStringTransport.__init__Ws��
$��
���r'c�X�|jjd||jzf�y)N�fileDescriptorReceived)r�r0r�)r$�
descriptors  r%�sendFileDescriptorz&UNIXStringTransport.sendFileDescriptor_s#�������4�j�4�:�:�6M�N�Or'c�>�|jjd|f�y)Nr1)r�r0rs  r%r,zUNIXStringTransport.writebs�������N�D�1�2r'c�4�|D]}|j|��yr))r,)r$�seqr*s   r%�
writeSequencez!UNIXStringTransport.writeSequencees���	�D��J�J�t��	r'c�t�|jjdttj��f�y)Nr6)r�r0rr
r�r-s r%r�z"UNIXStringTransport.loseConnectionis(�������,�g�e�6J�6J�6L�.M�N�Or'c�,�tjd�S)Nz/tmp/some-path�r�UNIXAddressr-s r%rzUNIXStringTransport.getHostls���"�"�#3�4�4r'c�,�tjd�S)Nz/tmp/another-pathr�r-s r%rbzUNIXStringTransport.getPeeros���"�"�#6�7�7r'N)r:r;r<r=r&r�r,r�r�rrbr?r'r%r�r�Ls,����P�3��P�5�8r'r�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�DescriptorTestsz�
    Tests for L{amp.Descriptor}, an argument type for passing a file descriptor
    over an AMP connection over a UNIX domain socket.
    c��d|_t|j��|_tjtj
tj���|_|jj|j�y)Nr�)r�)	�fuzzr�r+rrrkrlrrr-s r%rnzDescriptorTests.setUp~sU����	�,�D�I�I�F����-�-�c�.?�.?��@R�@R�@T�.U�V��
��
�
�$�$�T�^�^�4r'c�"�tj�}|jjd�|jjd�|jjd�|j	d|jd|j��|j	d|jd|j��|j	d|jd|j��|j	i|jj�y)a|
        L{Descriptor.fromStringProto} constructs a file descriptor value by
        extracting a previously received file descriptor corresponding to the
        wire value of the argument from the L{_DescriptorExchanger} state of the
        protocol passed to it.

        This is a whitebox test which involves direct L{_DescriptorExchanger}
        state inspection.
        r�r�r�0�1�2N)r�
Descriptorrr�rrd�_descriptorsr�s  r%�test_fromStringProtoz$DescriptorTests.test_fromStringProto�s����>�>�#���
�
�,�,�Q�/��
�
�,�,�Q�/��
�
�,�,�Q�/�����H�4�4�S�$�-�-�H�I�����H�4�4�S�$�-�-�H�I�����H�4�4�S�$�-�-�H�I�����T�]�]�7�7�8r'c��tj�}|jd|jd|j��|jdd|j
zf|jjjd��|jd|jd|j��|jdd|j
zf|jjjd��|jd|jd|j��|jdd|j
zf|jjjd��|ji|jj�y	)
a=
        To send a file descriptor, L{Descriptor.toStringProto} uses the
        L{IUNIXTransport.sendFileDescriptor} implementation of the transport of
        the protocol passed to it to copy the file descriptor.  Each subsequent
        descriptor sent over a particular AMP connection is assigned the next
        integer value, starting from 0.  The base ten string representation of
        this value is the byte encoding of the argument.

        This is a whitebox test which involves direct L{_DescriptorExchanger}
        state inspection and mutation.
        �0r!r�rr�r��2r�N)
rr�rr�rr�r+r�r�r�r�s  r%�test_toStringProtoz"DescriptorTests.test_toStringProto�s5���>�>�#������x�5�5�a����G�H����
%�q�4�9�9�}�5�t�~�~�7L�7L�7P�7P�QR�7S�	
�	
����x�5�5�a����G�H����
%�q�4�9�9�}�5�t�~�~�7L�7L�7P�7P�QR�7S�	
�	
����x�5�5�a����G�H����
%�q�4�9�9�}�5�t�~�~�7L�7L�7P�7P�QR�7S�	
�	
����T�]�]�7�7�8r'c��d}|jd�}i}d}||i}tj�}|j|||j	�|j
�tjtjtj���}|jjD]}t||d�|dd��i}	|j||j	�|	|�|j||jz|	|�y)z�
        L{amp.Descriptor.fromBox} can interpret an L{amp.AmpBox} constructed by
        L{amp.Descriptor.toBox} to reconstruct a file descriptor value.
        �alphar��rrN)r�rr�rhr]rrrkrlr+r��getattrrbrr�)
r$r^�nameAsBytesrfr��sendObjectsr(�receiver�event�receiveObjectss
          r%�test_roundTripzDescriptorTests.test_roundTrip�s���
���k�k�'�*�����
��Z�(���>�>�#�����{�G�[�-=�-=�-?����O��(�(��):�):�3�;M�;M�;O�)P�Q���^�^�*�*�	4�E�'�G�H�e�A�h�'��q�r��3�	4�������g�l�l�n�n�h�O�
	
����d�i�i�/���1E�Fr'N)r:r;r<r=rnr�r�r�r?r'r%r�r�xs���
5�9�&9�6Gr'r�c
�r�eZdZdZdZeddd�Zejdddddd	d
e�Zd�Z	d�Z
d
�Zd�Zy)�
DateTimeTestszO
    Tests for L{amp.DateTime}, L{amp._FixedOffsetTZInfo}, and L{amp.utc}.
    s 9876-01-23T12:34:56.054321-01:23r�r�i�&r��"�8i1�c�n�tj�}|jt|jd�y)z�
        L{amp.DateTime.fromString} raises L{ValueError} when passed a string
        which does not represent a timestamp in the proper format.
        �abcN)rr�r&r�r/�r$r]s  r%�test_invalidStringz DateTimeTests.test_invalidString�s%��

�L�L�N�����*�a�l�l�E�:r'c��tj�}|jt|jtj
dddddd��y)z�
        L{amp.DateTime.toString} raises L{ValueError} when passed a naive
        datetime (a datetime with no timezone information).
        r�r�r�rN)rr�r&r�r1r�r�s  r%�test_invalidDatetimez"DateTimeTests.test_invalidDatetime�s=��

�L�L�N�������
�
�H�$5�$5�d�B��A�q�!�$L�	
r'c��tj�}|j|j�}|j	||j
�y)z�
        L{amp.DateTime.fromString} returns a C{datetime.datetime} with all of
        its fields populated from the string passed to it.
        N)rr�r/r�rr��r$r(r$s   r%�test_fromStringzDateTimeTests.test_fromString�s7��
�<�<�>���#�#�D�K�K�0���������,r'c��tj�}|j|j�}|j	||j
�y)z�
        L{amp.DateTime.toString} returns a C{str} in the wire format including
        all of the information from the C{datetime.datetime} passed into it,
        including the timezone offset.
        N)rr�r1r�rr�r�s   r%�
test_toStringzDateTimeTests.test_toString�s7���<�<�>���!�!�$�+�+�.���������,r'N)
r:r;r<r=r�r�r�r�r�r�r�r�r�r?r'r%r�r��sO���1�F�
��Q��^�F�
�X�
�
�t�Q��B��B��v�
F�F�;�
�-�-r'r�c�(�eZdZdZd�Zd�Zd�Zd�Zy)�UTCTestsz
    Tests for L{amp.utc}.
    c�b�|jtjjd�d�y)z8
        L{amp.utc.tzname} returns C{"+00:00"}.
        Nz+00:00)rrr��tznamer-s r%�test_tznamezUTCTests.test_tzname
s!��	
���������-�x�8r'c��|jtjjd�t	j
d��y)z:
        L{amp.utc.dst} returns a zero timedelta.
        Nr)rrr��dstr��	timedeltar-s r%�test_dstzUTCTests.test_dst
s,��	
��������T�*�H�,>�,>�q�,A�Br'c��|jtjjd�t	j
d��y)z@
        L{amp.utc.utcoffset} returns a zero timedelta.
        Nr)rrr��	utcoffsetr�rr-s r%�test_utcoffsetzUTCTests.test_utcoffset

s.��	
������*�*�4�0�(�2D�2D�Q�2G�Hr'c�>�|jttddd�y)z�
        L{amp._FixedOffsetTZInfo.fromSignHoursMinutes} raises L{ValueError} if
        passed an offset sign other than C{'+'} or C{'-'}.
        �?rN)r&r�r�r-s r%�test_badSignzUTCTests.test_badSign
s��
	
���*�b�#�q�!�4r'N)r:r;r<r=rrrrr?r'r%rr�s���9�C�I�5r'rc�"�eZdZdZd�Zd�Zd�Zy)�RemoteAmpErrorTestsz*
    Tests for L{amp.RemoteAmpError}.
    c�f�tjdd�}|jdt|��y)z�
        L{amp.RemoteAmpError} renders the given C{errorCode} (C{bytes}) and
        C{description} into a native string.
        �BROKEN�Something has brokenz"Code<BROKEN>: Something has brokenN�rr�rr>rCs  r%�test_stringMessagez&RemoteAmpErrorTests.test_stringMessage 
s,��
�"�"�9�.D�E�����=�s�5�z�Jr'c�f�tjdd�}|jdt|��y)z�
        When C{errorCode} contains non-ASCII characters, L{amp.RemoteAmpError}
        renders then as backslash-escape sequences.
        sBROKEN-�rz'Code<BROKEN-\xff>: Something has brokenNrrCs  r%�&test_stringMessageReplacesNonAsciiTextz:RemoteAmpErrorTests.test_stringMessageReplacesNonAsciiText(
s,��
�"�"�>�3I�J�����C�S��Z�Pr'c��ttd��}tjdd|��}|j	t|�d�y)zs
        L{amp.RemoteAmpError} renders local errors with a "(local)" marker and
        a brief traceback.
        zSomething came looserr)�localz}^Code<BROKEN> [(]local[)]: Something has broken
Traceback [(]failure with no frames[)]: <.+Exception.>: Something came loose
N)rr|rr�rBr>)r$rdr
s   r%�"test_stringMessageWithLocalFailurez6RemoteAmpErrorTests.test_stringMessageWithLocalFailure0
sC��
�)�$:�;�<���"�"�9�.D�G�T�������J�9�	
r'N)r:r;r<r=rrrr?r'r%rr
s���K�Q�
r'r)�r=r�r~�typingrrrr�unittestr�zope.interfacer�zope.interface.verifyr	r
r�rrr
rrr�twisted.internet.testingr�twisted.protocolsr�twisted.pythonr�twisted.python.failurer�twisted.testr�twisted.trial.unittestrr�_ssl�	supported�ImportErrorr#�IReactorSSLr��reactorLacksSSL�_FixedOffsetTZInfo�fromSignHoursMinutesr�rZrr�rAr|rRrWrYrr[r<rjrr�r�r�r�r�r�r�r��ProtocolSwitchCommandr�r�r�r�r�r�r�r�r�rrr
rrr,rRrYrgr�rlr�r�r�r�r�r�r�r�rfr%r)r3r6r9r>rKrgrrrtrvrxrzr|r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�rrrrrrrYrerprurwr�r�r�r�r��IUNIXTransportr��
ITransportr�r�rrr?r'r%�<module>r/s���
�
��0�0��&�;�Q�Q�4�!�#�*��+��,��>�>������;��G��G����(�(��1��O��O�	���0�0��&6��!�!�&6�R,�c�g�g�,�,��,�,�)�,�1�i�1�
�C�L�L�
�Q�C�K�K�Q�(�E��
1�#�+�+�1�&�#�+�+��#�3�;�;�#��c�k�k��"�#�+�+�"�A�c�k�k�A�.�3�;�;�.�,�#�+�+�,�
+�c�/�/�+�
�x�-�-�
� *��	�	�	�$�c�g�g�$�&U&�_�U&�p(�'E�(�*�!?�*�$
3�<�
3�"(�5L�N��(�+�+�������2�(�2�:C.�8�C.�L*�*�(#1�#1�LL8�8�L8�^0�S�[�[�0�D�#�$�$�D�D��D��)��D����D�0\(�(�\(�~!��-��I@�(�I@�X
\
?�x�\
?�~��
��$�Y��������'�_�'���$�%���M�N�f5�x�f5�O�&�f5�R?
�8�?
�D�Y���)���#�+�+���{��	�{�	�	 �C�G�G�	 �
%�s�w�w�
%�
%�3�7�7�
%� 0
�h�0
�f�,W�,W�^���?���H���$�%���M�N�%�|�X�%�O�&�%�P'�5�'���$�%���M�N�
F��h�
F�O�&�
F� ��$�%���M�N��\�8��O�&��"%����%�69�s�{�{�9�"����"�J6����6�:�e�n��
�e�n���D��c��N���7O��z
�8�z
�z*0�*0�Z
W��#3�
W� �(�$4��:��#3��(,��#3�,�^/;�H�&6�/;�d
?�8�
?� =��=�.#�(�$4�#�L>5�(�>5�B
�Z�
&�
&�'�#8�#8�(�#8�N�J�!�!�#6�7��J�%�%�':�;�RG�h�RG�j,-�H�,-�^5�x�5�>#
�(�#
��g��
�C��s� X2�2X=�<X=

Zerion Mini Shell 1.0