def reverse_www(hosts, enabled=True, append=True):
    ''' Add or remove www subdomain '''

    if not enabled:
        return hosts

    # Check if hosts is a list and parse each host
    if isinstance(hosts, (list, tuple, types.GeneratorType)):
        reversed_hosts = [reverse_www(host) for host in hosts]

        if append:
            return list(set(hosts + reversed_hosts))
        else:
            return reversed_hosts

    # Add or remove www
    elif isinstance(hosts, string_types):
        host = hosts

        if host.startswith('www.'):
            return host[4:]
        else:
            if len(host.split('.')) > 2:
                return host
            else:
                return 'www.{0}'.format(host)

    # Handle invalid input type
    else:
        raise errors.AnsibleFilterError('The reverse_www filter expects a string or list of strings, got ' + repr(hosts))
dataset/ETHPy150Open roots/trellis/lib/trellis/plugins/filter/filters.py/reverse_www/original