
    F\h}|                     ~   S SK r S SKrS SKr S SKrSSKJr  SSKJr  SSKJr  SSKJ	r	  SSK
Jr  \b  \R                  \R                  4r " S S	\R                  5      r " S
 S\R                  5      rS rS r " S S\	R(                  \	R*                  5      r " S S\R.                  5      rg! \ a    Sr Nf = f)    N   )	constants)
exceptions)	protocols)
transports)loggerc                   (    \ rS rSrSrSrSrSrSrSr	g)	SSLProtocolState   	UNWRAPPEDDO_HANDSHAKEWRAPPEDFLUSHINGSHUTDOWN N)
__name__
__module____qualname____firstlineno__r   r   r   r   r   __static_attributes__r       '/usr/lib/python3.13/asyncio/sslproto.pyr
   r
      s    I!LGHHr   r
   c                   $    \ rS rSrSrSrSrSrSrg)AppProtocolState   
STATE_INITSTATE_CON_MADE	STATE_EOFSTATE_CON_LOSTr   N)	r   r   r   r   r   r   r   r   r   r   r   r   r   r      s     J%NI%Nr   r   c                 p    U (       a  [        S5      e[        R                  " 5       nU(       d  SUl        U$ )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                     U c  Uc  US-  nO
UnSU-  nOU nUc  US-  nOUnX4s=:  a  S:  d  O  [        SU< SU< S35      eX44$ )Ni      r   zhigh (z) must be >= low (z) must be >= 0)r!   )highlowkbhilos        r   add_flowcontrol_defaultsr0   =   sd    |;dBBRB
{1W=q=b" # 	# 6Mr   c                       \ rS rSrSr\R                  R                  rS r	SS jr
S rS rS rS	 r\4S
 jrS rS rS rSS jrS rS rSS jrS rS r\S 5       rS rS rS rS rS r S r!S r"Sr#g)_SSLProtocolTransportR   Tc                 *    Xl         X l        SU l        g )NF)_loop_ssl_protocol_closed)selfloopssl_protocols      r   __init___SSLProtocolTransport.__init__X   s    
)r   Nc                 8    U R                   R                  X5      $ )z#Get optional transport information.)r6   _get_extra_infor8   namedefaults      r   get_extra_info$_SSLProtocolTransport.get_extra_info]   s    !!11$@@r   c                 :    U R                   R                  U5        g N)r6   _set_app_protocol)r8   protocols     r   set_protocol"_SSLProtocolTransport.set_protocola   s    ,,X6r   c                 .    U R                   R                  $ rE   )r6   _app_protocolr8   s    r   get_protocol"_SSLProtocolTransport.get_protocold   s    !!///r   c                 \    U R                   =(       d    U R                  R                  5       $ rE   )r7   r6   _is_transport_closingrL   s    r   
is_closing _SSLProtocolTransport.is_closingg   s     ||It11GGIIr   c                 x    U R                   (       d"  SU l         U R                  R                  5         gSU l        g)zClose 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)r7   r6   _start_shutdownrL   s    r   close_SSLProtocolTransport.closej   s,     ||DL..0!%Dr   c                 b    U R                   (       d  SU l         UR                  S[        5        g g )NTz9unclosed transport <asyncio._SSLProtocolTransport object>)r7   warnResourceWarning)r8   	_warningss     r   __del___SSLProtocolTransport.__del__x   s)    ||DLNN*, r   c                 8    U R                   R                  (       + $ rE   )r6   _app_reading_pausedrL   s    r   
is_reading _SSLProtocolTransport.is_reading   s    %%9999r   c                 8    U R                   R                  5         g)z|Pause the receiving end.

No data will be passed to the protocol's data_received()
method until resume_reading() is called.
N)r6   _pause_readingrL   s    r   pause_reading#_SSLProtocolTransport.pause_reading   s     	))+r   c                 8    U R                   R                  5         g)zmResume the receiving end.

Data received will once again be passed to the protocol's
data_received() method.
N)r6   _resume_readingrL   s    r   resume_reading$_SSLProtocolTransport.resume_reading   s     	**,r   c                 n    U R                   R                  X5        U R                   R                  5         g)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)r6   _set_write_buffer_limits_control_app_writingr8   r+   r,   s      r   set_write_buffer_limits-_SSLProtocolTransport.set_write_buffer_limits   s*    & 	33D>//1r   c                 Z    U R                   R                  U R                   R                  4$ rE   )r6   _outgoing_low_water_outgoing_high_waterrL   s    r   get_write_buffer_limits-_SSLProtocolTransport.get_write_buffer_limits   *    ""66""779 	9r   c                 6    U R                   R                  5       $ )z-Return the current size of the write buffers.)r6   _get_write_buffer_sizerL   s    r   get_write_buffer_size+_SSLProtocolTransport.get_write_buffer_size   s    !!88::r   c                 n    U R                   R                  X5        U R                   R                  5         g)a7  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)r6   _set_read_buffer_limits_control_ssl_readingrl   s      r   set_read_buffer_limits,_SSLProtocolTransport.set_read_buffer_limits   s*    & 	224=//1r   c                 Z    U R                   R                  U R                   R                  4$ rE   )r6   _incoming_low_water_incoming_high_waterrL   s    r   get_read_buffer_limits,_SSLProtocolTransport.get_read_buffer_limits   rt   r   c                 6    U R                   R                  5       $ )z+Return the current size of the read buffer.)r6   _get_read_buffer_sizerL   s    r   get_read_buffer_size*_SSLProtocolTransport.get_read_buffer_size   s    !!7799r   c                 .    U R                   R                  $ rE   )r6   _app_writing_pausedrL   s    r   _protocol_paused&_SSLProtocolTransport._protocol_paused   s     !!555r   c                     [        U[        [        [        45      (       d!  [	        S[        U5      R                   35      eU(       d  gU R                  R                  U45        g)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   r6   _write_appdatar8   datas     r   write_SSLProtocolTransport.write   s[     $	: >?? ##':#6#6"79 : :))4'2r   c                 :    U R                   R                  U5        g)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)r6   r   )r8   list_of_datas     r   
writelines _SSLProtocolTransport.writelines   s     	)),7r   c                     [         e)zeClose the write end after flushing buffered data.

This raises :exc:`NotImplementedError` right now.
)NotImplementedErrorrL   s    r   	write_eof_SSLProtocolTransport.write_eof   s
    
 "!r   c                     g)zAReturn True if this transport supports write_eof(), False if not.Fr   rL   s    r   can_write_eof#_SSLProtocolTransport.can_write_eof   s    r   c                 &    U R                  S5        g)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_closerL   s    r   abort_SSLProtocolTransport.abort   s     	$r   c                 d    SU l         U R                  b  U R                  R                  U5        g g NT)r7   r6   _abortr8   excs     r   r   "_SSLProtocolTransport._force_close   s.    )%%c* *r   c                     U R                   R                  R                  U5        U R                   =R                  [	        U5      -  sl        g rE   )r6   _write_backlogappend_write_buffer_sizelenr   s     r   _test__append_write_backlog1_SSLProtocolTransport._test__append_write_backlog  s7    ))006--T:-r   )r7   r5   r6   rE   NN)$r   r   r   r   _start_tls_compatibler   _SendfileModeFALLBACK_sendfile_compatibler;   rB   rH   rM   rQ   rU   warningsr[   r_   rc   rg   rm   rr   rw   r|   r   r   propertyr   r   r   r   r   r   r   r   r   r   r   r   r2   r2   R   s     !$22;;
A70J& !) ,:,-2,9;2,9: 6 638" +
;r   r2   c                   4   \ rS rSrSrSrSrSr    S-S jrS r	S.S jr
S rS rS	 rS
 rS rS rS rS.S jrS rS rS rS rS rS rS rS rS rS rS rS rS rS r S r!S r"S r#S  r$S! r%S" r&S/S# jr'S$ r(S% r)S& r*S/S' jr+S( r,S) r-S* r.S0S+ jr/S,r0g)1SSLProtocoli  i   Nc
                    [         c  [        S5      e[        U R                  5      U l        [        U R                  5      U l        Uc  [        R                  nOUS::  a  [        SU 35      eU	c  [        R                  n	OU	S::  a  [        SU	 35      eU(       d  [        XV5      nXPl        U(       a  U(       d  X`l        OS U l        X0l        [        US9U l        ["        R$                  " 5       U l        SU l        X@l        Xl        U R/                  U5        S U l        SU l        S U l        Xl        Xl        [         R:                  " 5       U l        [         R:                  " 5       U l        [@        RB                  U l"        SU l#        U(       a  [H        RJ                  U l&        O[H        RN                  U l&        U R                  RQ                  U R<                  U R>                  U R                  U R                  S9U l)        SU l*        SU l+        SU l,        SU l-        SU l.        U R_                  5         SU l0        SU l1        SU l2        SU l3        U Ri                  5         U Rk                  5         g )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"   RuntimeErrorr   max_size_ssl_bufferr   _ssl_buffer_viewr   SSL_HANDSHAKE_TIMEOUTr!   SSL_SHUTDOWN_TIMEOUTr(   _server_side_server_hostname_sslcontextdict_extracollectionsdequer   r   _waiterr5   rF   _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_pausedr^   _ssl_reading_pausedr   r   rz   _eof_receivedr   rq   rp   rj   _get_app_transport)
r8   r9   app_protocolr'   waiterr%   r&   call_connection_madessl_handshake_timeoutssl_shutdown_timeouts
             r   r;   SSLProtocol.__init__  s5   
 ;@AA$T]]3 *4+;+; < ($-$C$C!"a',-/0 0  '#,#A#A !Q&+,./ / 2.J (;$3!$(D!% j1 *//1"#
|,"&+#&;#%9"&00.99DO.==DO''00NNDNN)) 11 1 3 $) #( #( $%!#$ $$&"#( $%!#$ %%'!r   c                     Xl         [        US5      (       aI  [        U[        R                  5      (       a*  UR
                  U l        UR                  U l        SU l	        g SU l	        g )N
get_bufferTF)
rK   hasattrr   r   BufferedProtocolr   _app_protocol_get_bufferbuffer_updated_app_protocol_buffer_updated_app_protocol_is_buffer)r8   r   s     r   rF   SSLProtocol._set_app_protocola  sT    )L,//<)C)CDD,8,C,CD)0<0K0KD-+/D(+0D(r   c                     U R                   c  g U R                   R                  5       (       d:  Ub  U R                   R                  U5        OU R                   R                  S 5        S U l         g rE   )r   	cancelledset_exception
set_resultr   s     r   _wakeup_waiterSSLProtocol._wakeup_waiterl  sR    <<||%%''**3/''-r   c                     U R                   c>  U R                  (       a  [        S5      e[        U R                  U 5      U l         SU l        U R                   $ )Nz$Creating _SSLProtocolTransport twiceT)r   r   r   r2   r5   rL   s    r   r   SSLProtocol._get_app_transportv  sJ    &**"#IJJ"7

D"ID*.D'"""r   c                 `    U R                   S L=(       a    U R                   R                  5       $ rE   )r   rQ   rL   s    r   rP   !SSLProtocol._is_transport_closing~  s#    d*Kt/I/I/KKr   c                 0    Xl         U R                  5         g)zHCalled when the low-level connection is made.

Start the SSL handshake.
N)r   _start_handshake)r8   	transports     r   connection_madeSSLProtocol.connection_made  s    
 $r   c                 d   U R                   R                  5         U R                  R                  5         U =R                  S-  sl        U R
                  b  SU R
                  l        U R                  [        R                  :w  a  U R                  [        R                  :X  d  U R                  [        R                  :X  aE  [        R                  U l
        U R                  R!                  U R"                  R$                  U5        U R'                  [        R(                  5        SU l        SU l        SU l        U R-                  U5        U R.                  (       a!  U R.                  R1                  5         SU l        U R2                  (       a"  U R2                  R1                  5         SU l        gg)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   r7   r   r
   r   r   r   r   r   r   r5   	call_soonrK   connection_lost
_set_stater   r   r   _shutdown_timeout_handlecancel_handshake_timeout_handler   s     r   r   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                     UnUS::  d  X R                   :  a  U R                   n[        U R                  5      U:  a*  [        U5      U l        [	        U R                  5      U l        U R
                  $ Nr   )r   r   r   r   r   r   )r8   nwants      r   r   SSLProtocol.get_buffer  s^    19}},==Dt 4'(D$.t/?/?$@D!$$$r   c                    U R                   R                  U R                  S U 5        U R                  [        R
                  :X  a  U R                  5         g U R                  [        R                  :X  a  U R                  5         g U R                  [        R                  :X  a  U R                  5         g U R                  [        R                  :X  a  U R                  5         g g rE   )r   r   r   r   r
   r   _do_handshaker   _do_readr   	_do_flushr   _do_shutdown)r8   nbytess     r   r   SSLProtocol.buffer_updated  s    T227F;<;;*777 [[,444MMO[[,555NN[[,555 6r   c                    SU l          U R                  R                  5       (       a  [        R                  " SU 5        U R
                  [        R                  :X  a  U R                  [        5        gU R
                  [        R                  :X  aB  U R                  [        R                  5        U R                  (       a  gU R                  5         gU R
                  [        R                  :X  a@  U R                  5         U R                  [        R                   5        U R#                  5         gU R
                  [        R                   :X  a  U R#                  5         gg! [$         a    U R&                  R)                  5         e f = f)zCalled 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   r5   	get_debugr   debugr   r
   r   _on_handshake_completeConnectionResetErrorr   r   r   r^   r  	_do_writer   r  	Exceptionr   rU   rL   s    r   eof_received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! 3AE! E! AE! 1.E! !&Fc                     XR                   ;   a  U R                   U   $ U R                  b  U R                  R                  X5      $ U$ rE   )r   r   rB   r?   s      r   r>   SSLProtocol._get_extra_info  s?    ;;;;t$$__(??11$@@Nr   c                 @   SnU[         R                  :X  a  SnOU R                  [         R                  :X  a  U[         R                  :X  a  SnOU R                  [         R                  :X  a  U[         R                  :X  a  SnOiU R                  [         R                  :X  a  U[         R
                  :X  a  SnO4U R                  [         R
                  :X  a  U[         R                  :X  a  SnU(       a  Xl        g [        SR                  U R                  U5      5      e)NFTz!cannot switch state from {} to {})	r
   r   r   r   r   r   r   r   format)r8   	new_statealloweds      r   r   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#K 3::KK,- -r   c                    U R                   R                  5       (       a7  [        R                  " SU 5        U R                   R	                  5       U l        OS U l        U R                  [        R                  5        U R                   R                  U R                  U R                  5      U l        U R                  5         g )Nz%r starts SSL handshake)r5   r  r   r  time_handshake_start_timer   r
   r   
call_laterr   _check_handshake_timeoutr  r
  rL   s    r   r   SSLProtocol._start_handshake  s    ::!!LL2D9)-):D&)-D&(556 JJ!!$"="="&"?"?A 	& 	r   c                     U R                   [        R                  :X  a+  SU R                   S3nU R	                  [        U5      5        g g )Nz$SSL handshake is taking longer than z! seconds: aborting the connection)r   r
   r   r   _fatal_errorConnectionAbortedError)r8   msgs     r   r$  $SSLProtocol._check_handshake_timeout(  sN    ;;*7776../ 0*+ 
 4S9: 8r   c                      U R                   R                  5         U R                  S 5        g ! [         a    U R	                  5          g [
        R                   a  nU R                  U5         S nAg S nAff = frE   )r   do_handshaker  SSLAgainErrors_process_outgoingr"   SSLErrorr   s     r   r
  SSLProtocol._do_handshake1  sb    	.LL%%' ''-  	%""$|| 	-'',,	-s   . A8
A8A33A8c                    U R                   b!  U R                   R                  5         S U l         U R                  n Uc   U R                  [        R
                  5        OUeUR                  5       nU R                  R                  5       (       aA  U R                  R!                  5       U R"                  -
  n[$        R&                  " SXS-  5        U R(                  R+                  UUR-                  5       UR/                  5       US9  U R0                  [2        R4                  :X  a>  [2        R6                  U l        U R8                  R;                  U R=                  5       5        U R                  5         U R?                  5         g ! [         aq  nS nU R                  [        R                  5        [        U[        R                  5      (       a  SnOSnU R                  XE5        U R                  U5         S nAg S nAff = f)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   r   r"   CertificateErrorr'  r   r5   r  r!  r"  r   r  r   updater3  r4  r   r   r   r   rK   r   r   r  )r8   handshake_excsslobjr2  r   r)  dts          r   r  "SSLProtocol._on_handshake_complete;  s   ))5**113-1D*	$ 0 8 89##))+H ::!!"T%?%??BLL94cJ 	H"(--/'-'9'9';&, 	 	. ??.999.==DO..t/F/F/HI1  		 MOO,667#s3344I,c'$		s   5F 
HA'G<<Hc                    U R                   [        R                  [        R                  [        R                  4;   a  g U R
                  b  SU R
                  l        U R                   [        R                  :X  a  U R                  S 5        g U R                  [        R                  5        U R                  R                  U R                  U R                  5      U l        U R                  5         g r   )r   r
   r   r   r   r   r7   r   r   r   r5   r#  r   _check_shutdown_timeoutr   r  rL   s    r   rT   SSLProtocol._start_shutdownd  s    KK )) )) **  **.D';;*777KKOO,556,0JJ,A,A**,,-D) NNr   c                     U R                   [        R                  [        R                  4;   a0  U R                  R                  [        R                  " S5      5        g g )NzSSL shutdown timed out)r   r
   r   r   r   r   r   TimeoutErrorrL   s    r   r>  #SSLProtocol._check_shutdown_timeouty  sN    KK )) )) 
 OO((''(@ACr   c                     U R                  5         U R                  [        R                  5        U R	                  5         g rE   )r  r   r
   r   r  rL   s    r   r  SSLProtocol._do_flush  s*    (112r   c                 X    U R                   (       d  U R                  R                  5         U R                  5         U R	                  5         U R                  S 5        g ! [         a    U R                  5          g [        R                   a  nU R                  U5         S nAg S nAff = frE   )	r   r   unwrapr.  _call_eof_received_on_shutdown_completer-  r"   r/  r   s     r   r  SSLProtocol._do_shutdown  s    
	-%%##% ""$##%&&t,  	%""$|| 	,&&s++	,s   +A B);B)B$$B)c                     U R                   b!  U R                   R                  5         S U l         U(       a  U R                  U5        g U R                  R	                  U R
                  R                  5        g rE   )r   r  r'  r5   r   r   rU   )r8   shutdown_excs     r   rH  !SSLProtocol._on_shutdown_complete  sU    ((4))002,0D)l+JJ  !6!67r   c                     U R                  [        R                  5        U R                  b  U R                  R	                  U5        g g rE   )r   r
   r   r   r   r   s     r   r   SSLProtocol._abort  s6    (223??&OO((- 'r   c                 H   U R                   [        R                  [        R                  [        R                  4;   aJ  U R
                  [        R                  :  a  [        R                  " S5        U =R
                  S-  sl        g U H<  nU R                  R                  U5        U =R                  [        U5      -  sl        M>      U R                   [        R                  :X  a  U R                  5         g g ! [          a  nU R#                  US5         S nAg S nAff = f)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'  )r8   r   r   exs       r   r   SSLProtocol._write_appdata  s    KK )) )) **  )"M"MM9:OOq O D&&t,##s4y0# !	A{{.666  7  	Ab"?@@	As   .C; ;
D!DD!c                     U R                   (       a  U R                   S   nU R                  R                  U5      n[        U5      nX#:  a'  XS  U R                   S'   U =R                  U-  sl        O"U R                   S	 U =R                  U-  sl        U R                   (       a  M  U R                  5         g ! [
         a     Nf = fr  )r   r   r   r   r   r-  r.  )r8   r   countdata_lens       r   r  SSLProtocol._do_write  s    	%%**1-**40t9#-1&\D''*++u4+++A.++x7+ %%% 	   		s   B%B: :
CCc                     U R                   (       dE  U R                  R                  5       n[        U5      (       a  U R                  R                  U5        U R                  5         g rE   )r   r   r   r   r   r   rk   r   s     r   r.  SSLProtocol._process_outgoing  sD    ''>>&&(D4yy%%d+!!#r   c                    U R                   [        R                  [        R                  4;  a  g  U R                  (       dd  U R
                  (       a  U R                  5         OU R                  5         U R                  (       a  U R                  5         OU R                  5         U R                  5         g ! [         a  nU R                  US5         S nAg S nAff = f)NrP  )r   r
   r   r   r^   r   _do_read__buffered_do_read__copiedr   r  r.  r{   r  r'  )r8   rS  s     r   r  SSLProtocol._do_read  s    KK (( ))  
 	A++//++-))+&&NN$**,%%' 	Ab"?@@	As   BB7 7
CCCc                     SnSnU R                  U R                  5       5      n[        U5      n U R                  R	                  XC5      nUS:  a_  UnX:  a3  U R                  R	                  XA-
  X1S  5      nUS:  a  X-  nOO,X:  a  M3  U R
                  R                  U R                  5        US:  a  U R                  U5        U(       d!  U R                  5         U R                  5         g g ! [         a     NLf = f)Nr   r   )r   r   r   r   r   r5   r   r  r-  r   rG  rT   )r8   offsetrV  bufwantss        r   r\  SSLProtocol._do_read__buffered  s    ++D,F,F,HIC	LL%%e1Eqyn LL--enc'lKEqy n JJ((7 A:--f5##%  " 	  		s   AC0 C0 %C0 0
C=<C=c                    SnSnSn  U R                   R                  U R                  5      nU(       d  O/U(       a  SnSnUnOU(       a  SnWU/nOWR                  U5        M\  U(       a  U R
                  R                  W5        O1U(       d*  U R
                  R                  SR                  W5      5        U(       d!  U R                  5         U R                  5         g g ! [         a     Nf = f)N   1TFr   )
r   r   r   r   r-  rK   data_receivedjoinrG  rT   )r8   chunkzeroonefirstr   s         r   r]  SSLProtocol._do_read__copied
  s    	))$--8 DC!EC!5>DKK&  ,,U3,,SXXd^<##%  "   		s   -C" /C" "
C/.C/c                 P    U R                   [        R                  :X  aN  [        R                  U l         U R                  R                  5       nU(       a  [        R                  " S5        g g g ! [        [        4 a    e [         a  nU R                  US5         S nAg S nAff = f)Nz?returning true from eof_received() has no effect when using sslzError calling eof_received())r   r   r   r   rK   r  r   rR  KeyboardInterrupt
SystemExitBaseExceptionr'  )r8   	keep_openrS  s      r   rG  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                 v   U R                  5       nXR                  :  a4  U R                  (       d#  SU l         U R                  R	                  5         g XR                  ::  a5  U R                  (       a#  SU l         U R                  R                  5         g g g ! [
        [        4 a    e [         a4  nU R                  R                  SUU R                  U S.5         S nAg S nAff = f! [
        [        4 a    e [         a4  nU R                  R                  SUU R                  U S.5         S nAg S nAff = f)NTzprotocol.pause_writing() failedmessage	exceptionr   rG   Fz protocol.resume_writing() failed)rv   rq   r   rK   pause_writingrn  ro  rp  r5   call_exception_handlerr   rp   resume_writing)r8   sizer   s      r   rk    SSLProtocol._control_app_writing7  s    **,,,,T5M5M'+D$
""002 ---$2J2J',D$
""113 3K- &z2   

11@!$!%!4!4 $	3   &z2   

11A!$!%!4!4 $	3  s/   B <C* C'3*C""C'*D8*D33D8c                 H    U R                   R                  U R                  -   $ rE   )r   pendingr   rL   s    r   rv   "SSLProtocol._get_write_buffer_sizeT  s    ~~%%(?(???r   c                 T    [        X[        R                  5      u  pXl        X l        g rE   )r0   r   !FLOW_CONTROL_HIGH_WATER_SSL_WRITErq   rp   rl   s      r   rj   $SSLProtocol._set_write_buffer_limitsW  s&    ,yBBD	$(!#& r   c                     SU l         g r   )r^   rL   s    r   rb   SSLProtocol._pause_reading_  s
    #' r   c                 z   ^  T R                   (       a)  ST l         U 4S jnT R                  R                  U5        g g )NFc                     > T R                   [        R                  :X  a  T R                  5         g T R                   [        R                  :X  a  T R                  5         g T R                   [        R                  :X  a  T R                  5         g g rE   )r   r
   r   r  r   r  r   r  rL   s   r   resume+SSLProtocol._resume_reading.<locals>.resumef  s`    ;;"2":"::MMO[[$4$=$==NN$[[$4$=$==%%' >r   )r^   r5   r   )r8   r  s   ` r   rf   SSLProtocol._resume_readingb  s2    ##',D$( JJ  ( $r   c                 .   U R                  5       nXR                  :  a3  U R                  (       d"  SU l        U R                  R	                  5         g XR
                  ::  a4  U R                  (       a"  SU l        U R                  R                  5         g g g )NTF)r   r   r   r   rc   r   rg   )r8   rz  s     r   r{    SSLProtocol._control_ssl_readingq  sq    ))+,,,T5M5M'+D$OO))+---$2J2J',D$OO**, 3K-r   c                 T    [        X[        R                  5      u  pXl        X l        g rE   )r0   r    FLOW_CONTROL_HIGH_WATER_SSL_READr   r   rl   s      r   rz   #SSLProtocol._set_read_buffer_limitsz  s&    ,yAAC	$(!#& r   c                 .    U R                   R                  $ rE   )r   r}  rL   s    r   r   !SSLProtocol._get_read_buffer_size  s    ~~%%%r   c                 8    U R                   (       a   eSU l         g)zLCalled when the low-level transport's buffer goes over
the high-water mark.
TN)r   rL   s    r   rw  SSLProtocol.pause_writing  s     ++++#' r   c                 X    U R                   (       d   eSU l         U R                  5         g)zNCalled when the low-level transport's buffer drains below
the low-water mark.
FN)r   r.  rL   s    r   ry  SSLProtocol.resume_writing  s'     ''''#(  r   c                    U R                   (       a  U R                   R                  U5        [        U[        5      (       a7  U R                  R                  5       (       a  [        R                  " SXSS9  g g [        U[        R                  5      (       d+  U R                  R                  UUU R                   U S.5        g g )Nz%r: %sT)exc_infort  )r   r   r   OSErrorr5   r  r   r  r   CancelledErrorrx  )r8   r   ru  s      r   r'  SSLProtocol._fatal_error  s    ??OO((-c7##zz##%%XttD &C!:!:;;JJ--" !__ 	/  <r   )%rK   r   r   r   r^   r   r   r   r   r   r   r   r"  r  r   r   r   r5   r   rq   rp   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   )FNTNNrE   r   )zFatal error on transport)1r   r   r   r   r   r"  r  r   r;   rF   r   r   rP   r   r   r   r   r  r>   r   r   r$  r
  r  rT   r>  r  r  rH  r   r   r  r.  r  r\  r]  rG  rk   rv   rj   rb   rf   r{   rz   r   rw  ry  r'  r   r   r   r   r   r     s    H  $# 59&*'+&*	Q"f	1#L "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(   r0   _FlowControlMixin	Transportr2   r   r   r   r   r   <module>r     s   
        ?**C,?,?@Ntyy &tyy & *r;J88&00r;jZ
),, Z
{  
Cs   B1 1B<;B<