o nnho@sddlmZddlZddlZddlmZmZddlmZ ddl m Z ddl m Z ddlmZddlmZeZd d Zdd d Zd dZddZddZdS)) annotationsN)MutableMappingMutableSequence) constants) AnsibleError)six)connection_loader)DisplaycCsxt|tr|}t|}nt|tr|dd}t|}n|S|D]\}}t|ttfr5t|||<q#|||<q#|S)aFunction to create a deep copy of module response data Designed to be used within the Ansible "engine" to improve performance issues where ``copy.deepcopy`` was used previously, largely with CPU and memory contention. This only supports the following data types, and was designed to only handle specific workloads: * ``dict`` * ``list`` The data we pass here will come from a serialization such as JSON, so we shouldn't have need for other data types such as ``set`` or ``tuple``. Take note that this function should not be used extensively as a replacement for ``deepcopy`` due to the naive way in which this handles other data types. Do not expect uses outside of those listed below to maintain backwards compatibility, in case we need to extend this function to handle our specific needs: * ``ansible.executor.task_result.TaskResult.clean_copy`` * ``ansible.vars.clean.clean_facts`` * ``ansible.vars.namespace_facts`` N) isinstancedictcopyr iteritemslist enumeratemodule_response_deepcopy)vretitemskeyvaluer=/usr/local/lib/python3.10/dist-packages/ansible/vars/clean.pyrs       rcCs|durt}t|tr |D]}t|ttfrt||dq|St|trTt|D]&}t|tjr@| dr@||vr@||=q+t||ttfrQt|||dq+|St dt |)N) exceptions _ansible_z!Cannot strip invalid keys from %s) tupler rrstrip_internal_keysrkeysr string_types startswithrtype)dirtyrelementkrrrrCs&    rcCst|D]}|dr|dks|tjvr$td|||f||=qdD] }||vr4||s4||=q't|diD]}|dsK|drP|d|=q?dS) z5 More nuanced version of strip_internal_keys r_ansible_parsedz9Removed unexpected internal key in module return: %s = %s)warnings deprecations ansible_factsdiscovered_interpreter_ansible_discovered_interpreter_N)rrrCINTERNAL_RESULT_KEYSdisplaywarningget)datarrrrremove_internal_keys`s r/c Cs:t|}t}t|}tjD] }||tj|q||tjtj ddD]1}t j t j |d}tdt|}|D]}||rS|drX|dr]||qGq-tjtjD] } | |vrp|| qetd} |D] }| |r||qx|D]} | dstd | || =qt|S) zI remove facts that can override internal keys or otherwise deemed unsafe T) path_onlyrz ^ansible_%s_)_bridge _gwbridgeansible_become_z^ansible_.*_interpreter$ansible_ssh_host_key_z+Removed restricted key from module data: %s)rsetrr)MAGIC_VARIABLE_MAPPINGupdate intersectionCOMMON_CONNECTION_VARSrallospathsplitextbasenamerecompileescapematchendswithraddRESTRICTED_RESULT_KEYSr*r+r,r) factsr. remove_keys fact_keys magic_var conn_path conn_namere_keyfact_keyhard re_interpr_keyrrr clean_factsts:        rQcCsRi}|D] }|dr|dvrt||||dd<qt||||<qd|iS)z@ return all facts inside 'ansible_facts' w/o an ansible_ prefix ansible_) ansible_localNr&)rr)rF deprefixedr"rrrnamespace_factss rV)N) __future__rr;r?collections.abcrransiblerr)ansible.errorsransible.module_utilsransible.plugins.loaderransible.utils.displayr r+rrr/rQrVrrrrs       / +