o
    .&ßa  ã                   @   sŒ   d dl mZ d dl mZ d dlZd dlmZmZ d dlmZ dd„ Z	dd	„ Z
d
d„ Zdd„ ZG dd„ dejƒZdd„ ZG dd„ dejƒZdS )é    )Újson)ÚOrderedDictN)Ú
ScalarNodeÚSequenceNode)Úsixc                 C   sœ   |j dd… }d}|dv rd}|| }|dkr)t|jtjƒr)|j dd¡}||iS t|tƒr7|  |¡}||iS t|tƒrE|  	|¡}||iS |  
|¡}||iS )zƒ
    YAML constructor to parse CloudFormation intrinsics.
    This will return a dictionary with key being the instrinsic name
    é   NzFn::)ÚRefÚ	ConditionÚ ÚGetAttÚ.)ÚtagÚ
isinstanceÚvaluer   Ústring_typesÚsplitr   Úconstruct_scalarr   Úconstruct_sequenceÚconstruct_mapping)ÚloaderÚ
tag_prefixÚnoder   ÚprefixÚcfntagr   © r   úQ/usr/lib/python3/dist-packages/awscli/customizations/cloudformation/yamlhelper.pyÚintrinsics_multi_constructor   s    
ô


ø

þr   c                 C   s   |   | ¡ ¡S ©N)Úrepresent_dictÚitems)ÚdumperÚdatar   r   r   Ú_dict_representer;   s   r"   c                 C   s   t  tt¡ tj| dt d�S )zW
    Dumps the dictionary as a YAML document
    :param dict_to_dump:
    :return:
    F)Údefault_flow_styleÚDumper)ÚFlattenAliasDumperÚadd_representerr   r"   ÚyamlÚdump)Údict_to_dumpr   r   r   Ú	yaml_dump?   s   ýr*   c                 C   s   |   |¡ t|  |¡ƒS r   )Úflatten_mappingr   Úconstruct_pairs)r   r   r   r   r   Ú_dict_constructorM   s   
r-   c                   @   s   e Zd ZdZdS )ÚSafeLoaderWrapperzMIsolated safe loader to allow for customizations without global changes.
    N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r.   S   s    r.   c                 C   sR   zt j| td�W S  ty(   t}| tjjj	t
¡ | dt¡ t | |¡ Y S w )zParse a yaml string)Úobject_pairs_hookú!)r   Úloadsr   Ú
ValueErrorr.   Úadd_constructorr'   ÚresolverÚBaseResolverÚDEFAULT_MAPPING_TAGr-   Úadd_multi_constructorr   Úload)Úyamlstrr   r   r   r   Ú
yaml_parseY   s   ÿûr>   c                   @   s   e Zd Zdd„ ZdS )r%   c                 C   s   dS )NTr   )Úselfr!   r   r   r   Úignore_aliasesi   s   z!FlattenAliasDumper.ignore_aliasesN)r/   r0   r1   r@   r   r   r   r   r%   h   s    r%   )Úbotocore.compatr   r   r'   Úyaml.resolverr   r   Úawscli.compatr   r   r"   r*   r-   Ú
SafeLoaderr.   r>   Ú
SafeDumperr%   r   r   r   r   Ú<module>   s   %