# 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 irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")


from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.utils import irc_lower
from fnmatch import fnmatch
                            else:
                                user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key))
                if encounteredItem:
                    user.sendMessage(irc.RPL_METADATAEND, ":End of metadata")
                else:
                    user.sendMessage(irc.ERR_NOMATCHINGKEYS, filter, ":no matching keys")
            else:
                encounteredItem = False
                for namespace in namespaceList:
                    for key, value in target.metadata[namespace].iteritems():
                        encounteredItem = True
                        if value:
                            user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key), ":{}".format(value))
                        else:
                            user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key))
                if encounteredItem:
                    user.sendMessage(irc.RPL_METADATAEND, ":End of metadata")
                else:
                    user.sendMessage(irc.ERR_NOMATCHINGKEYS, "*", ":no matching keys")
        elif subcmd == "SET":
            namespace, key = data["key"].split(".", 1)
            if namespace not in ["user", "client"]:
                user.sendMessage(irc.ERR_KEYNOPERMISSION, data["targetname"], key, ":permission denied")
                return
            # This may be restricted later to only keys in the key registry; for now, I don't think allowing
            # whatever keys in the user-settable namespaces is a major problem. //EA
            if data["value"]:
                target.setMetadata(namespace, key, data["value"])
                user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key), ":{}".format(data["value"]))
            else:

# 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 irc_lower(str):
#     return str.lower().replace("[","{").replace("]","}").replace("/","|").replace("~","^")


# Path: txircd/modules/ircv3_metadata.py
from twisted.words.protocols import irc
from txircd.modbase import Command
from txircd.utils import irc_lower
from fnmatch import fnmatch

                            else:
                                user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key))
                if encounteredItem:
                    user.sendMessage(irc.RPL_METADATAEND, ":End of metadata")
                else:
                    user.sendMessage(irc.ERR_NOMATCHINGKEYS, filter, ":no matching keys")
            else:
                encounteredItem = False
                for namespace in namespaceList:
                    for key, value in target.metadata[namespace].iteritems():
                        encounteredItem = True
                        if value:
                            user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key), ":{}".format(value))
                        else:
                            user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key))
                if encounteredItem:
                    user.sendMessage(irc.RPL_METADATAEND, ":End of metadata")
                else:
                    user.sendMessage(irc.ERR_NOMATCHINGKEYS, "*", ":no matching keys")
        elif subcmd == "SET":
            namespace, key = data["key"].split(".", 1)
            if namespace not in ["user", "client"]:
                user.sendMessage(irc.ERR_KEYNOPERMISSION, data["targetname"], key, ":permission denied")
                return
            # This may be restricted later to only keys in the key registry; for now, I don't think allowing
            # whatever keys in the user-settable namespaces is a major problem. //EA
            if data["value"]:
                target.setMetadata(namespace, key, data["value"])
                user.sendMessage(irc.RPL_KEYVALUE, data["targetname"], "{}.{}".format(namespace, key), ":{}".format(data["value"]))
            else:

                target.delMetadata(namespace, key)