a )g @sddlmZmZmZeZddlZddlZddlm Z ddl m Z ddl m Z ddZdd Zd d Zd d ZGdddejZdS))absolute_importdivisionprint_functionN)to_text)Mapping) is_sequencecCst|ddot|dd S)N __UNSAFE__F __ENCRYPTED__getattrvaluerD/usr/lib/python3.9/site-packages/ansible/module_utils/common/json.py _is_unsafesrcCs t|ddS)Nr Fr r rrr _is_vaultsrcCs\t|r dt|dddi}n8t|r8dd|D}n t|trXtdd|D}|S) zRecursively preprocess a data structure converting instances of ``AnsibleUnsafe`` into their JSON dict representations Used in ``AnsibleJSONEncoder.iterencode`` __ansible_unsafesurrogate_or_strictstricterrorsZ nonstringcSsg|] }t|qSr_preprocess_unsafe_encode).0vrrr #z-_preprocess_unsafe_encode..css|]\}}|t|fVqdSNr)rkrrrr %rz,_preprocess_unsafe_encode..)rr _strip_unsafer isinstancerdictitemsr rrrrs rcCstj|tdddS)NT)clsZ sort_keysindent)jsondumpsAnsibleJSONEncoder)Z structurerrr json_dump*sr*cs:eZdZdZd fdd ZfddZfddZZS) r)zS Simple encoder class to deal with JSON encoding of Ansible internal types Fc s&||_||_tt|jfi|dSr)_preprocess_unsafe_vault_to_textsuperr)__init__)selfZpreprocess_unsafeZ vault_to_textkwargs __class__rrr.3szAnsibleJSONEncoder.__init__cst|ddr6|jr t|dd}qdt|jdddi}ndt|ddrZd t|dddi}n@t|trnt|}n,t|tj tjfr| }nt t | |}|S) Nr Fr)rZ__ansible_vaultrrrr)r r,rZ _ciphertextr r!rr"datetimedateZ isoformatr-r)default)r/or r1rrr59s     zAnsibleJSONEncoder.defaultc s&|jrt|}tt|j|fi|S)zCustom iterencode, primarily design to handle encoding ``AnsibleUnsafe`` as the ``AnsibleUnsafe`` subclasses inherit from string types and ``json.JSONEncoder`` does not support custom encoders for string types )r+rr-r) iterencode)r/r6r0r1rrr7NszAnsibleJSONEncoder.iterencode)FF)__name__ __module__ __qualname____doc__r.r5r7 __classcell__rrr1rr).s r))Z __future__rrrtypeZ __metaclass__r'r3Zansible.module_utils._textrZ/ansible.module_utils.common._collections_compatrZ'ansible.module_utils.common.collectionsrrrrr*Z JSONEncoderr)rrrrs