
    A>qj7                    ,   d Z ddlm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      Z G d/ d0e      Z G d1 d2e      Z G d3 d4e      Z G d5 d6e      Z G d7 d8e      Z  G d9 d:e       Z! G d; d<e       Z" G d= d>e       Z# G d? d@e      Z$ G dA dBe      Z% G dC dDee&      Z' G dE dFee(      Z)ddGl*m+Z+m,Z,  e e-       dHdHdHdHdIJ       y)Ka/  
:mod:`websockets.exceptions` defines the following hierarchy of exceptions.

* :exc:`WebSocketException`
    * :exc:`ConnectionClosed`
        * :exc:`ConnectionClosedOK`
        * :exc:`ConnectionClosedError`
    * :exc:`InvalidURI`
    * :exc:`InvalidProxy`
    * :exc:`InvalidHandshake`
        * :exc:`SecurityError`
            * :exc:`RequestLineTooLong`
            * :exc:`StatusLineTooLong`
            * :exc:`HeaderLineTooLong`
            * :exc:`TooManyHeaders`
        * :exc:`ProxyError`
            * :exc:`InvalidProxyMessage`
            * :exc:`InvalidProxyStatus`
        * :exc:`InvalidMessage`
        * :exc:`InvalidMethod`
        * :exc:`InvalidProtocol`
        * :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InvalidProxyInvalidHandshakeSecurityErrorRequestLineTooLongStatusLineTooLongHeaderLineTooLongTooManyHeaders
ProxyErrorInvalidProxyMessageInvalidProxyStatusInvalidMessageInvalidMethodInvalidProtocolInvalidStatusInvalidHeaderInvalidHeaderFormatInvalidHeaderValueInvalidOriginInvalidUpgradeNegotiationErrorDuplicateParameterInvalidParameterNameInvalidParameterValueProtocolError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__     T/opt/rentech/trading_bot/.venv/lib/python3.12/site-packages/websockets/exceptions.pyr   r   U       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)selfr4   r5   r6   s       r.   __init__zConnectionClosed.__init__k   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 r3   r7   s    r.   __str__zConnectionClosed.__str__v   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DeprecationWarningr4   frames	CloseCodeABNORMAL_CLOSUREcoder:   s    r.   rC   zConnectionClosed.code   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 )r=   r>   r?   r4   reasonr:   s    r.   rF   zConnectionClosed.reason   s6    H	

 99yyr-   r2   )r4   frames.Close | Noner5   rG   r6   zbool | NonereturnNonerH   str)rH   int)	r(   r)   r*   r+   r8   r;   propertyrC   rF   r,   r-   r.   r   r   \   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	      rO   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 r2   urimsg)r7   rT   rU   s      r.   r8   zInvalidURI.__init__   s    r-   c                8    | j                    d| j                   S )Nz isn't a valid URI: rS   r:   s    r.   r;   zInvalidURI.__str__   s    ((/z::r-   N)rT   rK   rU   rK   rH   rI   rJ   r(   r)   r*   r+   r8   r;   r,   r-   r.   r
   r
      s    
;r-   r
   c                       e Zd ZdZddZddZy)r   z?
    Raised when connecting via a proxy that isn't valid.

    c                     || _         || _        y r2   proxyrU   )r7   r[   rU   s      r.   r8   zInvalidProxy.__init__   s    
r-   c                8    | j                    d| j                   S )Nz isn't a valid proxy: rZ   r:   s    r.   r;   zInvalidProxy.__str__   s    **3DHH:>>r-   N)r[   rK   rU   rK   rH   rI   rJ   rW   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      rO   r-   r   c                      e Zd ZdZy)r   zK
    Raised when the request line of a handshake request is too long.

    Nr'   r,   r-   r.   r   r      r/   r-   r   c                      e Zd ZdZy)r   zK
    Raised when the status line of a handshake response is too long.

    Nr'   r,   r-   r.   r   r      r/   r-   r   c                      e Zd ZdZy)r   zT
    Raised when a header line of a handshake request or response is too long.

    Nr'   r,   r-   r.   r   r      r/   r-   r   c                      e Zd ZdZy)r   zL
    Raised when a handshake request or response has too many headers.

    Nr'   r,   r-   r.   r   r      r/   r-   r   c                      e Zd ZdZy)r   z5
    Raised when failing to connect to a proxy.

    Nr'   r,   r-   r.   r   r      r/   r-   r   c                      e Zd ZdZy)r   z;
    Raised when an HTTP proxy response is malformed.

    Nr'   r,   r-   r.   r   r     r/   r-   r   c                       e Zd ZdZddZddZy)r   z<
    Raised when an HTTP proxy rejects the connection.

    c                    || _         y r2   responser7   rh   s     r.   r8   zInvalidProxyStatus.__init__  	     r-   c                6    d| j                   j                  dS )Nz proxy rejected connection: HTTP drh   status_coder:   s    r.   r;   zInvalidProxyStatus.__str__  s    1$--2K2KA1NOOr-   Nrh   zhttp11.ResponserH   rI   rJ   rW   r,   r-   r.   r   r   	  s    
!Pr-   r   c                      e Zd ZdZy)r   zD
    Raised when a handshake request or response is malformed.

    Nr'   r,   r-   r.   r   r     r/   r-   r   c                       e Zd ZdZddZddZy)r   z@
    Raised when a handshake request doesn't use HTTP GET.

    c                    || _         y r2   method)r7   rt   s     r.   r8   zInvalidMethod.__init__#  s	    r-   c                     d| j                    S )Nzunsupported HTTP method: rs   r:   s    r.   r;   zInvalidMethod.__str__&  s    *4;;-88r-   N)rt   rK   rH   rI   rJ   rW   r,   r-   r.   r   r     s    
9r-   r   c                       e Zd ZdZddZddZy)r   z@
    Raised when a handshake request doesn't use HTTP/1.1.

    c                    || _         y r2   protocol)r7   ry   s     r.   r8   zInvalidProtocol.__init__0  rj   r-   c                     d| j                    S )Nzunsupported HTTP version: rx   r:   s    r.   r;   zInvalidProtocol.__str__3  s    +DMM?;;r-   N)ry   rK   rH   rI   rJ   rW   r,   r-   r.   r   r   *  s    
!<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 r2   rg   ri   s     r.   r8   zInvalidStatus.__init__=  rj   r-   c                6    d| j                   j                  dS )Nz+server rejected WebSocket connection: HTTP rl   rm   r:   s    r.   r;   zInvalidStatus.__str__@  s    9$--:S:STU9VW	
r-   Nro   rJ   rW   r,   r-   r.   r   r   7  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 r2   namevaluer7   r   r   s      r.   r8   zInvalidHeader.__init__L      	
r-   c                    | 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   r:   s    r.   r;   zInvalidHeader.__str__P  sY    ::dii[00ZZ2DII;g..dii[	$**>>r-   r2   r   rK   r   
str | NonerH   rI   rJ   rW   r,   r-   r.   r   r   F  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 superr8   )r7   r   errorheaderpos	__class__s        r.   r8   zInvalidHeaderFormat.__init__a  s#    %SEfX>?r-   )
r   rK   r   rK   r   rK   r   rL   rH   rI   r(   r)   r*   r+   r8   __classcell__r   s   @r.   r   r   Y  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   e  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Originr   )r7   originr   s     r.   r8   zInvalidOrigin.__init__t  s    6*r-   )r   r   rH   rI   r   r   s   @r.   r   r   n  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   x  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 r2   r   r7   r   s     r.   r8   zDuplicateParameter.__init__  	    	r-   c                     d| j                    S )Nzduplicate parameter: r   r:   s    r.   r;   zDuplicateParameter.__str__  s    &tyyk22r-   Nr   rK   rH   rI   rJ   rW   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 r2   r   r   s     r.   r8   zInvalidParameterName.__init__  r   r-   c                     d| j                    S )Nzinvalid parameter name: r   r:   s    r.   r;   zInvalidParameterName.__str__  s    )$))55r-   Nr   rJ   rW   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 r2   r   r   s      r.   r8   zInvalidParameterValue.__init__  r   r-   c                    | 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: r   r:   s    r.   r;   zInvalidParameterValue.__str__  sU    ::1$))==ZZ2/		{;;1$))BtzzlKKr-   Nr   rJ   rW   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	 	 d	 	 	 	 	 	 	 ddZddZd	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.

    Nc                    t        |t              r*|J |J t        j                  dt               || _        y d | _        || _        |J || _        d | _        | j                  |       y )NzMPayloadTooBig(message) is deprecated; change to PayloadTooBig(size, max_size))

isinstancerK   r=   r>   r?   messagesizemax_sizecurrent_sizeset_current_size)r7   size_or_messager   r   s       r.   r8   zPayloadTooBig.__init__  sz     os+###'''MM:"
 (7DLDL$3DI'''!)DM,0D!!,/r-   c                    | j                   | j                   S d}| j                  |d| j                   dz  }| j                  |d| j                   dz  }|d| j                   dz  }|S )Nzframe zwith z bytes zafter reading zexceeds limit of z bytes)r   r   r   r   )r7   r   s     r.   r;   zPayloadTooBig.__str__  s    <<#<<Gyy$U499+W55  ,^D,=,=+>gFF*4==/@@GNr-   c                ^    | j                   J || xj                  |z  c_        || _         y y r2   )r   r   )r7   r   s     r.   r   zPayloadTooBig.set_current_size  s5      (((#MM\)M ,D $r-   )NN)r   zint | None | strr   
int | Noner   r   rH   rI   rJ   )r   r   rH   rI   )r(   r)   r*   r+   r8   r;   r   r,   r-   r.   r#   r#     sD    	  $#'	0)0 0 !	0
 
0.
-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$     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%     rO   r-   r%   )r@   http11z.legacy.exceptions)AbortHandshakeInvalidStatusCodeRedirectHandshakeWebSocketProtocolError)deprecated_aliases).r+   
__future__r   r=   importsr   __all__	Exceptionr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   AssertionErrorr$   RuntimeErrorr%   rE   r@   r   globalsr,   r-   r.   <module>r      s  'R #   !H ? ) ? D) , ;# ;?% ?) $    ] ! * 
P 
P% 
9$ 
9
<& 
<
$ 
?$ ?&	@- 	@ +M +] ' 
3) 
3
6+ 
6L, L&	& 	3-& 3-l%~ )<   I /11"6	r-   