'Implement the @tag functionality'

def func(self):

    if (not self.args):
        self.caller.msg('Usage:    @tag[/switches]    <obj>    [=    <tag>[:<category>]]')
        return
    if ('search' in self.switches):
        tag = self.args
        category = None
        if (':' in tag):
            (tag, category) = [part.strip() for part in tag.split(':', 1)]
        objs = search.search_tag(tag, category=category)
        nobjs = len(objs)
        if (nobjs > 0):
            catstr = (("    (category:    '|w%s|n')" % category) if category else ('' if (nobjs == 1) else '    (may    have    different    tag    categories)'))
            matchstr = ',    '.join((o.get_display_name(self.caller) for o in objs))
            string = ("Found    |w%i|n    object%s    with    tag    '|w%s|n'%s:\n    %s" % (nobjs, ('s' if (nobjs > 1) else ''), tag, catstr, matchstr))
        else:
            string = ("No    objects    found    with    tag    '%s%s'." % (tag, (('    (category:    %s)' % category) if category else '')))
        self.caller.msg(string)
        return
    if ('del' in self.switches):
        obj = self.caller.search(self.lhs, global_search=True)
        if (not obj):
            return
        if self.rhs:
            tag = self.rhs
            category = None
            if (':' in tag):
                (tag, category) = [part.strip() for part in tag.split(':', 1)]
            if obj.tags.get(tag, category=category):
                obj.tags.remove(tag, category=category)
                string = ("Removed    tag    '%s'%s    from    %s." % (tag, (('    (category:    %s)' % category) if category else ''), obj))
            else:
                string = ("No    tag    '%s'%s    to    delete    on    %s." % (tag, (('    (category:    %s)' % category) if category else ''), obj))
        else:
            old_tags = [('%s%s' % (tag, (('    (category:    %s' % category) if category else ''))) for (tag, category) in obj.tags.all(return_key_and_category=True)]
            if old_tags:
                obj.tags.clear()
                string = ('Cleared    all    tags    from    %s:    %s' % (obj, ',    '.join(old_tags)))
            else:
                string = ('No    Tags    to    clear    on    %s.' % obj)
        self.caller.msg(string)
        return
    if self.rhs:
        obj = self.caller.search(self.lhs, global_search=True)
        if (not obj):
            return
        tag = self.rhs
        category = None
        if (':' in tag):
            (tag, category) = [part.strip() for part in tag.split(':', 1)]
        obj.tags.add(tag, category=category)
        string = ("Added    tag    '%s'%s    to    %s." % (tag, (('    (category:    %s)' % category) if category else ''), obj))
        self.caller.msg(string)
    else:
        obj = self.caller.search(self.args, global_search=True)
        if (not obj):
            return
        tagtuples = obj.tags.all(return_key_and_category=True)
        ntags = len(tagtuples)
        tags = [tup[0] for tup in tagtuples]
        categories = [(('    (category:    %s)' % tup[1]) if tup[1] else '') for tup in tagtuples]
        if ntags:
            string = ('Tag%s    on    %s:    %s' % (('s' if (ntags > 1) else ''), obj, ',    '.join((("'%s'%s" % (tags[i], categories[i])) for i in range(ntags)))))
        else:
            string = ('No    tags    attached    to    %s.' % obj)
        self.caller.msg(string)
