# 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
# 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
# 
# def now():
#     return datetime.datetime.utcnow().replace(microsecond=0)
# 
# def epoch(utc_datetime):
#     delta = utc_datetime - UNIX_EPOCH
#     return int(delta.total_seconds())
# 
# 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


from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.utils import CaseInsensitiveDictionary, now, epoch, parse_duration
            expiryTime = epoch(now()) - parse_duration(self.ircd.servconfig["client_whowas_expire"])
            while epoch(self.history[user.nickname][0]["time"]) < expiryTime:
                self.history[user.nickname].pop(0)
        else:
            self.history[user.nickname] = [newEntry]

class Spawner(object):
    def __init__(self, ircd):
        self.ircd = ircd
        self.whowasCmd = None
    
    def spawn(self):
        if "client_whowas_limit" not in self.ircd.servconfig:
            self.ircd.servconfig["client_whowas_limit"] = 10
        if "client_whowas_expire" not in self.ircd.servconfig:
            self.ircd.servconfig["client_whowas_expire"] = "1d"
        self.whowasCmd = WhowasCommand()
        return {
            "commands": {
                "WHOWAS": self.whowasCmd
            },
            "actions": {
                "quit": self.whowasCmd.addToWhowas
            }
        }
    
    def data_serialize(self):
        expiryTime = epoch(now()) - parse_duration(self.ircd.servconfig["client_whowas_expire"])
        remove = []
        for nick, data in self.whowasCmd.history.iteritems():

# 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
# 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
# 
# def now():
#     return datetime.datetime.utcnow().replace(microsecond=0)
# 
# def epoch(utc_datetime):
#     delta = utc_datetime - UNIX_EPOCH
#     return int(delta.total_seconds())
# 
# 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


# Path: txircd/modules/cmd_whowas.py
from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.utils import CaseInsensitiveDictionary, now, epoch, parse_duration

            expiryTime = epoch(now()) - parse_duration(self.ircd.servconfig["client_whowas_expire"])
            while epoch(self.history[user.nickname][0]["time"]) < expiryTime:
                self.history[user.nickname].pop(0)
        else:
            self.history[user.nickname] = [newEntry]

class Spawner(object):
    def __init__(self, ircd):
        self.ircd = ircd
        self.whowasCmd = None
    
    def spawn(self):
        if "client_whowas_limit" not in self.ircd.servconfig:
            self.ircd.servconfig["client_whowas_limit"] = 10
        if "client_whowas_expire" not in self.ircd.servconfig:
            self.ircd.servconfig["client_whowas_expire"] = "1d"
        self.whowasCmd = WhowasCommand()
        return {
            "commands": {
                "WHOWAS": self.whowasCmd
            },
            "actions": {
                "quit": self.whowasCmd.addToWhowas
            }
        }
    
    def data_serialize(self):
        expiryTime = epoch(now()) - parse_duration(self.ircd.servconfig["client_whowas_expire"])
        remove = []
        for nick, data in self.whowasCmd.history.iteritems():

            while data and epoch(data[0]["time"]) < expiryTime: