U
    <{f8(                     @  s  d Z ddlmZ ddlZddlmZ ddlmZmZm	Z	 ddlm
Z
 dd	d
dddddddddddddddddddddd g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 d0d deZG d1d deZG d2d deZG d3d deZG d4d deZ G d5d dee!Z"G d6d deZ#G d7d deZ$G d8d deZ%e%Z&dS )9ay  
:mod:`websockets.exceptions` defines the following exception hierarchy:

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

    )annotationsN)Optional   )datastructuresframeshttp11)
StatusLikeWebSocketExceptionConnectionClosedConnectionClosedErrorConnectionClosedOKInvalidHandshakeSecurityErrorInvalidMessageInvalidHeaderInvalidHeaderFormatInvalidHeaderValueInvalidOriginInvalidUpgradeInvalidStatusInvalidStatusCodeNegotiationErrorDuplicateParameterInvalidParameterNameInvalidParameterValueAbortHandshakeRedirectHandshakeInvalidState
InvalidURIPayloadTooBigProtocolErrorWebSocketProtocolErrorc                   @  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'   T/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/websockets/exceptions.pyr	   E   s   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
   aG  
    Raised when trying to interact with a closed connection.

    Attributes:
        rcvd (Optional[Close]): if a close frame was received, its code and
            reason are available in ``rcvd.code`` and ``rcvd.reason``.
        sent (Optional[Close]): if a close frame was sent, its code and reason
            are available in ``sent.code`` and ``sent.reason``.
        rcvd_then_sent (Optional[bool]): 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Optional[frames.Close]zOptional[bool]None)rcvdsentrcvd_then_sentreturnc                 C  s   || _ || _|| _d S N)r*   r+   r,   )selfr*   r+   r,   r'   r'   r(   __init__[   s    zConnectionClosed.__init__strr-   c                 C  s   | j d krD| jd kr&| jd ks"tdS | jd ks4td| j dS nb| jd krj| jd ks\td| j  dS | jd k	sxt| jrd| 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,   AssertionErrorr/   r'   r'   r(   __str__e   s    


zConnectionClosed.__str__intc                 C  s   | j d krtjjS | j jS r.   )r*   r   Z	CloseCodeZABNORMAL_CLOSUREcoder4   r'   r'   r(   r7   z   s    
zConnectionClosed.codec                 C  s   | j d krdS | j jS )N )r*   reasonr4   r'   r'   r(   r9      s    
zConnectionClosed.reason)N)	r#   r$   r%   r&   r0   r5   propertyr7   r9   r'   r'   r'   r(   r
   L   s    
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   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   c                   @  s   e Zd ZdZdS )r   zK
    Raised during the handshake when the WebSocket connection fails.

    Nr"   r'   r'   r'   r(   r      s   c                   @  s   e Zd ZdZdS )r   zs
    Raised when a handshake request or response breaks a security rule.

    Security limits are hard coded.

    Nr"   r'   r'   r'   r(   r      s   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   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.

    Nr1   Optional[str]r)   namevaluer-   c                 C  s   || _ || _d S r.   r=   r>   r/   r=   r>   r'   r'   r(   r0      s    zInvalidHeader.__init__r2   c                 C  sH   | j d krd| j dS | j dkr0d| j dS d| j d| j  S d S )Nzmissing z headerr8   zempty zinvalid z	 header: r>   r=   r4   r'   r'   r(   r5      s
    

zInvalidHeader.__str__)Nr#   r$   r%   r&   r0   r5   r'   r'   r'   r(   r      s   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.

    r1   r6   r)   )r=   errorheaderposr-   c                   s"   t  || d| d|  d S )Nz at z in superr0   )r/   r=   rC   rD   rE   	__class__r'   r(   r0      s    zInvalidHeaderFormat.__init__r#   r$   r%   r&   r0   __classcell__r'   r'   rH   r(   r      s   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 a value isn't acceptable.

    Nr"   r'   r'   r'   r(   r      s   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.

    r;   r)   )originr-   c                   s   t  d| d S )NZOriginrF   )r/   rL   rH   r'   r(   r0      s    zInvalidOrigin.__init__rJ   r'   r'   rH   r(   r      s   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      s   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.

    zhttp11.Responser)   )responser-   c                 C  s
   || _ d S r.   )rM   )r/   rM   r'   r'   r(   r0      s    zInvalidStatus.__init__r1   r2   c                 C  s   d| j jdS )N+server rejected WebSocket connection: HTTP d)rM   status_coder4   r'   r'   r(   r5      s    zInvalidStatus.__str__NrB   r'   r'   r'   r(   r      s   c                   @  s0   e Zd ZdZddddddZdd	d
dZdS )r   zC
    Raised when a handshake response status code is invalid.

    r6   zdatastructures.Headersr)   )rP   headersr-   c                 C  s   || _ || _d S r.   )rP   rQ   )r/   rP   rQ   r'   r'   r(   r0     s    zInvalidStatusCode.__init__r1   r2   c                 C  s   d| j  S )NrN   )rP   r4   r'   r'   r(   r5     s    zInvalidStatusCode.__str__NrB   r'   r'   r'   r(   r      s   c                   @  s   e Zd ZdZdS )r   z6
    Raised when negotiating an extension fails.

    Nr"   r'   r'   r'   r(   r   	  s   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.

    r1   r)   r=   r-   c                 C  s
   || _ d S r.   r=   r/   r=   r'   r'   r(   r0     s    zDuplicateParameter.__init__r2   c                 C  s   d| j  S )Nzduplicate parameter: rS   r4   r'   r'   r(   r5     s    zDuplicateParameter.__str__NrB   r'   r'   r'   r(   r     s   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.

    r1   r)   rR   c                 C  s
   || _ d S r.   rS   rT   r'   r'   r(   r0   #  s    zInvalidParameterName.__init__r2   c                 C  s   d| j  S )Nzinvalid parameter name: rS   r4   r'   r'   r(   r5   &  s    zInvalidParameterName.__str__NrB   r'   r'   r'   r(   r     s   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.

    r1   r;   r)   r<   c                 C  s   || _ || _d S r.   r?   r@   r'   r'   r(   r0   0  s    zInvalidParameterValue.__init__r2   c                 C  sD   | j d krd| j S | j dkr,d| j S d| j d| j  S d S )Nzmissing value for parameter r8   zempty value for parameter zinvalid value for parameter z: rA   r4   r'   r'   r(   r5   4  s
    

zInvalidParameterValue.__str__NrB   r'   r'   r'   r(   r   *  s   c                   @  s4   e Zd ZdZdddddddd	Zd
dddZdS )r   a  
    Raised to abort the handshake on purpose and return an HTTP response.

    This exception is an implementation detail.

    The public API
    is :meth:`~websockets.server.WebSocketServerProtocol.process_request`.

    Attributes:
        status (~http.HTTPStatus): HTTP status code.
        headers (Headers): HTTP response headers.
        body (bytes): HTTP response body.
        r   zdatastructures.HeadersLikebytesr)   )statusrQ   bodyr-   c                 C  s"   t || _t|| _|| _d S r.   )http
HTTPStatusrW   r   ZHeadersrQ   rX   )r/   rW   rQ   rX   r'   r'   r(   r0   L  s    zAbortHandshake.__init__r1   r2   c                 C  s(   d| j ddt| j dt| j dS )NzHTTP rO   z, z
 headers, z bytes)rW   lenrQ   rX   r4   r'   r'   r(   r5   W  s    &zAbortHandshake.__str__N)rU   rB   r'   r'   r'   r(   r   =  s    c                   @  s.   e Zd ZdZdddddZdddd	Zd
S )r   zd
    Raised when a handshake gets redirected.

    This exception is an implementation detail.

    r1   r)   )urir-   c                 C  s
   || _ d S r.   r\   )r/   r\   r'   r'   r(   r0   g  s    zRedirectHandshake.__init__r2   c                 C  s   d| j  S )Nzredirect to r]   r4   r'   r'   r(   r5   j  s    zRedirectHandshake.__str__NrB   r'   r'   r'   r(   r   _  s   c                   @  s   e Zd ZdZdS )r   z
    Raised when an operation is forbidden in the current state.

    This exception is an implementation detail.

    It should never be raised in normal circumstances.

    Nr"   r'   r'   r'   r(   r   n  s   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.

    r1   r)   )r\   msgr-   c                 C  s   || _ || _d S r.   r\   r^   )r/   r\   r^   r'   r'   r(   r0     s    zInvalidURI.__init__r2   c                 C  s   | j  d| j S )Nz isn't a valid URI: r_   r4   r'   r'   r(   r5     s    zInvalidURI.__str__NrB   r'   r'   r'   r(   r   y  s   c                   @  s   e Zd ZdZdS )r   zS
    Raised when receiving a frame with a payload exceeding the maximum size.

    Nr"   r'   r'   r'   r(   r     s   c                   @  s   e Zd ZdZdS )r    z3
    Raised when a frame breaks the protocol.

    Nr"   r'   r'   r'   r(   r      s   )'r&   
__future__r   rY   typingr   r8   r   r   r   r   __all__	Exceptionr	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r3   r   r   r   r    r!   r'   r'   r'   r(   <module>   sp   ;

		
"