
    mhb)              	         d Z ddlmZ ddlZddlZddlmZ g dZ G d de          Z	 G d	 d
e	          Z
 G d de
          Z G d de
          Z G d de	          Z G d de	          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d d e          Z G d! d"e          Z G d# d$e          Z G d% d&e          Z G d' d(e          Z G d) d*e	          Z G d+ d,e	          Z G d- d.e	e          Z G d/ d0e	e          Zej         rdd1l!m"Z"m#Z#m$Z$m%Z% eZ&n e e'            d2d2d2d2d2d34           dd5l(m)Z)m*Z* dS )6a  
:mod:`websockets.exceptions` defines the following hierarchy of exceptions.

* :exc:`WebSocketException`
    * :exc:`ConnectionClosed`
        * :exc:`ConnectionClosedOK`
        * :exc:`ConnectionClosedError`
    * :exc:`InvalidURI`
    * :exc:`InvalidHandshake`
        * :exc:`SecurityError`
        * :exc:`InvalidMessage` (legacy)
        * :exc:`InvalidStatus`
        * :exc:`InvalidStatusCode` (legacy)
        * :exc:`InvalidHeader`
            * :exc:`InvalidHeaderFormat`
            * :exc:`InvalidHeaderValue`
            * :exc:`InvalidOrigin`
            * :exc:`InvalidUpgrade`
        * :exc:`NegotiationError`
            * :exc:`DuplicateParameter`
            * :exc:`InvalidParameterName`
            * :exc:`InvalidParameterValue`
        * :exc:`AbortHandshake` (legacy)
        * :exc:`RedirectHandshake` (legacy)
    * :exc:`ProtocolError` (Sans-I/O)
    * :exc:`PayloadTooBig` (Sans-I/O)
    * :exc:`InvalidState` (Sans-I/O)
    * :exc:`ConcurrencyError`

    )annotationsN   )lazy_import)WebSocketExceptionConnectionClosedConnectionClosedOKConnectionClosedError
InvalidURIInvalidHandshakeSecurityErrorInvalidMessageInvalidStatusInvalidStatusCodeInvalidHeaderInvalidHeaderFormatInvalidHeaderValueInvalidOriginInvalidUpgradeNegotiationErrorDuplicateParameterInvalidParameterNameInvalidParameterValueAbortHandshakeRedirectHandshakeProtocolErrorWebSocketProtocolErrorPayloadTooBigInvalidStateConcurrencyErrorc                      e Zd ZdZdS )r   z?
    Base class for all exceptions defined by websockets.

    N__name__
__module____qualname____doc__     @/usr/local/lib/python3.11/site-packages/websockets/exceptions.pyr   r   F              r'   r   c                  V    e Zd ZdZ	 ddd
ZddZedd            Zedd            ZdS )r   a  
    Raised when trying to interact with a closed connection.

    Attributes:
        rcvd: If a close frame was received, its code and reason are available
            in ``rcvd.code`` and ``rcvd.reason``.
        sent: If a close frame was sent, its code and reason are available
            in ``sent.code`` and ``sent.reason``.
        rcvd_then_sent: If close frames were received and sent, this attribute
            tells in which order this happened, from the perspective of this
            side of the connection.

    Nrcvdframes.Close | Nonesentrcvd_then_sentbool | NonereturnNonec                n    || _         || _        || _        | j        d u | j         d u p| j        d u k    sJ d S Nr+   r-   r.   )selfr+   r-   r.   s       r(   __init__zConnectionClosed.__init__\   sM     		,#t+d1B1WdiSWFWXXXXXXr'   strc                    | j         | j        dS d| j         dS | j        d| j          dS | j        rd| j          d| j         S d| j         d| j          S )Nzno close frame received or sentzsent z; no close frame receivedz	received z; no close frame sentz; then sent z; then received r4   r5   s    r(   __str__zConnectionClosed.__str__g   s    9y 88CtyCCCCy C49CCCC& JItyIIdiIIII49IIdiIIIr'   intc                ~    t          j        dt                     | j        t          j        j        S | j        j        S )NzZConnectionClosed.code is deprecated; use Protocol.close_code or ConnectionClosed.rcvd.code)warningswarnDeprecationWarningr+   frames	CloseCodeABNORMAL_CLOSUREcoder9   s    r(   rC   zConnectionClosed.codex   s?    D	
 	
 	

 9#44y~r'   c                `    t          j        dt                     | j        dS | j        j        S )Nz`ConnectionClosed.reason is deprecated; use Protocol.close_reason or ConnectionClosed.rcvd.reason )r=   r>   r?   r+   reasonr9   s    r(   rF   zConnectionClosed.reason   s9    H	
 	
 	

 92yr'   r3   )r+   r,   r-   r,   r.   r/   r0   r1   r0   r7   )r0   r;   )	r"   r#   r$   r%   r6   r:   propertyrC   rF   r&   r'   r(   r   r   M   s         $ '+		Y 	Y 	Y 	Y 	YJ J J J"    X       X     r'   r   c                      e Zd ZdZdS )r   z
    Like :exc:`ConnectionClosed`, when the connection terminated properly.

    A close code with code 1000 (OK) or 1001 (going away) or without a code was
    received and sent.

    Nr!   r&   r'   r(   r   r                 r'   r   c                      e Zd ZdZdS )r	   z
    Like :exc:`ConnectionClosed`, when the connection terminated with an error.

    A close frame with a code other than 1000 (OK) or 1001 (going away) was
    received or sent, or the closing handshake didn't complete properly.

    Nr!   r&   r'   r(   r	   r	      rJ   r'   r	   c                  "    e Zd ZdZd
dZddZd	S )r
   zL
    Raised when connecting to a URI that isn't a valid WebSocket URI.

    urir7   msgr0   r1   c                "    || _         || _        d S r3   rM   rN   )r5   rM   rN   s      r(   r6   zInvalidURI.__init__   s    r'   c                $    | j          d| j         S )Nz isn't a valid URI: rP   r9   s    r(   r:   zInvalidURI.__str__   s    (:::::r'   N)rM   r7   rN   r7   r0   r1   rG   r"   r#   r$   r%   r6   r:   r&   r'   r(   r
   r
      sF         
   ; ; ; ; ; ;r'   r
   c                      e Zd ZdZdS )r   zM
    Base class for exceptions raised when the opening handshake fails.

    Nr!   r&   r'   r(   r   r      r)   r'   r   c                      e Zd ZdZdS )r   z
    Raised when a handshake request or response breaks a security rule.

    Security limits can be configured with :doc:`environment variables
    <../reference/variables>`.

    Nr!   r&   r'   r(   r   r      rJ   r'   r   c                  "    e Zd ZdZd
dZddZd	S )r   zJ
    Raised when a handshake response rejects the WebSocket upgrade.

    responsehttp11.Responser0   r1   c                    || _         d S r3   )rV   )r5   rV   s     r(   r6   zInvalidStatus.__init__   s     r'   r7   c                "    d| j         j        dS )Nz+server rejected WebSocket connection: HTTP d)rV   status_coder9   s    r(   r:   zInvalidStatus.__str__   s!    2M-12 2	
r'   N)rV   rW   r0   r1   rG   rR   r&   r'   r(   r   r      sF         
! ! ! !
 
 
 
 
 
r'   r   c                  $    e Zd ZdZddd	Zdd
ZdS )r   zK
    Raised when an HTTP header doesn't have a valid format or value.

    Nnamer7   value
str | Noner0   r1   c                "    || _         || _        d S r3   r]   r^   r5   r]   r^   s      r(   r6   zInvalidHeader.__init__       	


r'   c                v    | j         d| j         dS | j         dk    rd| j         dS d| j         d| j          S )Nzmissing z headerrE   zempty zinvalid z	 header: r^   r]   r9   s    r(   r:   zInvalidHeader.__str__   sW    :0di0000Z2.DI....>di>>$*>>>r'   r3   r]   r7   r^   r_   r0   r1   rG   rR   r&   r'   r(   r   r      sK         
    ? ? ? ? ? ?r'   r   c                  $     e Zd ZdZd fd
Z xZS )r   z
    Raised when an HTTP header cannot be parsed.

    The format of the header doesn't match the grammar for that header.

    r]   r7   errorheaderposr;   r0   r1   c                \    t                                          || d| d|            d S )Nz at z in superr6   )r5   r]   rh   ri   rj   	__class__s        r(   r6   zInvalidHeaderFormat.__init__   s9    %>>S>>f>>?????r'   )
r]   r7   rh   r7   ri   r7   rj   r;   r0   r1   r"   r#   r$   r%   r6   __classcell__rn   s   @r(   r   r      sQ         @ @ @ @ @ @ @ @ @ @r'   r   c                      e Zd ZdZdS )r   z
    Raised when an HTTP header has a wrong value.

    The format of the header is correct but the value isn't acceptable.

    Nr!   r&   r'   r(   r   r      s           r'   r   c                  $     e Zd ZdZd fdZ xZS )r   zD
    Raised when the Origin header in a request isn't allowed.

    originr_   r0   r1   c                L    t                                          d|           d S )NOriginrl   )r5   rt   rn   s     r(   r6   zInvalidOrigin.__init__   s#    6*****r'   )rt   r_   r0   r1   ro   rq   s   @r(   r   r      sG         
+ + + + + + + + + +r'   r   c                      e Zd ZdZdS )r   zF
    Raised when the Upgrade or Connection header isn't correct.

    Nr!   r&   r'   r(   r   r     r)   r'   r   c                      e Zd ZdZdS )r   zG
    Raised when negotiating an extension or a subprotocol fails.

    Nr!   r&   r'   r(   r   r     r)   r'   r   c                  "    e Zd ZdZd	dZd
dZdS )r   zK
    Raised when a parameter name is repeated in an extension header.

    r]   r7   r0   r1   c                    || _         d S r3   r]   r5   r]   s     r(   r6   zDuplicateParameter.__init__      			r'   c                    d| j          S )Nzduplicate parameter: r{   r9   s    r(   r:   zDuplicateParameter.__str__  s    2ty222r'   Nr]   r7   r0   r1   rG   rR   r&   r'   r(   r   r     sF         
   3 3 3 3 3 3r'   r   c                  "    e Zd ZdZd	dZd
dZdS )r   zJ
    Raised when a parameter name in an extension header is invalid.

    r]   r7   r0   r1   c                    || _         d S r3   r{   r|   s     r(   r6   zInvalidParameterName.__init__%  r}   r'   c                    d| j          S )Nzinvalid parameter name: r{   r9   s    r(   r:   zInvalidParameterName.__str__(  s    5$)555r'   Nr   rG   rR   r&   r'   r(   r   r     sF         
   6 6 6 6 6 6r'   r   c                  "    e Zd ZdZddZdd	Zd
S )r   zK
    Raised when a parameter value in an extension header is invalid.

    r]   r7   r^   r_   r0   r1   c                "    || _         || _        d S r3   ra   rb   s      r(   r6   zInvalidParameterValue.__init__2  rc   r'   c                r    | j         
d| j         S | j         dk    r
d| j         S d| j         d| j          S )Nzmissing value for parameter rE   zempty value for parameter zinvalid value for parameter z: re   r9   s    r(   r:   zInvalidParameterValue.__str__6  sQ    :=$)===Z2;	;;;K$)KKtzKKKr'   Nrf   rG   rR   r&   r'   r(   r   r   ,  sL         
   L L L L L Lr'   r   c                      e Zd ZdZdS )r   a  
    Raised when receiving or sending a frame that breaks the protocol.

    The Sans-I/O implementation raises this exception when:

    * receiving or sending a frame that contains invalid data;
    * receiving or sending an invalid sequence of frames.

    Nr!   r&   r'   r(   r   r   ?  s           r'   r   c                      e Zd ZdZdS )r   aU  
    Raised when parsing a frame with a payload that exceeds the maximum size.

    The Sans-I/O layer uses this exception internally. It doesn't bubble up to
    the I/O layer.

    The :meth:`~websockets.extensions.Extension.decode` method of extensions
    must raise :exc:`PayloadTooBig` if decoding a frame would exceed the limit.

    Nr!   r&   r'   r(   r   r   K  s        	 	 	 	r'   r   c                      e Zd ZdZdS )r   a  
    Raised when sending a frame is forbidden in the current state.

    Specifically, the Sans-I/O layer raises this exception when:

    * sending a data frame to a connection in a state other
      :attr:`~websockets.protocol.State.OPEN`;
    * sending a control frame to a connection in a state other than
      :attr:`~websockets.protocol.State.OPEN` or
      :attr:`~websockets.protocol.State.CLOSING`.

    Nr!   r&   r'   r(   r   r   X  s           r'   r   c                      e Zd ZdZdS )r   z
    Raised when receiving or sending messages concurrently.

    WebSocket is a connection-oriented protocol. Reads must be serialized; so
    must be writes. However, reading and writing concurrently is possible.

    Nr!   r&   r'   r(   r   r   g  rJ   r'   r   )r   r   r   r   z.legacy.exceptions)r   r   r   r   r   )aliases)r@   http11)+r%   
__future__r   typingr=   importsr   __all__	Exceptionr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   AssertionErrorr   RuntimeErrorr   TYPE_CHECKINGlegacy.exceptionsr   r   r   r   r   globalsrE   r@   r   r&   r'   r(   <module>r      s   > # " " " " "                <       ?  ?  ?  ?  ? ) ?  ?  ? D    )       ,   ; ; ; ; ;# ; ; ;    )       $   
 
 
 
 
$ 
 
 
 ? ? ? ? ?$ ? ? ?&	@ 	@ 	@ 	@ 	@- 	@ 	@ 	@       + + + + +M + + +    ]       '   
3 
3 
3 
3 
3) 
3 
3 
3
6 
6 
6 
6 
6+ 
6 
6 
6L L L L L, L L L&	 	 	 	 	& 	 	 	
 
 
 
 
& 
 
 
    %~       )<    
             +K		22!5!5&:
 
	 	 	 	          r'   