o
    b4                     @   sj  d Z ddlZddlmZ ddlmZ G dd deZG dd deZG d	d
 d
eZ	G dd deZ
G dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG dd  d eZG d!d" d"eZG d#d$ d$eZG d%d& d&eZG d'd( d(eZG d)d* d*eZG d+d, d,eZz ddlZejeejeejeiZ e!ed-ree ej"< ee ej#< W n e$y   i Z Y nw d.d/ Z%G d0d1 d1eZ&G d2d3 d3e&Z'G d4d5 d5e'Z(G d6d7 d7e&Z)G d8d9 d9e'Z*G d:d; d;e'Z+G d<d= d=e,Z-G d>d? d?e,Z.G d@dA dAe/Z0e1edBdCdddDe2dA G dEdF dFe)Z3G dGdH dHe'Z4G dIdJ dJeZ5G dKdL dLe6Z7G dMdN dNe6Z8G dOdP dPe6Z9G dQdR dRe6Z:G dSdT dTe6Z;G dUdV dVe<Z=G dWdX dXeZ>G dYdZ dZeZ?G d[d\ d\eZ@G d]d^ d^eZAG d_d` d`eZBG dadb dbe,ZCg dcZDdS )dz<
Exceptions and errors for use in twisted.internet modules.
    N)Version)	deprecatec                   @   "   e Zd Zd ZZdefddZdS )	BindErrorz)An error occurred binding to an interfacereturnc                 C   ,   | j }| jrd|d| j}d| }|S Nz{}: {} %s.MESSAGEargsformatjoinselfs r   8/usr/lib/python3/dist-packages/twisted/internet/error.py__str__   
   zBindError.__str__N__name__
__module____qualname____doc__r   strr   r   r   r   r   r          r   c                   @   s&   e Zd ZdZdd ZdefddZdS )CannotListenErrora2  
    This gets raised by a call to startListening, when the object cannotstart
    listening.

    @ivar interface: the interface I tried to listen on
    @ivar port: the port I tried to listen on
    @ivar socketError: the exception I got when I tried to listen
    @type socketError: L{socket.error}
    c                 C   s&   t | ||| || _|| _|| _d S N)r   __init__	interfaceportsocketError)r   r!   r"   r#   r   r   r   r    &   s   
zCannotListenError.__init__r   c                 C   s   | j pd}d|| j| jS )NanyzCouldn't listen on {}:{}: {}.)r!   r   r"   r#   )r   ifacer   r   r   r   ,   s   

zCannotListenError.__str__N)r   r   r   r   r    r   r   r   r   r   r   r      s    
r   c                   @      e Zd ZdZdS )MulticastJoinErrorz6
    An attempt to join a multicast group failed.
    Nr   r   r   r   r   r   r   r   r'   3       r'   c                   @   r   )MessageLengthErrorzMessage is too long to sendr   c                 C   r   r   r   r   r   r   r   r   <   r   zMessageLengthError.__str__Nr   r   r   r   r   r*   9   r   r*   c                   @   r   )DNSLookupErrorzDNS lookup failedr   c                 C   r   r   r   r   r   r   r   r   G   r   zDNSLookupError.__str__Nr   r   r   r   r   r+   D   r   r+   c                   @   r&   )ConnectInProgressErrorz3A connect operation was started and isn't done yet.Nr(   r   r   r   r   r,   O   r)   r,   c                   @   s,   e Zd Zd ZZd	ddZdefddZdS )
ConnectErrorz"An error occurred while connectingN c                 C   s   || _ t| | d S r   )osError	Exceptionr    )r   r/   stringr   r   r   r    Y   s   zConnectError.__init__r   c                 C   sF   | j }| jr| d| j }| jd r| d| jd  }d| }|S )N: r   r
   )r   r/   r   r   r   r   r   r   ]   s   
zConnectError.__str__)Nr.   )r   r   r   r   r   r    r   r   r   r   r   r   r-   V   s    
r-   c                   @      e Zd Zd ZZdS )ConnectBindErrorzCouldn't bindNr   r   r   r   r   r   r   r   r   r4   g       r4   c                   @   r3   )UnknownHostErrorzHostname couldn't be looked upNr5   r   r   r   r   r7   k   r6   r7   c                   @   r3   )NoRouteErrorzNo route to hostNr5   r   r   r   r   r8   o   r6   r8   c                   @   r3   )ConnectionRefusedErrorz$Connection was refused by other sideNr5   r   r   r   r   r9   s   r6   r9   c                   @   r3   )TCPTimedOutErrorzTCP connection timed outNr5   r   r   r   r   r:   w   r6   r:   c                   @   r3   )BadFileErrorz$File used for UNIX socket is no goodNr5   r   r   r   r   r;   {   r6   r;   c                   @   r3   )ServiceNameUnknownErrorz%Service name given as port is unknownNr5   r   r   r   r   r<      r6   r<   c                   @   r3   )	UserErrorzUser aborted connectionNr5   r   r   r   r   r=      r6   r=   c                   @   r3   )TimeoutErrorz&User timeout caused connection failureNr5   r   r   r   r   r>      r6   r>   c                   @   r3   )SSLErrorzAn SSL error occurredNr5   r   r   r   r   r?      r6   r?   c                   @   r3   )VerifyErrorz:Could not verify something that was supposed to be signed.Nr5   r   r   r   r   r@      r6   r@   c                   @   r3   )PeerVerifyErrorz#The peer rejected our verify error.Nr5   r   r   r   r   rA      r6   rA   c                   @   r3   )CertificateErrorz<We did not find a certificate where we expected to find one.Nr5   r   r   r   r   rB      r6   rB   WSAECONNREFUSEDc                 C   sr   t | tr	| j}n| }z|\}}W n ty   t| d Y S w ttdr.t | tjr.t}nt	
|t}|||S )z2Given a socket exception, return connection error.)r1   gaierror)
isinstancer0   r   
ValueErrorr-   hasattrsocketrD   r7   errnoMappingget)er   numberr1   klassr   r   r   getConnectError   s   

rN   c                   @   r&   )ConnectionClosedz@
    Connection was closed, whether cleanly or non-cleanly.
    Nr(   r   r   r   r   rO      r)   rO   c                   @   r   )ConnectionLostzF
    Connection to the other side was lost in a non-clean fashion
    r   c                 C   sL   | j   d d }| jr|d |d| j |d d|S )N   r2   r	   .r.   )r   strip
splitlinesr   appendr   r   r   r   r   r      s   


zConnectionLost.__str__Nr   r   r   r   r   rP      s    rP   c                   @      e Zd ZdZdZdS )ConnectionAbortedz
    Connection was aborted locally, using
    L{twisted.internet.interfaces.ITCPTransport.abortConnection}.

    @since: 11.1
    zBConnection was aborted locally using ITCPTransport.abortConnectionNr5   r   r   r   r   rW      s    rW   c                   @   r   )ConnectionDonezConnection was closed cleanlyr   c                 C   r   r   r   r   r   r   r   r      r   zConnectionDone.__str__Nr   r   r   r   r   rX      r   rX   c                   @   rV   )FileDescriptorOverrunaw  
    A mis-use of L{IUNIXTransport.sendFileDescriptor} caused the connection to
    be closed.

    Each file descriptor sent using C{sendFileDescriptor} must be associated
    with at least one byte sent using L{ITransport.write}.  If at any point
    fewer bytes have been written than file descriptors have been sent, the
    connection is closed with this exception.
    zRA mis-use of IUNIXTransport.sendFileDescriptor caused the connection to be closed.Nr5   r   r   r   r   rY      s    rY   c                   @   r3   )ConnectionFdescWentAwayUhNr5   r   r   r   r   rZ      r6   rZ   c                   @   r   )AlreadyCalledz'Tried to cancel an already-called eventr   c                 C   r   r   r   r   r   r   r   r      r   zAlreadyCalled.__str__Nr   r   r   r   r   r\      r   r\   c                   @   r   )AlreadyCancelledz*Tried to cancel an already-cancelled eventr   c                 C   r   r   r   r   r   r   r   r     r   zAlreadyCancelled.__str__Nr   r   r   r   r   r]     r   r]   c                   @   rV   )PotentialZombieWarningz
    Emitted when L{IReactorProcess.spawnProcess} is called in a way which may
    result in termination of the created child process not being reported.

    Deprecated in Twisted 10.0.
    zspawnProcess called, but the SIGCHLD handler is not installed. This probably means you have not yet called reactor.run, or called reactor.run(installSignalHandler=0). You will probably never see this process finish, and it may become a zombie process.Nr5   r   r   r   r   r^     s    r^   Twisted
   z4There is no longer any potential for zombie process.c                   @   s   e Zd Zd ZZdd ZdS )ProcessDonez+A process has ended without apparent errorsc                 C   s"   t | d d| _d | _|| _d S )Nz!process finished with exit code 0r   )r0   r    exitCodesignalstatus)r   rd   r   r   r   r    0  s   
zProcessDone.__init__Nr   r   r   r   r   r    r   r   r   r   ra   -  s    ra   c                   @   s   e Zd Zd ZZdddZdS )ProcessTerminatedz
    A process has ended with a probable error condition

    @ivar exitCode: See L{__init__}
    @ivar signal: See L{__init__}
    @ivar status: See L{__init__}
    Nc                 C   sN   || _ || _|| _d}|dur|d|  }|dur|d|  }t| | dS )a  
        @param exitCode: The exit status of the process.  This is roughly like
            the value you might pass to L{os._exit}.  This is L{None} if the
            process exited due to a signal.
        @type exitCode: L{int} or L{None}

        @param signal: The exit signal of the process.  This is L{None} if the
            process did not exit due to a signal.
        @type signal: L{int} or L{None}

        @param status: The exit code of the process.  This is a platform
            specific combination of the exit code and the exit signal.  See
            L{os.WIFEXITED} and related functions.
        @type status: L{int}
        zprocess endedNz with exit code %sz by signal %s)rb   rc   rd   r0   r    )r   rb   rc   rd   r   r   r   r   r    @  s   zProcessTerminated.__init__)NNNre   r   r   r   r   rf   7  s    rf   c                   @   r&   )ProcessExitedAlreadyzd
    The process has already exited and the operation requested can no longer
    be performed.
    Nr(   r   r   r   r   rg   [  r)   rg   c                   @   r   )NotConnectingErrorzEThe Connector was not connecting when it was asked to stop connectingr   c                 C   r   r   r   r   r   r   r   r   g  r   zNotConnectingError.__str__Nr   r   r   r   r   rh   b  s
    rh   c                   @   r   )NotListeningErrorz>The Port was not listening when it was asked to stop listeningr   c                 C   r   r   r   r   r   r   r   r   r  r   zNotListeningError.__str__Nr   r   r   r   r   ri   o  r   ri   c                   @   r&   )ReactorNotRunningzJ
    Error raised when trying to stop a reactor which is not running.
    Nr(   r   r   r   r   rj   z  r)   rj   c                   @   r&   )ReactorNotRestartablezF
    Error raised when trying to run a reactor which was stopped.
    Nr(   r   r   r   r   rk     r)   rk   c                   @   r&   )ReactorAlreadyRunningzG
    Error raised when trying to start the reactor multiple times.
    Nr(   r   r   r   r   rl     r)   rl   c                   @   r&   )ReactorAlreadyInstalledErrorzE
    Could not install reactor because one is already installed.
    Nr(   r   r   r   r   rm     r)   rm   c                   @      e Zd ZdZdd ZdS )ConnectingCancelledErrorz
    An C{Exception} that will be raised when an L{IStreamClientEndpoint} is
    cancelled before it connects.

    @ivar address: The L{IAddress} that is the destination of the
        cancelled L{IStreamClientEndpoint}.
    c                 C   s   t | | || _dS )z
        @param address: The L{IAddress} that is the destination of the
            L{IStreamClientEndpoint} that was cancelled.
        N)r0   r    address)r   rp   r   r   r   r      s   
z!ConnectingCancelledError.__init__Nr   r   r   r   r    r   r   r   r   ro         ro   c                   @   r&   )
NoProtocolz
    An C{Exception} that will be raised when the factory given to a
    L{IStreamClientEndpoint} returns L{None} from C{buildProtocol}.
    Nr(   r   r   r   r   rs     r)   rs   c                   @   r&   )UnsupportedAddressFamilyz
    An attempt was made to use a socket with an address family (eg I{AF_INET},
    I{AF_INET6}, etc) which is not supported by the reactor.
    Nr(   r   r   r   r   rt     r)   rt   c                   @   r&   )UnsupportedSocketTypez
    An attempt was made to use a socket of a type (eg I{SOCK_STREAM},
    I{SOCK_DGRAM}, etc) which is not supported by the reactor.
    Nr(   r   r   r   r   ru     r)   ru   c                   @   r&   )AlreadyListenedzd
    An attempt was made to listen on a file descriptor which can only be
    listened on once.
    Nr(   r   r   r   r   rv     r)   rv   c                   @   rn   )InvalidAddressErrorz
    An invalid address was specified (i.e. neither IPv4 or IPv6, or expected
    one and got the other).

    @ivar address: See L{__init__}
    @ivar message: See L{__init__}
    c                 C   s   || _ || _dS )z
        @param address: The address that was provided.
        @type address: L{bytes}
        @param message: A native string of additional information provided by
            the calling context.
        @type address: L{str}
        N)rp   message)r   rp   rx   r   r   r   r      s   
zInvalidAddressError.__init__Nrq   r   r   r   r   rw     rr   rw   )(r   r   r'   r*   r+   r,   r-   r4   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rN   rO   rP   rX   rZ   r\   r]   r^   ra   rf   rg   rh   ri   rj   rl   rm   ro   rt   ru   rw   )Er   rH   incrementalr   twisted.pythonr   r0   r   r   r'   r*   IOErrorr+   r,   r-   r4   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   errnoENETUNREACHECONNREFUSED	ETIMEDOUTrI   rG   rC   WSAENETUNREACHImportErrorrN   rO   rP   rW   rX   rY   rZ   rF   r\   r]   Warningr^   deprecatedModuleAttributer   ra   rf   rg   RuntimeErrorrh   ri   rj   rk   rl   AssertionErrorrm   ro   rs   rt   ru   rv   rw   __all__r   r   r   r   <module>   s   



$