
    gb)              	      z   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* y)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y)r   z?
    Base class for all exceptions defined by websockets.

    N__name__
__module____qualname____doc__     J/var/www/openai/venv/lib/python3.12/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y)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.

    Nc                    || _         || _        || _        | j                  d u | j                   d u xs | j                  d u k(  sJ y Nrcvdsentrcvd_then_sent)selfr.   r/   r0   s       r(   __init__zConnectionClosed.__init__\   sK     		,##t+d1B1WdiiSWFWXXXr'   c                   | j                   | j                  y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 r-   r1   s    r(   __str__zConnectionClosed.__str__g   s    99yy 8tyyk)BCCyy "499+-BCC&&&tyykdii[II"499+-=dii[IIr'   c                    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coder4   s    r(   r=   zConnectionClosed.codex   sC    D	

 99##444yy~~r'   c                |    t        j                  dt               | j                  y| j                  j                  S )Nz`ConnectionClosed.reason is deprecated; use Protocol.close_reason or ConnectionClosed.rcvd.reason )r7   r8   r9   r.   reasonr4   s    r(   r@   zConnectionClosed.reason   s6    H	

 99yyr'   r,   )r.   frames.Close | Noner/   rA   r0   zbool | NonereturnNonerB   str)rB   int)	r"   r#   r$   r%   r2   r5   propertyr=   r@   r&   r'   r(   r   r   M   sj    $ '+		Y!	Y "	Y $		Y
 
	YJ"      r'   r   c                      e Zd ZdZy)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y)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	      rI   r'   r	   c                       e Zd ZdZddZddZy)r
   zL
    Raised when connecting to a URI that isn't a valid WebSocket URI.

    c                     || _         || _        y r,   urimsg)r1   rN   rO   s      r(   r2   zInvalidURI.__init__   s    r'   c                8    | j                    d| j                   S )Nz isn't a valid URI: rM   r4   s    r(   r5   zInvalidURI.__str__   s    ((/z::r'   N)rN   rE   rO   rE   rB   rC   rD   r"   r#   r$   r%   r2   r5   r&   r'   r(   r
   r
      s    
;r'   r
   c                      e Zd ZdZy)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y)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      rI   r'   r   c                       e Zd ZdZddZddZy)r   zJ
    Raised when a handshake response rejects the WebSocket upgrade.

    c                    || _         y r,   )response)r1   rV   s     r(   r2   zInvalidStatus.__init__   s	     r'   c                6    d| j                   j                  dS )Nz+server rejected WebSocket connection: HTTP d)rV   status_coder4   s    r(   r5   zInvalidStatus.__str__   s#    MM--a02	
r'   N)rV   zhttp11.ResponserB   rC   rD   rQ   r&   r'   r(   r   r      s    
!
r'   r   c                  "    e Zd ZdZdddZddZy)r   zK
    Raised when an HTTP header doesn't have a valid format or value.

    Nc                     || _         || _        y r,   namevaluer1   r]   r^   s      r(   r2   zInvalidHeader.__init__       	
r'   c                    | j                   d| j                   dS | j                   dk(  rd| j                   dS d| j                   d| j                    S )Nzmissing z headerr?   zempty zinvalid z	 header: r^   r]   r4   s    r(   r5   zInvalidHeader.__str__   sY    ::dii[00ZZ2DII;g..dii[	$**>>r'   r,   r]   rE   r^   
str | NonerB   rC   rD   rQ   r&   r'   r(   r   r      s    
?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.

    c                6    t         |   || d| d|        y )Nz at z in superr2   )r1   r]   errorheaderpos	__class__s        r(   r2   zInvalidHeaderFormat.__init__   s#    %SEfX>?r'   )
r]   rE   ri   rE   rj   rE   rk   rF   rB   rC   r"   r#   r$   r%   r2   __classcell__rl   s   @r(   r   r      s    @ @r'   r   c                      e Zd ZdZy)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.

    c                &    t         |   d|       y )NOriginrg   )r1   originrl   s     r(   r2   zInvalidOrigin.__init__   s    6*r'   )rt   rd   rB   rC   rm   ro   s   @r(   r   r      s    
+ +r'   r   c                      e Zd ZdZy)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y)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y)r   zK
    Raised when a parameter name is repeated in an extension header.

    c                    || _         y r,   r]   r1   r]   s     r(   r2   zDuplicateParameter.__init__  	    	r'   c                     d| j                    S )Nzduplicate parameter: ry   r4   s    r(   r5   zDuplicateParameter.__str__  s    &tyyk22r'   Nr]   rE   rB   rC   rD   rQ   r&   r'   r(   r   r     s    
3r'   r   c                       e Zd ZdZddZddZy)r   zJ
    Raised when a parameter name in an extension header is invalid.

    c                    || _         y r,   ry   rz   s     r(   r2   zInvalidParameterName.__init__%  r{   r'   c                     d| j                    S )Nzinvalid parameter name: ry   r4   s    r(   r5   zInvalidParameterName.__str__(  s    )$))55r'   Nr}   rD   rQ   r&   r'   r(   r   r     s    
6r'   r   c                       e Zd ZdZddZddZy)r   zK
    Raised when a parameter value in an extension header is invalid.

    c                     || _         || _        y r,   r\   r_   s      r(   r2   zInvalidParameterValue.__init__2  r`   r'   c                    | j                   d| j                   S | j                   dk(  rd| j                   S d| j                   d| j                    S )Nzmissing value for parameter r?   zempty value for parameter zinvalid value for parameter z: rb   r4   s    r(   r5   zInvalidParameterValue.__str__6  sU    ::1$))==ZZ2/		{;;1$))BtzzlKKr'   Nrc   rD   rQ   r&   r'   r(   r   r   ,  s    
Lr'   r   c                      e Zd ZdZy)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y)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y)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y)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  rI   r'   r   )r   r   r   r   z.legacy.exceptions)r   r   r   r   r   )aliases)r:   http11)+r%   
__future__r   typingr7   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   globalsr?   r:   r   r&   r'   r(   <module>r      sz  > #    < ? ) ? D) , ;# ;) $ 
$ 
 ?$ ?&	@- 	@ +M +] ' 
3) 
3
6+ 
6L, L&	& 	
& 
%~ )<  
  +	22!5!5&:
	  r'   