# Path: txircd/modbase.py
# class Mode(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
#     def checkSet(self, user, target, param):
#         return [True, param]
#     def checkUnset(self, user, target, param):
#         return [True, param]
#     def showParam(self, user, target, param):
#         return param
#     def checkPermission(self, user, cmd, data):
#         return data
# 
# Path: txircd/utils.py
# def irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")
# 
# def epoch(utc_datetime):
#     delta = utc_datetime - UNIX_EPOCH
#     return int(delta.total_seconds())
# 
# def now():
#     return datetime.datetime.utcnow().replace(microsecond=0)
# 
# class CaseInsensitiveDictionary(MutableMapping):
#     def __init__(self):
#         self._data = {}
# 
#     def __repr__(self):
#         return repr(self._data)
# 
#     def __delitem__(self, key):
#         try:
#             del self._data[irc_lower(key)]
#         except KeyError:
#             raise KeyError(key)
# 
#     def __getitem__(self, key):
#         try:
#             return self._data[irc_lower(key)]
#         except KeyError:
#             raise KeyError(key)
# 
#     def __iter__(self):
#         return iter(self._data)
# 
#     def __len__(self):
#         return len(self._data)
# 
#     def __setitem__(self, key, value):
#         self._data[irc_lower(key)] = value


from twisted.words.protocols import irc
from txircd.modbase import Mode
from txircd.utils import irc_lower, epoch, now, CaseInsensitiveDictionary
from fnmatch import fnmatch
                        if fnmatch(hostmask, irc_lower(mask)):
                            remove.append(chan)
                            user.sendMessage(irc.ERR_BANNEDFROMCHAN, chan.name, ":Cannot join channel (You're banned)")
                            break
            for chan in remove:
                index = channels.index(chan)
                channels.pop(index)
                keys.pop(index)
        data["targetchan"] = channels
        data["keys"] = keys
        del user.cache["ban_evaluating"]
        return data
    
    def showParam(self, user, target):
        if "b" in target.mode:
            for entry in target.mode["b"]:
                metadata = target.cache["bandata"][entry] if "bandata" in target.cache and entry in target.cache["bandata"] else [ self.ircd.name, epoch(now()) ]
                user.sendMessage(irc.RPL_BANLIST, target.name, entry, metadata[0], str(metadata[1]))
            if "bandata" in target.cache:
                removeMask = []
                for mask in target.cache["bandata"]:
                    if mask not in target.mode["b"]:
                        removeMask.append(mask)
                for mask in removeMask:
                    del target.cache["bandata"][mask]
        elif "bandata" in target.cache:
            del target.cache["bandata"] # clear all saved ban data if no bans are set on channel
        user.sendMessage(irc.RPL_ENDOFBANLIST, target.name, ":End of channel ban list")

class Spawner(object):

# Path: txircd/modbase.py
# class Mode(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
#     def checkSet(self, user, target, param):
#         return [True, param]
#     def checkUnset(self, user, target, param):
#         return [True, param]
#     def showParam(self, user, target, param):
#         return param
#     def checkPermission(self, user, cmd, data):
#         return data
# 
# Path: txircd/utils.py
# def irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")
# 
# def epoch(utc_datetime):
#     delta = utc_datetime - UNIX_EPOCH
#     return int(delta.total_seconds())
# 
# def now():
#     return datetime.datetime.utcnow().replace(microsecond=0)
# 
# class CaseInsensitiveDictionary(MutableMapping):
#     def __init__(self):
#         self._data = {}
# 
#     def __repr__(self):
#         return repr(self._data)
# 
#     def __delitem__(self, key):
#         try:
#             del self._data[irc_lower(key)]
#         except KeyError:
#             raise KeyError(key)
# 
#     def __getitem__(self, key):
#         try:
#             return self._data[irc_lower(key)]
#         except KeyError:
#             raise KeyError(key)
# 
#     def __iter__(self):
#         return iter(self._data)
# 
#     def __len__(self):
#         return len(self._data)
# 
#     def __setitem__(self, key, value):
#         self._data[irc_lower(key)] = value


# Path: txircd/modules/cmode_b.py
from twisted.words.protocols import irc
from txircd.modbase import Mode
from txircd.utils import irc_lower, epoch, now, CaseInsensitiveDictionary
from fnmatch import fnmatch

                        if fnmatch(hostmask, irc_lower(mask)):
                            remove.append(chan)
                            user.sendMessage(irc.ERR_BANNEDFROMCHAN, chan.name, ":Cannot join channel (You're banned)")
                            break
            for chan in remove:
                index = channels.index(chan)
                channels.pop(index)
                keys.pop(index)
        data["targetchan"] = channels
        data["keys"] = keys
        del user.cache["ban_evaluating"]
        return data
    
    def showParam(self, user, target):
        if "b" in target.mode:
            for entry in target.mode["b"]:
                metadata = target.cache["bandata"][entry] if "bandata" in target.cache and entry in target.cache["bandata"] else [ self.ircd.name, epoch(now()) ]
                user.sendMessage(irc.RPL_BANLIST, target.name, entry, metadata[0], str(metadata[1]))
            if "bandata" in target.cache:
                removeMask = []
                for mask in target.cache["bandata"]:
                    if mask not in target.mode["b"]:
                        removeMask.append(mask)
                for mask in removeMask:
                    del target.cache["bandata"][mask]
        elif "bandata" in target.cache:
            del target.cache["bandata"] # clear all saved ban data if no bans are set on channel
        user.sendMessage(irc.RPL_ENDOFBANLIST, target.name, ":End of channel ban list")

class Spawner(object):

    def __init__(self, ircd):