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__/network.cpython-39.pyc
a

�,�h`a�@sJdZddgZddlZddlZddlZz"ddlZejejejej	d�Z
Wney\dZYn0ddlm
Z
mZddlmZddlmZmZmZmZmZd	d
lmZmZmZmZd	dlmZmZmZm Z dd
l!m"Z"m#Z#e$e%d�dd�Z&Gdd�de
�Z'Gdd�de'�Z(Gdd�de(�Z)Gdd�de
�Z*Gdd�de*�Z+Gdd�de*�Z,dS)zFModule implementing low-level socket communication with MySQL servers.�MySQLTcpSocket�MySQLUnixSocket�N)�TLSv1�TLSv1.1�TLSv1.2�TLSv1.3)�ABC�abstractmethod)�deque)�Any�Deque�List�Optional�Tuple�)�InterfaceError�NotSupportedError�OperationalError�ProgrammingError)�COMPRESSED_PACKET_HEADER_LENGTH�MAX_PAYLOAD_LENGTH�MIN_COMPRESS_LENGTH�PACKET_HEADER_LENGTH�)�StreamWriter�open_connection)�err�returncCs |jst|�S|j�d|j��S)z`Reformat the IOError error message.

    This function reformats the IOError error message.
    � )�errno�str�strerror)r�r"�N/opt/nydus/tmp/pip-target-wkfpz8uv/lib64/python/mysql/connector/aio/network.py�_strioerrorGsr$c	@sNeZdZdZed	eeeee	ee	dd�dd��Z
eejee
d�dd��ZdS)
�
NetworkBrokeraPBroker class interface.

    The network object is a broker used as a delegate by a socket object. Whenever the
    socket wants to deliver or get packets to or from the MySQL server it needs to rely
    on its network broker (netbroker).

    The netbroker sends `payloads` and receives `packets`.

    A packet is a bytes sequence, it has a header and body (referred to as payload).
    The first `PACKET_HEADER_LENGTH` or `COMPRESSED_PACKET_HEADER_LENGTH`
    (as appropriate) bytes correspond to the `header`, the remaining ones represent the
    `payload`.

    The maximum payload length allowed to be sent per packet to the server is
    `MAX_PAYLOAD_LENGTH`. When  `send` is called with a payload whose length is greater
    than `MAX_PAYLOAD_LENGTH` the netbroker breaks it down into packets, so the caller
    of `send` can provide payloads of arbitrary length.

    Finally, data received by the netbroker comes directly from the server, expect to
    get a packet for each call to `recv`. The received packet contains a header and
    payload, the latter respecting `MAX_PAYLOAD_LENGTH`.
    N��writer�address�payload�
packet_number�compressed_packet_numberrc�sdS)a�Send `payload` to the MySQL server.

        If provided a payload whose length is greater than `MAX_PAYLOAD_LENGTH`, it is
        broken down into packets.

        Args:
            sock: Object holding the socket connection.
            address: Socket's location.
            payload: Packet's body to send.
            packet_number: Sequence id (packet ID) to attach to the header when sending
                           plain packets.
            compressed_packet_number: Same as `packet_number` but used when sending
                                      compressed packets.

        Raises:
            :class:`OperationalError`: If something goes wrong while sending packets to
                                       the MySQL server.
        Nr")�selfr'r(r)r*r+r"r"r#�writegs	zNetworkBroker.write��readerr(rc�sdS)a)Get the next available packet from the MySQL server.

        Args:
            sock: Object holding the socket connection.
            address: Socket's location.

        Returns:
            packet: A packet from the MySQL server.

        Raises:
            :class:`OperationalError`: If something goes wrong while receiving packets
                                       from the MySQL server.
            :class:`InterfaceError`: If something goes wrong while receiving packets
                                     from the MySQL server.
        Nr")r,r/r(r"r"r#�read�szNetworkBroker.read)NN)�__name__�
__module__�__qualname__�__doc__r	rr �bytesr�intr-�asyncio�StreamReader�	bytearrayr0r"r"r"r#r%Os��r%c@s�eZdZdZdd�dd�Zeeeeefd�dd��Z	de
edd	�d
d�Zee
edd�d
d�Zdejeed�dd�Zdee
ee
ee
edd�dd�Zeje
ed�dd�ZdS)�NetworkBrokerPlain�,Broker class for MySQL socket communication.N�rcCs
d|_dS�N�����_pktnr�r,r"r"r#�__init__�szNetworkBrokerPlain.__init__��pktrcCsBt|�tkrtd��t�d|dd�d�d|d}}||fS)�-Recover the header information from a packet.�3Can't recover header info from an incomplete packet�<Ir��)�lenr�
ValueError�struct�unpack)rD�pll�seqidr"r"r#�
get_header�s�zNetworkBrokerPlain.get_header��next_idrcCs0|dur|jd7_n||_|jd;_dS�z:Set the given packet id, if any, else increment packet id.Nr�r?�r,rRr"r"r#�_set_next_pktnr�sz"NetworkBrokerPlain._set_next_pktnr�r'r(rDrc
�s�z|�|�|��IdHWnhtyV}z"td|t|�fd�|�WYd}~n8d}~0ty�}ztdd�|�WYd}~n
d}~00dS)z!Write packet to the comm channel.N��r�valuesi��r)r-�drain�IOErrorrr$�AttributeError)r,r'r(rDrr"r"r#�
_write_pkt�s
��zNetworkBrokerPlain._write_pktr)r/�sizerc�sHtd�}t|�|krD|�|t|��IdH}|s:tdd��||7}q|S)z(Read `size` bytes from the comm channel.�Ni�r[)r9rJr0r)r,r/r`rD�chunkr"r"r#�_read_chunk�s

zNetworkBrokerPlain._read_chunkr&c
�s�|�|�d}tt|�t�D]F}|�||dt�d|j�|||t��IdH|��|t7}q|�||t�dt|�|�dd�t�d|j�||d��IdHdS)z�Send payload to the MySQL server.

        If provided a payload whose length is greater than `MAX_PAYLOAD_LENGTH`, it is
        broken down into packets.
        r�����<BNrGrH)rV�rangerJrr_rL�packr@)r,r'r(r)r*r+�offset�_r"r"r#r-�s.
���

�
��zNetworkBrokerPlain.writer.c
�s~z>|j|td�IdH}|�|�\}|_||j||d�IdHWStyx}z"td|t|�fd�|�WYd}~n
d}~00dS)z+Receive `one` packet from the MySQL server.�r`NrXrY)rcrrPr@r]rr$)r,r/r(�headerZpayload_lenrr"r"r#r0�s��zNetworkBrokerPlain.read)N)r)NN)r1r2r3r4rB�staticmethodr5rr6rPrrVrr r_r7r8r9rcr-r0r"r"r"r#r:�s,
����&r:cs�eZdZdZdd��fdd�Zeeeeed�dd��Z	eee
eeefd	�d
d��Zdeedd�d
d�Z
eeedd��fdd�Zdeeeeeeedd��fdd�
Zejedd��fdd�Zejeed��fdd�Z�ZS)�NetworkBrokerCompressedr;Nr<cst���d|_t�|_dSr=)�superrB�_compressed_pktnrr
�_queue_readrA��	__class__r"r#rBs
z NetworkBrokerCompressed.__init__)r)�pktnrrcCs�d}g}tt|�t�D]>}|�dt�d|�|||t��|dd}|t7}q|�t�dt|�|�dd�t�d|�||d��|S)	z2Prepare a payload for sending to the MySQL server.rrdrerrTrGrHN)rfrJr�appendrLrg)r)rsrhZpktsrir"r"r#�_prepare_packetss(
���

�
��z(NetworkBrokerCompressed._prepare_packetsrCcCsbt|�tkrtd��t�d|dd�d�d|dt�d|dd�d�d}}}|||fS)rErFrGrrHrI��)rJrrKrLrM)rD�compressed_pllrO�uncompressed_pllr"r"r#rP!s�
z"NetworkBrokerCompressed.get_headerrQcCs0|dur|jd7_n||_|jd;_dSrS)rorUr"r"r#�_set_next_compressed_pktnr/sz2NetworkBrokerCompressed._set_next_compressed_pktnrrWc�sbt�|�}t�dt|��dd�t�d|j�t�dt|��dd�|}t��|||�IdHS)z1Compress packet and write it to the comm channel.rGrrHreN)�zlib�compressrLrgrJrornr_)r,r'r(rD�compressed_pktrqr"r#r_7s
����z"NetworkBrokerCompressed._write_pktr&c		�s|�|�|�|�td��|�||j��}t|�ttkr�d}t	t|�t�D]4}|�
|||||t��IdH|��|t7}qP|�
||||d��IdHnrt|�tkr�|�
|||�IdHnPt��
||t
�dt|��dd�t
�d|j�t
�dd�dd�|�IdHdS)z�Send `payload` as compressed packets to the MySQL server.

        If provided a payload whose length is greater than `MAX_PAYLOAD_LENGTH`, it is
        broken down into packets.
        rarNrGrHre)rVrzr9�joinrur@rJrrrfr_rrnrLrgro)	r,r'r(r)r*r+Zpayload_preprhrirqr"r#r-Bs2

�

����zNetworkBrokerCompressed.write)r/rxrc	�s�tt�t�j||d�IdH��}d}|t|�kr�t�d|||td�d�d}t|t|�|kr�t�j|t	d�IdH}|�
|�\}|_}t�j||d�IdH}||dkr�|nt�|�7}|j�
|||t|��|t|7}q$dS)z&Handle reading of a compressed packet.rjNrrGrrI)r9r{�
decompressrnrcrJrLrMrrrProrprt)	r,r/rxrDrhrNrkryr}rqr"r#�_read_compressed_pktys6����	���z,NetworkBrokerCompressed._read_compressed_pktr.c
�s�|js�zft�j|td�IdH}|�|�\}|_}|dkrX|j�t�j||d�IdH�n|�||�IdHWn:ty�}z"t	d|t
|�fd�|�WYd}~n
d}~00|js�dS|j��}|d|_|S)z{Receive `one` or `several` packets from the MySQL server, enqueue them, and
        return the packet at the head.
        rjNrrXrYrH)
rprnrcrrPrortr�r]rr$�popleftr@)r,r/r(rkrxryrrDrqr"r#r0�s4�	����

zNetworkBrokerCompressed.read)N)NN)r1r2r3r4rBrlr5r6r
rurrPrrzrr r_r-r7r8r�r9r0�
__classcell__r"r"rqr#rms,
��8�(rmc
@seZdZdZdd�dd�Zeed�dd��Zee	dd�d	d
��Z
dd�dd�Zed�d
d�Z
edd�dd�Zdd�dd�Zejdd�dd�Zd eeeeedd�dd�Zed�dd�Zdddddggfeeeeeeeeeeeeeeeeejd�dd�ZdS)!�MySQLSocketz�MySQL socket communication interface.

    Examples:
        Subclasses: network.MySQLTCPSocket and network.MySQLUnixSocket.
    Nr<cCs*d|_d|_d|_d|_t�|_d|_dS)zsNetwork layer where transactions are made with plain (uncompressed) packets
        is enabled by default.
        NF)�_reader�_writer�_connection_timeout�_addressr:�
_netbroker�
_is_connectedrAr"r"r#rB�szMySQLSocket.__init__cCs|jS)zSocket location.)r�rAr"r"r#r(�szMySQLSocket.address��kwargsrc�sdS)zOpen the socket.Nr"�r,r�r"r"r#r�szMySQLSocket.open_connectionc�sB|jr8|j��|jjdur(|jj��|j��IdHd|_dS)zClose the connection.NF)r��close�	transport�abort�wait_closedr�rAr"r"r#�close_connection�s
zMySQLSocket.close_connectioncCs|jS)z�Check if the socket is connected.

        Return:
            bool: Returns `True` if the socket is connected to MySQL server.
        )r�rAr"r"r#�is_connected�szMySQLSocket.is_connected)�timeoutrcCs
||_dS)zSet the connection timeout.N)r�)r,r�r"r"r#�set_connection_timeout�sz"MySQLSocket.set_connection_timeoutcCst�|_dS)zIEnable network layer where transactions are made with compressed packets.N)rmr�rAr"r"r#�switch_to_compressed_mode�sz%MySQLSocket.switch_to_compressed_mode)�ssl_contextrc�sD|jdusJ�|jj�d�}|jdkr.td��|j�|�IdHdS)a?Upgrade an existing stream-based connection to TLS.

        The `start_tls()` method from `asyncio.streams.StreamWriter` is only available
        in Python 3.11. This method is used as a workaround.

        The MySQL TLS negotiation happens in the middle of the TCP connection.
        Therefore, passing a socket to open connection will cause it to negotiate
        TLS on an existing connection.

        Args:
            ssl_context: The SSL Context to be used.

        Raises:
            RuntimeError: If the transport does not expose the socket instance.
        N�socketrz,SSL is not supported when using Unix sockets)r�r��get_extra_info�familyr�	start_tls)r,r�r�r"r"r#�
switch_to_ssl�s

zMySQLSocket.switch_to_ssl)r)r*r+rc�s$|jj|j|j|||d�IdHdS)z!Send packets to the MySQL server.)r*r+N)r�r-r�r()r,r)r*r+r"r"r#r-s�zMySQLSocket.writec�s|j�|j|j�IdHS)z#Read packets from the MySQL server.N)r�r0r�r(rAr"r"r#r0&szMySQLSocket.readF)�ssl_ca�ssl_cert�ssl_key�ssl_verify_cert�ssl_verify_identity�tls_versions�tls_cipher_suitesrcCs|jstdd��tdur td���zx|r�|jdd�|d}t|}	t�|	�}
|dkr�d	|vrn|
jtjO_d
|vr�|
jtj	O_d|vr�|
jtj
O_nt��}
||
_|r�tj
|
_n|r�tj|
_ntj|
_|
��|�r,z|
�|�Wn<ttjf�y*}ztd|���|�WYd}~n
d}~00|�r�z|
�||�Wn<ttjf�y~}ztd
|���|�WYd}~n
d}~00|�r�|
�d�|��|
WSt�y�}ztd�|�WYd}~nHd}~0tttjtjf�y}ztt|��|�WYd}~n
d}~00dS)zBuild a SSLContext.ir[Nz&Python installation has no SSL supportT)�reverserrrrrzInvalid CA Certificate: zInvalid Certificate/Key: �:)r�r�ssl�RuntimeError�sort�TLS_VERSIONS�
SSLContext�options�
OP_NO_TLSv1_2�
OP_NO_TLSv1_1�OP_NO_TLSv1�create_default_context�check_hostname�
CERT_REQUIRED�verify_mode�
CERT_OPTIONAL�	CERT_NONE�load_default_certs�load_verify_locationsr]�SSLError�load_cert_chain�set_ciphersr~�	NameErrorr�NotImplementedError�CertificateErrorr )r,r�r�r�r�r�r�r�Ztls_version�ssl_protocol�contextrr"r"r#�build_ssl_context*s^



&&�zMySQLSocket.build_ssl_context)NN)r1r2r3r4rB�propertyr r(r	rrr��boolr�r6r�r�r�r�r�r5rr-r9r0r
r�r"r"r"r#r��sJ
���

�r�cs<eZdZdZdeeed��fdd�
Zedd	�d
d�Z	�Z
S)
rz�MySQL socket class using TCP/IP.

    Args:
        host: MySQL host name.
        port: MySQL port.
        force_ipv6: Force IPv6 usage.
    �	127.0.0.1��F)�host�port�
force_ipv6cs0t���||_||_||_|�d|��|_dS)Nr�)rnrB�_host�_portZ_force_ipv6r�)r,r�r�r�rqr"r#rBzs

zMySQLTcpSocket.__init__Nr�c�s0tf|j|jd�|��IdH\|_|_d|_dS)zOpen TCP/IP connection.)r�r�NT)rr�r�r�r�r�r�r"r"r#r�s��zMySQLTcpSocket.open_connection)r�r�F)r1r2r3r4r r6r�rBrrr�r"r"rqr#rqs	��	cs8eZdZdZd
ed��fdd�
Zedd�dd	�Z�ZS)rzbMySQL socket class using UNIX sockets.

    Args:
        unix_socket: UNIX socket file path.
    �/tmp/mysql.sock)�unix_socketcst���||_dS)N)rnrBr�)r,r�rqr"r#rB�s
zMySQLUnixSocket.__init__Nr�c�s.tjfd|ji|��IdH\|_|_d|_dS)zOpen UNIX socket connection.�pathNT)r7�open_unix_connectionr�r�r�r�r�r"r"r#r�s��
�zMySQLUnixSocket.open_connection)r�)	r1r2r3r4r rBrrr�r"r"rqr#r�s)-r4�__all__r7rLr{r��PROTOCOL_TLSv1�PROTOCOL_TLSv1_1�PROTOCOL_TLSv1_2�PROTOCOL_TLSr��ImportError�abcrr	�collectionsr
�typingrrr
rr�errorsrrrr�networkrrrr�utilsrrr]r r$r%r:rmr�rrr"r"r"r#�<module>s8�

GjJ)