<commit_before>#! python

#import sys
#import SocketServer
from string import *

from xml.sax import ContentHandler
from xml.sax import parseString
from xml.sax import make_parser
from xml.sax.handler import *


spade = dict()
domain = dict()
acc = dict()
ams = dict()
df = dict()
jabber = dict()
simba = dict()

class ParseObject(dict):
        def __getattr__(self, name): return self[name]

class spadeXML:
	'''Analizador de cadenas XML especificamente configurado
	para SPADE'''
	def __init__(self):
		self.ch = spadeXMLHandler()
	
	def parseString(self, xmlstream, tag_attr, chars):
		self.ch.tag_attr = tag_attr
		parseString(xmlstream, self.ch)
		return self.ch.tag_name, self.ch.message


class spadeXMLHandler(ContentHandler):
	def __init__(self):
		self.chars = ""
		self.message = ""
		self.current_tag = ""
		pass

	def startDocument(self):

		self.content = ParseObject()
		
	def startElement(self, name, attrs):
		'''Llamado cuando empieza un nodo XML en el flujo'''
		self.chars = ""
		self.tag_name = name
		if name == "platform":
			self.current_tag = "platform"
			self.content['platform'] = ParseObject()
			#print "Current Tag: " + name
		elif name == "acc":
			self.current_tag = "acc"
			self.content['acc'] = ParseObject()
			#print "Current Tag: " + name
		elif name == "ams":
			self.current_tag = "ams"
			self.content['ams'] = ParseObject()
			#print "Current Tag: " + name
		elif name == "df":
			self.current_tag = "df"
			self.content['df'] = ParseObject()
			#print "Current Tag: " + name
		elif name == "mtp":
			self.current_tag = attrs.getValue("name")
			self.content.acc[self.current_tag] = ParseObject()


		else:
			self.chars = ""
			self.tag_name = name

	def characters(self, ch):
		'''Caracteres incluidos en un nodo'''
		self.chars = str(self.chars + ch)
		
	def endElement(self, name):
		'''Llamado al finalizar un nodo'''
		#print 'Final de: ' + name + ' con current_tag: ' + self.current_tag
		#print 'Caracteres : ' + self.chars
		if name == "hostname":
			if self.current_tag == "platform":
				self.content.platform['hostname'] = self.chars
			elif self.current_tag == "ams":
				self.content.ams['hostname'] = self.chars
			elif self.current_tag == "df":
				self.content.df['hostname'] = self.chars
		elif name == "password":
			if self.current_tag == "ams":
				self.content.ams['password'] = self.chars
			elif self.current_tag == "df":
				self.content.df['password'] = self.chars
		elif name == "port":
			if self.current_tag == "platform":
				self.content.platform['port'] = self.chars
			elif self.current_tag == "ams":
				self.content.ams['port'] = self.chars
			elif self.current_tag == "df":
				self.content.df['port'] = self.chars

			else:
				self.content.acc[self.current_tag]['port'] = self.chars

		elif name == "protocol":
				self.content.acc[self.current_tag]['protocol'] = self.chars

		elif name == "address":
				self.content.acc[self.current_tag]['address'] = self.chars

		elif name == "instance":
				self.content.acc[self.current_tag]['instance'] = self.chars

class ConfigParser:
	
	"""def get(self, section, keyword):
		answer = ""
		try:
			d = spade[section]
			answer = d[keyword]
		except:
			print "Section %s does not have keyword %s" % (str(section), keyword)
		return answer"""

	def __init__(self):
    		# Create a parser
    		parser = make_parser()

    		# Tell the parser we are not interested in XML namespaces
    		parser.setFeature(feature_namespaces, 0)

    		# Create the handler
    		dh = spadeXMLHandler()

    		# Tell the parser to use our handler
    		parser.setContentHandler(dh)

	def parse(self,fn):

    		# Parse the input
    		parser.parse(fn)

		return dh.content

		"""
    		# Manage the results
    		spade['domain'] = domain
    		spade['acc'] = acc
    		spade['ams'] = ams
    		spade['df'] = df
    		spade['jabber'] = jabber
		spade['simba'] = simba
    		#print spade
		"""
<commit_msg>packaging<commit_after>#! python

#import sys
#import SocketServer
from string import *

from xml.sax import ContentHandler
from xml.sax import parseString
from xml.sax import make_parser
from xml.sax.handler import *


spade = dict()
domain = dict()
acc = dict()
ams = dict()
df = dict()
jabber = dict()
simba = dict()

class ParseObject(dict):
        def __getattr__(self, name): return self[name]

class spadeXML:
	'''Analizador de cadenas XML especificamente configurado
	para SPADE'''
	def __init__(self):
		self.ch = spadeXMLHandler()
	
	def parseString(self, xmlstream, tag_attr, chars):
		self.ch.tag_attr = tag_attr
		parseString(xmlstream, self.ch)
		return self.ch.tag_name, self.ch.message


class spadeXMLHandler(ContentHandler):
	def __init__(self):
		self.chars = ""
		self.message = ""
		self.current_tag = ""
		pass

	def startDocument(self):

		self.content = ParseObject()
		
	def startElement(self, name, attrs):
		'''Llamado cuando empieza un nodo XML en el flujo'''
		self.chars = ""
		self.tag_name = name
		if name == "platform":
			self.current_tag = "platform"
			self.content['platform'] = ParseObject()
			#print "Current Tag: " + name
		elif name == "acc":
			self.current_tag = "acc"
			self.content['acc'] = ParseObject()
			#print "Current Tag: " + name
		elif name == "ams":
			self.current_tag = "ams"
			self.content['ams'] = ParseObject()
			#print "Current Tag: " + name
		elif name == "df":
			self.current_tag = "df"
			self.content['df'] = ParseObject()
			#print "Current Tag: " + name
		elif name == "mtp":
			self.current_tag = attrs.getValue("name")
			self.content.acc[self.current_tag] = ParseObject()


		else:
			self.chars = ""
			self.tag_name = name

	def characters(self, ch):
		'''Caracteres incluidos en un nodo'''
		self.chars = str(self.chars + ch)
		
	def endElement(self, name):
		'''Llamado al finalizar un nodo'''
		#print 'Final de: ' + name + ' con current_tag: ' + self.current_tag
		#print 'Caracteres : ' + self.chars
		if name == "hostname":
			if self.current_tag == "platform":
				self.content.platform['hostname'] = self.chars
			elif self.current_tag == "ams":
				self.content.ams['hostname'] = self.chars
			elif self.current_tag == "df":
				self.content.df['hostname'] = self.chars
		elif name == "password":
			if self.current_tag == "ams":
				self.content.ams['password'] = self.chars
			elif self.current_tag == "df":
				self.content.df['password'] = self.chars
		elif name == "port":
			if self.current_tag == "platform":
				self.content.platform['port'] = self.chars
			elif self.current_tag == "ams":
				self.content.ams['port'] = self.chars
			elif self.current_tag == "df":
				self.content.df['port'] = self.chars

			else:
				self.content.acc[self.current_tag]['port'] = self.chars

		elif name == "protocol":
				self.content.acc[self.current_tag]['protocol'] = self.chars

		elif name == "address":
				self.content.acc[self.current_tag]['address'] = self.chars

		elif name == "instance":
				self.content.acc[self.current_tag]['instance'] = self.chars

class ConfigParser:
	
	"""def get(self, section, keyword):
		answer = ""
		try:
			d = spade[section]
			answer = d[keyword]
		except:
			print "Section %s does not have keyword %s" % (str(section), keyword)
		return answer"""

	def __init__(self):
    		# Create a parser
    		self.parser = make_parser()

    		# Tell the parser we are not interested in XML namespaces
    		self.parser.setFeature(feature_namespaces, 0)

    		# Create the handler
    		dh = spadeXMLHandler()

    		# Tell the parser to use our handler
    		self.parser.setContentHandler(dh)

	def parse(self,fn):

    		# Parse the input
    		self.parser.parse(fn)

		return dh.content

		"""
    		# Manage the results
    		spade['domain'] = domain
    		spade['acc'] = acc
    		spade['ams'] = ams
    		spade['df'] = df
    		spade['jabber'] = jabber
		spade['simba'] = simba
    		#print spade
		"""

{'fraction_non_alphanumeric': 0.1441326530612245, 'fraction_numerical': 0.00025510204081632655, 'mean_word_length': 3.3878007834359263, 'pattern_counts': {'":': 38, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 12}, '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': '5294311', 'n_tokens_mistral': 2970, 'n_tokens_neox': 2663, 'n_words': 664}