# Path: pysiriproxy/utils.py
# def toHex(string, separator=" "):
#     '''Convert a string to hexadecimal.
# 
#     * string -- The string to convert to hexadecimal
#     * seperator -- The seperator to use between each character
# 
#     '''
#     return separator.join(map(characterToHex, string))
# 
# Path: pysiriproxy/constants.py
# class Modes:
#     '''The Modes class contains properties which define different types of
#     data receiving modes.
# 
#     '''
# 
#     Line = "line"
#     '''The Line property indicates the mode in which lines of data is
#     sent and received.
# 
#     '''
# 
#     Raw = "raw"
#     '''The Raw property indicates the mode in which raw data is sent
#     and received.
# 
#     '''


from pysiriproxy.utils import toHex
from pysiriproxy.constants import Modes
from pyamp.processes.threading import Thread



class Player(Thread):
    '''The Player class loads a file containing data which it proceeds
    to send to the given protocol class using the same interface used
    to handle connections to the server. This allows us to save incoming
    data to the server and replay it for testing purposes.

    '''

    def __init__(self, protocol, filename, logger):
        '''
        * protocol -- The server protocol class
        * filename -- The filename containing to data to replay
        * logger -- The logger

        '''
        Thread.__init__(self)
        self.__log = logger.get("PacketPlayer")
        self.__protocol = protocol(logger=logger)

        self.__content = file(filename).read()
        self.__lines = self.__content.split("-END_OF_DATA-")
        self.__index = 0

        # Start in Line mode
        self.__setMode(Modes.Line)

        # Map the fuction to call based on the current mode

# Path: pysiriproxy/utils.py
# def toHex(string, separator=" "):
#     '''Convert a string to hexadecimal.
# 
#     * string -- The string to convert to hexadecimal
#     * seperator -- The seperator to use between each character
# 
#     '''
#     return separator.join(map(characterToHex, string))
# 
# Path: pysiriproxy/constants.py
# class Modes:
#     '''The Modes class contains properties which define different types of
#     data receiving modes.
# 
#     '''
# 
#     Line = "line"
#     '''The Line property indicates the mode in which lines of data is
#     sent and received.
# 
#     '''
# 
#     Raw = "raw"
#     '''The Raw property indicates the mode in which raw data is sent
#     and received.
# 
#     '''


# Path: pysiriproxy/packetPlayer.py
from pysiriproxy.utils import toHex
from pysiriproxy.constants import Modes
from pyamp.processes.threading import Thread




class Player(Thread):
    '''The Player class loads a file containing data which it proceeds
    to send to the given protocol class using the same interface used
    to handle connections to the server. This allows us to save incoming
    data to the server and replay it for testing purposes.

    '''

    def __init__(self, protocol, filename, logger):
        '''
        * protocol -- The server protocol class
        * filename -- The filename containing to data to replay
        * logger -- The logger

        '''
        Thread.__init__(self)
        self.__log = logger.get("PacketPlayer")
        self.__protocol = protocol(logger=logger)

        self.__content = file(filename).read()
        self.__lines = self.__content.split("-END_OF_DATA-")
        self.__index = 0

        # Start in Line mode
        self.__setMode(Modes.Line)

        # Map the fuction to call based on the current mode

        self.__modeMap = {Modes.Line: self.__sendLineData,