a ì)gòã@s´ddlmZmZmZeZddlZddlZddlm Z m Z ddl m Z ddlmZddlmZddlmZddlmZdd lmZeƒZd d „Zdd d „Zdd„Zdd„Zdd„ZdS)é)Úabsolute_importÚdivisionÚprint_functionN)ÚMutableMappingÚMutableSequence)Ú constants)Ú AnsibleError)Úsix)Úto_text)Úconnection_loader)ÚDisplaycCsxt|tƒr| ¡}t |¡}n$t|tƒr>|dd…}t|ƒ}n|S|D],\}}t|ttfƒrjt|ƒ||<qF|||<qF|S)aðFunction 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)Ú isinstanceÚdictÚcopyr Z iteritemsÚlistÚ enumerateÚmodule_response_deepcopy)ÚvÚretÚitemsÚkeyÚvalue©rú6/usr/lib/python3.9/site-packages/ansible/vars/clean.pyrs       rcCs¸|durtƒ}t|tƒr>|D]}t|ttfƒrt||dqnvt|tƒr¤t| ¡ƒD]L}t|tjƒr~|  d¡r~||vr~||=qTt||ttfƒrTt|||dqTnt dt |ƒƒ‚|S)N)Ú exceptionsÚ _ansible_z!Cannot strip invalid keys from %s) Útupler rrÚstrip_internal_keysrÚkeysr Z string_typesÚ startswithrÚtype)ZdirtyrÚelementÚkrrrrFs    rcCs¦t| ¡ƒD]<}| d¡r"|dks,|tjvr t d|||f¡||=q dD]}||vrN||sN||=qNt| di¡ ¡ƒD]"}| d¡s–| d¡r~|d|=q~dS) z5 More nuanced version of strip_internal_keys rZ_ansible_parsedz9Removed unexpected internal key in module return: %s = %s)ÚwarningsZ deprecationsÚ ansible_factsZdiscovered_interpreter_Zansible_discovered_interpreter_N)rrrÚCÚINTERNAL_RESULT_KEYSÚdisplayÚwarningÚget)ÚdatarrrrÚremove_internal_keyscsr+c Cs>t|ƒ}tƒ}t| ¡ƒ}tjD]}| | tj|¡¡q | | tj¡¡tj ddD]b}t j   t j   |¡¡d}t dt |¡¡}|D],}| |¡r¦| d¡r°| d¡rŽ| |¡qŽqZtjtjD]} | |vrÊ| | ¡qÊt d¡} |D]}|  |¡rð| |¡qð|D]&} |  d¡st d | ¡|| =qt|ƒS) zI remove facts that can override internal keys or otherwise deemed unsafe T)Z path_onlyrz ^ansible_%s_)Z_bridgeZ _gwbridgeZansible_become_z^ansible_.*_interpreter$Zansible_ssh_host_key_z+Removed restricted key from module data: %s)rÚsetrr%ZMAGIC_VARIABLE_MAPPINGÚupdateÚ intersectionZCOMMON_CONNECTION_VARSr ÚallÚosÚpathÚsplitextÚbasenameÚreÚcompileÚescapeÚmatchÚendswithrÚaddZRESTRICTED_RESULT_KEYSr&r'r(r) Úfactsr*Z remove_keysZ fact_keysZ magic_varZ conn_pathZ conn_nameZre_keyZfact_keyZhardZ re_interpZr_keyrrrÚ clean_factsws0        r;cCsRi}|D]@}| d¡r8|dvr8t||ƒ||dd…<qt||ƒ||<qd|iS)z@ return all facts inside 'ansible_facts' w/o an ansible_ prefix Zansible_)Z ansible_localéNr$)rr)r:Z deprefixedr"rrrÚnamespace_facts¢s r=)N)Z __future__rrrr Z __metaclass__r0r4Úcollections.abcrrZansiblerr%Zansible.errorsrZansible.module_utilsr Zansible.module_utils._textr Zansible.plugins.loaderr Zansible.utils.displayr r'rrr+r;r=rrrrÚs       / +