
    =XcA'                    Z   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	e      Z G d
 de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d de      Z G d  d!e      Z G d" d#e      Z G d$ d%e      Z G d& d'e      Z G d( d)e      Z G d* d+e      Z G d, d-e      Z G d. d/e      Z G d0 d1ee       Z! G d2 d3e      Z" G d4 d5e      Z# G d6 d7e      Z$e$Z%y)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                      e Zd ZdZy)r	   z?
    Base class for all exceptions defined by websockets.

    N__name__
__module____qualname____doc__     7/usr/lib/python3/dist-packages/websockets/exceptions.pyr	   r	   D       r)   r	   c                  V    e Zd ZdZ	 d	 	 	 	 	 	 	 ddZd	dZed
d       Zed	d       Zy)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.

    Nc                .    || _         || _        || _        y Nrcvdsentrcvd_then_sent)selfr0   r1   r2   s       r*   __init__zConnectionClosed.__init__Z   s     		,r)   c                   | j                   9| j                  | j                  J y| j                  J d| j                   dS | j                  | j                  J d| j                    dS | j                  J | 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 r/   r3   s    r*   __str__zConnectionClosed.__str__d   s    99yy **2228**222tyyk)BCCyy **222"499+-BCC**666&&&tyykdii[II"499+-=dii[IIr)   c                J    | j                   dS | j                   j                  S )Ni  )r0   coder6   s    r*   r9   zConnectionClosed.codey   s    yy(t<diinn<r)   c                J    | j                   dS | j                   j                  S )N )r0   reasonr6   s    r*   r<   zConnectionClosed.reason}   s     YY&r<DII,<,<<r)   r.   )r0   Optional[frames.Close]r1   r=   r2   zOptional[bool]returnNoner>   str)r>   int)	r$   r%   r&   r'   r4   r7   propertyr9   r<   r(   r)   r*   r
   r
   K   se    $ *.	-$- %- '	-
 
-J* = = = =r)   r
   c                      e Zd ZdZy)r   z
    Like :exc:`ConnectionClosed`, when the connection terminated with an error.

    A close 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)   r   c                      e Zd ZdZy)r   z
    Like :exc:`ConnectionClosed`, when the connection terminated properly.

    A close code 1000 (OK) or 1001 (going away) was received and sent.

    Nr#   r(   r)   r*   r   r          r)   r   c                      e Zd ZdZy)r   zK
    Raised during the handshake when the WebSocket connection fails.

    Nr#   r(   r)   r*   r   r      r+   r)   r   c                      e Zd ZdZy)r   zs
    Raised when a handshake request or response breaks a security rule.

    Security limits are hard coded.

    Nr#   r(   r)   r*   r   r      rF   r)   r   c                      e Zd ZdZy)r   zD
    Raised when a handshake request or response is malformed.

    Nr#   r(   r)   r*   r   r      r+   r)   r   c                  "    e Zd ZdZdddZddZy)r   zJ
    Raised when a HTTP header doesn't have a valid format or value.

    Nc                     || _         || _        y r.   namevaluer3   rM   rN   s      r*   r4   zInvalidHeader.__init__       	
r)   c                    | j                   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: rN   rM   r6   s    r*   r7   zInvalidHeader.__str__   sY    ::dii[00ZZ2DII;g..dii[	$**>>r)   r.   rM   rA   rN   Optional[str]r>   r?   r@   r$   r%   r&   r'   r4   r7   r(   r)   r*   r   r      s    
?r)   r   c                  $     e Zd ZdZd fdZ xZS )r   z
    Raised when a HTTP header cannot be parsed.

    The format of the header doesn't match the grammar for that header.

    c                6    t         |   || d| d|        y )Nz at z in superr4   )r3   rM   errorheaderpos	__class__s        r*   r4   zInvalidHeaderFormat.__init__   s#    %SEfX>?r)   )
rM   rA   rZ   rA   r[   rA   r\   rB   r>   r?   r$   r%   r&   r'   r4   __classcell__r]   s   @r*   r   r      s    @ @r)   r   c                      e Zd ZdZy)r   z~
    Raised when a 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      rF   r)   r   c                  $     e Zd ZdZd fdZ xZS )r   zD
    Raised when the Origin header in a request isn't allowed.

    c                &    t         |   d|       y )NOriginrX   )r3   originr]   s     r*   r4   zInvalidOrigin.__init__   s    6*r)   )re   rT   r>   r?   r^   r`   s   @r*   r   r      s    
+ +r)   r   c                      e Zd ZdZy)r   zF
    Raised when the Upgrade or Connection header isn't correct.

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

    c                    || _         y r.   )response)r3   ri   s     r*   r4   zInvalidStatus.__init__   s	     r)   c                6    d| j                   j                  dS )N+server rejected WebSocket connection: HTTP d)ri   status_coder6   s    r*   r7   zInvalidStatus.__str__   s#    MM--a02	
r)   N)ri   zhttp11.Responser>   r?   r@   rU   r(   r)   r*   r   r      s    
!
r)   r   c                       e Zd ZdZddZddZy)r   zC
    Raised when a handshake response status code is invalid.

    c                     || _         || _        y r.   )rm   headers)r3   rm   rp   s      r*   r4   zInvalidStatusCode.__init__   s    &r)   c                     d| j                    S )Nrk   )rm   r6   s    r*   r7   zInvalidStatusCode.__str__   s    <T=M=M<NOOr)   N)rm   rB   rp   zdatastructures.Headersr>   r?   r@   rU   r(   r)   r*   r   r      s    
Pr)   r   c                      e Zd ZdZy)r   z6
    Raised when negotiating an extension fails.

    Nr#   r(   r)   r*   r   r     r+   r)   r   c                       e Zd ZdZddZddZy)r   zK
    Raised when a parameter name is repeated in an extension header.

    c                    || _         y r.   rM   r3   rM   s     r*   r4   zDuplicateParameter.__init__  	    	r)   c                     d| j                    S )Nzduplicate parameter: ru   r6   s    r*   r7   zDuplicateParameter.__str__  s    &tyyk22r)   NrM   rA   r>   r?   r@   rU   r(   r)   r*   r   r   
  s    
3r)   r   c                       e Zd ZdZddZddZy)r   zJ
    Raised when a parameter name in an extension header is invalid.

    c                    || _         y r.   ru   rv   s     r*   r4   zInvalidParameterName.__init__  rw   r)   c                     d| j                    S )Nzinvalid parameter name: ru   r6   s    r*   r7   zInvalidParameterName.__str__   s    )$))55r)   Nry   r@   rU   r(   r)   r*   r   r     s    
6r)   r   c                       e Zd ZdZddZddZy)r   zK
    Raised when a parameter value in an extension header is invalid.

    c                     || _         || _        y r.   rL   rO   s      r*   r4   zInvalidParameterValue.__init__*  rP   r)   c                    | j                   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: rR   r6   s    r*   r7   zInvalidParameterValue.__str__.  sU    ::1$))==ZZ2/		{;;1$))BtzzlKKr)   NrS   r@   rU   r(   r)   r*   r   r   $  s    
Lr)   r   c                  2    e Zd ZdZ	 d	 	 	 	 	 	 	 ddZddZy)r   a  
    Raised to abort the handshake on purpose and return a 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.
    c                T    || _         t        j                  |      | _        || _        y r.   )statusr   Headersrp   body)r3   r   rp   r   s       r*   r4   zAbortHandshake.__init__F  s$     %--g6	r)   c                |    d| j                   ddt        | j                         dt        | j                         dS )NzHTTP rl   z, z
 headers, z bytes)r   lenrp   r   r6   s    r*   r7   zAbortHandshake.__str__P  s<    DKK?"4<< !499~f&	
r)   N)r)   )r   zhttp.HTTPStatusrp   zdatastructures.HeadersLiker   bytesr>   r?   r@   rU   r(   r)   r*   r   r   7  s<    $ 	 , 	
 

r)   r   c                       e Zd ZdZddZddZy)r   zd
    Raised when a handshake gets redirected.

    This exception is an implementation detail.

    c                    || _         y r.   uri)r3   r   s     r*   r4   zRedirectHandshake.__init__`  s	    r)   c                     d| j                    S )Nzredirect to r   r6   s    r*   r7   zRedirectHandshake.__str__c  s    dhhZ((r)   N)r   rA   r>   r?   r@   rU   r(   r)   r*   r   r   X  s    )r)   r   c                      e Zd ZdZy)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   g  s    r)   r   c                       e Zd ZdZddZddZy)r   zM
    Raised when connecting to an URI that isn't a valid WebSocket URI.

    c                     || _         || _        y r.   r   msg)r3   r   r   s      r*   r4   zInvalidURI.__init__x  s    r)   c                8    | j                    d| j                   S )Nz isn't a valid URI: r   r6   s    r*   r7   zInvalidURI.__str__|  s    ((/z::r)   N)r   rA   r   rA   r>   r?   r@   rU   r(   r)   r*   r   r   r  s    
;r)   r   c                      e Zd ZdZy)r   zS
    Raised when receiving a frame with a payload exceeding the maximum size.

    Nr#   r(   r)   r*   r   r     r+   r)   r   c                      e Zd ZdZy)r    z3
    Raised when a frame breaks the protocol.

    Nr#   r(   r)   r*   r    r      r+   r)   r    )&r'   
__future__r   httptypingr   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*   <module>r      sg  < #   , ,: 4=) 4=n, ) ) $ % ?$ ?&	@- 	@ +M +] 
$ 
 P( P' 
3) 
3
6+ 
6L, L&
% 
B)( )%~ ;# ;& &  ' r)   