a
    یxd'                     @  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	 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 d0d1 d1ee Z!G d2d3 d3eZ"G d4d5 d5eZ#G d6d7 d7eZ$e$Z%dS )8ay  
: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)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&   M/var/www/html/Ranjet/env/lib/python3.9/site-packages/websockets/exceptions.pyr   D   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	   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__Z   s    zConnectionClosed.__init__strr,   c                 C  s   | j d u rD| jd u r&| jd u s"J dS | jd u s4J d| j dS nb| jd u rj| jd u s\J d| j  dS | jd usxJ | 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&   r&   r'   __str__d   s    


zConnectionClosed.__str__intc                 C  s   | j d u rdS | j jS )Ni  )r)   coder3   r&   r&   r'   r6   y   s    
zConnectionClosed.codec                 C  s   | j d u rdS | j jS )N )r)   reasonr3   r&   r&   r'   r8      s    
zConnectionClosed.reason)N)	r"   r#   r$   r%   r0   r4   propertyr6   r8   r&   r&   r&   r'   r	   K   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                   @  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   zK
    Raised during the handshake when the WebSocket connection fails.

    Nr!   r&   r&   r&   r'   r      s   r   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   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                   @  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 u rd| j dS | j dkr0d| j dS d| j d| j  S d S )Nzmissing z headerr7   zempty zinvalid z	 header: r=   r<   r3   r&   r&   r'   r4      s
    

zInvalidHeader.__str__)Nr"   r#   r$   r%   r0   r4   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.

    r1   r5   r(   )r<   errorheaderposr,   c                   s"   t  || d| d|  d S )Nz at z in superr0   )r/   r<   rB   rC   rD   	__class__r&   r'   r0      s    zInvalidHeaderFormat.__init__r"   r#   r$   r%   r0   __classcell__r&   r&   rG   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 a 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.

    r:   r(   )originr,   c                   s   t  d| d S )NZOriginrE   )r/   rK   rG   r&   r'   r0      s    zInvalidOrigin.__init__rI   r&   r&   rG   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      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.

    zhttp11.Responser(   )responser,   c                 C  s
   || _ d S r-   )rL   )r/   rL   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)rL   status_coder3   r&   r&   r'   r4      s    zInvalidStatus.__str__NrA   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   zC
    Raised when a handshake response status code is invalid.

    r5   zdatastructures.Headersr(   )rO   headersr,   c                 C  s   || _ || _d S r-   )rO   rP   )r/   rO   rP   r&   r&   r'   r0      s    zInvalidStatusCode.__init__r1   r2   c                 C  s   d| j  S )NrM   )rO   r3   r&   r&   r'   r4     s    zInvalidStatusCode.__str__NrA   r&   r&   r&   r'   r      s   r   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   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.

    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: rR   r3   r&   r&   r'   r4     s    zDuplicateParameter.__str__NrA   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 parameter name in an extension header is invalid.

    r1   r(   rQ   c                 C  s
   || _ d S r-   rR   rS   r&   r&   r'   r0   "  s    zInvalidParameterName.__init__r2   c                 C  s   d| j  S )Nzinvalid parameter name: rR   r3   r&   r&   r'   r4   %  s    zInvalidParameterName.__str__NrA   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   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   /  s    zInvalidParameterValue.__init__r2   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 r7   zempty value for parameter zinvalid value for parameter z: r@   r3   r&   r&   r'   r4   3  s
    

zInvalidParameterValue.__str__NrA   r&   r&   r&   r'   r   )  s   r   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.
        zhttp.HTTPStatuszdatastructures.HeadersLikebytesr(   )statusrP   bodyr,   c                 C  s   || _ t|| _|| _d S r-   )rV   r   ZHeadersrP   rW   )r/   rV   rP   rW   r&   r&   r'   r0   K  s    zAbortHandshake.__init__r1   r2   c                 C  s(   d| j ddt| j dt| j dS )NzHTTP rN   z, z
 headers, z bytes)rV   lenrP   rW   r3   r&   r&   r'   r4   U  s    zAbortHandshake.__str__N)rT   rA   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   zd
    Raised when a handshake gets redirected.

    This exception is an implementation detail.

    r1   r(   )urir,   c                 C  s
   || _ d S r-   rY   )r/   rY   r&   r&   r'   r0   e  s    zRedirectHandshake.__init__r2   c                 C  s   d| j  S )Nzredirect to rZ   r3   r&   r&   r'   r4   h  s    zRedirectHandshake.__str__NrA   r&   r&   r&   r'   r   ]  s   r   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   l  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.

    r1   r(   )rY   msgr,   c                 C  s   || _ || _d S r-   rY   r[   )r/   rY   r[   r&   r&   r'   r0   }  s    zInvalidURI.__init__r2   c                 C  s   | j  d| j S )Nz isn't a valid URI: r\   r3   r&   r&   r'   r4     s    zInvalidURI.__str__NrA   r&   r&   r&   r'   r   w  s   r   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   r   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   )&r%   
__future__r   httptypingr   r7   r   r   r   __all__	Exceptionr   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   AssertionErrorr   r   r   r   r    r&   r&   r&   r'   <module>   s<   ;

		
!