
    Vh%                     n    d dl mZmZmZ eZdZdZdZd dl	m
Z
 d dlmZ d dlmZ d dlmZ  G d	 d
e      Zy)    )absolute_importdivisionprint_functiona]  
name: flattened
author: Serge van Ginderachter (!UNKNOWN) <serge@vanginderachter.be>
short_description: return single list completely flattened
description:
  - Given one or more lists, this lookup will flatten any list elements found recursively until only 1 list is left.
options:
  _terms:
    description: Lists to flatten.
    type: list
    elements: raw
    required: true
notes:
  - Unlike the P(ansible.builtin.items#lookup) lookup which only flattens 1 level, this plugin will continue to flatten until
    it cannot find lists anymore.
  - Aka highlander plugin, there can only be one (list).
z
- name: "'unnest' all elements into single list"
  ansible.builtin.debug:
    msg: "all in one list {{lookup('community.general.flattened', [1,2,3,[5,6]], ['a','b','c'], [[5,6,1,3], [34,'a','b','c']])}}"
z9
_raw:
  description:
    - Flattened list.
  type: list
)AnsibleError)string_types)
LookupBase)listify_lookup_plugin_termsc                        e Zd Zd Zd ZddZy)LookupModulec                     t        |t              r4t        |      dk(  r&|d   }t        |t              r| j                  |      }|S )N   r   )
isinstancelistlen_check_list_of_one_list)selfterms     n/home/dcms/DCMS/lib/python3.12/site-packages/ansible_collections/community/general/plugins/lookup/flattened.pyr   z$LookupModule._check_list_of_one_list/   s@     dD!c$i1n7D$%33D9    c                    g }|D ]  }| j                  |      }|dk(  s|dk(  r |S t        |t              r 	 t        || j                        }||gk7  r|}t        |t              r$| j                  ||      }|j                  |       |j                  |        |S # t
        $ r% t        || j                  | j                        }Y ~w xY w)NNonenull)templar)r   loader)r   r   r   r	   _templar	TypeError_loaderr   _do_flattenextendappend)r   terms	variablesretr   term2s         r   r   zLookupModule._do_flatten:   s     	!D//5Dv~* 
' $-j7dmmTE TF? D$%''i8

4 

4 1	!4 
 ! j 8dmm\`\h\hiEjs   B+CCNc                     t        |t              st        d      | j                  ||       | j	                  ||      S )Nzwith_flattened expects a list)var_optionsdirect)r   r   r   set_optionsr   )r   r!   r"   kwargss       r   runzLookupModule.runY   s>    %&>??Yv>y11r   )N)__name__
__module____qualname__r   r   r*    r   r   r   r   -   s    	>2r   r   N)
__future__r   r   r   type__metaclass__DOCUMENTATIONEXAMPLESRETURNansible.errorsr   ansible.module_utils.sixr   ansible.plugins.lookupr   ansible.utils.listifyr	   r   r.   r   r   <module>r9      sB    C B$
 ( 1 - =22: 22r   