# Path: umit/icm/agent/logger.py
# LOGLEVEL = 'DEBUG'
# 
# Path: umit/icm/agent/rpc/message.py
# MAX_MESSAGE_LENGTH = 1024 * 1024   # max message length is 1M
# class MalformedMessageError(Exception):
# class RawMessage(object):
#     def __init__(self):
#     def fill(self, data):
# 
# Path: umit/icm/agent/rpc/MessageFactory.py
# class MessageFactory(object):
#     """"""
#     _reader = BinaryReader()
#     _writer = BinaryWriter()
# 
#     #----------------------------------------------------------------------
#     #def __init__(self):
#         #"""Constructor"""
# 
#     @classmethod
#     def create(cls, msg_type):
#         return message_creator[msg_type]()
# 
#     @classmethod
#     def encode(cls, message):
#         cls._writer.reset()
#         msg_type = message.DESCRIPTOR.name
#         msg_type_id = message_type_to_id[msg_type]
#         msg_str = message.SerializeToString()
#         cls._writer.writeInt32(msg_type_id)
#         cls._writer.writeFixedLengthString(msg_str, len(msg_str))
#         return cls._writer.getString()
# 
#     @classmethod
#     def decode(cls, str_):
#         cls._reader.setString(str_)
#         msg_type_id = cls._reader.readInt32()
#         msg_type = message_id_to_type[msg_type_id]
#         message = cls.create(msg_type)
#         msg_str = cls._reader.readFixedLengthString(len(str_)-4)
#         message.ParseFromString(msg_str)
#         return message
# 
#     @classmethod
#     def encrypt(cls, str_):
#         pass
# 
#     @classmethod
#     def decrypt(cls, str_):
#         pass


import base64
import time
    import time
from umit.icm.agent.logger import g_logger
from umit.icm.agent.Global import *
from umit.icm.agent.rpc.message import WebsiteReportDetail, ServiceReportDetail
from umit.icm.agent.rpc.MessageFactory import MessageFactory
    from umit.icm.agent.rpc.message import *

            event_entry.TestType = record[1]
            event_entry.EventType = record[2]
            event_entry.TimeUTC = record[3]
            event_entry.SinceTimeUTC = record[4]
            event_entry.Locations = []
            for loc in record[5].split(';'):
                event_entry.Locations.append((float(loc.split(',')[0]),
                                              float(loc.split(',')[1])))
            if record[6] != 'None':
                event_entry.WebsiteReport = \
                           MessageFactory.decode(base64.b64decode(record[6]))
            if record[7] != 'None':
                event_entry.ServiceReport = \
                           MessageFactory.decode(base64.b64decode(record[7]))
            if event_entry not in self.event_repository:
                self.event_repository.append(event_entry)
        g_logger.info("Loaded %d events from DB." % len(rs))

    def save_event_to_db(self, event_entry):
        locs = []
        for loc in event_entry.Locations:
            locs.append("%f,%f" % loc)
        loc_str = ';'.join(locs)
        wr_str = None
        if event_entry.WebsiteReport:
            wr_str = base64.b64encode(
                MessageFactory.encode(event_entry.WebsiteReport))
        sr_str = None
        if event_entry.ServiceReport:
            sr_str = base64.b64encode(

# Path: umit/icm/agent/logger.py
# LOGLEVEL = 'DEBUG'
# 
# Path: umit/icm/agent/rpc/message.py
# MAX_MESSAGE_LENGTH = 1024 * 1024   # max message length is 1M
# class MalformedMessageError(Exception):
# class RawMessage(object):
#     def __init__(self):
#     def fill(self, data):
# 
# Path: umit/icm/agent/rpc/MessageFactory.py
# class MessageFactory(object):
#     """"""
#     _reader = BinaryReader()
#     _writer = BinaryWriter()
# 
#     #----------------------------------------------------------------------
#     #def __init__(self):
#         #"""Constructor"""
# 
#     @classmethod
#     def create(cls, msg_type):
#         return message_creator[msg_type]()
# 
#     @classmethod
#     def encode(cls, message):
#         cls._writer.reset()
#         msg_type = message.DESCRIPTOR.name
#         msg_type_id = message_type_to_id[msg_type]
#         msg_str = message.SerializeToString()
#         cls._writer.writeInt32(msg_type_id)
#         cls._writer.writeFixedLengthString(msg_str, len(msg_str))
#         return cls._writer.getString()
# 
#     @classmethod
#     def decode(cls, str_):
#         cls._reader.setString(str_)
#         msg_type_id = cls._reader.readInt32()
#         msg_type = message_id_to_type[msg_type_id]
#         message = cls.create(msg_type)
#         msg_str = cls._reader.readFixedLengthString(len(str_)-4)
#         message.ParseFromString(msg_str)
#         return message
# 
#     @classmethod
#     def encrypt(cls, str_):
#         pass
# 
#     @classmethod
#     def decrypt(cls, str_):
#         pass


# Path: umit/icm/agent/core/EventManager.py
import base64
import time
    import time
from umit.icm.agent.logger import g_logger
from umit.icm.agent.Global import *
from umit.icm.agent.rpc.message import WebsiteReportDetail, ServiceReportDetail
from umit.icm.agent.rpc.MessageFactory import MessageFactory
    from umit.icm.agent.rpc.message import *

            event_entry.TestType = record[1]
            event_entry.EventType = record[2]
            event_entry.TimeUTC = record[3]
            event_entry.SinceTimeUTC = record[4]
            event_entry.Locations = []
            for loc in record[5].split(';'):
                event_entry.Locations.append((float(loc.split(',')[0]),
                                              float(loc.split(',')[1])))
            if record[6] != 'None':
                event_entry.WebsiteReport = \
                           MessageFactory.decode(base64.b64decode(record[6]))
            if record[7] != 'None':
                event_entry.ServiceReport = \
                           MessageFactory.decode(base64.b64decode(record[7]))
            if event_entry not in self.event_repository:
                self.event_repository.append(event_entry)
        g_logger.info("Loaded %d events from DB." % len(rs))

    def save_event_to_db(self, event_entry):
        locs = []
        for loc in event_entry.Locations:
            locs.append("%f,%f" % loc)
        loc_str = ';'.join(locs)
        wr_str = None
        if event_entry.WebsiteReport:
            wr_str = base64.b64encode(
                MessageFactory.encode(event_entry.WebsiteReport))
        sr_str = None
        if event_entry.ServiceReport:
            sr_str = base64.b64encode(

                MessageFactory.encode(event_entry.ServiceReport))
