# Path: txircd/modbase.py
# class Command(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
#     def onUse(self, user, data):
#         pass
#     def processParams(self, user, params):
#         return {
#             "user": user,
#             "params": params
#         }
#     def updateActivity(self, user):
#         user.lastactivity = now()
# 
# Path: txircd/utils.py
# def epoch(utc_datetime):
#     delta = utc_datetime - UNIX_EPOCH
#     return int(delta.total_seconds())
# 
# def now():
#     return datetime.datetime.utcnow().replace(microsecond=0)
# 
# def irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")
# 
# def parse_duration(duration_string):
#     """
#     Parses a string duration given in 1y2w3d4h5m6s format
#     returning the total number of seconds
#     """
#     try: # attempt to parse as a number of seconds if we get just a number before we go through the parsing process
#         return int(duration_string)
#     except ValueError:
#         pass
#     timeparts = DURATION_REGEX.match(duration_string).groupdict()
# 
#     duration = 0
#     for unit, amount in timeparts.iteritems():
#         if amount is not None:
#             try:
#                 duration += int(amount) * time_lengths[unit]
#             except ValueError:
#                 pass
#     return duration
# 
# 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 Command
from txircd.utils import epoch, now, irc_lower, parse_duration, CaseInsensitiveDictionary
from fnmatch import fnmatch
            if user.cache["except_line"]:
                return None
            matchMask = "{}@{}".format(user.username, user.hostname)
            for mask, linedata in self.shunList.iteritems():
                if fnmatch(matchMask, mask):
                    return linedata["reason"]
            matchMask = "{}@{}".format(user.username, user.ip)
            for mask, linedata in self.shunList.iteritems():
                if fnmatch(matchMask, mask):
                    return linedata["reason"]
            return None
        elif "shunned" in user.cache:
            if user.cache["shunned"]:
                return "Shunned"
            return None
        else:
            matchMask = "{}@{}".format(user.username, user.hostname)
            for mask in self.shunList.iterkeys():
                if fnmatch(matchMask, mask):
                    user.cache["shunned"] = True
                    return ""
            matchMask = "{}@{}".format(user.username, user.ip)
            for mask in self.shunList.iterkeys():
                if fnmatch(matchMask, mask):
                    user.cache["shunned"] = True
                    return ""
            user.cache["shunned"] = False
            return None
    
    def expire_shuns(self):

# Path: txircd/modbase.py
# class Command(object):
#     def hook(self, base):
#         self.ircd = base
#         return self
#     def onUse(self, user, data):
#         pass
#     def processParams(self, user, params):
#         return {
#             "user": user,
#             "params": params
#         }
#     def updateActivity(self, user):
#         user.lastactivity = now()
# 
# Path: txircd/utils.py
# def epoch(utc_datetime):
#     delta = utc_datetime - UNIX_EPOCH
#     return int(delta.total_seconds())
# 
# def now():
#     return datetime.datetime.utcnow().replace(microsecond=0)
# 
# def irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")
# 
# def parse_duration(duration_string):
#     """
#     Parses a string duration given in 1y2w3d4h5m6s format
#     returning the total number of seconds
#     """
#     try: # attempt to parse as a number of seconds if we get just a number before we go through the parsing process
#         return int(duration_string)
#     except ValueError:
#         pass
#     timeparts = DURATION_REGEX.match(duration_string).groupdict()
# 
#     duration = 0
#     for unit, amount in timeparts.iteritems():
#         if amount is not None:
#             try:
#                 duration += int(amount) * time_lengths[unit]
#             except ValueError:
#                 pass
#     return duration
# 
# 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/shun.py
from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.utils import epoch, now, irc_lower, parse_duration, CaseInsensitiveDictionary
from fnmatch import fnmatch

            if user.cache["except_line"]:
                return None
            matchMask = "{}@{}".format(user.username, user.hostname)
            for mask, linedata in self.shunList.iteritems():
                if fnmatch(matchMask, mask):
                    return linedata["reason"]
            matchMask = "{}@{}".format(user.username, user.ip)
            for mask, linedata in self.shunList.iteritems():
                if fnmatch(matchMask, mask):
                    return linedata["reason"]
            return None
        elif "shunned" in user.cache:
            if user.cache["shunned"]:
                return "Shunned"
            return None
        else:
            matchMask = "{}@{}".format(user.username, user.hostname)
            for mask in self.shunList.iterkeys():
                if fnmatch(matchMask, mask):
                    user.cache["shunned"] = True
                    return ""
            matchMask = "{}@{}".format(user.username, user.ip)
            for mask in self.shunList.iterkeys():
                if fnmatch(matchMask, mask):
                    user.cache["shunned"] = True
                    return ""
            user.cache["shunned"] = False
            return None
    
    def expire_shuns(self):

        current_time = epoch(now())