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

�,�h�m�@sJdZddlZddlZddlZddlZddlmZmZddlm	Z	ddl
mZmZm
Z
mZmZmZz2ddlZejejejejd�Zeed�o�ejZWney�dZdZYn0d	d
lmZmZmZmZdZ dZ!d
Z"dZ#e$e%d�dd�Z&Gdd�de�Z'Gdd�de'�Z(Gdd�de(�Z)Gdd�de�Z*Gdd�de*�Z+Gdd�de*�Z,dS)zGModule implementing low-level socket communication with MySQL servers.
�N)�ABC�abstractmethod)�deque)�Any�Deque�List�Optional�Tuple�Union)�TLSv1�TLSv1.1�TLSv1.2�TLSv1.3�HAS_TLSv1_3F�)�InterfaceError�NotSupportedError�OperationalError�ProgrammingError�2i�����)�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�J/opt/nydus/tmp/pip-target-wkfpz8uv/lib64/python/mysql/connector/network.py�_strioerrorEsr c	@sPeZdZdZed	ejeeee	ee	dd�dd��Z
eejeed�dd��ZdS)
�
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��sock�address�payload�
packet_number�compressed_packet_numberrcCsdS)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'rrr�sendes	zNetworkBroker.send�r#r$rcCsdS)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$rrr�recv�szNetworkBroker.recv)NN)
�__name__�
__module__�__qualname__�__doc__r�socketr�bytesr�intr)�	bytearrayr+rrrrr!Ms��r!c@s�eZdZdZdd�dd�Zdd�dd�Zejeedd�d	d
�Z	deje
ed�d
d�Zdejeee
e
e
e
dd�dd�Zejeed�dd�ZdS)�NetworkBrokerPlain�,Broker class for MySQL socket communication.N�rcCs
d|_dS�N�����_pktnr�r(rrr�__init__�szNetworkBrokerPlain.__init__cCs|jdd|_dS�zIncrement packet id.r�Nr9r;rrr�_set_next_pktnr�sz"NetworkBrokerPlain._set_next_pktnr�r#r$�pktrc
Cs|z|�|�WnhtyH}z"td|t|�fd�|�WYd}~n8d}~0tyv}ztdd�|�WYd}~n
d}~00dS)z!Write packet to the comm channel.��r�valuesNi��r)�sendall�IOErrorrr �AttributeError)r(r#r$rArrrr�	_send_pkt�s��zNetworkBrokerPlain._send_pktr)r#�sizercCsTt|�}t|�}|rP|�||�}|dkr:|dkr:tdd��||d�}||8}q|S)z(Read `size` bytes from the comm channel.ri�rEN)r3�
memoryview�	recv_intor)r(r#rJrAZpkt_view�readrrr�_recv_chunk�s

zNetworkBrokerPlain._recv_chunkr"c
Cs�|dur|��n||_t|�tkr�d}tt|�t�D]@}|�||dt�d|j�|||t��|��|t7}q8||d�}|�||t�dt|��dd�t�d|j�|�dS)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.
        Nr�����<B�<I�)r?r:�len�MAX_PAYLOAD_LENGTH�rangerI�struct�pack)r(r#r$r%r&r'�offset�_rrrr)�s6

���
���zNetworkBrokerPlain.sendr*c
Cs�zJ|j|td�}t�d|dd�d�d|d}|_||j||d�WSty�}z"td|t|�fd�|�WYd}~n
d}~00dS)	z+Receive `one` packet from the MySQL server.�rJrQrrR�rBrCN)rN�PACKET_HEADER_LENGTHrV�unpackr:rGrr )r(r#r$�headerZpayload_lenrrrrr+�s���zNetworkBrokerPlain.recv)r)NN)r,r-r.r/r<r?r0rr1rIr2r3rNrr)r+rrrrr4�s ��,r4cs�eZdZdZdd��fdd�Zeeeeed�dd��Z	dd�d	d
�Z
ejeedd��fdd
�Z
dejeeeeeedd��fdd�
Zejeedd��fdd�Zejeed��fdd�Z�ZS)�NetworkBrokerCompressedr5Nr6cst���d|_t�|_dSr7)�superr<�_compressed_pktnrr�_queue_readr;��	__class__rrr<�s
z NetworkBrokerCompressed.__init__)r%�pktnrrcCs�g}t|�tkrpd}tt|�t�D]>}|�dt�d|�|||t��|dd}|t7}q$||d�}|�t�dt|��dd�t�d|�|�|S)	z2Prepare a payload for sending to the MySQL server.rrOrPrr>NrQrR)rSrTrU�appendrVrW)r%reZpktsrXrYrrr�_prepare_packets�s$
���
&�z(NetworkBrokerCompressed._prepare_packetscCs|jdd|_dSr=)rar;rrr�_set_next_compressed_pktnrsz2NetworkBrokerCompressed._set_next_compressed_pktnrr@cs\t�|�}t�dt|��dd�t�d|j�t�dt|��dd�|}t��|||�S)z1Compress packet and write it to the comm channel.rQrrRrP)�zlib�compressrVrWrSrar`rI)r(r#r$rA�compressed_pktrcrrrIs
����z!NetworkBrokerCompressed._send_pktr"c		s|dur|��n||_|dur*|��n||_td��|�||j��}t|�tt	kr�d}t
t|�t�D].}|�|||||t��|��|t7}ql|�||||d��nft|�tkr�|�|||�nJt
��||t�dt|��dd�t�d|j�t�dd�dd�|�dS)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.
        N�rrQrRrP)r?r:rhrar3�joinrgrSrTr\rUrI�MIN_COMPRESS_LENGTHr`rVrW)	r(r#r$r%r&r'Zpayload_preprXrYrcrrr)&s:

�
����zNetworkBrokerCompressed.send)r#�compressed_pll�uncompressed_pllrc	s"t�j||d�}|dkr|ntt�|��}d}|t|�k�rt�d|||td�d�d}t|t|�|kr�t�j|t	d�}t�d|dd�d�d|dt�d|dd�d�d}|_
}t�j||d�}||dkr�|nt�|�7}|j�|||t|��|t|7}q.d	S)
z&Handle reading of a compressed packet.rZrrQrr[rRrrN)
r`rNr3ri�
decompressrSrVr]r\�COMPRESSED_PACKET_HEADER_LENGTHrarbrf)	r(r#rorprkrArXZpllr^rcrr�_recv_compressed_pktcs<��������z,NetworkBrokerCompressed._recv_compressed_pktr*c
s�|js�zht�j|td�}t�d|dd�d�d|dt�d|dd�d�d}|_}|�|||�Wn:ty�}z"t	d|t
|�fd	�|�WYd
}~n
d
}~00|js�d
S|j��}|d|_|S)z{Receive `one` or `several` packets from the MySQL server, enqueue them, and
        return the packet at the head.
        rZrQrrRr[rrrBrCN)
rbr`rNrrrVr]rarsrGrr �popleftr:)r(r#r$r^rorprrArcrrr+�s.����

zNetworkBrokerCompressed.recv)NN)r,r-r.r/r<�staticmethodr1r2rrgrhr0rrIrr)rsr3r+�
__classcell__rrrcrr_�s(��>�0r_c
@seZdZdZdd�dd�Zdd�dd�Zdd�dd	�Zdd�d
d�Zdd�dd
�Ze	e
dd�dd�Zee
dd�dd�Zd!e	e
e	e
e	e
e	ee	ee	ee
e	ee
ed�dd�Zd"ee	e
e	e
dd�dd�Zed�dd�Zedd�dd��Zeee
d�dd ���ZdS)#�MySQLSocketz�MySQL socket communication interface.

    Examples:
        Subclasses: network.MySQLTCPSocket and network.MySQLUnixSocket.
    Nr6cCsd|_d|_d|_t�|_dS)zsNetwork layer where transactions are made with plain (uncompressed) packets
        is enabled by default.
        N)r#�_connection_timeout�server_hostr4�
_netbrokerr;rrrr<�szMySQLSocket.__init__cCst�|_dS)zIEnable network layer where transactions are made with compressed packets.N)r_rzr;rrr�switch_to_compressed_mode�sz%MySQLSocket.switch_to_compressed_modec	Cs8z|j�tj�|j��Wnttfy2Yn0dS)z'Shut down the socket before closing it.N)r#�shutdownr0�	SHUT_RDWR�closerH�OSErrorr;rrrr|�s
zMySQLSocket.shutdownc	Cs*z|j��Wnttfy$Yn0dS)zClose the socket.N)r#r~rHrr;rrr�close_connection�szMySQLSocket.close_connectioncCs|��dS�N)r|r;rrr�__del__�szMySQLSocket.__del__)�timeoutrcCs||_|jr|j�|�dS)zSet the connection timeout.N)rxr#�
settimeout)r(r�rrr�set_connection_timeout�sz"MySQLSocket.set_connection_timeout)�ssl_context�hostrc
Cs |jdusJ�|jjdkr"td��tdur2td��z|j|j|d�|_Wn�tyv}ztd�|�WYd}~n�d}~0tjtfy�}z$t	d|j
t|�fd�|�WYd}~nnd}~0tjy�}zt	t
|��|�WYd}~n<d}~0t�y}zt	t
|��|�WYd}~n
d}~00dS)a�Upgrade an existing connection to TLS.

        Args:
            ssl_context (ssl.SSLContext): The SSL Context to be used.
            host (str): Server host name.

        Returns:
            None.

        Raises:
            ProgrammingError: If the transport does not expose the socket instance.
            NotSupportedError: If Python installation has no SSL support.
        Nrz,SSL is not supported when using Unix sockets�&Python installation has no SSL support)�server_hostnamerBrC)r#�familyr�sslr�wrap_socket�	NameError�SSLErrorrGrr$r �CertificateErrorr�NotImplementedError)r(r�r�rrrr�
switch_to_ssl�s&��"zMySQLSocket.switch_to_sslF)�ssl_ca�ssl_cert�ssl_key�ssl_verify_cert�ssl_verify_identity�tls_versions�tls_cipher_suitesrcCs&|jstdd��tdur td��|dur,g}|dur8g}�zx|r�|jdd�|d}t|}	t�|	�}
|dkr�d	|vr�|
jtjO_d
|vr�|
jtj	O_d|vr�|
jtj
O_nt��}
||
_|r�tj
|
_n|r�tj|
_ntj|
_|
��|�rDz|
�|�Wn<ttjf�yB}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)a�Build a SSLContext.

        Args:
            ssl_ca: Certificate authority, opptional.
            ssl_cert: SSL certificate, optional.
            ssl_key: Private key, optional.
            ssl_verify_cert: Verify the SSL certificate if `True`.
            ssl_verify_identity: Verify host identity if `True`.
            tls_versions: TLS protocol versions, optional.
            tls_cipher_suites: Set of steps that helps to establish a secure connection.

        Returns:
            ssl_context (ssl.SSLContext): An SSL Context ready be used.

        Raises:
            NotSupportedError: Python installation has no SSL support.
            InterfaceError: Socket undefined or invalid ssl data.
        irENr�T)�reverserrr
rrzInvalid CA Certificate: zInvalid Certificate/Key: �:)r#rr�r�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_locationsrGr��load_cert_chain�set_ciphersrmr�r�r�r)r(r�r�r�r�r�r�r�Ztls_version�ssl_protocol�contextrrrr�build_ssl_contextsf



&&�zMySQLSocket.build_ssl_context)r%r&r'rcCs|jj|j|j|||d�S)atSend `payload` to the MySQL server.

        NOTE: if `payload` is an instance of `bytearray`, then `payload` might be
        changed by this method - `bytearray` is similar to passing a variable by
        reference.

        If you're sure you won't read `payload` after invoking `send()`,
        then you can use `bytearray.` Otherwise, you must use `bytes`.
        )r&r')rzr)r#r$)r(r%r&r'rrrr)ds�zMySQLSocket.sendcCs|j�|j|j�S)z.Get packet from the MySQL server comm channel.)rzr+r#r$r;rrrr+{szMySQLSocket.recvcCsdS)zOpen the socket.Nrr;rrr�open_connectionszMySQLSocket.open_connectioncCsdS)zGet the location of the socket.Nrr;rrrr$�szMySQLSocket.address)NNNFFNN)NN)r,r-r.r/r<r{r|r�r�rr2r�rrr��boolrr�r1r)r3r+rr��propertyr$rrrrrw�sN
&�

�a��rwcs\eZdZdZdedd��fdd�
Zeed�dd	��Zdd�d
d�Ze	e	dd�d
d�Z
�ZS)�MySQLUnixSocketzpMySQL socket class using UNIX sockets.

    Opens a connection through the UNIX socket of the MySQL Server.
    �/tmp/mysql.sockN)�unix_socketrcst���||_||_dSr�)r`r<r��_address)r(r�rcrrr<�s
zMySQLUnixSocket.__init__r6cCs|jSr��r�r;rrrr$�szMySQLUnixSocket.addressc
Cs�z2t�tjtj�|_|j�|j�|j�|j�Wnltyn}z$t	d|j
t|�fd�|�WYd}~n:d}~0ty�}zt	t
|��|�WYd}~n
d}~00dS)Ni�rC)r0�AF_UNIX�SOCK_STREAMr#r�rx�connectr�rGrr$r �	Exceptionr)r(rrrrr��s���zMySQLUnixSocket.open_connection)�args�kwargsrcOst�dt�dS)zSwitch the socket to use SSL.z2SSL is disabled when using unix socket connectionsN)�warnings�warn�Warning)r(r�r�rrrr��s�zMySQLUnixSocket.switch_to_ssl)r�)r,r-r.r/rr<r�r$r�rr�rvrrrcrr��s�r�csNeZdZdZdeeedd��fdd�
Zeed	�d
d��Z	dd	�dd
�Z
�ZS)�MySQLTCPSocketzYMySQL socket class using TCP/IP.

    Opens a TCP/IP connection to the MySQL Server.
    �	127.0.0.1��FN)r��port�
force_ipv6rcs6t���||_||_||_d|_|�d|��|_dS)Nrr�)r`r<ry�server_portr��_familyr�)r(r�r�r�rcrrr<�s
zMySQLTCPSocket.__init__r6cCs|jSr�r�r;rrrr$�szMySQLTCPSocket.addressc	
Cs�d}z�t�|j|jdtjtj�}|D]6}|jrD|dtjkrD|}q\|dtjkr$|}q\q$|jr~|ddur~t	d|j����|ddur�|d}Wn<t
y�}z$t	d|jt|�fd�|�WYd}~n
d}~00|\|_
}}}}z0t�|j
||�|_|j�|j�|j�|�Wntt
�yT}z(t	d|j|jt|�fd�|�WYd}~n<d}~0t�y�}ztt|��|�WYd}~n
d}~00dS)z/Open the TCP/IP connection to the MySQL server.)NNNNNrNzNo IPv6 address found for i�rC)r0�getaddrinforyr�r��SOL_TCPr��AF_INET6�AF_INETrrGr$r r�r#r�rxr�r�rr)	r(�addrinfo�	addrinfos�infor�socktype�protorY�sockaddrrrrr��sX
�
������zMySQLTCPSocket.open_connection)r�r�F)r,r-r.r/rr2r�r<r�r$r�rvrrrcrr��s��
r�)-r/r0rVr�ri�abcrr�collectionsr�typingrrrrr	r
r��PROTOCOL_TLSv1�PROTOCOL_TLSv1_1�PROTOCOL_TLSv1_2�PROTOCOL_TLSr��hasattrrZTLS_V1_3_SUPPORTED�ImportError�errorsrrrrrnrTr\rrrGrr r!r4r_rwr�r�rrrr�<module>s@ �
GaAU)