????

Your IP : 3.16.130.230


Current Path : /opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/__pycache__/mysql_lib.cpython-311.pyc

�

K�f�����ddlmZddlZddlmZmZddlmZddlZddl	m
Z
ddlmZdZ
dZd	ZGd
�de��ZGd�d
��Zd�Ze
eefd�dd�Zdd�Zdd�ZdS)�)�annotationsN)�Iterable�List)�deque)�
DictCursor)�	load_fastz/etc/psa/psa.confz/etc/my.cnfz/etc/mysql/my.cnfc��eZdZdZdS)�
MySQLErrorz4
    Exception related to operation with MySQL.
    N)�__name__�
__module__�__qualname__�__doc__����/builddir/build/BUILDROOT/alt-python27-cllib-3.4.8-1.el8.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/mysql_lib.pyr
r
s���������rr
c�z�eZdZddd�Zd�Zd�Zdd�Zdd
�Zdd�Zd�Z	e
d
���Zddd�Ze
dd���ZdS) �MySQLConnectorF�as_dict�boolc��|�|�dd��|��d|_|rtnd|_||_dS)N�host�	localhost)�add_unix_socket_if_localhost�get�_connectionr�_cursor_type�_connect_kwargs)�selfr�kwargss   r�__init__zMySQLConnector.__init__ sM���)�)�&�*�*�V�[�*I�*I�6�R�R�R����*1�;�J�J�t���%����rc�*�|���S�N)�connect�rs r�	__enter__zMySQLConnector.__enter__'s���|�|�~�~�rc�.�|���dSr")�close)r�exc_type�	exc_value�	tracebacks    r�__exit__zMySQLConnector.__exit__*s���
�
�����r�returnc��	tjdi|j��|_|S#tj$r"}tt
|����|�d}~wwxYw)Nr)�pymysqlr#rr�Errorr
�str)r�es  rr#zMySQLConnector.connect-s^��	,�&��F�F��1E�F�F�D���K���}�	,�	,�	,��S��V�V�$�$�!�+�����	,���s��A�A�A�Nonec�J�|j�|j���dSdSr")rr'r$s rr'zMySQLConnector.close4s.����'���"�"�$�$�$�$�$�(�'rc�J�|j�|j���dSdSr")r�commitr$s rr5zMySQLConnector.commit8s.����'���#�#�%�%�%�%�%�(�'rc�@�|j�|j��Sr")�
connection�cursorrr$s rr8zMySQLConnector.cursor<s����%�%�d�&7�8�8�8rc�F�|j�|���|jSr")rr#r$s rr7zMySQLConnector.connection?s!����#��L�L�N�N�N���rN�	sql_queryr0�args�Iterable[object] | None�&tuple[object, ...] | dict[str, object]c���|j�|j��5}|�||���|���cddd��S#1swxYwYdS)z:
        Execute SQL query and return the result.
        )r;N)r7r8r�execute�fetchall)rr:r;r8s    r�
execute_queryzMySQLConnector.execute_queryEs����_�
#�
#�D�$5�
6�
6�	%�&��N�N�9�4�N�0�0�0��?�?�$�$�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%����	%�	%�	%�	%�	%�	%s�+A�A�Arr�dictc�D�|dkrd|vrt��|d<dSdSdS)ag
        Add 'unix_socket' to kwargs if host is 'localhost'.

        It seems that when the host is set to 'localhost',
        establishing a connection through TCP/IP might encounter issues
        due to some MySQL configuration options.
        To prioritize a Unix socket connection,
        we should include the 'unix_socket' query parameter.
        r�unix_socketN)�get_unix_socket_path)rrs  rrz+MySQLConnector.add_unix_socket_if_localhostMs=���;���=��#>�#>�$8�$:�$:�F�=�!�!�!���#>�#>r)F)rr)r,r)r,r2r")r:r0r;r<r,r=)rr0rrBr,r2)rrr
r r%r+r#r'r5r8�propertyr7rA�staticmethodrrrrrrs�������&�&�&�&�&�������,�,�,�,�%�%�%�%�&�&�&�&�9�9�9�� � ��X� �
%�%�%�%�%��;�;�;��\�;�;�;rrc�P�t�|j|j��|S)zF
    Get a modified RFC 1738 URL for a MySQL database connection.
    )rrr�query)�urls r�get_rfc1738_db_urirK\s#���/�/���#�)�D�D�D��Jr)�plesk_config_path�
mysql_configsrLr0rM�
Iterable[str]r,c��tj�|��r*t|d���}|�d��}|�|St|��}t
|��dkr�|���}tj�|��s�Gt|d���}|�d��}|�|S|�t|����t
|��dk��d	S)
z�
    Get the Unix socket path for MySQL connection.

    Check Plesk and MySQL config files for the socket path.
    If found, return that path. If not, return default socket path.
    � )�	delimiter�MYSQL_SOCKETNrT)�strip_quotes�socketz/var/lib/mysql/mysql.sock)
�os�path�isfilerrr�len�popleft�extend�
get_cnf_paths)rLrM�psa_conf�psa_conf_socket�mysql_configs_queue�my_conf_path�my_conf�my_conf_sockets        rrErEds��
�w�~�~�'�(�(�#��.�#�>�>�>��"�,�,�~�6�6���&�"�"��
�.�.��

�!�
"�
"�Q�
&�
&�*�2�2�4�4���w�~�~�l�+�+�	���L�t�<�<�<�� ���X�.�.���%�!�!�	�"�"�=��#>�#>�?�?�?��!�
"�
"�Q�
&�
&�'�&rrV�	list[str]c��g}g}	t|dd���5}|D�]	}|���}	|�d��r\|�d�����}tj�|��r|�|��np|�d��r[|�d�����}tj�|��r|�|����#t$rY��wxYw|D]}|t|��z
}�	ddd��n#1swxYwYn/#ttf$r}td|�d	|����|�d}~wwxYw|S)
z�
    Get all included config files paths in the given config file
    marked with !include and !includedir.

    Returns an empty list if there are no paths.
    �r�surrogateescape)�errorsz!includedirz	!include z!includeNzError reading config file z: )�open�strip�
startswith�removeprefixrUrV�isdir�appendrW�
IndexError�get_cnf_files_in_dir�OSError�IOErrorr
)	rV�include_dirs�
list_of_paths�config_file�line�included_dir_path�included_file_path�dir_pathr1s	         rr[r[�s��!�L�!�M�J�
�$��$5�
6�
6�
6�	@�+�#�

�

���z�z�|�|������}�5�5�E�,0�,=�,=�m�,L�,L�,R�,R�,T�,T�)��7�=�=�):�;�;�C�(�/�/�0A�B�B�B������5�5�E�-1�->�->�z�-J�-J�-P�-P�-R�-R�*��7�>�>�*<�=�=�E�)�0�0�1C�D�D�D���!�����D�����)�
@�
@���!5�h�!?�!?�?�
�
�
@�	@�	@�	@�	@�	@�	@�	@�	@�	@�	@�	@����	@�	@�	@�	@���"
�W��J�J�J��A�d�A�A�a�A�A�B�B��I�����J�����s^�E�E
�C!D�E
�
D#�E
�"D#�#E
�>E�
E�E�E�E�F�'E=�=Fc��g}tj�|��r�tj|��D]�}tj�tj�||����r\tj�|��ddkr3|�tj�||������|S)zT
    Get paths list in given dir
    Returns an empty list if there is no paths
    �z.cnf)rUrVrk�listdirrW�join�splitextrl)rVrr�items   rrnrn�s���
�M�	�w�}�}�T���?��J�t�$�$�	?�	?�D��w�~�~�b�g�l�l�4��6�6�7�7�
?�B�G�<L�<L�T�<R�<R�ST�<U�Y_�<_�<_��$�$�R�W�\�\�$��%=�%=�>�>�>���r)rLr0rMrNr,r0)rVr0r,rb)�
__future__rrU�typingrr�collectionsrr.�pymysql.cursorsr�clcommon.clconfparsr�PLESK_CONFIG_PATH�MY_CONFIG_PATH�MY_CONFIG_PATH2�	Exceptionr
rrKrEr[rnrrr�<module>r�sJ��#�"�"�"�"�"�	�	�	�	�!�!�!�!�!�!�!�!�����������&�&�&�&�&�&�)�)�)�)�)�)�'����%�����������;;�;;�;;�;;�;;�;;�;;�;;�|���/�$2�O�#D� '� '� '� '� '� '�F����B
�
�
�
�
�
r