Your IP : 3.145.103.119


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

�

\�Dg`���ddlZddlmZmZddlmZddlZddlmZddl	m
Z
dZdZdZ
Gd	�d
e��ZGd�d��Zd
�Zeee
fd�dedeedefd�Zdedeefd�Zdedeefd�ZdS)�N)�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__���r/builddir/build/BUILD/imunify360-venv-2.4.0/opt/imunify360/venv/lib/python3.11/site-packages/clcommon/mysql_lib.pyr	r	s���������rr	c
���eZdZddefd�Zd�Zd�Zd�Zdd�Zdd
�Z	dd�Z
d�Zed
���Z
	ddedeed	zdeedfeeefzfd�Zedededd	fd���Zd	S)�MySQLConnectorF�as_dictc��|�|�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�.�|���dS�N��close�rs r�__del__zMySQLConnector.__del__&����
�
�����rc�*�|���Sr )�connectr#s r�	__enter__zMySQLConnector.__enter__)s���|�|�~�~�rc�.�|���dSr r!)r�exc_type�	exc_value�	tracebacks    r�__exit__zMySQLConnector.__exit__,r%r�returnc��|j�|S	tjdi|j��|_|S#tj$r"}tt
|����|�d}~wwxYw)Nr)r�pymysqlr'r�Errorr	�str)r�es  rr'zMySQLConnector.connect/sl����'��K�	,�&��F�F��1E�F�F�D���K���}�	,�	,�	,��S��V�V�$�$�!�+�����	,���s�(�A�A�ANc�X�|j�"|j���d|_dSdSr )rr"r#s rr"zMySQLConnector.close8s6����'���"�"�$�$�$�#�D����(�'rc�J�|j�|j���dSdSr )r�commitr#s rr6zMySQLConnector.commit=s.����'���#�#�%�%�%�%�%�(�'rc�@�|j�|j��Sr )�
connection�cursorrr#s rr9zMySQLConnector.cursorAs����%�%�d�&7�8�8�8rc�F�|j�|���|jSr )rr'r#s rr8zMySQLConnector.connectionDs!����#��L�L�N�N�N���r�	sql_query�args.c���|j�|j��5}|�||���|���cddd��S#1swxYwYdS)z:
        Execute SQL query and return the result.
        )r<N)r8r9r�execute�fetchall)rr;r<r9s    r�
execute_queryzMySQLConnector.execute_queryJs����_�
#�
#�D�$5�
6�
6�	%�&��N�N�9�4�N�0�0�0��?�?�$�$�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%�	%����	%�	%�	%�	%�	%�	%s�+A�A�Arrc�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_localhostVs=���;���=��#>�#>�$8�$:�$:�F�=�!�!�!���#>�#>r)F)r.r)r.Nr )r
rr�boolrr$r(r-r'r"r6r9�propertyr8r2r�object�tuple�dictr@�staticmethodrrrrrrsW������&�&��&�&�&�&����������,�,�,�,�$�$�$�$�
&�&�&�&�9�9�9�� � ��X� �)-�
%�
%��
%��v���%�
%�
�v�s�{�	�d�3��;�/�	/�	
%�
%�
%�
%��;�3�;��;��;�;�;��\�;�;�;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_urirMes#���/�/���#�)�D�D�D��Jr)�plesk_config_path�
mysql_configsrNrOr.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)rNrO�psa_conf�psa_conf_socket�mysql_configs_queue�my_conf_path�my_conf�my_conf_sockets        rrCrCms��
�w�~�~�'�(�(�#��.�#�>�>�>��"�,�,�~�6�6���&�"�"��
�.�.��

�!�
"�
"�Q�
&�
&�*�2�2�4�4���w�~�~�l�+�+�	���L�t�<�<�<�� ���X�.�.���%�!�!�	�"�"�=��#>�#>�?�?�?��!�
"�
"�Q�
&�
&�'�&rrWc��g}g}	t|ddd���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.
    �rzutf-8�surrogateescape)�encoding�errorsz!includedirz	!include z!includeNzError reading config file z: )�open�strip�
startswith�removeprefixrVrW�isdir�appendrX�
IndexError�get_cnf_files_in_dir�OSError�IOErrorr	)	rW�include_dirs�
list_of_paths�config_file�line�included_dir_path�included_file_path�dir_pathr3s	         rr\r\�s��!�L�!�M�J�
�$��g�6G�
H�
H�
H�	@�K�#�

�

���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)rVrWrl�listdirrX�join�splitextrm)rWrs�items   rroro�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)rV�typingrr�collectionsrr0�pymysql.cursorsr�clcommon.clconfparsr�PLESK_CONFIG_PATH�MY_CONFIG_PATH�MY_CONFIG_PATH2�	Exceptionr	rrMr2rC�listr\rorrr�<module>r�s���
�	�	�	�!�!�!�!�!�!�!�!�����������&�&�&�&�&�&�)�)�)�)�)�)�'����%�����������E;�E;�E;�E;�E;�E;�E;�E;�P���/�$2�O�#D� '� '� '�� '��C�=� '�	�	 '� '� '� '�F����S�	�����B
�s�
�t�C�y�
�
�
�
�
�
r

?>