
    Rh{                     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
{1W=q=b" # 	# r6Mr   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,     ||DL..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)    ||DLNN*, 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)zPause 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)zResume 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3D#>//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24=//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)zWrite 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)zWrite 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)zClose 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 (;$3D!$(D!% j1 *//1"#
|,"&+#&;#%9"&00.99DO.==DO''00NNDNN)) 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,CD)0<0K0KD-+/D(+0D(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"ID*.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)zCalled 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,0D)))**113-1D* *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`    19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27F;<;;*777 [[,444MMO[[,555NN[[,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    "	zz##%.5{{.;;;++,@A 0 8 88 0 9 9:++NN$ 0 9 99  0 9 9:!!# 0 9 99!!# :  	OO!!#	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 KK+555)666G KK+888)111G KK+333)222G KK+444)222G#DK 3::KK,- -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    ::!LL2D9)-):D&)-D&(556 JJ!!$"="="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*+ 
 4S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    	.LL%%' ''-  	%""$|| 	-'',,	-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-1D*	$ 0 8 89##))+H ::!"T%?%??BLL94cJ 	H"(--/'-'9'9';&, 	 	. ??.999.==DO..t/F/F/HI1  		 MOO,667#s334I,c3'$		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    KK )) )) **  **.D';;*777KKOO,556,0JJ,A,A**6-D) NN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    KK )) )) 
 OO((''(@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,0D)l+JJ  !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??&OO((- '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    KK )) )) **  )"M"MM9:OOq O  	1D&&t,##s4y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t9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4y%%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    KK (( ))  
 	A++//++-))+&&NN$**,%%' 	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	LL%%eS1Eqyun LL--efnc&'lKEqy% un JJ(()@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KK&   ,,U3,,SXXd^<##%  "   		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"<"< ..;;=	NN $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,,,T5M5M'+D$
""002 T---$2J2J',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":"::MMO[[$4$=$==NN$[[$4$=$==%%' >r   )rQ   r0   r   )r3   rJ  s   ` r   rW   zSSLProtocol._resume_reading_  s2    ##',D$( JJ  ( $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,,,T5M5M'+D$OO))+T---$2J2J',D$OO**, 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    ??OO((-c7#zz##%XtWtD &C!:!:;JJ--" !__ 	/  <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# "2H% !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tyy &tyy & *r;J88&00r;jW
),, W
{  
Cs   B0 0B:9B: