# Path: lib/cuckoo/common/utils.py
# def convert_to_printable(s):
#     """Convert char to printable.
#     @param s: string.
#     @return: sanitized string.
#     """
#     if is_printable(s):
#         return s
#     return "".join(convert_char(c) for c in s)


import cStringIO
import re
import logging
from lib.cuckoo.common.utils import convert_to_printable
        "TRACE", "ADMIN", "INFO", "SERVLIST",
        "SQUERY", "WHO", "WHOIS", "WHOWAS", "KILL", "PING", "PONG", "ERROR", "AWAY", "REHASH", "DIE", "RESTART",
        "SUMMON", "USERS", "WALLOPS",
        "USERHOST", "NICK", "ISON"
    ))

    def __init__(self):
        self._messages = []
        # Server commandis : prefix - command - params 
        self._sc = {}
        # Client commands : command - params 
        self._cc = {}

    def _unpack(self, buf):
        """Extract into a list irc messages of a tcp streams.
        @buf: tcp stream data
        """
        try:
            f = cStringIO.StringIO(buf)
            lines = f.readlines()
        except Exception:
            log.error("Failed reading tcp stream buffer")
            return False

        for element in lines:
            if not re.match("^:", element) is None:
                command = "([a-zA-Z]+|[0-9]{3})"
                params = "(\x20.+)"
                irc_server_msg = re.findall("(^:[\w+.{}!@|()]+\x20)"+command+params,element)
                if irc_server_msg:

# Path: lib/cuckoo/common/utils.py
# def convert_to_printable(s):
#     """Convert char to printable.
#     @param s: string.
#     @return: sanitized string.
#     """
#     if is_printable(s):
#         return s
#     return "".join(convert_char(c) for c in s)


# Path: lib/cuckoo/common/irc.py
import cStringIO
import re
import logging
from lib.cuckoo.common.utils import convert_to_printable

        "TRACE", "ADMIN", "INFO", "SERVLIST",
        "SQUERY", "WHO", "WHOIS", "WHOWAS", "KILL", "PING", "PONG", "ERROR", "AWAY", "REHASH", "DIE", "RESTART",
        "SUMMON", "USERS", "WALLOPS",
        "USERHOST", "NICK", "ISON"
    ))

    def __init__(self):
        self._messages = []
        # Server commandis : prefix - command - params 
        self._sc = {}
        # Client commands : command - params 
        self._cc = {}

    def _unpack(self, buf):
        """Extract into a list irc messages of a tcp streams.
        @buf: tcp stream data
        """
        try:
            f = cStringIO.StringIO(buf)
            lines = f.readlines()
        except Exception:
            log.error("Failed reading tcp stream buffer")
            return False

        for element in lines:
            if not re.match("^:", element) is None:
                command = "([a-zA-Z]+|[0-9]{3})"
                params = "(\x20.+)"
                irc_server_msg = re.findall("(^:[\w+.{}!@|()]+\x20)"+command+params,element)
                if irc_server_msg:

                    self._sc["prefix"] = convert_to_printable(irc_server_msg[0][0].strip())