<commit_before>"""
This module hosts the Connection class that manages the connection to the mysql database,
 and the `conn` function that provides access to a persistent connection in datajoint.
"""

from contextlib import contextmanager
import pymysql as client
import logging
from . import config
from . import DataJointError
from .erd import ERM
from .jobs import JobManager

logger = logging.getLogger(__name__)


# The following is a temporary hack to address issue #
# START HACK
hack = False
if hack:
    import binascii

    def escape_bytes(bs, mapping=None):
        assert isinstance(bs, (bytes, bytearray))
        return '0x' + binascii.b2a_hex(bs).decode('ascii')

    connector.connections.escape_bytes = escape_bytes
# END HACK


def conn(host=None, user=None, passwd=None, init_fun=None, reset=False):
    """
    Returns a persistent connection object to be shared by multiple modules.
    If the connection is not yet established or reset=True, a new connection is set up.
    If connection information is not provided, it is taken from config which takes the
    information from dj_local_conf.json. If the password is not specified in that file
    datajoint prompts for the password.

    :param host: hostname<commit_msg>cleanup<commit_after>"""
This module hosts the Connection class that manages the connection to the mysql database,
 and the `conn` function that provides access to a persistent connection in datajoint.
"""

from contextlib import contextmanager
import pymysql as client
import logging
from . import config
from . import DataJointError
from .erd import ERM
from .jobs import JobManager

logger = logging.getLogger(__name__)


def conn(host=None, user=None, passwd=None, init_fun=None, reset=False):
    """
    Returns a persistent connection object to be shared by multiple modules.
    If the connection is not yet established or reset=True, a new connection is set up.
    If connection information is not provided, it is taken from config which takes the
    information from dj_local_conf.json. If the password is not specified in that file
    datajoint prompts for the password.

    :param host: hostname
{'fraction_non_alphanumeric': 0.05705009276437848, 'fraction_numerical': 0.0009276437847866419, 'mean_word_length': 4.2227602905569, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7425017', 'n_tokens_mistral': 567, 'n_tokens_neox': 545, 'n_words': 270}