a
    ñ»jä3  ã                   @  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                   @  s   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$   ú;E:\soccer\ml_env\Lib\site-packages\websockets/exceptions.pyr   I   s   r   c                   @  sX   e Zd ZdZddddddœdd„Zd	d
œdd„Zedd
œdd„ƒZed	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.

    Nzframes.Close | Nonezbool | NoneÚNone)ÚrcvdÚsentÚrcvd_then_sentÚreturnc                 C  s8   || _ || _|| _| jd u | j d u p,| jd u ks4J ‚d S ©N©r'   r(   r)   )Úselfr'   r(   r)   r$   r$   r%   Ú__init___   s    zConnectionClosed.__init__Ústr©r*   c                 C  sr   | j d u r(| jd u rdS d| j› d�S nF| jd u r@d| j › d�S | jrZd| j › d| j› �S d| j› d| j › �S d 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,   ©r-   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Úcoder1   r$   r$   r%   r8   {   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Ú )r4   r5   r6   r'   Úreasonr1   r$   r$   r%   r:   †   s    ý
zConnectionClosed.reason)N)	r    r!   r"   r#   r.   r2   Úpropertyr8   r:   r$   r$   r$   r%   r   P   s    ü
r   c                   @  s   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   ’   s   r   c                   @  s   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   œ   s   r   c                   @  s0   e Zd ZdZddddœdd„Zddœdd	„Zd
S )r	   zL
    Raised when connecting to a URI that isn't a valid WebSocket URI.

    r/   r&   )ÚuriÚmsgr*   c                 C  s   || _ || _d S r+   ©r<   r=   )r-   r<   r=   r$   r$   r%   r.   ¬   s    zInvalidURI.__init__r0   c                 C  s   | j › d| j› �S )Nz isn't a valid URI: r>   r1   r$   r$   r%   r2   °   s    zInvalidURI.__str__N©r    r!   r"   r#   r.   r2   r$   r$   r$   r%   r	   ¦   s   r	   c                   @  s0   e Zd ZdZddddœdd„Zddœdd	„Zd
S )r
   z?
    Raised when connecting via a proxy that isn't valid.

    r/   r&   )Úproxyr=   r*   c                 C  s   || _ || _d S r+   ©r@   r=   )r-   r@   r=   r$   r$   r%   r.   º   s    zInvalidProxy.__init__r0   c                 C  s   | j › d| j› �S )Nz isn't a valid proxy: rA   r1   r$   r$   r%   r2   ¾   s    zInvalidProxy.__str__Nr?   r$   r$   r$   r%   r
   ´   s   r
   c                   @  s   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   Â   s   r   c                   @  s   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   É   s   r   c                   @  s   e Zd ZdZdS )r   z5
    Raised when failing to connect to a proxy.

    Nr   r$   r$   r$   r%   r   Ó   s   r   c                   @  s   e Zd ZdZdS )r   z;
    Raised when an HTTP proxy response is malformed.

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

    úhttp11.Responser&   ©Úresponser*   c                 C  s
   || _ d S r+   ©rD   ©r-   rD   r$   r$   r%   r.   ç   s    zInvalidProxyStatus.__init__r/   r0   c                 C  s   d| j jd›�S )Nz proxy rejected connection: HTTP Úd©rD   Ústatus_coder1   r$   r$   r%   r2   ê   s    zInvalidProxyStatus.__str__Nr?   r$   r$   r$   r%   r   á   s   r   c                   @  s   e Zd ZdZdS )r   zD
    Raised when a handshake request or response is malformed.

    Nr   r$   r$   r$   r%   r   î   s   r   c                   @  s.   e Zd ZdZdddœdd„Zddœd	d
„ZdS )r   zJ
    Raised when a handshake response rejects the WebSocket upgrade.

    rB   r&   rC   c                 C  s
   || _ d S r+   rE   rF   r$   r$   r%   r.   û   s    zInvalidStatus.__init__r/   r0   c                 C  s   d| j jd›�S )Nz+server rejected WebSocket connection: HTTP rG   rH   r1   r$   r$   r%   r2   þ   s    ÿzInvalidStatus.__str__Nr?   r$   r$   r$   r%   r   õ   s   r   c                   @  s2   e Zd ZdZdddddœdd„Zdd	œd
d„ZdS )r   zK
    Raised when an HTTP header doesn't have a valid format or value.

    Nr/   ú
str | Noner&   ©ÚnameÚvaluer*   c                 C  s   || _ || _d S r+   ©rL   rM   ©r-   rL   rM   r$   r$   r%   r.   
  s    zInvalidHeader.__init__r0   c                 C  sH   | j d u rd| j› d�S | j dkr0d| j› d�S d| j› d| j › �S d S )Nzmissing z headerr9   zempty zinvalid z	 header: ©rM   rL   r1   r$   r$   r%   r2     s
    

zInvalidHeader.__str__)Nr?   r$   r$   r$   r%   r     s   r   c                      s.   e Zd ZdZddddd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.

    r/   r3   r&   )rL   ÚerrorÚheaderÚposr*   c                   s"   t ƒ  ||› d|› d|› �¡ d S )Nz at z in ©Úsuperr.   )r-   rL   rQ   rR   rS   ©Ú	__class__r$   r%   r.     s    zInvalidHeaderFormat.__init__©r    r!   r"   r#   r.   Ú__classcell__r$   r$   rV   r%   r     s   r   c                   @  s   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   c                      s(   e Zd ZdZdddœ‡ fdd„Z‡  ZS )r   zD
    Raised when the Origin header in a request isn't allowed.

    rJ   r&   )Úoriginr*   c                   s   t ƒ  d|¡ d S )NZOriginrT   )r-   rZ   rV   r$   r%   r.   2  s    zInvalidOrigin.__init__rX   r$   r$   rV   r%   r   ,  s   r   c                   @  s   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   6  s   r   c                   @  s   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   =  s   r   c                   @  s.   e Zd ZdZdddœdd„Zddœdd	„Zd
S )r   zK
    Raised when a parameter name is repeated in an extension header.

    r/   r&   ©rL   r*   c                 C  s
   || _ d S r+   ©rL   ©r-   rL   r$   r$   r%   r.   J  s    zDuplicateParameter.__init__r0   c                 C  s   d| j › �S )Nzduplicate parameter: r\   r1   r$   r$   r%   r2   M  s    zDuplicateParameter.__str__Nr?   r$   r$   r$   r%   r   D  s   r   c                   @  s.   e Zd ZdZdddœdd„Zddœdd	„Zd
S )r   zJ
    Raised when a parameter name in an extension header is invalid.

    r/   r&   r[   c                 C  s
   || _ d S r+   r\   r]   r$   r$   r%   r.   W  s    zInvalidParameterName.__init__r0   c                 C  s   d| j › �S )Nzinvalid parameter name: r\   r1   r$   r$   r%   r2   Z  s    zInvalidParameterName.__str__Nr?   r$   r$   r$   r%   r   Q  s   r   c                   @  s0   e Zd ZdZddddœdd„Zddœd	d
„ZdS )r   zK
    Raised when a parameter value in an extension header is invalid.

    r/   rJ   r&   rK   c                 C  s   || _ || _d S r+   rN   rO   r$   r$   r%   r.   d  s    zInvalidParameterValue.__init__r0   c                 C  sD   | j d u rd| j› �S | j dkr,d| j› �S d| j› d| j › �S d S )Nzmissing value for parameter r9   zempty value for parameter zinvalid value for parameter z: rP   r1   r$   r$   r%   r2   h  s
    

zInvalidParameterValue.__str__Nr?   r$   r$   r$   r%   r   ^  s   r   c                   @  s   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   q  s   r   c                   @  sD   e Zd ZdZddddddœdd„Zd	d
œdd„Zdd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.

    Nzint | None | strz
int | Noner&   )Úsize_or_messageÚmax_sizeÚcur_sizer*   c                 C  sh   t |tƒr6|d u sJ ‚|d u s"J ‚t dt¡ || _n.d | _|| _|d usNJ ‚|| _d | _|  	|¡ d S )NzMPayloadTooBig(message) is deprecated; change to PayloadTooBig(size, max_size))
Ú
isinstancer/   r4   r5   r6   ÚmessageÚsizer_   r`   Úset_current_size)r-   r^   r_   r`   r$   r$   r%   r.   ‰  s    
ýzPayloadTooBig.__init__r/   r0   c                 C  sf   | j d ur| j S d}| jd ur0|d| j› d�7 }| jd urL|d| j› d�7 }|d| j› d�7 }|S d S )Nzframe zwith z bytes zafter reading zexceeds limit of z bytes)rb   rc   r`   r_   )r-   rb   r$   r$   r%   r2      s    


zPayloadTooBig.__str__)r`   r*   c                 C  s.   | j d u sJ ‚|d ur*|  j|7  _|| _ d S r+   )r`   r_   )r-   r`   r$   r$   r%   rd   ¬  s    zPayloadTooBig.set_current_size)NN)r    r!   r"   r#   r.   r2   rd   r$   r$   r$   r%   r   }  s     ür   c                   @  s   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   ³  s   r   c                   @  s   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   Â  s   r   )r7   Úhttp11z.legacy.exceptions)ZAbortHandshakeZInvalidStatusCodeZRedirectHandshakeZWebSocketProtocolError)Zdeprecated_aliases)(r#   Ú
__future__r   r4   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   r9   r7   re   Úglobalsr$   r$   r$   r%   Ú<module>   sN   #B


	
6ûþ