U
    g                     @   st   d dl Z ddlmZ ddlmZmZ ddlm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dS )    N   )datastructures)InvalidHandshakeProtocolError)
StatusLikec                   @   s   e Zd ZdZdS )InvalidMessagezD
    Raised when a handshake request or response is malformed.

    N)__name__
__module____qualname____doc__ r   r   @/tmp/pip-unpacked-wheel-dx_q7dq3/websockets/legacy/exceptions.pyr      s   r   c                   @   s2   e Zd ZdZeejddddZedddZ	dS )	InvalidStatusCodezC
    Raised when a handshake response status code is invalid.

    N)status_codeheadersreturnc                 C   s   || _ || _d S N)r   r   )selfr   r   r   r   r   __init__   s    zInvalidStatusCode.__init__r   c                 C   s   d| j  S )Nz+server rejected WebSocket connection: HTTP )r   r   r   r   r   __str__   s    zInvalidStatusCode.__str__)
r   r	   r
   r   intr   Headersr   strr   r   r   r   r   r      s   r   c                   @   s6   e Zd ZdZd
eejeddddZe	ddd	Z
dS )AbortHandshakea  
    Raised to abort the handshake on purpose and return an HTTP response.

    This exception is an implementation detail.

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

    Attributes:
        status (~http.HTTPStatus): HTTP status code.
        headers (Headers): HTTP response headers.
        body (bytes): HTTP response body.
        N)statusr   bodyr   c                 C   s"   t || _t|| _|| _d S r   )http
HTTPStatusr   r   r   r   r   )r   r   r   r   r   r   r   r   /   s    zAbortHandshake.__init__r   c                 C   s(   d| j ddt| j dt| j dS )NzHTTP dz, z
 headers, z bytes)r   lenr   r   r   r   r   r   r   :   s    &zAbortHandshake.__str__)r   )r   r	   r
   r   r   r   ZHeadersLikebytesr   r   r   r   r   r   r   r       s    r   c                   @   s.   e Zd ZdZeddddZedddZdS )	RedirectHandshakezd
    Raised when a handshake gets redirected.

    This exception is an implementation detail.

    N)urir   c                 C   s
   || _ d S r   r%   )r   r%   r   r   r   r   J   s    zRedirectHandshake.__init__r   c                 C   s   d| j  S )Nzredirect to r&   r   r   r   r   r   M   s    zRedirectHandshake.__str__)r   r	   r
   r   r   r   r   r   r   r   r   r$   B   s   r$   )r    r   
exceptionsr   r   ZWebSocketProtocolErrortypingr   r   r   r   r$   r   r   r   r   <module>   s   "