HEX
Server: Apache
System: Linux 185.122.168.184.host.secureserver.net 5.14.0-570.60.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Nov 5 05:00:59 EST 2025 x86_64
User: barbeatleanalyti (1024)
PHP: 8.1.33
Disabled: NONE
Upload Files
File: //var/opt/nydus/ops/mysql/connector/aio/__pycache__/utils.cpython-39.pyc
a

�,�hn�	@s�dZddgZddlZddlZddlZzddlZWneyFdZYn0ddlmZm	Z	m
Z
mZerne�d�Gdd�dej
�Z
Gd	d�dejj�Zdd
d�eeee	eejefd�d
d�Ze
e	e	ejd�dd�ZdS)z
Utilities.�	to_thread�open_connection�N)�
TYPE_CHECKING�Any�Callable�Tuple�StreamWriterc@s"eZdZdZejdd�dd�ZdS)�StreamReaderProtocolz�Extends 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.
    N)�writer�returncCs&|j}||_||_|�d�du|_dS)zQReplace stream writer.

        Args:
            writer: Stream Writer.
        �
sslcontextN)�	transport�_stream_writer�
_transport�get_extra_info�	_over_ssl)�selfr
r
�r�L/opt/nydus/tmp/pip-target-wkfpz8uv/lib64/python/mysql/connector/aio/utils.py�_replace_writer:sz$StreamReaderProtocol._replace_writer)�__name__�
__module__�__qualname__�__doc__�asynciorrrrrrr	3sr	c@s.eZdZdZddd�ejeedd�dd�ZdS)rz�Extends 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_contextrrrc�sT|jjdu}|j}|��IdH|jj|j|||||d�IdH}||_|�|�dS)z�Upgrade 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_siderr)�	_protocol�_client_connected_cb�drain�_loop�	start_tlsrr)rrrrr�protocolZ
new_transportrrrr#Ms�
�zStreamWriter.start_tls)	rrrr�ssl�
SSLContext�str�intr#rrrrrFs
��i)�limit)�host�portr)�kwdsrc	�sbt��}tjj||d�}t||d��|j�fdd�||fi|��IdH\}}t|�||�}||fS)aA 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.
    )r)�loop)r-cs�S)Nrr�r$rr�<lambda>��z!open_connection.<locals>.<lambda>N)r�get_running_loop�streams�StreamReaderr	�create_connectionr)	r*r+r)r,r-�readerr
�_r
rr.rrms()�func�args�kwargsrc�s>t��}t��}tj|j|g|�Ri|��}|�d|�IdHS)aQAsynchronously 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)rr1�contextvars�copy_context�	functools�partial�run�run_in_executor)r7r8r9r-�ctx�	func_callrrrr�s
)NN)r�__all__rr:r<r%�ImportError�typingrrrr�appendr	r2rr'r(r3r�Futurerrrrr�<module> s*

(���