Ë
    òT•jû{  ã                   óz  — d dl Z d dlZd dlZ	 d dlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
mZ e�ej                  ej                  fZ G d„ d	ej                  «      Z G d
„ dej                  «      Zd„ Zd„ Z G d„ de	j(                  e	j*                  «      Z G d„ dej.                  «      Zy# e$ r dZY Œ§w xY w)é    Né   )Ú	constants)Ú
exceptions)Ú	protocols)Ú
transports)Úloggerc                   ó    — e Zd ZdZdZdZdZdZy)ÚSSLProtocolStateÚ	UNWRAPPEDÚDO_HANDSHAKEÚWRAPPEDÚFLUSHINGÚSHUTDOWNN)Ú__name__Ú
__module__Ú__qualname__r   r   r   r   r   © ó    ú'/usr/lib/python3.12/asyncio/sslproto.pyr
   r
      s   „ Ø€IØ!€LØ€GØ€HØ�Hr   r
   c                   ó   — e Zd ZdZdZdZdZy)ÚAppProtocolStateÚ
STATE_INITÚSTATE_CON_MADEÚ	STATE_EOFÚSTATE_CON_LOSTN)r   r   r   r   r   r   r   r   r   r   r   r      s   „ ð €JØ%€NØ€IØ%�Nr   r   c                 óZ   — | rt        d«      ‚t        j                  «       }|sd|_        |S )Nz(Server side SSL needs a valid SSLContextF)Ú
ValueErrorÚsslÚcreate_default_contextÚcheck_hostname)Úserver_sideÚserver_hostnameÚ
sslcontexts      r   Ú_create_transport_contextr$   /   s2   € ÙÜÐCÓDÐDô ×+Ñ+Ó-€JÙØ$)ˆ
Ô!ØÐr   c                 ó„   — | €|€|dz  }n
|}d|z  }n| }|€|dz  }n|}||cxk\  rdk\  sn t        d|›d|›d�«      ‚||fS )Ni   é   r   zhigh (z) must be >= low (z) must be >= 0)r   )ÚhighÚlowÚkbÚhiÚlos        r   Úadd_flowcontrol_defaultsr,   =   sh   € Ø€|Øˆ;Ø�d‘‰BàˆBØ�R‘‰BàˆØ
€{Ø�1‰W‰àˆà�Œ=�qŒ=ÝÚšbð"ó #ð 	#ð ˆrˆ6€Mr   c                   óà   — e Zd ZdZej
                  j                  Zd„ Zdd„Z	d„ Z
d„ Zd„ Zd„ Zefd	„Zd
„ Zd„ Zd„ Zdd„Zd„ Zd„ Zdd„Zd„ Zd„ Zed„ «       Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z d„ Z!y)Ú_SSLProtocolTransportTc                 ó.   — || _         || _        d| _        y )NF)Ú_loopÚ_ssl_protocolÚ_closed)ÚselfÚloopÚssl_protocols      r   Ú__init__z_SSLProtocolTransport.__init__X   s   € ØˆŒ
Ø)ˆÔØˆ�r   Nc                 ó:   — | j                   j                  ||«      S )z#Get optional transport information.)r1   Ú_get_extra_info©r3   ÚnameÚdefaults      r   Úget_extra_infoz$_SSLProtocolTransport.get_extra_info]   s   € à×!Ñ!×1Ñ1°$¸Ó@Ð@r   c                 ó:   — | j                   j                  |«       y ©N)r1   Ú_set_app_protocol)r3   Úprotocols     r   Úset_protocolz"_SSLProtocolTransport.set_protocola   s   € Ø×Ñ×,Ñ,¨XÕ6r   c                 ó.   — | j                   j                  S r>   )r1   Ú_app_protocol©r3   s    r   Úget_protocolz"_SSLProtocolTransport.get_protocold   s   € Ø×!Ñ!×/Ñ/Ð/r   c                 ó   — | j                   S r>   )r2   rD   s    r   Ú
is_closingz _SSLProtocolTransport.is_closingg   s   € Ø�|‰|Ðr   c                 ón   — | j                   s"d| _         | j                  j                  «        yd| _        y)a  Close the transport.

        Buffered data will be flushed asynchronously.  No more data
        will be received.  After all buffered data is flushed, the
        protocol's connection_lost() method will (eventually) called
        with None as its argument.
        TN)r2   r1   Ú_start_shutdownrD   s    r   Úclosez_SSLProtocolTransport.closej   s,   € ð �|Š|ØˆDŒLØ×Ñ×.Ñ.Õ0à!%ˆDÕr   c                 óX   — | j                   sd| _         |j                  dt        «       y y )NTz9unclosed transport <asyncio._SSLProtocolTransport object>)r2   ÚwarnÚResourceWarning)r3   Ú	_warningss     r   Ú__del__z_SSLProtocolTransport.__del__x   s)   € Ø�|Š|ØˆDŒLØ�N‰NðÜ*õ,ð r   c                 ó0   — | j                   j                   S r>   )r1   Ú_app_reading_pausedrD   s    r   Ú
is_readingz _SSLProtocolTransport.is_reading   s   € Ø×%Ñ%×9Ñ9Ð9Ð9r   c                 ó8   — | j                   j                  «        y)z”Pause the receiving end.

        No data will be passed to the protocol's data_received()
        method until resume_reading() is called.
        N)r1   Ú_pause_readingrD   s    r   Úpause_readingz#_SSLProtocolTransport.pause_reading‚   s   € ð 	×Ñ×)Ñ)Õ+r   c                 ó8   — | j                   j                  «        y)z…Resume the receiving end.

        Data received will once again be passed to the protocol's
        data_received() method.
        N)r1   Ú_resume_readingrD   s    r   Úresume_readingz$_SSLProtocolTransport.resume_readingŠ   s   € ð 	×Ñ×*Ñ*Õ,r   c                 óp   — | j                   j                  ||«       | j                   j                  «        y)a¦  Set the high- and low-water limits for write flow control.

        These two values control when to call the protocol's
        pause_writing() and resume_writing() methods.  If specified,
        the low-water limit must be less than or equal to the
        high-water limit.  Neither value can be negative.

        The defaults are implementation-specific.  If only the
        high-water limit is given, the low-water limit defaults to an
        implementation-specific value less than or equal to the
        high-water limit.  Setting high to zero forces low to zero as
        well, and causes pause_writing() to be called whenever the
        buffer becomes non-empty.  Setting low to zero causes
        resume_writing() to be called only once the buffer is empty.
        Use of zero for either limit is generally sub-optimal as it
        reduces opportunities for doing I/O and computation
        concurrently.
        N)r1   Ú_set_write_buffer_limitsÚ_control_app_writing©r3   r'   r(   s      r   Úset_write_buffer_limitsz-_SSLProtocolTransport.set_write_buffer_limits’   s,   € ð& 	×Ñ×3Ñ3°D¸#Ô>Ø×Ñ×/Ñ/Õ1r   c                 óZ   — | j                   j                  | j                   j                  fS r>   )r1   Ú_outgoing_low_waterÚ_outgoing_high_waterrD   s    r   Úget_write_buffer_limitsz-_SSLProtocolTransport.get_write_buffer_limits¨   ó*   € Ø×"Ñ"×6Ñ6Ø×"Ñ"×7Ñ7ð9ð 	9r   c                 ó6   — | j                   j                  «       S )z-Return the current size of the write buffers.)r1   Ú_get_write_buffer_sizerD   s    r   Úget_write_buffer_sizez+_SSLProtocolTransport.get_write_buffer_size¬   s   € à×!Ñ!×8Ñ8Ó:Ð:r   c                 óp   — | j                   j                  ||«       | j                   j                  «        y)a¯  Set the high- and low-water limits for read flow control.

        These two values control when to call the upstream transport's
        pause_reading() and resume_reading() methods.  If specified,
        the low-water limit must be less than or equal to the
        high-water limit.  Neither value can be negative.

        The defaults are implementation-specific.  If only the
        high-water limit is given, the low-water limit defaults to an
        implementation-specific value less than or equal to the
        high-water limit.  Setting high to zero forces low to zero as
        well, and causes pause_reading() to be called whenever the
        buffer becomes non-empty.  Setting low to zero causes
        resume_reading() to be called only once the buffer is empty.
        Use of zero for either limit is generally sub-optimal as it
        reduces opportunities for doing I/O and computation
        concurrently.
        N)r1   Ú_set_read_buffer_limitsÚ_control_ssl_readingr\   s      r   Úset_read_buffer_limitsz,_SSLProtocolTransport.set_read_buffer_limits°   s,   € ð& 	×Ñ×2Ñ2°4¸Ô=Ø×Ñ×/Ñ/Õ1r   c                 óZ   — | j                   j                  | j                   j                  fS r>   )r1   Ú_incoming_low_waterÚ_incoming_high_waterrD   s    r   Úget_read_buffer_limitsz,_SSLProtocolTransport.get_read_buffer_limitsÆ   rb   r   c                 ó6   — | j                   j                  «       S )z+Return the current size of the read buffer.)r1   Ú_get_read_buffer_sizerD   s    r   Úget_read_buffer_sizez*_SSLProtocolTransport.get_read_buffer_sizeÊ   s   € à×!Ñ!×7Ñ7Ó9Ð9r   c                 ó.   — | j                   j                  S r>   )r1   Ú_app_writing_pausedrD   s    r   Ú_protocol_pausedz&_SSLProtocolTransport._protocol_pausedÎ   s   € ð ×!Ñ!×5Ñ5Ð5r   c                 óº   — t        |t        t        t        f«      s!t	        dt        |«      j                  › �«      ‚|sy| j                  j                  |f«       y)z�Write some data bytes to the transport.

        This does not block; it buffers the data and arranges for it
        to be sent out asynchronously.
        z+data: expecting a bytes-like instance, got N)	Ú
isinstanceÚbytesÚ	bytearrayÚ
memoryviewÚ	TypeErrorÚtyper   r1   Ú_write_appdata©r3   Údatas     r   Úwritez_SSLProtocolTransport.writeÓ   sX   € ô ˜$¤¬	´:Ð >Ô?Üð #Ü#'¨£:×#6Ñ#6Ð"7ð9ó :ð :áØØ×Ñ×)Ñ)¨4¨'Õ2r   c                 ó:   — | j                   j                  |«       y)z¯Write a list (or any iterable) of data bytes to the transport.

        The default implementation concatenates the arguments and
        calls write() on the result.
        N)r1   r{   )r3   Úlist_of_datas     r   Ú
writelinesz _SSLProtocolTransport.writelinesà   s   € ð 	×Ñ×)Ñ)¨,Õ7r   c                 ó   — t         ‚)zuClose the write end after flushing buffered data.

        This raises :exc:`NotImplementedError` right now.
        )ÚNotImplementedErrorrD   s    r   Ú	write_eofz_SSLProtocolTransport.write_eofè   s
   € ô
 "Ð!r   c                  ó   — y)zAReturn True if this transport supports write_eof(), False if not.Fr   rD   s    r   Úcan_write_eofz#_SSLProtocolTransport.can_write_eofï   s   € àr   c                 ó&   — | j                  d«       y)zÝClose the transport immediately.

        Buffered data will be lost.  No more data will be received.
        The protocol's connection_lost() method will (eventually) be
        called with None as its argument.
        N)Ú_force_closerD   s    r   Úabortz_SSLProtocolTransport.abortó   s   € ð 	×Ñ˜$Õr   c                 ób   — d| _         | j                  �| j                  j                  |«       y y ©NT)r2   r1   Ú_abort©r3   Úexcs     r   rˆ   z"_SSLProtocolTransport._force_closeü   s.   € ØˆŒØ×ÑÐ)Ø×Ñ×%Ñ% cÕ*ð *r   c                 óž   — | j                   j                  j                  |«       | j                   xj                  t	        |«      z  c_        y r>   )r1   Ú_write_backlogÚappendÚ_write_buffer_sizeÚlenr|   s     r   Ú_test__append_write_backlogz1_SSLProtocolTransport._test__append_write_backlog  s7   € à×Ñ×)Ñ)×0Ñ0°Ô6Ø×Ñ×-Ò-´°T³Ñ:Ö-r   r>   ©NN)"r   r   r   Ú_start_tls_compatibler   Ú_SendfileModeÚFALLBACKÚ_sendfile_compatibler6   r<   rA   rE   rG   rJ   ÚwarningsrO   rR   rU   rX   r]   ra   re   ri   rm   rp   Úpropertyrs   r~   r�   r„   r†   r‰   rˆ   r”   r   r   r   r.   r.   R   s©   „ ð !ÐØ$×2Ñ2×;Ñ;Ðòó
Aò7ò0òò&ð !)ó ,ò:ò,ò-ó2ò,9ò;ó2ò,9ò:ð ñ6ó ð6ò3ò8ò"òò ò+ó
;r   r.   c                   ó  — e Zd ZdZdZdZdZ	 	 	 	 d*d„Zd„ Zd+d„Z	d„ Z
d„ Zd„ Zd	„ Zd
„ Zd„ Zd+d„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Z d„ Z!d„ Z"d„ Z#d „ Z$d,d!„Z%d"„ Z&d#„ Z'd$„ Z(d,d%„Z)d&„ Z*d'„ Z+d(„ Z,d-d)„Z-y).ÚSSLProtocoli   Nc
                 óÖ  — t         €t        d«      ‚t        | j                  «      | _        t        | j                  «      | _        |€t        j                  }n|dk  rt        d|› �«      ‚|	€t        j                  }	n|	dk  rt        d|	› �«      ‚|st        ||«      }|| _        |r
|s|| _        nd | _        || _        t        |¬«      | _        t#        j$                  «       | _        d| _        || _        || _        | j/                  |«       d | _        d| _        d | _        || _        |	| _        t        j:                  «       | _        t        j:                  «       | _        t@        jB                  | _"        d| _#        |rtH        jJ                  | _&        ntH        jN                  | _&        | j                  jQ                  | j<                  | j>                  | j                  | j                  ¬«      | _)        d| _*        d| _+        d| _,        d| _-        d| _.        | j_                  «        d| _0        d| _1        d| _2        d| _3        | ji                  «        | jk                  «        y )Nzstdlib ssl module not availabler   z7ssl_handshake_timeout should be a positive number, got z6ssl_shutdown_timeout should be a positive number, got )r#   F)r!   r"   )6r   ÚRuntimeErrorrw   Úmax_sizeÚ_ssl_bufferrx   Ú_ssl_buffer_viewr   ÚSSL_HANDSHAKE_TIMEOUTr   ÚSSL_SHUTDOWN_TIMEOUTr$   Ú_server_sideÚ_server_hostnameÚ_sslcontextÚdictÚ_extraÚcollectionsÚdequer�   r’   Ú_waiterr0   r?   Ú_app_transportÚ_app_transport_createdÚ
_transportÚ_ssl_handshake_timeoutÚ_ssl_shutdown_timeoutÚ	MemoryBIOÚ	_incomingÚ	_outgoingr
   r   Ú_stateÚ
_conn_lostr   r   Ú
_app_stater   Úwrap_bioÚ_sslobjÚ_ssl_writing_pausedrQ   Ú_ssl_reading_pausedrl   rk   rg   Ú_eof_receivedrr   r`   r_   rZ   Ú_get_app_transport)
r3   r4   Úapp_protocolr#   Úwaiterr!   r"   Úcall_connection_madeÚssl_handshake_timeoutÚssl_shutdown_timeouts
             r   r6   zSSLProtocol.__init__  sE  € ô
 ˆ;ÜÐ@ÓAÐAä$ T§]¡]Ó3ˆÔÜ *¨4×+;Ñ+;Ó <ˆÔà Ð(Ü$-×$CÑ$CÑ!Ø" aÒ'ÜðØ,Ð-ð/ó0ð 0ð  Ð'Ü#,×#AÑ#AÑ Ø! QÒ&ÜðØ+Ð,ð.ó/ð /ñ Ü2Ø˜_ó.ˆJð (ˆÔÙ¡;Ø$3ˆDÕ!à$(ˆDÔ!Ø%ˆÔô  jÔ1ˆŒô *×/Ñ/Ó1ˆÔØ"#ˆÔàˆŒØˆŒ
Ø×Ñ˜|Ô,Ø"ˆÔØ&+ˆÔ#àˆŒØ&;ˆÔ#Ø%9ˆÔ"äŸ™›ˆŒÜŸ™›ˆŒÜ&×0Ñ0ˆŒØˆŒÙÜ.×9Ñ9ˆD�Oä.×=Ñ=ˆDŒOØ×'Ñ'×0Ñ0Ø�N‰N˜DŸN™NØ×)Ñ)Ø ×1Ñ1ð 1ó 3ˆŒð $)ˆÔ à#(ˆÔ à#(ˆÔ Ø$%ˆÔ!Ø#$ˆÔ Ø×$Ñ$Ô&Ø"ˆÔà#(ˆÔ Ø$%ˆÔ!Ø#$ˆÔ Ø×%Ñ%Ô'Ø×ÑÕ!r   c                 óÀ   — || _         t        |d«      rDt        |t        j                  «      r*|j
                  | _        |j                  | _        d| _	        y d| _	        y )NÚ
get_bufferTF)
rC   Úhasattrru   r   ÚBufferedProtocolrÄ   Ú_app_protocol_get_bufferÚbuffer_updatedÚ_app_protocol_buffer_updatedÚ_app_protocol_is_buffer)r3   r¾   s     r   r?   zSSLProtocol._set_app_protocola  sP   € Ø)ˆÔä�L ,Ô/Ü˜<¬×)CÑ)CÔDØ,8×,CÑ,CˆDÔ)Ø0<×0KÑ0KˆDÔ-Ø+/ˆDÕ(à+0ˆDÕ(r   c                 óà   — | j                   €y | j                   j                  «       s@|�#| j                   j                  |«       d | _         y | j                   j                  d «       d | _         y r>   )r¬   Ú	cancelledÚset_exceptionÚ
set_resultr�   s     r   Ú_wakeup_waiterzSSLProtocol._wakeup_waiterl  sZ   € Ø�<‰<ÐØØ�|‰|×%Ñ%Ô'ØˆØ—‘×*Ñ*¨3Ô/ð ˆ�ð —‘×'Ñ'¨Ô-Øˆ�r   c                 ó¤   — | j                   €9| j                  rt        d«      ‚t        | j                  | «      | _         d| _        | j                   S )Nz$Creating _SSLProtocolTransport twiceT)r­   r®   rŸ   r.   r0   rD   s    r   r½   zSSLProtocol._get_app_transportv  sJ   € Ø×ÑÐ&Ø×*Ò*Ü"Ð#IÓJÐJÜ"7¸¿
¹
ÀDÓ"IˆDÔØ*.ˆDÔ'Ø×"Ñ"Ð"r   c                 ó2   — || _         | j                  «        y)zXCalled when the low-level connection is made.

        Start the SSL handshake.
        N)r¯   Ú_start_handshake)r3   Ú	transports     r   Úconnection_madezSSLProtocol.connection_made~  s   € ð
 $ˆŒØ×ÑÕr   c                 óH  — | j                   j                  «        | j                  j                  «        | xj                  dz  c_        | j
                  �d| j
                  _        | j                  t        j                  k7  r| j                  t        j                  k(  s| j                  t        j                  k(  rEt        j                  | _
        | j                  j!                  | j"                  j$                  |«       | j'                  t        j(                  «       d| _        d| _        d| _        | j-                  |«       | j.                  r!| j.                  j1                  «        d| _        | j2                  r"| j2                  j1                  «        d| _        yy)zÝCalled when the low-level connection is lost or closed.

        The argument is an exception object or None (the latter
        meaning a regular EOF is received or the connection was
        aborted or closed).
        r   NT)r�   Úclearr´   Úreadr¶   r­   r2   rµ   r
   r   r·   r   r   r   r   r0   Ú	call_soonrC   Úconnection_lostÚ
_set_stater   r¯   rÏ   Ú_shutdown_timeout_handleÚcancelÚ_handshake_timeout_handler�   s     r   rÙ   zSSLProtocol.connection_lost†  s9  € ð 	×Ñ×!Ñ!Ô#Ø�‰×ÑÔØ�Š˜1Ñ�ð ×ÑÐ*Ø*.ˆD×ÑÔ'à�;‰;Ô*×7Ñ7Ò7à—‘Ô#3×#BÑ#BÒBØ—‘Ô#3×#=Ñ#=Ò=ä"2×"AÑ"A�”Ø—
‘
×$Ñ$ T×%7Ñ%7×%GÑ%GÈÔMØ�‰Ô(×2Ñ2Ô3ØˆŒØ"ˆÔØ!ˆÔØ×Ñ˜CÔ à×(Ò(Ø×)Ñ)×0Ñ0Ô2Ø,0ˆDÔ)Ø×)Ò)Ø×*Ñ*×1Ñ1Ô3Ø-1ˆDÕ*ð *r   c                 óâ   — |}|dk  s|| j                   kD  r| j                   }t        | j                  «      |k  r*t        |«      | _        t	        | j                  «      | _        | j
                  S ©Nr   )r    r“   r¡   rw   rx   r¢   )r3   ÚnÚwants      r   rÄ   zSSLProtocol.get_bufferª  s`   € ØˆØ�1Š9˜˜tŸ}™}Ò,Ø—=‘=ˆDÜˆt×ÑÓ  4Ò'Ü(¨›ˆDÔÜ$.¨t×/?Ñ/?Ó$@ˆDÔ!Ø×$Ñ$Ð$r   c                 óÄ  — | j                   j                  | j                  d | «       | j                  t        j
                  k(  r| j                  «        y | j                  t        j                  k(  r| j                  «        y | j                  t        j                  k(  r| j                  «        y | j                  t        j                  k(  r| j                  «        y y r>   )r³   r~   r¢   rµ   r
   r   Ú_do_handshaker   Ú_do_readr   Ú	_do_flushr   Ú_do_shutdown)r3   Únbytess     r   rÈ   zSSLProtocol.buffer_updated³  s�   € Ø�‰×Ñ˜T×2Ñ2°7°FÐ;Ô<à�;‰;Ô*×7Ñ7Ò7Ø×ÑÕ à�[‰[Ô,×4Ñ4Ò4Ø�M‰M�Oà�[‰[Ô,×5Ñ5Ò5Ø�N‰NÕà�[‰[Ô,×5Ñ5Ò5Ø×ÑÕð 6r   c                 óô  — d| _         	 | j                  j                  «       rt        j                  d| «       | j
                  t        j                  k(  r| j                  t        «       y| j
                  t        j                  k(  r=| j                  t        j                  «       | j                  ry| j                  «        y| j
                  t        j                  k(  r@| j                  «        | j                  t        j                   «       | j#                  «        y| j
                  t        j                   k(  r| j#                  «        yy# t$        $ r | j&                  j)                  «        ‚ w xY w)a  Called when the other end of the low-level stream
        is half-closed.

        If this returns a false value (including None), the transport
        will close itself.  If it returns a true value, closing the
        transport is up to the protocol.
        Tz%r received EOFN)r¼   r0   Ú	get_debugr   Údebugrµ   r
   r   Ú_on_handshake_completeÚConnectionResetErrorr   rÚ   r   rQ   rå   Ú	_do_writer   ræ   Ú	Exceptionr¯   rJ   rD   s    r   Úeof_receivedzSSLProtocol.eof_receivedÂ  s  € ð "ˆÔð	Ø�z‰z×#Ñ#Ô%Ü—‘Ð.°Ô5à�{‰{Ô.×;Ñ;Ò;Ø×+Ñ+Ô,@ÕAà—‘Ô 0× 8Ñ 8Ò8Ø—‘Ô 0× 9Ñ 9Ô:Ø×+Ò+Øà—N‘NÕ$à—‘Ô 0× 9Ñ 9Ò9Ø—‘Ô Ø—‘Ô 0× 9Ñ 9Ô:Ø×!Ñ!Õ#à—‘Ô 0× 9Ñ 9Ò9Ø×!Ñ!Õ#ð :øô ò 	Ø�O‰O×!Ñ!Ô#Øð	ús&   ‰A"E Á,AE Â5E ÃAE Ä#-E Å%E7c                 ó�   — || j                   v r| j                   |   S | j                  �| j                  j                  ||«      S |S r>   )r©   r¯   r<   r9   s      r   r8   zSSLProtocol._get_extra_infoå  sC   € Ø�4—;‘;ÑØ—;‘;˜tÑ$Ð$Ø�_‰_Ð(Ø—?‘?×1Ñ1°$¸Ó@Ð@àˆNr   c                 ó&  — d}|t         j                  k(  rd}nË| j                  t         j                  k(  r|t         j                  k(  rd}n˜| j                  t         j                  k(  r|t         j                  k(  rd}ne| j                  t         j                  k(  r|t         j
                  k(  rd}n2| j                  t         j
                  k(  r|t         j                  k(  rd}|r|| _        y t        dj                  | j                  |«      «      ‚)NFTz!cannot switch state from {} to {})	r
   r   rµ   r   r   r   r   rŸ   Úformat)r3   Ú	new_stateÚalloweds      r   rÚ   zSSLProtocol._set_stateí  sï   € ØˆàÔ(×2Ñ2Ò2Ø‰Gð �K‰KÔ+×5Ñ5Ò5ØÔ)×6Ñ6Ò6à‰Gð �K‰KÔ+×8Ñ8Ò8ØÔ)×1Ñ1Ò1à‰Gð �K‰KÔ+×3Ñ3Ò3ØÔ)×2Ñ2Ò2à‰Gð �K‰KÔ+×4Ñ4Ò4ØÔ)×2Ñ2Ò2àˆGáØ#ˆD�Kô Ø3×:Ñ:Ø—K‘K ó,ó-ð -r   c                 ón  ‡ — ‰ j                   j                  «       r6t        j                  d‰ «       ‰ j                   j	                  «       ‰ _        nd ‰ _        ‰ j                  t        j                  «       ‰ j                   j                  ‰ j                  ˆ fd„«      ‰ _        ‰ j                  «        y )Nz%r starts SSL handshakec                  ó$   •— ‰ j                  «       S r>   )Ú_check_handshake_timeoutrD   s   €r   ú<lambda>z.SSLProtocol._start_handshake.<locals>.<lambda>!  s   ø€ ¨$×*GÑ*GÓ*I€ r   )r0   ré   r   rê   ÚtimeÚ_handshake_start_timerÚ   r
   r   Ú
call_laterr°   rÝ   rã   rD   s   `r   rÒ   zSSLProtocol._start_handshake  s†   ø€ Ø�:‰:×ÑÔ!Ü�L‰LÐ2°DÔ9Ø)-¯©¯©Ó):ˆDÕ&à)-ˆDÔ&à�‰Ô(×5Ñ5Ô6ð �J‰J×!Ñ! $×"=Ñ"=Û"IóKð 	Ô&ð 	×ÑÕr   c                 ó”   — | j                   t        j                  k(  r+d| j                  › d�}| j	                  t        |«      «       y y )Nz$SSL handshake is taking longer than z! seconds: aborting the connection)rµ   r
   r   r°   Ú_fatal_errorÚConnectionAbortedError)r3   Úmsgs     r   r÷   z$SSLProtocol._check_handshake_timeout%  sN   € Ø�;‰;Ô*×7Ñ7Ò7à6Ø×.Ñ.Ð/ð 0*ð+ð ð
 ×ÑÔ4°SÓ9Õ:ð 8r   c                 óò   — 	 | j                   j                  «        | j                  d «       y # t        $ r | j	                  «        Y y t
        j                  $ r}| j                  |«       Y d }~y d }~ww xY wr>   )r¹   Údo_handshakerë   ÚSSLAgainErrorsÚ_process_outgoingr   ÚSSLErrorr�   s     r   rã   zSSLProtocol._do_handshake.  sb   € ð	.Ø�L‰L×%Ñ%Ô'ð ×'Ñ'¨Õ-øô ò 	%Ø×"Ñ"Ö$Ü�|‰|ò 	-Ø×'Ñ'¨×,Ñ,ûð	-ús   ‚. ®A6Á	A6ÁA1Á1A6c                 óô  — | j                   �!| j                   j                  «        d | _         | j                  }	 |€ | j                  t        j
                  «       n|‚|j                  «       }| j                  j                  «       rA| j                  j!                  «       | j"                  z
  }t%        j&                  d| |dz  «       | j(                  j+                  ||j-                  «       |j/                  «       |¬«       | j0                  t2        j4                  k(  r>t2        j6                  | _        | j8                  j;                  | j=                  «       «       | j                  «        | j?                  «        y # t        $ rm}d }| j                  t        j                  «       t        |t        j                  «      rd}nd}| j                  ||«       | j                  |«       Y d }~y d }~ww xY w)Nz1SSL handshake failed on verifying the certificatezSSL handshake failedz%r: SSL handshake took %.1f msg     @�@)ÚpeercertÚcipherÚcompressionÚ
ssl_object) rÝ   rÜ   r¹   rÚ   r
   r   Úgetpeercertrî   r   ru   r   ÚCertificateErrorrý   rÏ   r0   ré   rù   rú   r   rê   r©   Úupdater  r  r·   r   r   r   rC   rÔ   r½   rä   )r3   Úhandshake_excÚsslobjr  rŽ   rÿ   Údts          r   rë   z"SSLProtocol._on_handshake_complete8  s‘  € Ø×)Ñ)Ð5Ø×*Ñ*×1Ñ1Ô3Ø-1ˆDÔ*à—‘ˆð	ØÐ$Ø—‘Ô 0× 8Ñ 8Õ9à#Ð#à×)Ñ)Ó+ˆHð �:‰:×ÑÔ!Ø—‘—‘Ó" T×%?Ñ%?Ñ?ˆBÜ�L‰LÐ9¸4ÀÀcÁÔJð 	�‰×Ñ HØ"(§-¡-£/Ø'-×'9Ñ'9Ó';Ø&,ð 	ô 	.ð �?‰?Ô.×9Ñ9Ò9Ü.×=Ñ=ˆDŒOØ×Ñ×.Ñ.¨t×/FÑ/FÓ/HÔIØ×ÑÔØ�‰�øô1 ò 		Ø ˆMØ�O‰OÔ,×6Ñ6Ô7Ü˜#œs×3Ñ3Ô4ØI‘à,�Ø×Ñ˜c 3Ô'Ø×Ñ Ô$Üûð		ús   »4F Æ	G7Æ
A#G2Ç2G7c                 óÐ  ‡ — ‰ j                   t        j                  t        j                  t        j                  fv ry ‰ j
                  �d‰ j
                  _        ‰ j                   t        j                  k(  r‰ j                  d «       y ‰ j                  t        j                  «       ‰ j                  j                  ‰ j                  ˆ fd„«      ‰ _        ‰ j                  «        y )NTc                  ó$   •— ‰ j                  «       S r>   )Ú_check_shutdown_timeoutrD   s   €r   rø   z-SSLProtocol._start_shutdown.<locals>.<lambda>r  s   ø€ ˜×4Ñ4Ó6€ r   )rµ   r
   r   r   r   r­   r2   r   rŒ   rÚ   r0   rû   r±   rÛ   rå   rD   s   `r   rI   zSSLProtocol._start_shutdowna  s¯   ø€ à�K‰KÜ ×)Ñ)Ü ×)Ñ)Ü ×*Ñ*ðñ ð Ø×ÑÐ*Ø*.ˆD×ÑÔ'Ø�;‰;Ô*×7Ñ7Ò7Ø�K‰K˜Õà�O‰OÔ,×5Ñ5Ô6Ø,0¯J©J×,AÑ,AØ×*Ñ*Û6ó-ˆDÔ)ð �N‰NÕr   c                 óº   — | j                   t        j                  t        j                  fv r/| j                  j                  t        j                  d«      «       y y )NzSSL shutdown timed out)rµ   r
   r   r   r¯   rˆ   r   ÚTimeoutErrorrD   s    r   r  z#SSLProtocol._check_shutdown_timeoutv  sN   € à�K‰KÜ ×)Ñ)Ü ×)Ñ)ðñ ð
 �O‰O×(Ñ(Ü×'Ñ'Ð(@ÓAõCðr   c                 ó‚   — | j                  «        | j                  t        j                  «       | j	                  «        y r>   )rä   rÚ   r
   r   ræ   rD   s    r   rå   zSSLProtocol._do_flush€  s*   € Ø�‰ŒØ�‰Ô(×1Ñ1Ô2Ø×ÑÕr   c                 óJ  — 	 | j                   s| j                  j                  «        | j                  «        | j	                  «        | j                  d «       y # t        $ r | j                  «        Y y t        j                  $ r}| j                  |«       Y d }~y d }~ww xY wr>   )	r¼   r¹   Úunwrapr  Ú_call_eof_receivedÚ_on_shutdown_completer  r   r  r�   s     r   ræ   zSSLProtocol._do_shutdown…  sƒ   € ð
	-Ø×%Ò%Ø—‘×#Ñ#Ô%ð ×"Ñ"Ô$Ø×#Ñ#Ô%Ø×&Ñ& tÕ,øô ò 	%Ø×"Ñ"Ö$Ü�|‰|ò 	,Ø×&Ñ& s×+Ñ+ûð	,ús   ‚&A ÁB"Á5B"ÂBÂB"c                 óä   — | j                   �!| j                   j                  «        d | _         |r| j                  |«       y | j                  j	                  | j
                  j                  «       y r>   )rÛ   rÜ   rý   r0   rØ   r¯   rJ   )r3   Úshutdown_excs     r   r  z!SSLProtocol._on_shutdown_complete’  sU   € Ø×(Ñ(Ð4Ø×)Ñ)×0Ñ0Ô2Ø,0ˆDÔ)áØ×Ñ˜lÕ+à�J‰J× Ñ  §¡×!6Ñ!6Õ7r   c                 ó’   — | j                  t        j                  «       | j                  �| j                  j	                  |«       y y r>   )rÚ   r
   r   r¯   rˆ   r�   s     r   rŒ   zSSLProtocol._abortœ  s6   € Ø�‰Ô(×2Ñ2Ô3Ø�?‰?Ð&Ø�O‰O×(Ñ(¨Õ-ð 'r   c                 ó8  — | j                   t        j                  t        j                  t        j                  fv rH| j
                  t        j                  k\  rt        j                  d«       | xj
                  dz  c_        y |D ];  }| j                  j                  |«       | xj                  t        |«      z  c_        Œ= 	 | j                   t        j                  k(  r| j                  «        y y # t         $ r}| j#                  |d«       Y d }~y d }~ww xY w)NzSSL connection is closedr   úFatal error on SSL protocol)rµ   r
   r   r   r   r¶   r   Ú!LOG_THRESHOLD_FOR_CONNLOST_WRITESr   Úwarningr�   r‘   r’   r“   r   rí   rî   rý   )r3   r€   r}   Úexs       r   r{   zSSLProtocol._write_appdata£  sè   € à�K‰KÜ ×)Ñ)Ü ×)Ñ)Ü ×*Ñ*ðñ ð �‰¤)×"MÑ"MÒMÜ—‘Ð9Ô:Ø�OŠO˜qÑ �OØà ò 	1ˆDØ×Ñ×&Ñ& tÔ,Ø×#Ò#¤s¨4£yÑ0Ö#ð	1ð	AØ�{‰{Ô.×6Ñ6Ò6Ø—‘Õ ð 7øô ò 	AØ×Ñ˜bÐ"?×@Ñ@ûð	Aús   Ã-C4 Ã4	DÃ=DÄDc                 ó~  — 	 | j                   r‘| j                   d   }| j                  j                  |«      }t        |«      }||k  r(||d  | j                   d<   | xj                  |z  c_        n"| j                   d= | xj                  |z  c_        | j                   rŒ‘| j                  «        y # t
        $ r Y Œw xY wrß   )r�   r¹   r~   r“   r’   r  r  )r3   r}   ÚcountÚdata_lens       r   rí   zSSLProtocol._do_write»  s¸   € ð	Ø×%Ò%Ø×*Ñ*¨1Ñ-�ØŸ™×*Ñ*¨4Ó0�Ü˜t›9�Ø˜8Ò#Ø-1°%°&¨\�D×'Ñ'¨Ñ*Ø×+Ò+¨uÑ4Ö+à×+Ñ+¨AÐ.Ø×+Ò+¨xÑ7Õ+ð ×%Ó%ð 	×ÑÕ øô ò 	Ùð	ús   ‚BB0 Â0	B<Â;B<c                 ó¼   — | j                   s@| j                  j                  «       }t        |«      r| j                  j                  |«       | j                  «        y r>   )rº   r´   r×   r“   r¯   r~   r[   r|   s     r   r  zSSLProtocol._process_outgoingË  sB   € Ø×'Ò'Ø—>‘>×&Ñ&Ó(ˆDÜ�4ŒyØ—‘×%Ñ% dÔ+Ø×!Ñ!Õ#r   c                 óœ  — | j                   t        j                  t        j                  fvry 	 | j                  sZ| j
                  r| j                  «        n| j                  «        | j                  r| j                  «        n| j                  «        | j                  «        y # t        $ r}| j                  |d«       Y d }~y d }~ww xY w)Nr  )rµ   r
   r   r   rQ   rÊ   Ú_do_read__bufferedÚ_do_read__copiedr�   rí   r  rh   rî   rý   )r3   r!  s     r   rä   zSSLProtocol._do_readÔ  s«   € à�K‰KÜ ×(Ñ(Ü ×)Ñ)ð ñ ð
 ð	AØ×+Ò+Ø×/Ò/Ø×+Ñ+Õ-à×)Ñ)Ô+Ø×&Ò&Ø—N‘NÕ$à×*Ñ*Ô,Ø×%Ñ%Õ'øÜò 	AØ×Ñ˜bÐ"?×@Ñ@ûð	Aús   ¯A6B& Â&	CÂ/CÃCc                 óè  ‡ — d}d}‰ j                  ‰ j                  «       «      }t        |«      }	 ‰ j                  j	                  ||«      }|dkD  rY|}||k  r4‰ j                  j	                  ||z
  ||d  «      }|dkD  r||z  }nn$||k  rŒ4‰ j
                  j                  ˆ fd„«       |dkD  r‰ j                  |«       |s!‰ j                  «        ‰ j                  «        y y # t        $ r Y ŒEw xY w)Nr   r   c                  ó$   •— ‰ j                  «       S r>   )rä   rD   s   €r   rø   z0SSLProtocol._do_read__buffered.<locals>.<lambda>ý  s   ø€ °·±³€ r   )rÇ   ro   r“   r¹   r×   r0   rØ   r  rÉ   r  rI   )r3   Úoffsetr#  ÚbufÚwantss   `    r   r'  zSSLProtocol._do_read__bufferedê  sù   ø€ ØˆØˆà×+Ñ+¨D×,FÑ,FÓ,HÓIˆÜ�C“ˆð	Ø—L‘L×%Ñ% e¨SÓ1ˆEà�qŠyØ�Ø˜u’nØ ŸL™L×-Ñ-¨e°f©n¸cÀ&À'¸lÓK�EØ˜q’yØ %™™àð ˜u“nð —J‘J×(Ñ(Ó)@ÔAð �AŠ:Ø×-Ñ-¨fÔ5Ùà×#Ñ#Ô%Ø× Ñ Õ"ð øô	 ò 	Ùð	ús   ±AC% ÂC% Ã%	C1Ã0C1c                 ó¦  — d}d}d}	 	 | j                   j                  | j                  «      }|sn$|rd}d}|}n|rd}|g}nj                  |«       ŒL	 |r| j
                  j                  «       n,|s*| j
                  j                  dj                  «      «       |s!| j                  «        | j                  «        y y # t        $ r Y Œyw xY w)Nó   1TFr   )
r¹   r×   r    r‘   r  rC   Údata_receivedÚjoinr  rI   )r3   ÚchunkÚzeroÚoneÚfirstr}   s         r   r(  zSSLProtocol._do_read__copied  sÜ   € ØˆØˆØˆð	ØØŸ™×)Ñ)¨$¯-©-Ó8�ÙØÙØ �DØ�CØ!‘EÙØ�CØ! 5˜>‘Dà—K‘K Ô&ð ð ñ Ø×Ñ×,Ñ,¨UÕ3ÙØ×Ñ×,Ñ,¨S¯X©X°d«^Ô<Ùà×#Ñ#Ô%Ø× Ñ Õ"ð øô ò 	Ùð	ús   ˆAC Ã	CÃCc                 ó>  — 	 | j                   t        j                  k(  rHt        j                  | _         | j                  j                  «       }|rt        j                  d«       y y y # t        t        f$ r ‚ t        $ r}| j                  |d«       Y d }~y d }~ww xY w)Nz?returning true from eof_received() has no effect when using sslzError calling eof_received())r·   r   r   r   rC   rï   r   r   ÚKeyboardInterruptÚ
SystemExitÚBaseExceptionrý   )r3   Ú	keep_openr!  s      r   r  zSSLProtocol._call_eof_received%  s•   € ð
	BØ�‰Ô"2×"AÑ"AÒAÜ"2×"<Ñ"<�”Ø ×.Ñ.×;Ñ;Ó=�	ÙÜ—N‘Nð $Bõ Cð ð Bøô "¤:Ð.ò 	ØÜò 	BØ×Ñ˜bÐ"@×AÑAûð	Bús   ‚A#A( Á(BÂ BÂBc                 óZ  — | j                  «       }|| j                  k\  r/| j                  s#d| _        	 | j                  j	                  «        y || j                  k  r0| j                  r#d| _        	 | j                  j                  «        y y y # t
        t        f$ r ‚ t        $ r4}| j                  j                  d|| j                  | dœ«       Y d }~y d }~ww xY w# t
        t        f$ r ‚ t        $ r4}| j                  j                  d|| j                  | dœ«       Y d }~y d }~ww xY w)NTzprotocol.pause_writing() failed©ÚmessageÚ	exceptionrÓ   r@   Fz protocol.resume_writing() failed)rd   r`   rr   rC   Úpause_writingr7  r8  r9  r0   Úcall_exception_handlerr­   r_   Úresume_writing)r3   ÚsizerŽ   s      r   r[   z SSLProtocol._control_app_writing4  s$  € Ø×*Ñ*Ó,ˆØ�4×,Ñ,Ò,°T×5MÒ5MØ'+ˆDÔ$ð
Ø×"Ñ"×0Ñ0Õ2ð �T×-Ñ-Ò-°$×2JÒ2JØ',ˆDÔ$ð
Ø×"Ñ"×1Ñ1Õ3ð 3KÐ-øô &¤zÐ2ò ØÜ ò Ø—
‘
×1Ñ1Ø@Ø!$Ø!%×!4Ñ!4Ø $ñ	3÷ ñ ûðûô &¤zÐ2ò ØÜ ò Ø—
‘
×1Ñ1ØAØ!$Ø!%×!4Ñ!4Ø $ñ	3÷ ñ ûðús/   ´B Á2C ÂCÂ'*CÃCÃD*Ã6*D%Ä%D*c                 óH   — | j                   j                  | j                  z   S r>   )r´   Úpendingr’   rD   s    r   rd   z"SSLProtocol._get_write_buffer_sizeQ  s   € Ø�~‰~×%Ñ%¨×(?Ñ(?Ñ?Ð?r   c                 ó\   — t        ||t        j                  «      \  }}|| _        || _        y r>   )r,   r   Ú!FLOW_CONTROL_HIGH_WATER_SSL_WRITEr`   r_   r\   s      r   rZ   z$SSLProtocol._set_write_buffer_limitsT  s.   € Ü,Ø�#”y×BÑBóD‰	ˆˆcà$(ˆÔ!Ø#&ˆÕ r   c                 ó   — d| _         y r‹   )rQ   rD   s    r   rT   zSSLProtocol._pause_reading\  s
   € Ø#'ˆÕ r   c                 ón   ‡ — ‰ j                   r(d‰ _         ˆ fd„}‰ j                  j                  |«       y y )NFc                  ó  •— ‰ j                   t        j                  k(  r‰ j                  «        y ‰ j                   t        j                  k(  r‰ j                  «        y ‰ j                   t        j                  k(  r‰ j                  «        y y r>   )rµ   r
   r   rä   r   rå   r   ræ   rD   s   €r   Úresumez+SSLProtocol._resume_reading.<locals>.resumec  s`   ø€ Ø—;‘;Ô"2×":Ñ":Ò:Ø—M‘M•OØ—[‘[Ô$4×$=Ñ$=Ò=Ø—N‘NÕ$Ø—[‘[Ô$4×$=Ñ$=Ò=Ø×%Ñ%Õ'ð >r   )rQ   r0   rØ   )r3   rJ  s   ` r   rW   zSSLProtocol._resume_reading_  s2   ø€ Ø×#Ò#Ø',ˆDÔ$ô(ð �J‰J× Ñ  Õ(ð $r   c                 ó  — | j                  «       }|| j                  k\  r.| j                  s"d| _        | j                  j	                  «        y || j
                  k  r/| j                  r"d| _        | j                  j                  «        y y y )NTF)ro   rl   r»   r¯   rU   rk   rX   )r3   rB  s     r   rh   z SSLProtocol._control_ssl_readingn  su   € Ø×)Ñ)Ó+ˆØ�4×,Ñ,Ò,°T×5MÒ5MØ'+ˆDÔ$Ø�O‰O×)Ñ)Õ+Ø�T×-Ñ-Ò-°$×2JÒ2JØ',ˆDÔ$Ø�O‰O×*Ñ*Õ,ð 3KÐ-r   c                 ó\   — t        ||t        j                  «      \  }}|| _        || _        y r>   )r,   r   Ú FLOW_CONTROL_HIGH_WATER_SSL_READrl   rk   r\   s      r   rg   z#SSLProtocol._set_read_buffer_limitsw  s.   € Ü,Ø�#”y×AÑAóC‰	ˆˆcà$(ˆÔ!Ø#&ˆÕ r   c                 ó.   — | j                   j                  S r>   )r³   rD  rD   s    r   ro   z!SSLProtocol._get_read_buffer_size}  s   € Ø�~‰~×%Ñ%Ð%r   c                 ó.   — | j                   rJ ‚d| _         y)z\Called when the low-level transport's buffer goes over
        the high-water mark.
        TN)rº   rD   s    r   r?  zSSLProtocol.pause_writing‚  s   € ð ×+Ò+Ð+Ð+Ø#'ˆÕ r   c                 óN   — | j                   sJ ‚d| _         | j                  «        y)z^Called when the low-level transport's buffer drains below
        the low-water mark.
        FN)rº   r  rD   s    r   rA  zSSLProtocol.resume_writing‰  s'   € ð ×'Ò'Ð'Ð'Ø#(ˆÔ Ø×ÑÕ r   c                 óf  — | j                   r| j                   j                  |«       t        |t        «      r5| j                  j                  «       rt        j                  d| |d¬«       y y t        |t        j                  «      s+| j                  j                  ||| j                   | dœ«       y y )Nz%r: %sT)Úexc_infor<  )r¯   rˆ   ru   ÚOSErrorr0   ré   r   rê   r   ÚCancelledErrorr@  )r3   rŽ   r=  s      r   rý   zSSLProtocol._fatal_error‘  sˆ   € Ø�?Š?Ø�O‰O×(Ñ(¨Ô-ä�cœ7Ô#Ø�z‰z×#Ñ#Ô%Ü—‘˜X t¨W¸tÖDð &ä˜C¤×!:Ñ!:Ô;Ø�J‰J×-Ñ-Ø"Ø Ø!Ÿ_™_Ø ñ	/õ ð <r   )FNTNNr>   r•   )zFatal error on transport).r   r   r   r    rú   rÝ   rÛ   r6   r?   rÏ   r½   rÔ   rÙ   rÄ   rÈ   rï   r8   rÚ   rÒ   r÷   rã   rë   rI   r  rå   ræ   r  rŒ   r{   rí   r  rä   r'  r(  r  r[   rd   rZ   rT   rW   rh   rg   ro   r?  rA  rý   r   r   r   r�   r�     sõ   „ Ø€Hà ÐØ $ÐØ#Ðð 59Ø&*Ø'+Ø&*ó	Q"òf	1óò#ò ò"2òH%ò ò!óFò$-òPò ;ò.ò%òRò*Còò
-ò8ò.òAò0!ò $òAò,#ò:#ò<Bòò:@ó'ò(ò)ò-ó'ò&ò
(ò!ôr   r�   )rª   Úenumrš   r   ÚImportErrorÚ r   r   r   r   Úlogr   ÚSSLWantReadErrorÚSSLSyscallErrorr  ÚEnumr
   r   r$   r,   Ú_FlowControlMixinÚ	Transportr.   rÆ   r�   r   r   r   ú<module>r^     s·   ðó
 Û Û ðÛõ Ý Ý Ý Ý à€?Ø×*Ñ*¨C×,?Ñ,?Ð@€Nô�t—y‘yô ô&�t—y‘yô &ò òô*r;˜J×8Ñ8Ø&×0Ñ0ôr;ôjW
�)×,Ñ,õ W
øð{ ò Ø
‚Cðús   ŽB0 Â0B:Â9B: