
    ,h                     n   d Z ddgZddlZddlZddlZ	 ddlZddlmZm	Z	m
Z
mZ erddlmZ ej                  d        G d d	ej                        Z G d
 dej                   j"                        Z	 ddddededede	deej(                  ef   f
dZde
de	de	dej,                  fdZy# e$ r dZY w xY w)z
Utilities.	to_threadopen_connection    N)TYPE_CHECKINGAnyCallableTuple)MySQLConnectionAbstractStreamWriterc                   4    e Zd ZdZdej
                  ddfdZy)StreamReaderProtocolzExtends asyncio.streams.StreamReaderProtocol for adding start_tls().

    The ``start_tls()`` is based on ``asyncio.streams.StreamWriter`` introduced
    in Python 3.11. It provides the same functionality for older Python versions.
    writerreturnNc                 h    |j                   }|| _        || _        |j                  d      du| _        y)zQReplace stream writer.

        Args:
            writer: Stream Writer.
        
sslcontextN)	transport_stream_writer
_transportget_extra_info	_over_ssl)selfr   r   s      [/var/www/html/Resume-Scraper/venv/lib/python3.12/site-packages/mysql/connector/aio/utils.py_replace_writerz$StreamReaderProtocol._replace_writer<   s5     $$	$#"11,?tK    )__name__
__module____qualname____doc__asyncior
   r    r   r   r   r   5   s#    	Lg&:&: 	Lt 	Lr   r   c            	       D    e Zd ZdZddddej
                  dededdfdZy)	r
   zExtends asyncio.streams.StreamWriter for adding start_tls().

    The ``start_tls()`` is based on ``asyncio.streams.StreamWriter`` introduced
    in Python 3.11. It provides the same functionality for older Python versions.
    N)server_hostnamessl_handshake_timeoutssl_contextr!   r"   r   c                "  K   | j                   j                  du}| j                   }| j                          d{    | j                  j	                  | j
                  |||||       d{   }|| _        |j                  |        y7 P7 w)zUpgrade an existing stream-based connection to TLS.

        Args:
            ssl_context: Configured SSL context.
            server_hostname: Server host name.
            ssl_handshake_timeout: SSL handshake timeout.
        N)server_sider!   r"   )	_protocol_client_connected_cbdrain_loop	start_tlsr   r   )r   r#   r!   r"   r%   protocolnew_transports          r   r*   zStreamWriter.start_tlsO   s      nn99E>>jjl"jj22OO#+"7 3 
 
  	 	  & 	
s!   8BB2B-B.BB)	r   r   r   r   ssl
SSLContextstrintr*   r   r   r   r
   r
   H   s>      $%)'^^' 	'
  #' 
'r   i   )limithostportr1   kwdsr   c                   	K   t        j                         }t         j                  j                  ||      }t	        ||      	 |j
                  	fd| |fi | d{   \  }}t        |	||      }||fS 7 w)a  A wrapper for create_connection() returning a (reader, writer) pair.

    This function is based on ``asyncio.streams.open_connection`` and adds a custom
    stream reader.

    MySQL expects TLS negotiation to happen in the middle of a TCP connection, not at
    the start.
    This function in conjunction with ``_StreamReaderProtocol`` and ``_StreamWriter``
    allows the TLS negotiation on an existing connection.

    Args:
        host: Server host name.
        port: Server port.
        limit: The buffer size limit used by the returned ``StreamReader`` instance.
               By default the limit is set to 64 KiB.

    Returns:
        tuple: Returns a pair of reader and writer objects that are instances of
               ``StreamReader`` and ``StreamWriter`` classes.
    )r1   loop)r6   c                       S )Nr   )r+   s   r   <lambda>z!open_connection.<locals>.<lambda>   s     r   N)r   get_running_loopstreamsStreamReaderr   create_connectionr
   )
r2   r3   r1   r4   r6   readerr   _r   r+   s
            @r   r   r   o   s     . ##%D__))D)AF#F6H///0@$UPTUULIq)Xvt<F6> Vs   AA=!A;"A=funcargskwargsc                    K   t        j                         }t        j                         }t	        j
                  |j                  | g|i |}|j                  d|       d{   S 7 w)aQ  Asynchronously run function ``func`` in a separate thread.

    This function is based on ``asyncio.to_thread()`` introduced in Python 3.9, which
    provides the same functionality for older Python versions.

    Returns:
        coroutine: A coroutine that can be awaited to get the eventual result of
                   ``func``.
    N)r   r9   contextvarscopy_context	functoolspartialrunrun_in_executor)r?   r@   rA   r6   ctx	func_calls         r   r   r      s]      ##%D

"
"
$C!!#''4A$A&AI%%dI6666s   A"A+$A)%A+)NN)r   __all__r   rC   rE   r-   ImportErrortypingr   r   r   r   mysql.connector.aio.abstractsr	   appendr   r:   r
   r/   r0   r;   r   Futurer   r   r   r   <module>rQ      s   @ )
*    7 6ENN>"L777 L&$'7??// $'P #'8=
25GJ
7-.>7( 73 7# 7'.. 7I  
Cs   B* *B43B4