# Path: cwmud/core/events.py
# EVENTS = EventManager()
# 
# Path: cwmud/core/logs.py
# def get_logger(*args, **kwargs):
#     """Fetch an instance of logging.Logger.
# 
#     This is just a stub that can later be expanded if we want to perform any
#     processing on the Logger instance before passing it on.
# 
#     Using this as a middle-man also ensures that our logging configuration will
#     always be loaded before a Logger is used, as none of the other code will
#     load the logging module directly.
# 
#     :param sequence args: Positional arguments passed on to logging.getLogger
#     :param mapping kwargs: Keyword arguments passed on to logging.getLogger
#     :returns logging.Logger: A Logger instance
# 
#     """
#     logger = logging.getLogger(*args, **kwargs)
#     return logger
# 
# Path: cwmud/core/text.py
# def strip_caret_codes(text):
#     """Strip out any caret codes from a string.
# 
#     :param str text: The text to strip the codes from
#     :returns str: The clean text
# 
#     """
#     text = text.replace("^^", "\0")
#     for code in CARET_CODES:
#         text = text.replace(code, "")
#     return text.replace("\0", "^")


from collections import deque
from time import time as now
from .events import EVENTS
from .logs import get_logger
from .messages import BROKER, get_pubsub
from .text import strip_caret_codes
        BROKER.publish("{}:output:{}".format(self._protocol, self._uid), data)


class ClientManager:

    """A manager for client handlers."""

    def __init__(self, protocol, client_class=Client):
        """Create a new client manager."""
        self._client_class = client_class
        self._clients = {}
        self._messages = get_pubsub()
        self._protocol = protocol
        self._messages.subscribe("{}:connect".format(protocol))
        self._messages.subscribe("{}:disconnect".format(protocol))

    def _add_client(self, uid, host, port, quiet=False):
        if uid in self._clients:
            log.warning("UID collision! {}:{}.".format(self._protocol, uid))
        client = self._client_class(self._protocol, uid, host, port)
        self._clients[uid] = client
        if not quiet:
            with EVENTS.fire("client_connected", client, no_pre=True):
                log.info("Incoming connection from %s.", client)
        return client

    def _remove_client(self, uid):
        client = self._clients.get(uid)
        if not client:
            return

# Path: cwmud/core/events.py
# EVENTS = EventManager()
# 
# Path: cwmud/core/logs.py
# def get_logger(*args, **kwargs):
#     """Fetch an instance of logging.Logger.
# 
#     This is just a stub that can later be expanded if we want to perform any
#     processing on the Logger instance before passing it on.
# 
#     Using this as a middle-man also ensures that our logging configuration will
#     always be loaded before a Logger is used, as none of the other code will
#     load the logging module directly.
# 
#     :param sequence args: Positional arguments passed on to logging.getLogger
#     :param mapping kwargs: Keyword arguments passed on to logging.getLogger
#     :returns logging.Logger: A Logger instance
# 
#     """
#     logger = logging.getLogger(*args, **kwargs)
#     return logger
# 
# Path: cwmud/core/text.py
# def strip_caret_codes(text):
#     """Strip out any caret codes from a string.
# 
#     :param str text: The text to strip the codes from
#     :returns str: The clean text
# 
#     """
#     text = text.replace("^^", "\0")
#     for code in CARET_CODES:
#         text = text.replace(code, "")
#     return text.replace("\0", "^")


# Path: cwmud/core/clients.py
from collections import deque
from time import time as now
from .events import EVENTS
from .logs import get_logger
from .messages import BROKER, get_pubsub
from .text import strip_caret_codes

        BROKER.publish("{}:output:{}".format(self._protocol, self._uid), data)


class ClientManager:

    """A manager for client handlers."""

    def __init__(self, protocol, client_class=Client):
        """Create a new client manager."""
        self._client_class = client_class
        self._clients = {}
        self._messages = get_pubsub()
        self._protocol = protocol
        self._messages.subscribe("{}:connect".format(protocol))
        self._messages.subscribe("{}:disconnect".format(protocol))

    def _add_client(self, uid, host, port, quiet=False):
        if uid in self._clients:
            log.warning("UID collision! {}:{}.".format(self._protocol, uid))
        client = self._client_class(self._protocol, uid, host, port)
        self._clients[uid] = client
        if not quiet:
            with EVENTS.fire("client_connected", client, no_pre=True):
                log.info("Incoming connection from %s.", client)
        return client

    def _remove_client(self, uid):
        client = self._clients.get(uid)
        if not client:
            return

        with EVENTS.fire("client_disconnected", client, no_pre=True):