o
    ¯bÞ"  ã                   @   sn   d dl Z d dlZd dlmZ d dlmZ d dlmZ G dd„ dejƒZ	G dd„ dejƒZ
G d	d
„ d
ejƒZdS )é    N)Úerror)ÚplatformType)Úunittestc                   @   s6  e Zd ZdZg dejf‘dejdgf‘dejddgf‘dejdd	e d
¡ff‘dejf‘dejddgf‘dej	f‘dej	ddgf‘dej
f‘dej
dgf‘dej
g ddif‘dej
ddgf‘dejf‘dejdgf‘dejddgf‘dejf‘dejf‘dejf‘dejf‘dejf‘dejf‘dejf‘dejf‘d ejf‘d!ejf‘d"ejddgf‘d#ejf‘d$ejddgf‘d%ejf‘d&ejf‘d'ejddgf‘d(ejf‘d)ejd*d+gf‘d,ejd-gf‘d.ejf‘d/ejg d0d1if‘d2ejg d3d4if‘d5ejf‘d6ejd*d7gf‘d8ejf‘d9ejd:d;gf‘Zd<d=„ Zd>d?„ Z d-S )@ÚStringificationTestsz6Test that the exceptions have useful stringifications.z*An error occurred binding to an interface.z/An error occurred binding to an interface: foo.Úfooz3An error occurred binding to an interface: foo bar.Úbarz"Couldn't listen on eth0:4242: Foo.Úeth0i’  ÚFoozMessage is too long to send.z%Message is too long to send: foo bar.zDNS lookup failed.zDNS lookup failed: foo bar.z#An error occurred while connecting.z0An error occurred while connecting: someOsError.ÚsomeOsErrorz(An error occurred while connecting: foo.Ústringz5An error occurred while connecting: someOsError: foo.zCouldn't bind.zCouldn't bind: someOsError.z Couldn't bind: someOsError: foo.zHostname couldn't be looked up.zNo route to host.z%Connection was refused by other side.zTCP connection timed out.z%File used for UNIX socket is no good.z&Service name given as port is unknown.zUser aborted connection.z'User timeout caused connection failure.zAn SSL error occurred.z=Connection to the other side was lost in a non-clean fashion.zFConnection to the other side was lost in a non-clean fashion: foo bar.zConnection was closed cleanly.z'Connection was closed cleanly: foo bar.zUh.z(Tried to cancel an already-called event.z1Tried to cancel an already-called event: foo bar.z+Tried to cancel an already-cancelled event.z0Tried to cancel an already-cancelled event: x 2.ÚxÚ2zOA process has ended without apparent errors: process finished with exit code 0.NzCA process has ended with a probable error condition: process ended.zUA process has ended with a probable error condition: process ended with exit code 42.ÚexitCodeé*   zTA process has ended with a probable error condition: process ended by signal SIGBUS.ÚsignalÚSIGBUSzFThe Connector was not connecting when it was asked to stop connecting.zLThe Connector was not connecting when it was asked to stop connecting: x 13.Ú13z?The Port was not listening when it was asked to stop listening.zEThe Port was not listening when it was asked to stop listening: a 12.ÚaÚ12c              	   C   s‚   | j D ];}|d }|d }z|d }W n ty   d}Y nw z|d }W n ty0   i }Y nw |  t||i |¤Žƒ|¡ qd S )Nr   é   é   © é   )ÚlistOfTestsÚ
IndexErrorÚassertEqualÚstr)ÚselfÚentryÚoutputÚ	exceptionÚargsÚkwargsr   r   ú9/usr/lib/python3/dist-packages/twisted/test/test_error.pyÚtestThemAll�   s   
ÿÿôz StringificationTests.testThemAllc                 C   s"   t ƒ }t |¡}|  |j|¡ dS )zP
        L{error.ConnectingCancelledError} has an C{address} attribute.
        N)Úobjectr   ÚConnectingCancelledErrorÚassertIsÚaddress)r   r(   Úer   r   r#   Útest_connectingCancelledErrorž   s   
z2StringificationTests.test_connectingCancelledError)!Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Ú	BindErrorÚCannotListenErrorÚsocketÚMessageLengthErrorÚDNSLookupErrorÚConnectErrorÚConnectBindErrorÚUnknownHostErrorÚNoRouteErrorÚConnectionRefusedErrorÚTCPTimedOutErrorÚBadFileErrorÚServiceNameUnknownErrorÚ	UserErrorÚTimeoutErrorÚSSLErrorÚConnectionLostÚConnectionDoneÚConnectionFdescWentAwayÚAlreadyCalledÚAlreadyCancelledÚProcessDoneÚProcessTerminatedÚNotConnectingErrorÚNotListeningErrorr   r$   r*   r   r   r   r#   r      s(   þýýü
ý÷òýñìëêýéüä#ýÞ'Ù(Ø*ý×.Ò/Ñ0Ð1Ï2Î3Í4Ì5Ë6Ê8þÉ<ýÅ@ÀBý¿GþºJ¶LýµP°Rý¯Wýª\þ¥`ü¡fü›lþ•pý‘uþŒyýˆr   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚSubclassingTestsz=
    Some exceptions are subclasses of other exceptions.
    c                 C   ó   |   ttjtjƒ¡ dS )zW
        L{error.ConnectionClosed} is a superclass of L{error.ConnectionLost}.
        N)Ú
assertTrueÚ
issubclassr   r?   ÚConnectionClosed©r   r   r   r#   Ú-test_connectionLostSubclassOfConnectionClosed¬   ó   z>SubclassingTests.test_connectionLostSubclassOfConnectionClosedc                 C   rI   )zW
        L{error.ConnectionClosed} is a superclass of L{error.ConnectionDone}.
        N)rJ   rK   r   r@   rL   rM   r   r   r#   Ú-test_connectionDoneSubclassOfConnectionClosed²   rO   z>SubclassingTests.test_connectionDoneSubclassOfConnectionClosedc                 C   s   |   ttjtƒ¡ dS )zP
        L{ValueError} is a superclass of L{error.InvalidAddressError}.
        N)rJ   rK   r   ÚInvalidAddressErrorÚ
ValueErrorrM   r   r   r#   Ú,test_invalidAddressErrorSubclassOfValueError¸   s   z=SubclassingTests.test_invalidAddressErrorSubclassOfValueErrorN)r+   r,   r-   r.   rN   rP   rS   r   r   r   r#   rH   §   s
    rH   c                   @   s8   e Zd ZdZdd„ Zdd„ Zdd„ Zdd	„ Zd
d„ ZdS )ÚGetConnectErrorTestsz¢
    Given an exception instance thrown by C{socket.connect},
    L{error.getConnectError} returns the appropriate high-level Twisted
    exception instance.
    c                 C   s&   |df}t  |¡}|  |d||¡ dS )zª
        When called with a tuple with the given errno,
        L{error.getConnectError} returns an exception which is an instance of
        the expected class.
        ÚlalalaN)r   ÚgetConnectErrorÚassertCorrectException)r   ÚerrnoÚexpectedClassr)   Úresultr   r   r#   ÚassertErrnoExceptionÆ   s   
z)GetConnectErrorTests.assertErrnoExceptionc                 C   s0   |   |j|¡ |   |j|¡ |   |j|f¡ dS )z 
        The given result of L{error.getConnectError} has the given attributes
        (C{osError} and C{args}), and is an instance of the given class.
        N)r   Ú	__class__ÚosErrorr!   )r   rX   ÚmessagerZ   rY   r   r   r#   rW   Ð   s   z+GetConnectErrorTests.assertCorrectExceptionc                 C   s`   |   tjtj¡ |   tjtj¡ |   tjtj¡ t	dkr.|   tj
tj¡ |   tjtj¡ dS dS )zW
        L{error.getConnectError} converts based on errno for C{socket.error}.
        Úwin32N)r[   rX   ÚENETUNREACHr   r7   ÚECONNREFUSEDr8   Ú	ETIMEDOUTr9   r   ÚWSAECONNREFUSEDÚWSAENETUNREACHrM   r   r   r#   Ú
test_errnoÛ   s   ÿüzGetConnectErrorTests.test_errnoc                 C   s(   t  t dd¡¡}|  dd|t j¡ dS )z
        L{error.getConnectError} converts to a L{error.UnknownHostError} given
        a C{socket.gaierror} instance.
        é   ÚhelloN)r   rV   r1   ÚgaierrorrW   r6   )r   rZ   r   r   r#   Útest_gaierrorè   s   z"GetConnectErrorTests.test_gaierrorc                 C   s&   t ƒ }t |¡}|  d||tj¡ dS )z�
        L{error.getConnectError} converts to a L{error.ConnectError} given
        an argument that cannot be unpacked.
        N)Ú	Exceptionr   rV   rW   r4   )r   r)   rZ   r   r   r#   Útest_nonTupleð   s   
z"GetConnectErrorTests.test_nonTupleN)	r+   r,   r-   r.   r[   rW   re   ri   rk   r   r   r   r#   rT   ¿   s    
rT   )rX   r1   Útwisted.internetr   Útwisted.python.runtimer   Útwisted.trialr   ÚSynchronousTestCaser   rH   rT   r   r   r   r#   Ú<module>   s    