}CeddlZddlmZ ddlZddlmZn$#e$r ddlZddlmZn #e$rdZYnwxYwYnwxYwddl m Z ddl m Z dZ dZdZGd d Zd Zd efd ZdS)N)Optional) DictCursor) load_fast) NoPackagez/etc/psa/psa.confz /etc/my.cnfz/etc/mysql/my.cnfceZdZddefdZdZdZddZdd Zdd Z d Z e d Z dd e deedefdZede deddfdZdS)MySQLConnectorFas_dictc ttd||dd|d|_|rt nd|_||_dS)NzFCan not connect to database; MySQL-client libraries are not installed.host localhost)pymysqlradd_unix_socket_if_localhostget _connectionr _cursor_type_connect_kwargs)selfr kwargss /builddir/build/BUILDROOT/alt-python27-cllib-3.3.7-2.el7.cloudlinux.x86_64/opt/cloudlinux/venv/lib/python3.11/site-packages/clcommon/mysql_lib.py__init__zMySQLConnector.__init__#si ?X  ))&**V[*I*I6RRR*1;JJt%c*|SN)connectrs r __enter__zMySQLConnector.__enter__/s||~~rc.|dSr)close)rexc_type exc_value tracebacks r__exit__zMySQLConnector.__exit__2s rreturnc<tjdi|j|_|S)N)r rrrrs rrzMySQLConnector.connect5s""?BBT-ABB rNcJ|j|jdSdSr)rrrs rrzMySQLConnector.close9s.   '   " " $ $ $ $ $ ( 'rcJ|j|jdSdSr)rcommitrs rr(zMySQLConnector.commit=s.   '   # # % % % % % ( 'rc@|j|jSr) connectioncursorrrs rr+zMySQLConnector.cursorAs%%d&7888rcF|j||jSr)rrrs rr*zMySQLConnector.connectionDs!   # LLNNNr sql_queryargsc|j|j5}||||cdddS#1swxYwYdS)z: Execute SQL query and return the result. )r.N)r*r+rexecutefetchall)rr-r.r+s r execute_queryzMySQLConnector.execute_queryJs_ # #D$5 6 6 %& NN94N 0 0 0??$$ % % % % % % % % % % % % % % % % % %s+AAAr rcD|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)r rs rrz+MySQLConnector.add_unix_socket_if_localhostRs= ;  =#>#>$8$:$:F= ! ! !  #>#>r)F)r#r)r#Nr)__name__ __module__ __qualname__boolrrr"rrr(r+propertyr*strrtupler2 staticmethoddictrr%rrrr!s & & & & & &%%%%&&&&999  X %%s%(5/%U%%%% ;3 ; ; ; ; ;\ ; ; ;rrcPt|j|j|S)zF Get a modified RFC 1738 URL for a MySQL database connection. )rrr query)urls rget_rfc1738_db_urirBas#//#)DDD Jrr#c`tjtr/t td}|d}||St tfD]K}tj|r*t |}|d}||cSLdS)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_SOCKETNsocketz/var/lib/mysql/mysql.sock)ospathisfilePLESK_CONFIG_PATHrrMY_CONFIG_PATHMY_CONFIG_PATH2)psa_confpsa_conf_socket my_conf_pathmy_confmy_conf_sockets rr5r5is w~~'((#.#>>>",,~66  &" "'9&& 7>>, ' ' & --G$[[22N)%%%% & &r)rHtypingrr pymysql.cursorsr ImportErrorMySQLdbMySQLdb.cursorsclcommon.clconfparsrclcommon.cpapi.cpapiexceptionsrrKrLrMrrBr;r5r%rrrZsG  +NNN+******////!!!! /...... /*)))))444444'%=;=;=;=;=;=;=;=;@'c''''''s$8(828288