Viewing File: /opt/imunify360/venv/lib/python3.11/site-packages/clcommon/__pycache__/mysql_lib.cpython-311.pyc



]j`ddlZddlmZmZddlmZddlZddlmZddl	m
Z
dZdZdZ
Gd	d
eZGddZd
Zeee
fddedeedefdZdedeefdZdedeefdZdS)N)IterableList)deque)
DictCursor)	load_fastz/etc/psa/psa.confz/etc/my.cnfz/etc/mysql/my.cnfceZdZdZdS)
MySQLErrorz4
    Exception related to operation with MySQL.
    N)__name__
__module____qualname____doc__r/builddir/build/BUILD/imunify360-venv-2.6.3/opt/imunify360/venv/lib/python3.11/site-packages/clcommon/mysql_lib.pyr	r	srr	c
eZdZddefdZdZdZdZddZdd
Z	ddZ
dZed
Z
	ddedeed	zdeedfeeefzfdZedededd	fdZd	S)MySQLConnectorFas_dictc||dd|d|_|rtnd|_||_dS)Nhost	localhost)add_unix_socket_if_localhostget_connectionr_cursor_type_connect_kwargs)selfrkwargss   r__init__zMySQLConnector.__init__sM))&**V[*I*I6RRR*1;JJt%rc.|dSNclosers r__del__zMySQLConnector.__del__&

rc*|Sr )connectr#s r	__enter__zMySQLConnector.__enter__)s||~~rc.|dSr r!)rexc_type	exc_value	tracebacks    r__exit__zMySQLConnector.__exit__,r%rreturnc|j|S	tjdi|j|_|S#tj$r"}tt
||d}~wwxYw)Nr)rpymysqlr'rErrorr	str)res  rr'zMySQLConnector.connect/sl'K	,&FF1EFFDK}	,	,	,SVV$$!+	,s(AAANcX|j"|jd|_dSdSr )rr"r#s rr"zMySQLConnector.close8s6'""$$$#D('rcJ|j|jdSdSr )rcommitr#s rr6zMySQLConnector.commit=s.'##%%%%%('rc@|j|jSr )
connectioncursorrr#s rr9zMySQLConnector.cursorAs%%d&7888rcF|j||jSr )rr'r#s rr8zMySQLConnector.connectionDs!#LLNNNr	sql_queryargs.c|j|j5}||||cdddS#1swxYwYdS)z:
        Execute SQL query and return the result.
        )r<N)r8r9rexecutefetchall)rr;r<r9s    r
execute_queryzMySQLConnector.execute_queryJs_
#
#D$5
6
6	%&NN94N000??$$	%	%	%	%	%	%	%	%	%	%	%	%	%	%	%	%	%	%s+AAArrcD|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.
        runix_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"r6r9propertyr8r2robjecttupledictr@staticmethodrrrrrrsW&&&&&&,,,,$$$$
&&&&999  X )-
%
%
%v%
%
vs{	d3;/	/	
%
%
%
%;3;;;;;\;;;rrcPt|j|j|S)zF
    Get a modified RFC 1738 URL for a MySQL database connection.
    )rrrquery)urls rget_rfc1738_db_urirMes#//#)DDDJr)plesk_config_path
mysql_configsrNrOr.ctj|r*t|d}|d}||St|}t
|dkr|}tj|sGt|d}|d}||S|t|t
|dkd	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_quotessocketz/var/lib/mysql/mysql.sock)
ospathisfilerrrlenpopleftextend
get_cnf_paths)rNrOpsa_confpsa_conf_socketmysql_configs_queuemy_conf_pathmy_confmy_conf_sockets        rrCrCms
w~~'((#.#>>>",,~66&""
..

!
"
"Q
&
&*2244w~~l++	Lt<<< X..%!!	""=#>#>???!
"
"Q
&
&'&rrWcg}g}	t|ddd5}|D]	}|}	|dr\|d}tj|r||np|dr[|d}tj|r||#t$rYwxYw|D]}|t|z
}	dddn#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-8surrogateescape)encodingerrorsz!includedirz	!include z!includeNzError reading config file z: )openstrip
startswithremoveprefixrVrWisdirappendrX
IndexErrorget_cnf_files_in_dirOSErrorIOErrorr	)	rWinclude_dirs
list_of_pathsconfig_filelineincluded_dir_pathincluded_file_pathdir_pathr3s	         rr\r\s!L!MJ
$g6G
H
H
H	@K#



zz||}55E,0,=,=m,L,L,R,R,T,T)7==):;;C(//0ABBB55E-1->->z-J-J-P-P-R-R*7>>*<==E)001CDDD!D)
@
@!5h!?!??


@	@	@	@	@	@	@	@	@	@	@	@	@	@	@	@"
WJJJAdAAaAABBIJs^EEC!DE
D$ E#D$$E?EEEEEF(E>>Fcg}tj|rtj|D]}tjtj||r\tj|ddkr3|tj|||S)zT
    Get paths list in given dir
    Returns an empty list if there is no paths
    z.cnf)rVrWrllistdirrXjoinsplitextrm)rWrsitems   rroros
M	w}}T?Jt$$	?	?Dw~~bgll46677
?BG<L<LT<R<RST<UY_<_<_$$RW\\$%=%=>>>r)rVtypingrrcollectionsrr0pymysql.cursorsrclcommon.clconfparsrPLESK_CONFIG_PATHMY_CONFIG_PATHMY_CONFIG_PATH2	Exceptionr	rrMr2rClistr\rorrr<module>rs
			!!!!!!!!&&&&&&))))))'%E;E;E;E;E;E;E;E;P/$2O#D ' ' ' 'C= '		 ' ' ' 'FS	B
s
tCy





r
Back to Directory File Manager