# 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
                return {}
        if banmask in self.exceptList:
            user.sendMessage("NOTICE", ":*** An e:line is already set on {}!  Check /stats E to view currently set e:lines.".format(banmask))
            return {}
        return {
            "user": user,
            "mask": banmask,
            "duration": parse_duration(params[1]),
            "reason": " ".join(params[2:])
        }
    
    def statsList(self, user, statsType):
        if statsType != "E":
            return
        self.expire_elines()
        for mask, linedata in self.exceptList.iteritems():
            user.sendMessage(irc.RPL_STATSELINES, "{} {} {} {} :{}".format(mask, linedata["created"], linedata["duration"], linedata["setter"], linedata["reason"]))
    
    def check_register(self, user):
        if self.match_eline(user):
            user.cache["except_line"] = True
        return True
    
    def match_eline(self, user):
        self.expire_elines()
        matchMask = irc_lower("{}@{}".format(user.username, user.hostname))
        for mask, linedata in self.exceptList.iteritems():
            if fnmatch(matchMask, mask):
                user.cache["except_line"] = True
                return linedata["reason"]

# 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/cmd_eline.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

                return {}
        if banmask in self.exceptList:
            user.sendMessage("NOTICE", ":*** An e:line is already set on {}!  Check /stats E to view currently set e:lines.".format(banmask))
            return {}
        return {
            "user": user,
            "mask": banmask,
            "duration": parse_duration(params[1]),
            "reason": " ".join(params[2:])
        }
    
    def statsList(self, user, statsType):
        if statsType != "E":
            return
        self.expire_elines()
        for mask, linedata in self.exceptList.iteritems():
            user.sendMessage(irc.RPL_STATSELINES, "{} {} {} {} :{}".format(mask, linedata["created"], linedata["duration"], linedata["setter"], linedata["reason"]))
    
    def check_register(self, user):
        if self.match_eline(user):
            user.cache["except_line"] = True
        return True
    
    def match_eline(self, user):
        self.expire_elines()
        matchMask = irc_lower("{}@{}".format(user.username, user.hostname))
        for mask, linedata in self.exceptList.iteritems():
            if fnmatch(matchMask, mask):
                user.cache["except_line"] = True
                return linedata["reason"]

        matchMask = irc_lower("{}@{}".format(user.username, user.ip))