a
     ÑOc)  ã                   @   s¶   d Z ddlZddlmZmZmZ ddlZddlmZ ddl	m
Z
 ddlmZmZ ddlmZmZmZmZmZmZ dd	lmZ dd
lmZmZ ddlmZmZmZmZ G dd„ dƒZdS )zWebSocket client for asyncio.é    N)ÚAnyÚOptionalÚcasté   )ÚClientError)ÚClientResponse)Ú
call_laterÚ
set_result)ÚWS_CLOSED_MESSAGEÚWS_CLOSING_MESSAGEÚWebSocketErrorÚWSCloseCodeÚ	WSMessageÚ	WSMsgType)ÚWebSocketWriter)Ú	EofStreamÚFlowControlDataQueue)ÚDEFAULT_JSON_DECODERÚDEFAULT_JSON_ENCODERÚJSONDecoderÚJSONEncoderc                   @   s   e Zd Zdddddœdeee eeeee	j
ee ee eeddœdd„Zdd	œd
d„Zdd	œdd„Zdd	œdd„Zdd	œdd„Zeed	œdd„ƒZeee d	œdd„ƒZeee d	œdd„ƒZeed	œdd„ƒZeed	œdd„ƒZdDeeedœdd„Zee d	œdd „ZdEedd"œd#d$„ZdFedd"œd%d&„ZdGeee dd'œd(d)„ZdHeee dd'œd*d+„ZdIe d,œeee e!dd-œd.d/„Z"e#j$d!d0œeeed1œd2d3„Z%dJee e&d4œd5d6„Z'dd7œee ed4œd8d9„Z(dd7œee ed4œd:d;„Z)e*dd<œe+ee ed=œd>d?„Z,d d	œd@dA„Z-e&d	œdBdC„Z.dS )KÚClientWebSocketResponseNr   F)Úreceive_timeoutÚ	heartbeatÚcompressÚclient_notakeoverzFlowControlDataQueue[WSMessage])ÚreaderÚwriterÚprotocolÚresponseÚtimeoutÚ	autocloseÚautopingÚloopr   r   r   r   Úreturnc	                C   s˜   || _ |j| _|| _|| _|| _d| _d| _d | _|| _	|	| _
|| _|| _|
| _d | _|
d urh|
d | _d | _|| _d | _d | _|| _|| _|  ¡  d S )NFg       @)Ú	_responseÚ
connectionZ_connÚ_writerÚ_readerÚ	_protocolÚ_closedÚ_closingÚ_close_codeÚ_timeoutÚ_receive_timeoutÚ
_autocloseÚ	_autopingÚ
_heartbeatÚ_heartbeat_cbÚ_pong_heartbeatÚ_pong_response_cbÚ_loopÚ_waitingÚ
_exceptionÚ	_compressÚ_client_notakeoverÚ_reset_heartbeat)Úselfr   r   r   r   r    r!   r"   r#   r   r   r   r   © r<   úH/var/www/html/gsl.tools/lib/python3.9/site-packages/aiohttp/client_ws.pyÚ__init__   s.    
z ClientWebSocketResponse.__init__)r$   c                 C   s8   | j d ur| j  ¡  d | _ | jd ur4| j ¡  d | _d S ©N)r4   Úcancelr2   ©r;   r<   r<   r=   Ú_cancel_heartbeatH   s    



z)ClientWebSocketResponse._cancel_heartbeatc                 C   s*   |   ¡  | jd ur&t| j| j| jƒ| _d S r?   )rB   r1   r   Ú_send_heartbeatr5   r2   rA   r<   r<   r=   r:   Q   s
    
ÿz(ClientWebSocketResponse._reset_heartbeatc                 C   sN   | j d urJ| jsJ| j | j ¡ ¡ | jd ur6| j ¡  t| j	| j
| jƒ| _d S r?   )r1   r*   r5   Zcreate_taskr'   Úpingr4   r@   r   Ú_pong_not_receivedr3   rA   r<   r<   r=   rC   Y   s    

ÿz'ClientWebSocketResponse._send_heartbeatc                 C   s,   | j s(d| _ tj| _t ¡ | _| j ¡  d S )NT)	r*   r   ÚABNORMAL_CLOSUREr,   ÚasyncioÚTimeoutErrorr7   r%   ÚcloserA   r<   r<   r=   rE   f   s
    
z*ClientWebSocketResponse._pong_not_receivedc                 C   s   | j S r?   )r*   rA   r<   r<   r=   Úclosedm   s    zClientWebSocketResponse.closedc                 C   s   | j S r?   )r,   rA   r<   r<   r=   Ú
close_codeq   s    z"ClientWebSocketResponse.close_codec                 C   s   | j S r?   )r)   rA   r<   r<   r=   r   u   s    z ClientWebSocketResponse.protocolc                 C   s   | j S r?   )r8   rA   r<   r<   r=   r   y   s    z ClientWebSocketResponse.compressc                 C   s   | j S r?   )r9   rA   r<   r<   r=   r   }   s    z)ClientWebSocketResponse.client_notakeover)ÚnameÚdefaultr$   c                 C   s2   | j j}|du r|S |j}|du r&|S | ||¡S )z$extra info from connection transportN)r%   r&   Ú	transportÚget_extra_info)r;   rL   rM   ÚconnrN   r<   r<   r=   rO   �   s    z&ClientWebSocketResponse.get_extra_infoc                 C   s   | j S r?   )r7   rA   r<   r<   r=   Ú	exception‹   s    z!ClientWebSocketResponse.exceptionó    )Úmessager$   c                 Ã   s   | j  |¡I d H  d S r?   )r'   rD   ©r;   rS   r<   r<   r=   rD   Ž   s    zClientWebSocketResponse.pingc                 Ã   s   | j  |¡I d H  d S r?   )r'   ÚpongrT   r<   r<   r=   rU   ‘   s    zClientWebSocketResponse.pong)Údatar   r$   c                 Ã   s6   t |tƒstdt|ƒ ƒ‚| jj|d|d�I d H  d S )Nzdata argument must be str (%r)F©Úbinaryr   )Ú
isinstanceÚstrÚ	TypeErrorÚtyper'   Úsend©r;   rV   r   r<   r<   r=   Úsend_str”   s    
z ClientWebSocketResponse.send_strc                 Ã   s<   t |tttfƒs tdt|ƒ ƒ‚| jj|d|d�I d H  d S )Nz#data argument must be byte-ish (%r)TrW   )rY   ÚbytesÚ	bytearrayÚ
memoryviewr[   r\   r'   r]   r^   r<   r<   r=   Ú
send_bytes™   s    z"ClientWebSocketResponse.send_bytes)Údumps)rV   r   rd   r$   c                Ã   s   | j ||ƒ|d�I d H  d S )N)r   )r_   )r;   rV   r   rd   r<   r<   r=   Ú	send_jsonž   s    z!ClientWebSocketResponse.send_json)ÚcoderS   )rf   rS   r$   c             
   Ã   sÂ  | j d ur*| js*| j td¡ | j I d H  | j�sº|  ¡  d| _z| j ||¡I d H  W nd tj	y€   t
j| _| j ¡  ‚ Y n> ty¼ } z&t
j| _|| _| j ¡  W Y d }~dS d }~0 0 | jrÒ| j ¡  dS zXt | j¡4 I d H š( | j ¡ I d H }W d   ƒI d H  �q(1 I d H �s0    Y  W nh tj	�yT   t
j| _| j ¡  ‚ Y n@ t�y’ } z&t
j| _|| _| j ¡  W Y d }~dS d }~0 0 |jtjkrÒ|j| _| j ¡  dS qÒndS d S )Nr   TF)r6   r*   r(   Z	feed_datar   rB   r'   rI   rG   ÚCancelledErrorr   rF   r,   r%   Ú	Exceptionr7   r+   Úasync_timeoutr    r-   Úreadr\   r   ÚCLOSErV   )r;   rf   rS   ÚexcÚmsgr<   r<   r=   rI   §   sJ    


B


zClientWebSocketResponse.close)r    r$   c              
   Ã   s”  | j d urtdƒ‚| jrtS | jr4|  ¡ I d H  tS z¢| j ¡ | _ zvt 	|pP| j
¡4 I d H š& | j ¡ I d H }W d   ƒI d H  q˜1 I d H sŽ0    Y  |  ¡  W | j }d | _ t|dƒ n| j }d | _ t|dƒ 0 W �n" tjtjfyü   tj| _‚ Y � nþ t�y2   tj| _|  ¡ I d H  ttjd d ƒ Y S  t�yV   d| _tj| _t Y S  t�y¤ } z6|j| _| j|jd�I d H  ttj|d ƒW  Y d }~S d }~0  t�yø } z<|| _d| _tj| _|  ¡ I d H  ttj|d ƒW  Y d }~S d }~0 0 |j tj!k�r6d| _|j"| _| j�s�| j#�r�|  ¡ I d H  nZ|j tj$k�rLd| _nD|j tj%k�rx| j&�rx|  '|j"¡I d H  q n|j tj(k�r�| j&�r�q |S )Nz+Concurrent call to receive() is not allowedT)rf   ))r6   ÚRuntimeErrorr*   r
   r+   rI   r5   Zcreate_futureri   r    r.   r(   rj   r:   r	   rG   rg   rH   r   rF   r,   r   ÚOKr   r   ÚCLOSEDr   r   rf   ÚERRORrh   r7   r\   rk   rV   r/   ÚCLOSINGZPINGr0   rU   ZPONG)r;   r    rm   Úwaiterrl   r<   r<   r=   ÚreceiveÖ   sj    
:
þ"$zClientWebSocketResponse.receive©r    c                Ã   sB   |   |¡I d H }|jtjkr6td|j› d|j›d�ƒ‚tt|jƒS )NúReceived message ú:z is not str)rt   r\   r   ZTEXTr[   rV   r   rZ   ©r;   r    rm   r<   r<   r=   Úreceive_str  s    z#ClientWebSocketResponse.receive_strc                Ã   sB   |   |¡I d H }|jtjkr6td|j› d|j›d�ƒ‚tt|jƒS )Nrv   rw   z is not bytes)rt   r\   r   ÚBINARYr[   rV   r   r`   rx   r<   r<   r=   Úreceive_bytes  s    z%ClientWebSocketResponse.receive_bytes)Úloadsr    )r|   r    r$   c                Ã   s   | j |d�I d H }||ƒS )Nru   )ry   )r;   r|   r    rV   r<   r<   r=   Úreceive_json  s    z$ClientWebSocketResponse.receive_jsonc                 C   s   | S r?   r<   rA   r<   r<   r=   Ú	__aiter__%  s    z!ClientWebSocketResponse.__aiter__c                 Ã   s,   |   ¡ I d H }|jtjtjtjfv r(t‚|S r?   )rt   r\   r   rk   rr   rp   ÚStopAsyncIteration)r;   rm   r<   r<   r=   Ú	__anext__(  s    z!ClientWebSocketResponse.__anext__)N)rR   )rR   )N)N)N)N)/Ú__name__Ú
__module__Ú__qualname__r   r   rZ   r   ÚfloatÚboolrG   ZAbstractEventLoopÚintr>   rB   r:   rC   rE   ÚpropertyrJ   rK   r   r   r   r   rO   ÚBaseExceptionrQ   r`   rD   rU   r_   rc   r   r   re   r   ro   rI   r   rt   ry   r{   r   r   r}   r~   r€   r<   r<   r<   r=   r      sz   òñ*	
 ýûú	/:	üû	r   ) Ú__doc__rG   Útypingr   r   r   ri   Zclient_exceptionsr   Zclient_reqrepr   Zhelpersr   r	   Úhttpr
   r   r   r   r   r   Zhttp_websocketr   Zstreamsr   r   Ztypedefsr   r   r   r   r   r<   r<   r<   r=   Ú<module>   s    