<commit_before># -*- coding: cp1252 -*-
import sys
import xmpp
import threading
import thread
import Queue
import time
import MessageReceiver
import AID
import XMLCodec
import ACLParser
import Envelope
import ACLMessage
import BasicFipaDateTime
import Behaviour
import SL0Parser
#from AMS import AmsAgentDescription

class AbstractAgent(MessageReceiver.MessageReceiver):
    """
    Abstract Agent
    only for heritance
    Child classes: PlatformAgent, Agent
    """
    
    def __init__(self, agentjid, serverplatform):
	"""
	inits an agent with a JID (user@server) and a platform JID (acc.platformserver)
	"""
        MessageReceiver.MessageReceiver.__init__(self)
        self._aid = AID.aid(name=agentjid, addresses=[ "xmpp://acc."+serverplatform ])
        self._jabber = None
        self._serverplatform = serverplatform
        self._defaultbehaviour = None
        self._behaviourList = dict()
        self._isAlive = True



    def jabber_messageCB(self, conn, mess):
	"""
	message callback
	read the message envelope and post the message to the agent
	"""
        if (mess.getError() == None):
            envxml=None
            payload=mess.getBody()
            children = mess.getChildren()
            for child in children:
                if (child.getNamespace() == "jabber:x:fipa") or (child.getNamespace() == u"jabber:x:fipa"):
                    envxml = child.getData()
            if (envxml != None):
		print "FIPA MESSAGE RECEIVED: " + str(mess.getBody())
                xc = XMLCodec.XMLCodec()
                envelope = xc.parse(str(envxml))

		
		if   str(envelope.getAclRepresentation()).lower() == "fipa.acl.rep.string.std":
			ac = ACLParser.ACLParser()
		elif str(envelope.getAclRepresentation()).lower() == "fipa.acl.rep.xml.std":
			ac = ACLParser.ACLxmlParser()
		else:
			print "NO TENGO PARSER!"

		print ">>>>a parsear " + str(type(ac))
		print str(payload)
                ACLmsg = ac.parse(payload)
		print ">>>> parseado " + str(type(ac))
                ACLmsg = ac.parse(payload)
	        content = ACLmsg.getContent()
        	comillas_esc = '"'
	        barrainv_esc = '\\'
	        mtmp1 = comillas_esc.join(content.split('\\"'))
        	mtmp2 = barrainv_esc.join(mtmp1.split('\\\\'))
	        payload_esc = mtmp2
		ACLmsg.setContent(payload_esc)

                self.postMessage(ACLmsg)
            else:
                self.other_messageCB(conn,mess)


    def other_messageCB(self, conn, mess):
	"""
	non jabber:x:fipa chat messages callback
	"""
	print "NON-FIPA MESSAGE RECEIVED: " + str(mess)
        pass

    
    def jabber_process(self):<commit_msg>packaging<commit_after># -*- coding: cp1252 -*-
import sys
import xmpp
import threading
import thread
import Queue
import time
import MessageReceiver
import AID
import XMLCodec
import ACLParser
import Envelope
import ACLMessage
import BasicFipaDateTime
import Behaviour
import SL0Parser
#from AMS import AmsAgentDescription

class AbstractAgent(MessageReceiver.MessageReceiver):
    """
    Abstract Agent
    only for heritance
    Child classes: PlatformAgent, Agent
    """
    
    def __init__(self, agentjid, serverplatform):
	"""
	inits an agent with a JID (user@server) and a platform JID (acc.platformserver)
	"""
        MessageReceiver.MessageReceiver.__init__(self)
        self._aid = AID.aid(name=agentjid, addresses=[ "xmpp://acc."+serverplatform ])
        self._jabber = None
        self._serverplatform = serverplatform
        self._defaultbehaviour = None
        self._behaviourList = dict()
        self._isAlive = True



    def jabber_messageCB(self, conn, mess):
	"""
	message callback
	read the message envelope and post the message to the agent
	"""
        if (mess.getError() == None):
            envxml=None
            payload=mess.getBody()
            children = mess.getChildren()
            for child in children:
                if (child.getNamespace() == "jabber:x:fipa") or (child.getNamespace() == u"jabber:x:fipa"):
                    envxml = child.getData()
            if (envxml != None):
		print "FIPA MESSAGE RECEIVED: " + str(mess.getBody())
                xc = XMLCodec.XMLCodec()
                envelope = xc.parse(str(envxml))

		
		if   str(envelope.getAclRepresentation()).lower() == "fipa.acl.rep.string.std":
			ac = ACLParser.ACLParser()
			print "ACL PARSER SELECCIONADO"
		elif str(envelope.getAclRepresentation()).lower() == "fipa.acl.rep.xml.std":
			ac = ACLParser.ACLxmlParser()
			print "XML PARSER SELECCIONADO"
		else:
			print "NO TENGO PARSER!"

		print ">>>>a parsear " + str(type(ac))
		print str(payload)
                ACLmsg = ac.parse(payload)
		print ">>>> parseado " + str(type(ac))
                ACLmsg = ac.parse(payload)
	        content = ACLmsg.getContent()
        	comillas_esc = '"'
	        barrainv_esc = '\\'
	        mtmp1 = comillas_esc.join(content.split('\\"'))
        	mtmp2 = barrainv_esc.join(mtmp1.split('\\\\'))
	        payload_esc = mtmp2
		ACLmsg.setContent(payload_esc)

                self.postMessage(ACLmsg)
            else:
                self.other_messageCB(conn,mess)


    def other_messageCB(self, conn, mess):
	"""
	non jabber:x:fipa chat messages callback
	"""
	print "NON-FIPA MESSAGE RECEIVED: " + str(mess)
        pass

    
    def jabber_process(self):
{'fraction_non_alphanumeric': 0.11589278973197432, 'fraction_numerical': 0.0033975084937712344, 'mean_word_length': 2.6419243986254295, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 19, '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': '1624034', 'n_tokens_mistral': 1761, 'n_tokens_neox': 1664, 'n_words': 379}