o
    /h8(                     @  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
 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/d0 d0eZ G d1d2 d2ee!Z"G d3d4 d4eZ#G d5d6 d6eZ$G d7d8 d8e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                   @     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(   N/var/www/html/govbot/env/lib/python3.10/site-packages/websockets/exceptions.pyr	   E       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
   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.

    NrcvdOptional[frames.Close]sentrcvd_then_sentOptional[bool]returnNonec                 C  s   || _ || _|| _d S Nr+   r-   r.   )selfr+   r-   r.   r(   r(   r)   __init__[   s   
zConnectionClosed.__init__strc                 C  s   | j d u r!| jd u r| jd u sJ dS | jd u sJ d| j dS | jd u r4| jd u s-J d| j  dS | jd us;J | jrHd| 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   r4   r(   r(   r)   __str__e   s   


zConnectionClosed.__str__intc                 C  s   | j d u r	tjjS | j jS r2   )r+   r   	CloseCodeABNORMAL_CLOSUREcoder7   r(   r(   r)   r<   z   s   
zConnectionClosed.codec                 C  s   | j d u rdS | j jS )N )r+   reasonr7   r(   r(   r)   r>      s   
zConnectionClosed.reasonr2   )r+   r,   r-   r,   r.   r/   r0   r1   r0   r6   )r0   r9   )	r$   r%   r&   r'   r5   r8   propertyr<   r>   r(   r(   r(   r)   r
   L   s    

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                   @  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   zK
    Raised during the handshake when the WebSocket connection fails.

    Nr#   r(   r(   r(   r)   r      r*   r   c                   @  r"   )r   zs
    Raised when a handshake request or response breaks a security rule.

    Security limits are hard coded.

    Nr#   r(   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                   @  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namer6   valueOptional[str]r0   r1   c                 C     || _ || _d S r2   rA   rB   r4   rA   rB   r(   r(   r)   r5         
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: rB   rA   r7   r(   r(   r)   r8      s
   

zInvalidHeader.__str__r2   rA   r6   rB   rC   r0   r1   r?   r$   r%   r&   r'   r5   r8   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.

    rA   r6   errorheaderposr9   r0   r1   c                   s"   t  || d| d|  d S )Nz at z in superr5   )r4   rA   rK   rL   rM   	__class__r(   r)   r5      s   "zInvalidHeaderFormat.__init__)
rA   r6   rK   r6   rL   r6   rM   r9   r0   r1   r$   r%   r&   r'   r5   __classcell__r(   r(   rP   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 a 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.

    originrC   r0   r1   c                   s   t  d| d S )NOriginrN   )r4   rT   rP   r(   r)   r5         zInvalidOrigin.__init__)rT   rC   r0   r1   rR   r(   r(   rP   r)   r      s    r   c                   @  r"   )r   zF
    Raised when the Upgrade or Connection header isn't correct.

    Nr#   r(   r(   r(   r)   r      r*   r   c                   @  s$   e Zd ZdZdddZdd	d
ZdS )r   zJ
    Raised when a handshake response rejects the WebSocket upgrade.

    responsehttp11.Responser0   r1   c                 C  
   || _ d S r2   )rW   )r4   rW   r(   r(   r)   r5         
zInvalidStatus.__init__r6   c                 C  s   d| j jdS )N+server rejected WebSocket connection: HTTP d)rW   status_coder7   r(   r(   r)   r8      s   zInvalidStatus.__str__N)rW   rX   r0   r1   r?   rJ   r(   r(   r(   r)   r          
r   c                   @  s$   e Zd ZdZddd	ZdddZdS )r   zC
    Raised when a handshake response status code is invalid.

    r]   r9   headersdatastructures.Headersr0   r1   c                 C  rD   r2   )r]   r_   )r4   r]   r_   r(   r(   r)   r5     rG   zInvalidStatusCode.__init__r6   c                 C     d| j  S )Nr[   )r]   r7   r(   r(   r)   r8        zInvalidStatusCode.__str__N)r]   r9   r_   r`   r0   r1   r?   rJ   r(   r(   r(   r)   r          
r   c                   @  r"   )r   z6
    Raised when negotiating an extension 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.

    rA   r6   r0   r1   c                 C  rY   r2   rA   r4   rA   r(   r(   r)   r5     rZ   zDuplicateParameter.__init__c                 C  ra   )Nzduplicate parameter: re   r7   r(   r(   r)   r8     rb   zDuplicateParameter.__str__NrA   r6   r0   r1   r?   rJ   r(   r(   r(   r)   r     r^   r   c                   @  rd   )r   zJ
    Raised when a parameter name in an extension header is invalid.

    rA   r6   r0   r1   c                 C  rY   r2   re   rf   r(   r(   r)   r5   #  rZ   zInvalidParameterName.__init__c                 C  ra   )Nzinvalid parameter name: re   r7   r(   r(   r)   r8   &  rb   zInvalidParameterName.__str__Nrg   r?   rJ   r(   r(   r(   r)   r     r^   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.

    rA   r6   rB   rC   r0   r1   c                 C  rD   r2   rE   rF   r(   r(   r)   r5   0  rG   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: rH   r7   r(   r(   r)   r8   4  s
   

zInvalidParameterValue.__str__NrI   r?   rJ   r(   r(   r(   r)   r   *  rc   r   c                   @  s(   e Zd ZdZ	ddddZ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.
        statusr   r_   datastructures.HeadersLikebodybytesr0   r1   c                 C  s"   t || _t|| _|| _d S r2   )http
HTTPStatusri   r   Headersr_   rk   )r4   ri   r_   rk   r(   r(   r)   r5   L  s   
zAbortHandshake.__init__r6   c                 C  s(   d| j ddt| j dt| j dS )NzHTTP r\   z, z
 headers, z bytes)ri   lenr_   rk   r7   r(   r(   r)   r8   W  s   zAbortHandshake.__str__N)rh   )ri   r   r_   rj   rk   rl   r0   r1   r?   rJ   r(   r(   r(   r)   r   =  s
    r   c                   @  rd   )r   zd
    Raised when a handshake gets redirected.

    This exception is an implementation detail.

    urir6   r0   r1   c                 C  rY   r2   rq   )r4   rq   r(   r(   r)   r5   g  rZ   zRedirectHandshake.__init__c                 C  ra   )Nzredirect to rr   r7   r(   r(   r)   r8   j  rb   zRedirectHandshake.__str__N)rq   r6   r0   r1   r?   rJ   r(   r(   r(   r)   r   _  s    
r   c                   @  r"   )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  r*   r   c                   @  s$   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.

    rq   r6   msgr0   r1   c                 C  rD   r2   rq   rs   )r4   rq   rs   r(   r(   r)   r5     rG   zInvalidURI.__init__c                 C  s   | j  d| j S )Nz isn't a valid URI: rt   r7   r(   r(   r)   r8     rV   zInvalidURI.__str__N)rq   r6   rs   r6   r0   r1   r?   rJ   r(   r(   r(   r)   r   y  rc   r   c                   @  r"   )r   zS
    Raised when receiving a frame with a payload exceeding the maximum size.

    Nr#   r(   r(   r(   r)   r     r*   r   c                   @  r"   )r    z3
    Raised when a frame breaks the protocol.

    Nr#   r(   r(   r(   r)   r      r*   r    )'r'   
__future__r   rm   typingr   r=   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   AssertionErrorr   r   r   r    r!   r(   r(   r(   r)   <module>   s@    ;

		
"