<commit_before># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

# Database Module
# --------------------

from __future__ import unicode_literals
import MySQLdb
from MySQLdb.times import DateTimeDeltaType
from markdown2 import UnicodeWithAttrs
import warnings
import datetime
import frappe
import frappe.defaults
import frappe.async
import re
import frappe.model.meta
from frappe.utils import now, get_datetime, cstr
from frappe import _
from types import StringType, UnicodeType

class Database:
	"""
	   Open a database connection with the given parmeters, if use_default is True, use the
	   login details from `conf.py`. This is called by the request handler and is accessible using
	   the `db` global variable. the `sql` method is also global to run queries
	"""
	def __init__(self, host=None, user=None, password=<PASSWORD>, ac_name=None, use_default = 0):
		self.host = host or frappe.conf.db_host or 'localhost'
		self.user = user or frappe.conf.db_name
		self._conn = None

		if ac_name:
			self.user = self.get_db_login(ac_name) or frappe.conf.db_name

		if use_default:
			self.user = frappe.conf.db_name

		self.transaction_writes = 0
		self.auto_commit_on_many_writes = 0

		self.password = <PASSWORD> <PASSWORD>
		self.value_cache = {}

	def get_db_login(self, ac_name):
		return ac_name

	def connect(self):
		"""Connects to a database as set in `site_config.json`."""
		warnings.filterwarnings('ignore', category=MySQLdb.Warning)
		self._conn = MySQLdb.connect(user=self.user, host=self.host, passwd=self.password,
			use_unicode=True, charset='utf8')
		self._conn.converter[246]=float
		self._conn.converter[12]=get_datetime
		self._conn.encoders[UnicodeWithAttrs] = self._conn.encoders[UnicodeType]
		self._conn.encoders[DateTimeDeltaType] = self._conn.encoders[StringType]

		MYSQL_OPTION_MULTI_STATEMENTS_OFF = 1
		self._conn.set_server_option(MYSQL_OPTION_MULTI_STATEMENTS_OFF)

		self._cursor = self._conn.cursor()
		if self.user != 'root':
			self.use(self.user)
		frappe.local.rollback_observers = []

	def use(self, db_name):
		"""`USE` db_name."""<commit_msg>[check] use utf8mb4 as the connection charset<commit_after># Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
# MIT License. See license.txt

# Database Module
# --------------------

from __future__ import unicode_literals
import MySQLdb
from MySQLdb.times import DateTimeDeltaType
from markdown2 import UnicodeWithAttrs
import warnings
import datetime
import frappe
import frappe.defaults
import frappe.async
import re
import frappe.model.meta
from frappe.utils import now, get_datetime, cstr
from frappe import _
from types import StringType, UnicodeType

class Database:
	"""
	   Open a database connection with the given parmeters, if use_default is True, use the
	   login details from `conf.py`. This is called by the request handler and is accessible using
	   the `db` global variable. the `sql` method is also global to run queries
	"""
	def __init__(self, host=None, user=None, password=<PASSWORD>, ac_name=None, use_default = 0):
		self.host = host or frappe.conf.db_host or 'localhost'
		self.user = user or frappe.conf.db_name
		self._conn = None

		if ac_name:
			self.user = self.get_db_login(ac_name) or frappe.conf.db_name

		if use_default:
			self.user = frappe.conf.db_name

		self.transaction_writes = 0
		self.auto_commit_on_many_writes = 0

		self.password = password or <PASSWORD>
		self.value_cache = {}

	def get_db_login(self, ac_name):
		return ac_name

	def connect(self):
		"""Connects to a database as set in `site_config.json`."""
		warnings.filterwarnings('ignore', category=MySQLdb.Warning)
		self._conn = MySQLdb.connect(user=self.user, host=self.host, passwd=self.password,
			use_unicode=True, charset='utf8mb4')
		self._conn.converter[246]=float
		self._conn.converter[12]=get_datetime
		self._conn.encoders[UnicodeWithAttrs] = self._conn.encoders[UnicodeType]
		self._conn.encoders[DateTimeDeltaType] = self._conn.encoders[StringType]

		MYSQL_OPTION_MULTI_STATEMENTS_OFF = 1
		self._conn.set_server_option(MYSQL_OPTION_MULTI_STATEMENTS_OFF)

		self._cursor = self._conn.cursor()
		if self.user != 'root':
			self.use(self.user)
		frappe.local.rollback_observers = []

	def use(self, db_name):
		"""`USE` db_name."""
{'fraction_non_alphanumeric': 0.10482374768089053, 'fraction_numerical': 0.007653061224489796, 'mean_word_length': 4.615885416666667, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 8, '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': '4181896', 'n_tokens_mistral': 1529, 'n_tokens_neox': 1436, 'n_words': 374}