'Return all groups in the system with parents and children'

def find_groups(self, groupname_pattern, search_attr=None, group_name_attr=None, group_member_attr=None, group_filter=None, find_by_dn=False, scope=ldap.SCOPE_SUBTREE):

    if find_by_dn:
        data = filter((lambda attrs: (attrs['dn'] == groupname_pattern)), self._instance.groups.values())
        if (data and (scope == ldap.SCOPE_SUBTREE)):
            sub_data = filter((lambda attrs: attrs['dn'].endswith(data[0]['dn'])), self._instance.groups.values())
            data.extend(sub_data)
    else:
        groupname_pattern = ('^%s$' % groupname_pattern.replace('.', '\\.').replace('*', '.*'))
        groupnames = filter((lambda username: re.match(groupname_pattern, username)), self._instance.groups.keys())
        data = [self._instance.groups.get(groupname) for groupname in groupnames]
    return data
