<commit_before>##############################################################################
#
#    Copyright (C) 2014-2015 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################
import logging
from odoo.tools.config import config

logger = logging.getLogger(__name__)

try:
    import MySQLdb as MySQLdb
except ImportError:
    logger.warning("Please install MySQLdb")


class MysqlConnector(object):

    """ Contains all the utility methods needed to talk with a MySQL server
    which connection settings are stored in the object mysql.config.settings.
    """

    def __init__(
            self,
            mysql_host="mysql_host",
            mysql_user="mysql_user",
            mysql_pw="mysql_pw",
            mysql_db="mysql_db",
    ):
        """Establishes the connection to the MySQL server used."""
        mh = config.get(mysql_host)
        mu = config.get(mysql_user)
        mp = config.get(mysql_pw)
        md = config.get(mysql_db)
        self._con = False
        try:
            self._con = MySQLdb.connect(mh, mu, mp, md, charset="utf8")
            self._cur = self._con.cursor(MySQLdb.cursors.DictCursor)
        except MySQLdb.Error as e:
            logger.debug(f"Error {e.args[0]}: {e.args[1]}")

    def __del__(self):
        """ Close the MySQL connection. """
        if self._con:
            self._con.close()

    def query(self, statement, args=None):
        """ Performs a MySQL query that has no return value.
        Args:
            - statement (string) : the query to be executed.
            - args (list or dict) : the arguments of the query. If args is a
                                    sequence, then %s must be used as the
                                    parameter placeholder in the query. If a
                                    mapping is used, %(key)s must be
                                    used as the placeholder.
        Returns:
            - long integer rows affected, if any, True otherwise.
        """
        if args and not isinstance(args, (list, tuple, dict)):
            args = [args]
        self._cur.execute(statement, args)
        return self._cur.lastrowid or True

    def select_one(self, statement, args=None):
        """ Performs a MySQL SELECT statement and returns one single row.
        Args:
            - statement (string) : the query to be executed.
            - args (list or dict) : the arguments of the query. If args is a
                                    sequence, then %s must be used as the
                                    parameter placeholder in the query. If a<commit_msg>Fix upload to translate plateform<commit_after>##############################################################################
#
#    Copyright (C) 2014-2015 Compassion CH (http://www.compassion.ch)
#    Releasing children from poverty in Jesus' name
#    @author: <NAME> <<EMAIL>>
#
#    The licence is in the file __manifest__.py
#
##############################################################################
import logging
from odoo.tools.config import config

logger = logging.getLogger(__name__)

try:
    import MySQLdb as MySQLdb
except ImportError:
    logger.warning("Please install MySQLdb")


class MysqlConnector(object):

    """ Contains all the utility methods needed to talk with a MySQL server
    which connection settings are stored in the object mysql.config.settings.
    """

    def __init__(
            self,
            mysql_host="mysql_host",
            mysql_user="mysql_user",
            mysql_pw="mysql_pw",
            mysql_db="mysql_db",
    ):
        """Establishes the connection to the MySQL server used."""
        mh = config.get(mysql_host)
        mu = config.get(mysql_user)
        mp = config.get(mysql_pw)
        md = config.get(mysql_db)
        self._con = False
        try:
            self._con = MySQLdb.connect(mh, mu, mp, md, charset="utf8")
            self._cur = self._con.cursor(MySQLdb.cursors.DictCursor)
        except MySQLdb.Error as e:
            logger.debug(f"Error {e.args[0]}: {e.args[1]}")

    def __del__(self):
        """ Close the MySQL connection. """
        if self._con:
            self._con.close()

    def query(self, statement, args=None):
        """ Performs a MySQL query that has no return value.
        Args:
            - statement (string) : the query to be executed.
            - args (list or dict) : the arguments of the query. If args is a
                                    sequence, then %s must be used as the
                                    parameter placeholder in the query. If a
                                    mapping is used, %(key)s must be
                                    used as the placeholder.
        Returns:
            - long integer rows affected, if any, True otherwise.
        """
        if args and not isinstance(args, (list, tuple, dict)):
            args = [args]
        self._cur.execute(statement, args)
        self._con.commit()
        return self._cur.lastrowid or True

    def select_one(self, statement, args=None):
        """ Performs a MySQL SELECT statement and returns one single row.
        Args:
            - statement (string) : the query to be executed.
            - args (list or dict) : the arguments of the query. If args is a
                                    sequence, then %s must be used as the
                                    parameter placeholder in the query. If a
{'fraction_non_alphanumeric': 0.1389824499202269, 'fraction_numerical': 0.003900017727353306, 'mean_word_length': 1.963235294117647, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3004784', 'n_tokens_mistral': 1486, 'n_tokens_neox': 1399, 'n_words': 502}