U
    Ê¼µbJ"  ã                   @   sœ   d dl Z ddlmZ ddlT ddlT ddlmZmZmZ dd„ Zdd	„ Z	d
d„ Z
dd„ ZeeeedeiZdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )é    Né   )ÚLocalProtocolError)Ú*)ÚConnectionStateÚ_SWITCH_UPGRADEÚ_SWITCH_CONNECTc               	   C   s  t ƒ } | jttttikst‚|  tt¡ | jtttt	iks>t‚t
 t¡� |  tt¡ W 5 Q R X | jtttt	iksvt‚|  tt¡ | jtttt	iks˜t‚|  tt¡ | jttttiksºt‚|  tt¡ |  tt¡ | jttttiksèt‚|  tt¡ | jttttik�st‚d S ©N)r   ÚstatesÚCLIENTÚIDLEÚSERVERÚAssertionErrorÚprocess_eventÚRequestÚ	SEND_BODYÚSEND_RESPONSEÚpytestÚraisesr   ÚInformationalResponseÚResponseÚEndOfMessageÚDONEÚConnectionClosedÚ
MUST_CLOSEZCLOSED©Úcs© r   ú8/tmp/pip-unpacked-wheel-rko__zic/h11/tests/test_state.pyÚtest_ConnectionState   s     r   c                  C   sn   t ƒ } |  tt¡ |  ¡  |  tt¡ | jtttt	iks<t
‚|  tt¡ |  tt¡ | jttttiksjt
‚d S r   )r   r   r
   r   Úprocess_keep_alive_disabledr   r	   r   r   r   r   r   r   r   r   r   Útest_ConnectionState_keep_alive'   s    r    c                  C   sN   t ƒ } |  tt¡ |  tt¡ | jt tks0t‚|  ¡  | jt t	ksJt‚d S r   )
r   r   r
   r   r   r	   r   r   r   r   r   r   r   r   Ú'test_ConnectionState_keep_alive_in_DONE3   s    r!   c                  C   s  t tfD �] } dD ]ö}tƒ }| | ¡ | tt¡ | tt¡ |jtt	t
tiksTt‚| |jksbt‚|r|| t
t¡ |jr|t‚| tt¡ |r¤|jttt
t	iks¢t‚q|jttt
tiksºt‚| t
t¡ |jttt
tiksÜt‚| t
t¡ |jttt
t	iksþt‚|jrt‚qqd S )N)TF)r   r   r   Úprocess_client_switch_proposalr   r
   r   ÚDatar	   r   r   r   r   Zpending_switch_proposalsr   r   r   ÚMIGHT_SWITCH_PROTOCOLr   )Zswitch_typeZ
deny_earlyr   r   r   r   Ú"test_ConnectionState_switch_denied>   s4    

 ÿ
 ÿ
r%   c                  C   s¼   t tfD ]®} tƒ }| | ¡ | tt¡ | tt¡ |jtt	t
tiksJt‚| tt¡ |jttt
tikslt‚| t
t¡ |jttt
tiksŽt‚| t
t|  | ¡ |jttt
tikst‚qd S r   )r   r   r   r"   r   r
   r   r#   r	   r   r   r   r   r   r$   r   Ú_response_type_for_switchÚSWITCHED_PROTOCOL)Zswitch_eventr   r   r   r   Ú-test_ConnectionState_protocol_switch_acceptedd   s6    
 ÿ
 ÿ
 ÿ
þ ÿr(   c                  C   s¤   d t tfD ]”} tƒ }| t ¡ | t¡ | tt¡ | tt¡ |jtt	t
tiksVt‚| t
t|  | ¡ | d krˆ|jttt
tiksžt‚q
|jttt
tiks
t‚q
d S r   )r   r   r   r"   r   r
   r   r   r	   r$   r   r   r   r&   r   r   r'   )Úserver_switchr   r   r   r   Ú+test_ConnectionState_double_protocol_switch{   s(    

 ÿ
þ ÿr*   c               
   C   sx   g t fg tftgt ft gtffD ]R\} }tƒ }| D ]}| |¡ q2| tt¡ t t	¡� | t
t|¡ W 5 Q R X q d S r   )r   r   r   r"   r   r
   r   r   r   r   r   r   )Zclient_switchesr)   r   Zclient_switchr   r   r   Ú1test_ConnectionState_inconsistent_protocol_switch�   s    ür+   c                  C   sŽ   t ƒ } |  t¡ |  tt¡ |  ¡  |  tt¡ | jtt	t
tiksFt‚|  tt¡ | jttt
tiksht‚|  t
t¡ | jttt
t	iksŠt‚d S r   )r   r"   r   r   r
   r   r   r#   r	   r   r   r   r   r   r$   r   r   r   r   r   r   Ú:test_ConnectionState_keepalive_protocol_switch_interactionž   s    
r,   c               	   C   sþ  t ƒ } t t¡� |  ¡  W 5 Q R X |  tt¡ |  tt¡ t t¡� |  ¡  W 5 Q R X |  t	t
¡ |  t	t¡ |  ¡  | jttt	tiks�t‚|  tt¡ |  ¡  |  tt¡ |  t	t
¡ |  t	t¡ t t¡� |  ¡  W 5 Q R X t ƒ } |  tt¡ |  tt¡ |  tt¡ |  t	t
¡ |  t	t¡ t t¡� |  ¡  W 5 Q R X t ƒ } |  t¡ |  tt¡ |  tt¡ |  t	tt¡ t t¡� |  ¡  W 5 Q R X t ƒ } |  t¡ |  tt¡ |  tt¡ |  t	t
¡ |  t	t¡ |  ¡  | jttt	tik�sút‚d S r   )r   r   r   r   Zstart_next_cycler   r
   r   r   r   r   r	   r   r   r   r   r"   r   r   r   r   r   r   Útest_ConnectionState_reuse°   sR    

r-   c               	   C   s,   t ƒ } t t¡� |  tt¡ W 5 Q R X d S r   )r   r   r   r   r   r   r   r   r   r   r   Útest_server_request_is_illegalð   s    r.   )r   Z_utilr   Z_eventsÚ_stater   r   r   r   r    r!   r%   r   r   r&   r(   r*   r+   r,   r-   r.   r   r   r   r   Ú<module>   s*   !   ý@