<commit_before>
#from pox.lib.revent.revent import *
#from pox.lib.recoco.recoco import *
from pox.core import core as core
from pox.messenger.messenger import MessageRecieved
#import weakref
import json

log = core.getLogger()


from pox.core import core
from pox.messenger.messenger import *
from pox.lib.revent.revent import *
import traceback

from pox.log_messenger.log_messenger import LogMessenger

log = core.getLogger()

class GuiMessengerService (EventMixin):
  def __init__ (self, connection, params):
    self.connection = connection
    connection._newlines = params.get("newlines", True) == True #HACK

    # Make LogMessenger always send back "source":"logger"
    params['opaque'] = {'source':'logger'}
    self._logService = LogMessenger(connection, params) # Aggregate
    # Unhook its message received listener (we will pass it those events
    # manually ourselves...)
    connection.removeListener(dict(self._logService._listeners)[MessageRecieved])

    self.listenTo(connection)

  def _handle_MessageRecieved (self, event):
    if event.con.isReadable():
      r = event.con.read()
      if type(r) is dict:
        self._processParameters(r)
        if "bye" in r:
          event.con.close()
        else:
          # Dispatch message
          if r["type"] == "lavi":
            log.info("got lavi")
          elif r["type"] == "monitoring":
            log.info("got monitoring")
          elif r["type"] == "spanning_tree":
            log.info("got spanning_tree")
          elif r["type"] == "sample_routing":
            log.info("got sample_routing")
          elif r["type"] == "flowtracer":
            log.info("got flowtracer")
          elif r["type"] == "logging":
            self._logService._processParameters(r)
          else:
            self.warn("Unknown type for message: %s", r)


class GuiMessengerServiceListener (object):
  def __init__ (self):
    core.messenger.addListener(MessageRecieved, self._handle_global_MessageRecieved)

  def _handle_global_MessageRecieved (self, event):
    try:
      n = event.con.read()
      if n['hello'] == 'gui':
        # It's for me!
        try:
          GuiMessengerService(event.con, n)<commit_msg>add 'missing type' warning, change 'logger' to 'log' for consistency,<commit_after>
#from pox.lib.revent.revent import *
#from pox.lib.recoco.recoco import *
from pox.core import core as core
from pox.messenger.messenger import MessageRecieved
#import weakref
import json

log = core.getLogger()


from pox.core import core
from pox.messenger.messenger import *
from pox.lib.revent.revent import *
import traceback

from pox.log_messenger.log_messenger import LogMessenger

log = core.getLogger()

class GuiMessengerService (EventMixin):
  def __init__ (self, connection, params):
    self.connection = connection
    connection._newlines = params.get("newlines", True) == True #HACK

    # Make LogMessenger always send back "source":"logger"
    params['opaque'] = {'type':'log'}
    self._logService = LogMessenger(connection, params) # Aggregate
    # Unhook its message received listener (we will pass it those events
    # manually ourselves...)
    connection.removeListener(dict(self._logService._listeners)[MessageRecieved])

    self.listenTo(connection)

  def _handle_MessageRecieved (self, event):
    if event.con.isReadable():
      r = event.con.read()
      if type(r) is dict:
        if "bye" in r:
          event.con.close()
        else:
          if "type" in r:
            # Dispatch message
            if r["type"] == "topology":
              pass
            elif r["type"] == "monitoring":
              pass
            elif r["type"] == "spanning_tree":
              pass
            elif r["type"] == "sample_routing":
              pass
            elif r["type"] == "flowtracer":
              pass
            elif r["type"] == "log":
              self._logService._processParameters(r)
            else:
              log.warn("Unknown type for message: %s", r)
          else:
            log.warn("Missing type for message: %s", r)
 

class GuiMessengerServiceListener (object):
  def __init__ (self):
    core.messenger.addListener(MessageRecieved, self._handle_global_MessageRecieved)

  def _handle_global_MessageRecieved (self, event):
    try:
      n = event.con.read()
      if n['hello'] == 'gui':
        # It's for me!
        try:
          GuiMessengerService(event.con, n)
{'fraction_non_alphanumeric': 0.11541072640868975, 'fraction_numerical': 0.0, 'mean_word_length': 2.7553101104502975, 'pattern_counts': {'":': 14, '<': 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': '2339835', 'n_tokens_mistral': 1359, 'n_tokens_neox': 1314, 'n_words': 341}