U
    g                     @   s   d dl mZmZmZmZmZmZmZmZ 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dee eeeeeef dddZedddZG dd deZeeeeeef edddZdS )    )AnyDictNoReturnPatternTupleTypeTypeVarUnionProtocolErrorLocalProtocolErrorRemoteProtocolErrorvalidatebytesifyc                   @   s$   e Zd ZdZdeeddddZdS )r
   aM  Exception indicating a violation of the HTTP/1.1 protocol.

    This as an abstract base class, with two concrete base classes:
    :exc:`LocalProtocolError`, which indicates that you tried to do something
    that HTTP/1.1 says is illegal, and :exc:`RemoteProtocolError`, which
    indicates that the remote peer tried to do something that HTTP/1.1 says is
    illegal. See :ref:`error-handling` for details.

    In addition to the normal :exc:`Exception` features, it has one attribute:

    .. attribute:: error_status_hint

       This gives a suggestion as to what status code a server might use if
       this error occurred as part of a request.

       For a :exc:`RemoteProtocolError`, this is useful as a suggestion for
       how you might want to respond to a misbehaving peer, if you're
       implementing a server.

       For a :exc:`LocalProtocolError`, this can be taken as a suggestion for
       how your peer might have responded to *you* if h11 had allowed you to
       continue.

       The default is 400 Bad Request, a generic catch-all for protocol
       violations.

      N)msgerror_status_hintreturnc                 C   s*   t | tkrtdt| | || _d S )Nz+tried to directly instantiate ProtocolError)typer
   	TypeError	Exception__init__r   )selfr   r    r   -/tmp/pip-unpacked-wheel-ib4s2i_e/h11/_util.pyr   )   s    zProtocolError.__init__)r   )__name__
__module____qualname____doc__strintr   r   r   r   r   r
      s   c                   @   s   e Zd ZedddZdS )r   r   c                 C   s   t | _| d S N)r   	__class__r   r   r   r   !_reraise_as_remote_protocol_error<   s    
z4LocalProtocolError._reraise_as_remote_protocol_errorN)r   r   r   r   r$   r   r   r   r   r   ;   s   c                   @   s   e Zd ZdS )r   N)r   r   r   r   r   r   r   r   P   s   malformed data)regexdatar   format_argsr   c                 G   s,   |  |}|s$|r|j| }t|| S r!   )	fullmatchformatr   	groupdict)r&   r'   r   r(   matchr   r   r   r   T   s    

_T_SentinelSentinel)boundc                       sN   e Zd Zee eeedf eee	f e	ed fddZ
edddZ  ZS )r.   .)clsnamebases	namespacekwdsr   c                    s.   |t fkstt j| |||f|}||_|S r!   )r.   AssertionErrorsuper__new__r"   )r0   r1   r2   r3   r4   vr"   r   r   r7   l   s    zSentinel.__new__r    c                 C   s   | j S r!   )r   r#   r   r   r   __repr__x   s    zSentinel.__repr__)r   r   r   r   r-   r   r   r   r   r   r7   r:   __classcell__r   r   r9   r   r.   k   s   

)sr   c                 C   s>   t | tkr| S t| tr$| d} t| tr6tdt| S )Nasciiz#expected bytes-like object, not int)r   bytes
isinstancer   encoder   r   )r<   r   r   r   r      s    


N)r%   )typingr   r   r   r   r   r   r   r	   __all__r   r
   r   r   r>   r   r   r-   r   r.   	bytearray
memoryviewr   r   r   r   r   r   <module>   s(   (	/    
