
    Vhk&                        d dl mZ d dlZ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e
j                        Z G d d	e
j                        Z G d
 de
j                        Zy)    )annotationsN)Sequence)error)unittestc                     e Zd ZU dZg dej
                  g i fdej
                  dgi fdej
                  ddgi fdej                  dd	 ej                  d
      fi fdej                  g i fdej                  ddgi fdej                  g i fdej                  ddgi fdej                  g i fdej                  dgi fdej                  g ddifdej                  ddgi fdej                  g i fdej                  dgi fdej                  ddgi fdej                  g i fdej                  g i fdej                  g i fdej                  g i fdej                   g i fdej"                  g i fdej$                  g i fdej&                  g i fd ej(                  g i fd!ej*                  g i fd"ej*                  ddgi fd#ej,                  g i fd$ej,                  ddgi fd%ej.                  g i fd&ej0                  g i fd'ej0                  ddgi fd(ej2                  g i fd)ej2                  d*d+gi fd,ej4                  d-gi fd.ej6                  g i fd/ej6                  g d0d1ifd2ej6                  g d3d4ifd5ej8                  g i fd6ej8                  d*d7gi fd8ej:                  g i fd9ej:                  d:d;gi fZd<ed=<   d@d>Z d@d?Z!y-)A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12z_list[tuple[str, type[Exception], Sequence[str | int | Exception | None], dict[str, str | int]]]listOfTestsc           
         | j                   D ]7  }|d   }|d   }|d   }|d   }| j                  t         ||i |      |       9 y )Nr            )r   assertEqualstr)selfentryoutput	exceptionargskwargss         G/home/dcms/DCMS/lib/python3.12/site-packages/twisted/test/test_error.pytestThemAllz StringificationTests.testThemAll   s\    %% 	FE1XFaI8D1XFSD!;F!;<fE	F    c                z    t               }t        j                  |      }| j                  |j                  |       y)zP
        L{error.ConnectingCancelledError} has an C{address} attribute.
        N)objectr   ConnectingCancelledErrorassertIsaddress)r   r,   es      r%   test_connectingCancelledErrorz2StringificationTests.test_connectingCancelledError   s-     (**73aii)r'   returnNone)"__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   __annotations__r&   r.    r'   r%   r   r      s`   @^		5uBO^	 >OOG		
^	 BOOEN		
^	  1##T<6<<./		
^	* 
()A)A2rJ+^	. 4$$EN		
-^	8 
u33R<9^	: 
'(<(<uenbQ;^	< 
/0B0BBK=^	@ ?O		
?^	L 7u		
K^	X DE"		
W^	b 
5112r:c^	d 
'(>(>QSTe^	h /""E"		
g^	r 
+E,B,BBKs^	t 
e00"b9u^	v 
1%2N2NPRTVWw^	x 
%e&<&<b"Ey^	z 
1%2D2Db"M{^	~ 5))		
}^	H 
$U__b"=I^	J 
3E4F4FBOK^	L 
"5>>2r:M^	P L  		
O^	\ U  EN		
[^	f 
*5+?+?RHg^	j 6  EN		
i^	v ))		
u^	@ 
4U5H5H"bQA^	D @EN		
C^	N 
78N8NPRTVWO^	R ?""#J		
Q^	^ ^F		
]^	j R##		
i^	v d##		
u^	B c##x 		
A^	N U$$		
M^	Z [$$$K		
Y^	f N##		
e^	r T##$K		
q^	   eNF*r'   r   c                  (    e Zd ZdZddZddZddZy)SubclassingTestsz=
    Some exceptions are subclasses of other exceptions.
    c                r    | j                  t        t        j                  t        j                               y)zW
        L{error.ConnectionClosed} is a superclass of L{error.ConnectionLost}.
        N)
assertTrue
issubclassr   rF   ConnectionClosedr   s    r%   -test_connectionLostSubclassOfConnectionClosedz>SubclassingTests.test_connectionLostSubclassOfConnectionClosed   #     	
5#7#79O9OPQr'   c                r    | j                  t        t        j                  t        j                               y)zW
        L{error.ConnectionClosed} is a superclass of L{error.ConnectionDone}.
        N)rT   rU   r   rG   rV   rW   s    r%   -test_connectionDoneSubclassOfConnectionClosedz>SubclassingTests.test_connectionDoneSubclassOfConnectionClosed   rY   r'   c                ^    | j                  t        t        j                  t                     y)zP
        L{ValueError} is a superclass of L{error.InvalidAddressError}.
        N)rT   rU   r   InvalidAddressError
ValueErrorrW   s    r%   ,test_invalidAddressErrorSubclassOfValueErrorz=SubclassingTests.test_invalidAddressErrorSubclassOfValueError   s     	
5#<#<jIJr'   Nr/   )r2   r3   r4   r5   rX   r[   r_   rP   r'   r%   rR   rR      s    RRKr'   rR   c                  X    e Zd ZdZ	 	 	 	 	 	 ddZ	 	 	 	 	 	 	 	 	 	 d	dZd
dZd
dZd
dZy)GetConnectErrorTestsz
    Given an exception instance thrown by C{socket.connect},
    L{error.getConnectError} returns the appropriate high-level Twisted
    exception instance.
    c                ^    |df}t        j                  |      }| j                  |d||       y)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-   results        r%   assertErrnoExceptionz)GetConnectErrorTests.assertErrnoException   s2     H&&q)##E8V]Kr'   c                    | j                  |j                  |       | j                  |j                  |       | j                  |j                  |f       y)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   rf   messagerh   rg   s        r%   re   z+GetConnectErrorTests.assertCorrectException   sD     	))=9/wj1r'   c                   | j                  t        j                  t        j                         | j                  t        j
                  t        j                         | j                  t        j                  t        j                         t        j                  dk(  r]| j                  t        j                  t        j                         | j                  t        j                  t        j                         yy)zW
        L{error.getConnectError} converts based on errno for C{socket.error}.
        win32N)ri   rf   ENETUNREACHr   r>   ECONNREFUSEDr?   	ETIMEDOUTr@   sysplatformWSAECONNREFUSEDWSAENETUNREACHrW   s    r%   
test_errnozGetConnectErrorTests.test_errno  s     	!!%"3"3U5G5GH!!%"4"4e6R6RS!!%//53I3IJ<<7"%%%%u'C'C %%e&:&:E<N<NO	 #r'   c                    t        j                  t        j                  dd            }| j	                  dd|t         j
                         y)z
        L{error.getConnectError} converts to a L{error.UnknownHostError} given
        a C{socket.gaierror} instance.
           helloN)r   rd   r8   gaierrorre   r=   )r   rh   s     r%   test_gaierrorz"GetConnectErrorTests.test_gaierror  s9    
 &&vr7'CD##B9O9OPr'   c                    t               }t        j                  |      }| j                  d||t        j                         y)z
        L{error.getConnectError} converts to a L{error.ConnectError} given
        an argument that cannot be unpacked.
        N)	Exceptionr   rd   re   r;   )r   r-   rh   s      r%   test_nonTuplez"GetConnectErrorTests.test_nonTuple  s5    
 K&&q)##D!VU5G5GHr'   N)rf   intrg   type[error.ConnectError]r0   r1   )
rf   z
int | Nonerm   r)   rh   zerror.ConnectErrorrg   r   r0   r1   r/   )	r2   r3   r4   r5   ri   re   rw   r|   r   rP   r'   r%   ra   ra      so    
L
L)A
L	
L22 2 #	2
 02 
2"PQIr'   ra   )
__future__r   rf   r8   rs   typingr   twisted.internetr   twisted.trialr   SynchronousTestCaser   rR   ra   rP   r'   r%   <module>r      s[    #   
  " "y*877 y*xKx33 K0@I877 @Ir'   