U
    Ê¼µbi  ã                   @   s°   d dl Z d dlZd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zee d¡ƒj	Z
W n ek
r€   dd„ Z
Y nX ddd„ZG dd„ deƒZdd„ Zdd„ ZdS )é    NÚProtocolErrorÚLocalProtocolErrorÚRemoteProtocolErrorÚvalidateÚmake_sentinelÚbytesifyc                   @   s   e Zd ZdZ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.

    é�  c                 C   s*   t | ƒtkrtdƒ‚t | |¡ || _d S )Nz+tried to directly instantiate ProtocolError)Útyper   Ú	TypeErrorÚ	ExceptionÚ__init__Úerror_status_hint)ÚselfÚmsgr   © r   ú-/tmp/pip-unpacked-wheel-rko__zic/h11/_util.pyr   #   s    zProtocolError.__init__N)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r      s   c                   @   s   e Zd Zdd„ ZdS )r   c                 C   s&   t | _tjd dkr| ‚ntdƒ d S )Nr   é   z2raise RemoteProtocolError, self, sys.exc_info()[2])r   Ú	__class__ÚsysÚversion_infoÚexec©r   r   r   r   Ú!_reraise_as_remote_protocol_error6   s    z4LocalProtocolError._reraise_as_remote_protocol_errorN)r   r   r   r   r   r   r   r   r   5   s   c                   @   s   e Zd ZdS )r   N)r   r   r   r   r   r   r   r   O   s   Ú c                 C   s&   |   |¡}|r"| ¡ t|ƒkr"d }|S ©N)ÚmatchÚendÚlen)ÚregexÚdatar   r   r   r   Ú
_fullmatchU   s    
r$   úmalformed datac                 G   s,   t | |ƒ}|s$|r|j|Ž }t|ƒ‚| ¡ S r   )r$   Úformatr   Ú	groupdict)r"   r#   r   Zformat_argsr   r   r   r   r   [   s    

c                   @   s   e Zd Zdd„ ZdS )Ú_SentinelBasec                 C   s   | j S r   )r   r   r   r   r   Ú__repr__l   s    z_SentinelBase.__repr__N)r   r   r   r)   r   r   r   r   r(   k   s   r(   c                 C   s   t | t fi ƒ}||_|S r   )r(   r   )ÚnameÚclsr   r   r   r   o   s    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Ú
isinstanceÚstrÚencodeÚintr
   )Úsr   r   r   r   w   s    


)r%   )r   ÚreÚ__all__r   r   r   r   r	   ÚcompileÚ	fullmatchr$   ÚAttributeErrorr   r(   r   r   r   r   r   r   Ú<module>   s"     ÿ.
