<commit_before>#!/usr/bin/python

import sys
import os
import sqlite3
import sqlitebck
import psycopg2
import time
import lzo
try:
	import cPickle as pickle
except ImportError:
	import pickle
import json
from copy import deepcopy
import random
import uuid

import additional.custom_func as custom_func
import additional.custom_graph as custom_graph

from . import ngmeth
from . import ngsimu

from weakref import WeakSet


class NamingGamesDB(object):

	def __new__(cls, inst_uuid=None, *args, **kwargs):
		if "instances" not in cls.__dict__:
			cls.instances = set()#WeakSet()
		if inst_uuid is not None:
			inst_list = [inst for inst in cls.instances if hasattr(inst,'uuid') and inst_uuid == inst.uuid]
			if inst_list:
				inst = inst_list[0]
				inst.just_retrieved = True
				return inst
			else:
				instance = object.__new__(cls)
				cls.instances.add(instance)
				return instance
		else:
			instance = object.__new__(cls)
			cls.instances.add(instance)
			return instance

	def __getnewargs__(self):
		if hasattr(self,'uuid'):
			return (self.uuid,)
		else:
			return ()

	def change_uuid(self,new_uuid):
		if self.uuid != new_uuid:
			inst_list = [inst for inst in self.__class__.instances if hasattr(inst,'uuid') and new_uuid == inst.uuid]
			if inst_list:
				raise ValueError('UUID already taken for active database:\n'+str(new_uuid)+'\n')
			else:
				self.uuid = new_uuid

	def __init__(self, conn_info=None, db_type = 'sqlite3', name=None, do_not_close=False, db_uuid=None):
		if not hasattr(self,'uuid'):
			self.db_type = db_type
			self.sql = sys.modules[db_type]<commit_msg>changed constructor for ngdb postgres<commit_after>#!/usr/bin/python

import sys
import os
import sqlite3
import sqlitebck
import psycopg2
import time
import lzo
try:
	import cPickle as pickle
except ImportError:
	import pickle
import json
from copy import deepcopy
import random
import uuid

import additional.custom_func as custom_func
import additional.custom_graph as custom_graph

from . import ngmeth
from . import ngsimu

from weakref import WeakSet


class NamingGamesDB(object):

	def __new__(cls, conn_info=None, db_type='sqlite3', inst_uuid=None, *args, **kwargs):
		if "instances" not in cls.__dict__:
			cls.instances = set()#WeakSet()
		if inst_uuid is not None:
			inst_list = [inst for inst in cls.instances if hasattr(inst,'uuid') and inst_uuid == inst.uuid]
			if inst_list:
				inst = inst_list[0]
				inst.just_retrieved = True
				return inst
			else:
				instance = object.__new__(cls)
				cls.instances.add(instance)
				return instance
		elif db_type == 'psycopg2':
			if conn_info is None:
				_conn_info = "host='localhost' dbname='naminggames' user='naminggames' password='<PASSWORD>'"
			else:
				_conn_info = conn_info
			inst_list = [inst for inst in cls.instances if hasattr(inst,'conn_info') and _conn_info == inst.conn_info]
			if inst_list:
				inst = inst_list[0]
				inst.just_retrieved = True
				return inst
			else:
				instance = object.__new__(cls)
				cls.instances.add(instance)
				return instance
		else:
			instance = object.__new__(cls)
			cls.instances.add(instance)
			return instance

	def __getnewargs__(self):
		if hasattr(self,'uuid'):
			return (self.uuid,)
		else:
			return ()

	def change_uuid(self,new_uuid):
		if self.uuid != new_uuid:
			inst_list = [inst for inst in self.__class__.instances if hasattr(inst,'uuid') and new_uuid == inst.uuid]
			if inst_list:
				raise ValueError('UUID already taken for active database:\n'+str(new_uuid)+'\n')
			else:
				self.uuid = new_uuid

	def __init__(self, conn_info=None, db_type = 'sqlite3', inst_uuid=None, name=None, do_not_close=False):
		if not hasattr(self,'uuid'):
			self.db_type = db_type
			self.sql = sys.modules[db_type]
{'fraction_non_alphanumeric': 0.09967845659163987, 'fraction_numerical': 0.002947481243301179, 'mean_word_length': 4.228291316526611, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, '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': '1419859', 'n_tokens_mistral': 1429, 'n_tokens_neox': 1253, 'n_words': 351}