
    d{                     P   d dl Z d dlZd dlZ	 d dlZn# e$ r dZY nw xY w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dS )    N   )	constants)
exceptions)	protocols)
transports)loggerc                   "    e Zd ZdZdZdZdZdZdS )SSLProtocolState	UNWRAPPEDDO_HANDSHAKEWRAPPEDFLUSHINGSHUTDOWNN)__name__
__module____qualname__r   r   r   r   r        "  /croot/python-split_1694437901252/_h_env_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_placehold_plac/lib/python3.11/asyncio/sslproto.pyr
   r
      s'        I!LGHHHHr   r
   c                       e Zd ZdZdZdZdZdS )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%NNNr   r   c                 `    | 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$   +   s@     ECD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,   9   s    |;dBBBRBB
{1W====q====j""bbb" # # 	# 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!dS )_SSLProtocolTransportTc                 0    || _         || _        d| _        d S )NF)_loop_ssl_protocol_closed)selfloopssl_protocols      r   __init__z_SSLProtocolTransport.__init__T   s    
)r   Nc                 8    | j                             ||          S )z#Get optional transport information.)r1   _get_extra_infor3   namedefaults      r   get_extra_infoz$_SSLProtocolTransport.get_extra_infoY   s    !11$@@@r   c                 :    | j                             |           d S N)r1   _set_app_protocol)r3   protocols     r   set_protocolz"_SSLProtocolTransport.set_protocol]   s    ,,X66666r   c                     | j         j        S r>   )r1   _app_protocolr3   s    r   get_protocolz"_SSLProtocolTransport.get_protocol`   s    !//r   c                     | j         S r>   )r2   rD   s    r   
is_closingz _SSLProtocolTransport.is_closingc   s
    |r   c                 f    | j         s"d| _         | j                                         dS d| _        dS )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.closef   s>     | 	&DL..00000!%Dr   c                 \    | j         s$d| _         |                    dt                     d S d S )NTz9unclosed transport <asyncio._SSLProtocolTransport object>)r2   warnResourceWarning)r3   	_warningss     r   __del__z_SSLProtocolTransport.__del__t   sE    | 	,DLNN*, , , , ,	, 	,r   c                     | j         j         S r>   )r1   _app_reading_pausedrD   s    r   
is_readingz _SSLProtocolTransport.is_reading{   s    %999r   c                 8    | j                                          dS )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                                          dS )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                 n    | j                             ||           | j                                          dS )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   s8    & 	33D#>>>//11111r   c                 2    | 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"79 	9r   c                 4    | 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                 n    | j                             ||           | j                                          dS )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   s8    & 	224===//11111r   c                 2    | 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                 4    | 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99r   c                     | j         j        S r>   )r1   _app_writing_pausedrD   s    r   _protocol_pausedz&_SSLProtocolTransport._protocol_paused   s     !55r   c                     t          |t          t          t          f          s$t	          dt          |          j                   |sdS | j                            |f           dS )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   sv     $	: >?? 	: 9#'::#69 9 : : : 	F))4'22222r   c                 :    | j                             |           dS )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!     	)),7777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                     dS )zAReturn True if this transport supports write_eof(), False if not.Fr   rD   s    r   can_write_eofz#_SSLProtocolTransport.can_write_eof   s    ur   c                 X    d| _         | j        | j                                         dS dS )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.
        TNr2   r1   _abortrD   s    r   abortz_SSLProtocolTransport.abort   s7     )%%''''' *)r   c                 H    d| _         | j                            |           d S NTr   r3   excs     r   _force_closez"_SSLProtocolTransport._force_close   s&    !!#&&&&&r   c                     | j         j                            |           | j         xj        t	          |          z  c_        d S r>   )r1   _write_backlogappend_write_buffer_sizelenr|   s     r   _test__append_write_backlogz1_SSLProtocolTransport._test__append_write_backlog   s?    )0066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.   N   s        !$2;  
A A A A7 7 70 0 0  & & & !) , , , ,: : :, , ,- - -2 2 2 2,9 9 9; ; ;2 2 2 2,9 9 9: : : 6 6 X63 3 38 8 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,d0d,Z-dS )1SSLProtocoli   NFTc
                    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| _        || _        || _        |                     |           d | _        d| _        d | _        || _        |	| _        t          j                    | _        t          j                    | _        t@          j!        | _"        d| _#        |rtH          j%        | _&        ntH          j'        | _&        | j        (                    | j        | j        | j        | j                  | _)        d| _*        d| _+        d| _,        d| _-        d| _.        | /                                 d| _0        d| _1        d| _2        d| _3        | 4                                 | 5                                 d S )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__  s   
 ;@AAA$T]33 *4+; < < ($-$C!!"a''/,/ /0 0 0  '#,#A  !Q&&.+. ./ / /  	.2_. .J ( 	); 	)$3D!!$(D!% j111 */11"#
|,,,"&+#&;#%9"&0 	>.9DOO.=DO'00NDN) 1 1 3 3 $) #( #( $%!#$ $$&&&"#( $%!#$ %%'''!!!!!r   c                     || _         t          |d          r;t          |t          j                  r!|j        | _        |j        | _        d| _	        d S d| _	        d S )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_protocol^  sc    )L,// 	1<)CDD	1,8,CD)0<0KD-+/D(((+0D(((r   c                     | j         d S | j                                         s7|| j                             |           n| j                             d            d | _         d S r>   )r   	cancelledset_exception
set_resultr   s     r   _wakeup_waiterzSSLProtocol._wakeup_waiteri  sd    <F|%%'' 	.**3////''---r   c                     | j         7| 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_transports  sK    &* K"#IJJJ"7
D"I"ID*.D'""r   c                 <    || _         |                                  dS )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                    | j                                          | j                                         | xj        dz  c_        | j        d| j        _        | j        t          j	        k    r`| j
        t          j        k    s| j
        t          j        k    r6t          j        | _
        | j                            | j        j        |           |                     t          j                   d| _        d| _        d| _        |                     |           | j        r | j                                         d| _        | j        r"| j                                         d| _        dS dS )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  sO    	!!###1 **.D';*777#3#BBB#3#==="2"A
$$T%7%GMMM(2333"!C   ( 	1)00222,0D)) 	2*11333-1D***	2 	2r   c                     |}|dk    s|| j         k    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  sc    199t},,=Dt  4''(D$.t/?$@$@D!$$r   c                    | j                             | j        d |                    | j        t          j        k    r|                                  d S | j        t          j        k    r|                                  d S | j        t          j	        k    r| 
                                 d S | j        t          j        k    r|                                  d S d S 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27F7;<<<;*777     [,444MMOOOOO[,555NN[,555 65r   c                    d| _         	 | j                                        rt          j        d|            | j        t          j        k    r|                     t                     dS | j        t          j
        k    r>|                     t          j                   | j        rdS |                                  dS | j        t          j        k    rI|                                  |                     t          j                   |                                  dS | j        t          j        k    r|                                  dS dS # t$          $ r | 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  sg    "	z##%% 6.555{.;;;++,@AAAAA 0 888 0 9:::+ %4NN$$$$$ 0 999    0 9:::!!##### 0 999!!##### :9  	 	 	O!!###	s%   AE (;E %E ;AE )E %E+c                 v    || j         v r| j         |         S | j        | j                            ||          S |S r>   )r   r   r<   r9   s      r   r8   zSSLProtocol._get_extra_info  sA    4;;t$$_(?11$@@@Nr   c                    d}|t           j        k    rd}n| j        t           j        k    r|t           j        k    rd}nw| j        t           j        k    r|t           j        k    rd}nO| j        t           j        k    r|t           j        k    rd}n'| j        t           j        k    r|t           j        k    rd}|r	|| _        d S t          d                    | 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GG K+555)666GG K+888)111GG K+333)222GG K+444)222G 	-#DKKK 3::K, ,- - -r   c                 f     j                                         r4t          j        d             j                                          _        nd  _                             t          j                    j         	                     j
         fd           _                                          d S )Nz%r starts SSL handshakec                  ,                                      S r>   )_check_handshake_timeoutrD   s   r   <lambda>z.SSLProtocol._start_handshake.<locals>.<lambda>  s    $*G*G*I*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2D999)-):):D&&)-D&(5666 J!!$"="I"I"I"IK K 	& 	r   c                     | j         t          j        k    r/d| j         d}|                     t          |                     d S d S )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"  s_    ;*777+.+ + + 
 4S99::::: 87r   c                    	 | j                                          |                     d            d S # t          $ r |                                  Y d S t
          j        $ r }|                     |           Y d }~d S d }~ww xY wr>   )r   do_handshaker   SSLAgainErrors_process_outgoingr   SSLErrorr   s     r   r   zSSLProtocol._do_handshake+  s    	.L%%''' ''-----  	% 	% 	%""$$$$$$| 	- 	- 	-'',,,,,,,,,	-s   2 BB!A<<Bc                    | j          | j                                          d | _         | j        }	 | |                     t          j                   n||                                }n# t          $ rt}|                     t          j                   t          |t          j                  rd}nd}|                     ||           |                     |           Y d }~d S d }~ww xY w| j                                        r:| j                                        | j        z
  }t%          j        d| |dz             | j                            ||                                |                                |           | j        t2          j        k    r=t2          j        | _        | j                            |                                            |                                  |                                  d S )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_complete5  s   )5*11333-1D*	$ 0 89999##))++HH 	 	 	OO,6777#s344 -I,c3'''$$$FFFFF	 :!! 	K""T%??BL94cJJJ 	H"(--//'-'9'9';';&, 	 	. 	. 	. ?.999.=DO..t/F/F/H/HIIIs   8A) )
C'3A)C""C'c                      j         t          j        t          j        t          j        fv rd S  j        d j        _         j         t          j        k    r                                  d S  	                    t          j                    j
                             j         fd           _                                          d S )NTc                  ,                                      S r>   )_check_shutdown_timeoutrD   s   r   r   z-SSLProtocol._start_shutdown.<locals>.<lambda>n  s    4466 r   )r   r
   r   r   r   r   r2   r   r   r   r0   r   r   r   r   rD   s   `r   rI   zSSLProtocol._start_shutdown]  s    K ) ) *   F**.D';*777KKMMMMMOO,5666,0J,A,A*6666- -D) NNr   c                     | j         t          j        t          j        fv r.| j                            t          j        d                     d S d S )NzSSL shutdown timed out)r   r
   r   r   r   r   r   TimeoutErrorrD   s    r   r  z#SSLProtocol._check_shutdown_timeoutr  sf    K ) )  
 O(('(@AAC C C C C r   c                     |                                   |                     t          j                   |                                  d S r>   )r   r   r
   r   r   rD   s    r   r   zSSLProtocol._do_flush|  s=    (1222r   c                 f   	 | j         s| j                                         |                                  |                                  |                     d            d S # t          $ r |                                  Y d S t          j        $ r }|                     |           Y d }~d S 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! !B0B0B++B0c                     | j          | j                                          d | _         |r|                     |           d S | j                            | j        j                   d S r>   )r   r   r   r0   r   r   rJ   )r3   shutdown_excs     r   r  z!SSLProtocol._on_shutdown_complete  sk    (4)00222,0D) 	8l+++++J  !677777r   c                     |                      t          j                   | j        | j                                         d S d S r>   )r   r
   r   r   r   rD   s    r   r   zSSLProtocol._abort  sB    (2333?&O!!##### '&r   c                    | j         t          j        t          j        t          j        fv r;| j        t          j        k    rt          j	        d           | xj        dz  c_        d S |D ]9}| j
                            |           | xj        t          |          z  c_        :	 | j         t          j        k    r|                                  d S d S # t           $ r!}|                     |d           Y d }~d S 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 ) ) *   )"MMM9:::OOq OOF  	1 	1D&&t,,,##s4yy0###	A{.666      76  	A 	A 	Ab"?@@@@@@@@@	As   #)C 
C;C66C;c                 \   	 | j         r~| j         d         }| j                            |          }t          |          }||k     r#||d          | j         d<   | xj        |z  c_        n| j         d= | xj        |z  c_        | j         ~n# t
          $ r Y nw xY w|                                  d S r   )r   r   r~   r   r   r  r  )r3   r}   countdata_lens       r   r   zSSLProtocol._do_write  s    	% 	8*1-**400t998##-1%&&\D'*++u4++++A.++x7++ % 	8  	 	 	D	     s   BB 
BBc                     | j         sB| j                                        }t          |          r| j                            |           |                                  d S r>   )r   r   r   r   r   r~   r[   r|   s     r   r  zSSLProtocol._process_outgoing  s\    ' 	,>&&((D4yy ,%%d+++!!#####r   c                    | j         t          j        t          j        fvrd S 	 | j        s`| j        r|                                  n|                                  | j        r| 	                                 n| 
                                 |                                  d S # t          $ r!}|                     |d           Y d }~d S 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 ( )   
 F	A+ -/ ,++----))+++& -NN$$$$**,,,%%''''' 	A 	A 	Ab"?@@@@@@@@@	As   A;B   
C*CCc                 ,    d}d}                                                                 }t          |          }	  j                            ||          }|dk    r^|}||k     r9 j                            ||z
  ||d                    }|dk    r||z  }nn#||k     9 j                             fd           n# t          $ r Y nw xY w|dk    r                     |           |s* 	                                  
                                 d S d S )Nr   r   c                  ,                                      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  sK   ++D,F,F,H,HIIC	L%%eS11Eqyyunn L--efnc&''lKKEqyy% unn J(()@)@)@)@AAA 	 	 	D	A::--f555 	###%%%  """""	# 	#s   A?B= =
C
	C
c                    d}d}d}	 	 | j                             | j                  }|sn(|rd}d}|}n|rd}||g}n|                    |           Jn# t          $ r Y nw xY w|r| j                            |           n/|s-| j                            d                    |                     |s*|                                  | 	                                 d S d S )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  s3   	'))$-88  ' DC!EE 'C!5>DDKK&&&'   	 	 	D	 	=,,U3333 	=,,SXXd^^<<< 	###%%%  """""	# 	#s   AA 
A! A!c                 8   	 | j         t          j        k    rBt          j        | _         | j                                        }|rt          j        d           d S d S d S # t          t          f$ r  t          $ r!}|                     |d           Y d }~d S 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"< .;;==	 CN $B C C C C C	 BAC C ":. 	 	 	 	B 	B 	Bb"@AAAAAAAAA	Bs   AA B8BBc                 :   |                                  }|| j        k    rw| j        spd| _        	 | j                                         d S # t
          t          f$ r  t          $ r/}| j        	                    d|| j
        | d           Y d }~d S d }~ww xY w|| j        k    rw| j        rrd| _        	 | j                                         d S # t
          t          f$ r  t          $ r/}| j        	                    d|| j
        | d           Y d }~d S d }~ww xY wd S d S )NTzprotocol.pause_writing() failedmessage	exceptionr   r@   Fz protocol.resume_writing() failed)rd   r`   rr   rC   pause_writingr8  r9  r:  r0   call_exception_handlerr   r_   resume_writing)r3   sizer   s      r   r[   z SSLProtocol._control_app_writing0  s   **,,4,,,T5M,'+D$
"0022222%z2       
11@!$!%!4 $	3 3          T---$2J-',D$
"1133333%z2       
11A!$!%!4 $	3 3          .---s/   A
 
B%$BB1C D'$DDc                 *    | j         j        | j        z   S r>   )r   pendingr   rD   s    r   rd   z"SSLProtocol._get_write_buffer_sizeM  s    ~%(???r   c                 ^    t          ||t          j                  \  }}|| _        || _        d S r>   )r,   r   !FLOW_CONTROL_HIGH_WATER_SSL_WRITEr`   r_   r\   s      r   rZ   z$SSLProtocol._set_write_buffer_limitsP  s7    ,#yBD D	c$(!#&   r   c                     d| _         d S r   )rQ   rD   s    r   rT   zSSLProtocol._pause_readingX  s    #'   r   c                 f      j         r(d _          fd} j                            |           d S d S )NFc                  
    j         t          j        k    r                                  d S  j         t          j        k    r                                  d S  j         t          j        k    r                                  d S d S r>   )r   r
   r   r   r   r   r   r   rD   s   r   resumez+SSLProtocol._resume_reading.<locals>.resume_  s}    ;"2":::MMOOOOO[$4$===NN$$$$$[$4$===%%''''' >=r   )rQ   r0   r   )r3   rK  s   ` r   rW   zSSLProtocol._resume_reading[  sW    # 
	)',D$( ( ( ( ( J  (((((
	) 
	)r   c                    |                                  }|| j        k    r)| j        s"d| _        | j                                         d S || j        k    r)| j        r$d| _        | j                                         d S d S d S )NTF)ro   rl   r   r   rU   rk   rX   )r3   rC  s     r   rh   z SSLProtocol._control_ssl_readingj  s    ))++4,,,T5M,'+D$O))+++++T---$2J-',D$O**,,,,, .---r   c                 ^    t          ||t          j                  \  }}|| _        || _        d S r>   )r,   r    FLOW_CONTROL_HIGH_WATER_SSL_READrl   rk   r\   s      r   rg   z#SSLProtocol._set_read_buffer_limitss  s7    ,#yAC C	c$(!#&   r   c                     | j         j        S r>   )r   rE  rD   s    r   ro   z!SSLProtocol._get_read_buffer_sizey  s    ~%%r   c                 &    | j         rJ d| _         dS )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| _         |                                  dS )z^Called when the low-level transport's buffer drains below
        the low-water mark.
        FN)r   r  rD   s    r   rB  zSSLProtocol.resume_writing  s3     ''''#(      r   Fatal error on transportc                 \   | j         r| j                             |           t          |t                    r5| j                                        rt          j        d| |d           d S d S t          |t          j	                  s&| j        
                    ||| j         | d           d S d S )Nz%r: %sT)exc_infor=  )r   r   ru   OSErrorr0   r   r   r   r   CancelledErrorrA  )r3   r   r>  s      r   r   zSSLProtocol._fatal_error  s    ? 	.O((---c7## 		z##%% EXtWtDDDDDDE EC!:;; 	J--" !_ 	/ /     	 	r   )FNTNNr>   r   )rR  ).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@  rB  r   r   r   r   r   r     s       H  $# 59&*'+&*	Q" Q" Q" Q"f	1 	1 	1   # # #     "2 "2 "2H% % %     ! ! !F   $- $- $-P   ; ; ;. . .$ $ $P  *C C C  
- - -8 8 8$ $ $A A A0! ! ! $ $ $A A A,# # #:# # #<B B 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        JJJJ   
CCC                              ?*C,?@N    ty   & & & & &ty & & &     *s; s; s; s; s;J8&0s; s; s;lV
 V
 V
 V
 V
), V
 V
 V
 V
 V
s    