o
    Zh2                     @  s  d Z ddlmZ ddlZddlmZ g d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G d/d0 d0eZG d1d2 d2eZG d3d4 d4eZG d5d6 d6eZG d7d8 d8ee Z!G d9d: d:ee"Z#dd;l$m%Z%m&Z& ee' d<d<d<d<d=d> dS )?aU  
: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:`ProxyError`
            * :exc:`InvalidProxyMessage`
            * :exc:`InvalidProxyStatus`
        * :exc:`InvalidMessage`
        * :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
ProxyErrorInvalidProxyMessageInvalidProxyStatusInvalidMessageInvalidStatusInvalidHeaderInvalidHeaderFormatInvalidHeaderValueInvalidOriginInvalidUpgradeNegotiationErrorDuplicateParameterInvalidParameterNameInvalidParameterValueProtocolError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__ r%   r%   L/var/www/html/lang_env/lib/python3.10/site-packages/websockets/exceptions.pyr   I       r   c                   @  sD   e Zd ZdZ	ddd
dZdddZedddZed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                 C  s8   || _ || _|| _| jd u | j d u p| jd u ksJ d S Nr(   r*   r+   )selfr(   r*   r+   r%   r%   r&   __init___   s   &zConnectionClosed.__init__strc                 C  sl   | j d u r| jd u rdS d| j dS | jd u r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 r0   r1   r%   r%   r&   __str__j   s   


zConnectionClosed.__str__intc                 C  s&   t dt | jd u rtjjS | jjS )NzZConnectionClosed.code is deprecated; use Protocol.close_code or ConnectionClosed.rcvd.code)warningswarnDeprecationWarningr(   framesZ	CloseCodeZABNORMAL_CLOSUREcoder4   r%   r%   r&   r;   {   s   
zConnectionClosed.codec                 C  s"   t dt | jd u rdS | jjS )Nz`ConnectionClosed.reason is deprecated; use Protocol.close_reason or ConnectionClosed.rcvd.reason )r7   r8   r9   r(   reasonr4   r%   r%   r&   r=      s   
zConnectionClosed.reasonr/   )r(   r)   r*   r)   r+   r,   r-   r.   r-   r3   )r-   r6   )	r!   r"   r#   r$   r2   r5   propertyr;   r=   r%   r%   r%   r&   r   P   s    

r   c                   @  r   )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                   @  r   )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      r'   r   c                   @  $   e Zd ZdZdddZdd	d
ZdS )r	   zL
    Raised when connecting to a URI that isn't a valid WebSocket URI.

    urir3   msgr-   r.   c                 C     || _ || _d S r/   rA   rB   )r1   rA   rB   r%   r%   r&   r2         
zInvalidURI.__init__c                 C     | j  d| j S )Nz isn't a valid URI: rD   r4   r%   r%   r&   r5         zInvalidURI.__str__N)rA   r3   rB   r3   r-   r.   r>   r!   r"   r#   r$   r2   r5   r%   r%   r%   r&   r	          
r	   c                   @  r@   )r
   z?
    Raised when connecting via a proxy that isn't valid.

    proxyr3   rB   r-   r.   c                 C  rC   r/   rJ   rB   )r1   rJ   rB   r%   r%   r&   r2      rE   zInvalidProxy.__init__c                 C  rF   )Nz isn't a valid proxy: rK   r4   r%   r%   r&   r5      rG   zInvalidProxy.__str__N)rJ   r3   rB   r3   r-   r.   r>   rH   r%   r%   r%   r&   r
      rI   r
   c                   @  r   )r   zM
    Base class for exceptions raised when the opening handshake fails.

    Nr    r%   r%   r%   r&   r      r'   r   c                   @  r   )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      r'   r   c                   @  r   )r   z5
    Raised when failing to connect to a proxy.

    Nr    r%   r%   r%   r&   r      r'   r   c                   @  r   )r   z;
    Raised when an HTTP proxy response is malformed.

    Nr    r%   r%   r%   r&   r      r'   r   c                   @  $   e Zd ZdZdddZdd	d
ZdS )r   z<
    Raised when an HTTP proxy rejects the connection.

    responsehttp11.Responser-   r.   c                 C  
   || _ d S r/   rM   r1   rM   r%   r%   r&   r2         
zInvalidProxyStatus.__init__r3   c                 C     d| j jdS )Nz proxy rejected connection: HTTP drM   status_coder4   r%   r%   r&   r5      s   zInvalidProxyStatus.__str__NrM   rN   r-   r.   r>   rH   r%   r%   r%   r&   r          
r   c                   @  r   )r   zD
    Raised when a handshake request or response is malformed.

    Nr    r%   r%   r%   r&   r      r'   r   c                   @  rL   )r   zJ
    Raised when a handshake response rejects the WebSocket upgrade.

    rM   rN   r-   r.   c                 C  rO   r/   rP   rQ   r%   r%   r&   r2      rR   zInvalidStatus.__init__r3   c                 C  rS   )Nz+server rejected WebSocket connection: HTTP rT   rU   r4   r%   r%   r&   r5      s   zInvalidStatus.__str__NrW   r>   rH   r%   r%   r%   r&   r      rX   r   c                   @  s&   e Zd ZdZddd	d
ZdddZdS )r   zK
    Raised when an HTTP header doesn't have a valid format or value.

    Nnamer3   value
str | Noner-   r.   c                 C  rC   r/   rY   rZ   r1   rY   rZ   r%   r%   r&   r2   
  rE   zInvalidHeader.__init__c                 C  sD   | j d u r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: rZ   rY   r4   r%   r%   r&   r5     s
   

zInvalidHeader.__str__r/   rY   r3   rZ   r[   r-   r.   r>   rH   r%   r%   r%   r&   r     s    r   c                      s"   e Zd ZdZd fd
dZ  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.

    rY   r3   errorheaderposr6   r-   r.   c                   s"   t  || d| d|  d S )Nz at z in superr2   )r1   rY   r`   ra   rb   	__class__r%   r&   r2     s   "zInvalidHeaderFormat.__init__)
rY   r3   r`   r3   ra   r3   rb   r6   r-   r.   r!   r"   r#   r$   r2   __classcell__r%   r%   re   r&   r     s    r   c                   @  r   )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   #  r'   r   c                      s"   e Zd ZdZd fddZ  ZS )	r   zD
    Raised when the Origin header in a request isn't allowed.

    originr[   r-   r.   c                   s   t  d| d S )NZOriginrc   )r1   ri   re   r%   r&   r2   2  rG   zInvalidOrigin.__init__)ri   r[   r-   r.   rg   r%   r%   re   r&   r   ,  s    r   c                   @  r   )r   zF
    Raised when the Upgrade or Connection header isn't correct.

    Nr    r%   r%   r%   r&   r   6  r'   r   c                   @  r   )r   zG
    Raised when negotiating an extension or a subprotocol fails.

    Nr    r%   r%   r%   r&   r   =  r'   r   c                   @  $   e Zd ZdZdddZddd	Zd
S )r   zK
    Raised when a parameter name is repeated in an extension header.

    rY   r3   r-   r.   c                 C  rO   r/   rY   r1   rY   r%   r%   r&   r2   J  rR   zDuplicateParameter.__init__c                 C     d| j  S )Nzduplicate parameter: rk   r4   r%   r%   r&   r5   M     zDuplicateParameter.__str__NrY   r3   r-   r.   r>   rH   r%   r%   r%   r&   r   D  rX   r   c                   @  rj   )r   zJ
    Raised when a parameter name in an extension header is invalid.

    rY   r3   r-   r.   c                 C  rO   r/   rk   rl   r%   r%   r&   r2   W  rR   zInvalidParameterName.__init__c                 C  rm   )Nzinvalid parameter name: rk   r4   r%   r%   r&   r5   Z  rn   zInvalidParameterName.__str__Nro   r>   rH   r%   r%   r%   r&   r   Q  rX   r   c                   @  s$   e Zd ZdZddd	Zdd
dZdS )r   zK
    Raised when a parameter value in an extension header is invalid.

    rY   r3   rZ   r[   r-   r.   c                 C  rC   r/   r\   r]   r%   r%   r&   r2   d  rE   zInvalidParameterValue.__init__c                 C  s@   | j d u r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: r^   r4   r%   r%   r&   r5   h  s
   

zInvalidParameterValue.__str__Nr_   r>   rH   r%   r%   r%   r&   r   ^  rI   r   c                   @  r   )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   q  r'   r   c                   @  s4   e Zd ZdZ		ddd
dZdddZdd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.

    Nsize_or_messageint | None | strmax_size
int | Nonecur_sizer-   r.   c                 C  sj   t |tr|d u sJ |d u sJ tdt || _d S d | _|| _|d us(J || _d | _| 	| d S )NzMPayloadTooBig(message) is deprecated; change to PayloadTooBig(size, max_size))

isinstancer3   r7   r8   r9   messagesizerr   rt   set_current_size)r1   rp   rr   rt   r%   r%   r&   r2     s   

zPayloadTooBig.__init__r3   c                 C  sb   | j d ur| j S d}| jd ur|d| j d7 }| jd ur&|d| j d7 }|d| j d7 }|S )Nzframe zwith z bytes zafter reading zexceeds limit of z bytes)rv   rw   rt   rr   )r1   rv   r%   r%   r&   r5     s   


zPayloadTooBig.__str__c                 C  s2   | j d u sJ |d ur|  j|7  _|| _ d S d S r/   )rt   rr   )r1   rt   r%   r%   r&   rx     s
   
zPayloadTooBig.set_current_size)NN)rp   rq   rr   rs   rt   rs   r-   r.   r>   )rt   rs   r-   r.   )r!   r"   r#   r$   r2   r5   rx   r%   r%   r%   r&   r   }  s    
r   c                   @  r   )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     r'   r   c                   @  r   )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     r'   r   )r:   http11z.legacy.exceptions)ZAbortHandshakeZInvalidStatusCodeZRedirectHandshakeZWebSocketProtocolError)Zdeprecated_aliases)(r$   
__future__r   r7   Z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   AssertionErrorr   RuntimeErrorr   r<   r:   ry   globalsr%   r%   r%   r&   <module>   sP    #B


	
6
