<commit_before>import datetime, os, sys
from Malcom.auxiliary.toolbox import debug_output
import Malcom.auxiliary.toolbox as toolbox

try:
	import geoip2.database
	file = os.path.abspath(__file__)
	current_path = os.path.dirname(os.path.abspath(__file__))
	geoip_reader = geoip2.database.Reader(current_path+'/../auxiliary/geoIP/GeoIP2-City.mmdb')
	geoip = True
except Exception, e:
	debug_output("Could not load GeoIP library - %s" % e, type='error')
	geoip = False





class Element(dict):

	default_fields = [('value', "Value"), ('type', "Type"), ('tags', "Tags"), ('date_updated', 'Updated'), ('date_created', 'Created'), ('last_analysis', 'Analyzed') ]

	def __init__(self):
		self['tags'] = []
		self['value'] = None
		self['type'] = None
		self['refresh_period'] = None
		self['evil'] = {}

	def to_dict(self):
		return self.__dict__

	def __getattr__(self, name):
		return self.get(name, None)

	def __setattr__(self, name, value):
		self[name] = value

	def upgrade_tags(self, tags):
		self['tags'].extend(tags)
		self['tags'] = list(set(self['tags']))

	# necessary for pickling
	def __getstate__(self): return self.__dict__
	def __setstate__(self, d): self.__dict__.update(d)

	def add_evil(self, evil):
		if not self.get('evil'):
			self['evil'] = {}

		if not evil.get('id'):
			raise ValueError("Evil info does not have a unique ID:\n{}".format(evil))
		if not evil.get('source'):
			raise ValueError("Evil info does not have a source:\n{}".format(evil))<commit_msg>Add __str__ function for elements<commit_after>import datetime, os, sys
from Malcom.auxiliary.toolbox import debug_output
import Malcom.auxiliary.toolbox as toolbox

try:
	import geoip2.database
	file = os.path.abspath(__file__)
	current_path = os.path.dirname(os.path.abspath(__file__))
	geoip_reader = geoip2.database.Reader(current_path+'/../auxiliary/geoIP/GeoIP2-City.mmdb')
	geoip = True
except Exception, e:
	debug_output("Could not load GeoIP library - %s" % e, type='error')
	geoip = False





class Element(dict):

	default_fields = [('value', "Value"), ('type', "Type"), ('tags', "Tags"), ('date_updated', 'Updated'), ('date_created', 'Created'), ('last_analysis', 'Analyzed') ]

	def __init__(self):
		self['tags'] = []
		self['value'] = None
		self['type'] = None
		self['refresh_period'] = None
		self['evil'] = {}

	def to_dict(self):
		return self.__dict__

	def __getattr__(self, name):
		return self.get(name, None)

	def __setattr__(self, name, value):
		self[name] = value

	def __str__(self):
		return "[{} {} (tags: {})]".format(self.type, self.value, ",".join(self.tags))

	def upgrade_tags(self, tags):
		self['tags'].extend(tags)
		self['tags'] = list(set(self['tags']))

	# necessary for pickling
	def __getstate__(self): return self.__dict__
	def __setstate__(self, d): self.__dict__.update(d)

	def add_evil(self, evil):
		if not self.get('evil'):
			self['evil'] = {}

		if not evil.get('id'):
			raise ValueError("Evil info does not have a unique ID:\n{}".format(evil))
		if not evil.get('source'):
			raise ValueError("Evil info does not have a source:\n{}".format(evil))
{'fraction_non_alphanumeric': 0.17120622568093385, 'fraction_numerical': 0.0019455252918287938, 'mean_word_length': 4.990291262135922, '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': '4194390', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1055, 'n_words': 258}