B
    d`                 @   sN  d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 ddl
ZddlZ
yddl
mZ ddl
mZ W n, ek
r   dd	l
mZ dd
l
mZ Y nX dZdd Zede edejd  edddZdd Zeee eee eejedZee	dddZeejedZeej edZ efe	edddZ!eej"edZ"dS )zg
Abstract :mod:`yaml` with Pegasus specific defaults.

.. moduleauthor:: Rajiv Mayani <mayani@isi.edu>
    N)OrderedDict)partial)Path)Dict)CSafeDumper)CSafeLoader)
SafeDumper)
SafeLoader)loadloadsload_alldumpdumpsdump_allc             C   s$   ddd}|  |}|| |S )z
    Ensure :mod:`yaml` handles booleans in the expected fashion.

    Ensure :mod:`yaml` does not translate on, yes to True, and off, no to False.

    .. notes::

        In YAML 1.2 the usage of off/on/yes/no was dropped.
    TF)truefalse)Zconstruct_scalargetlower)selfnodeZbool_valuesv r   Y/work/yifan.wang/ringdown/master-ringdown-env/lib/python3.7/site-packages/Pegasus/yaml.py_construct_bool!   s    
r   ztag:yaml.org,2002:boolztag:yaml.org,2002:timestampztag:yaml.org,2002:str)datac             C   s   |  dt|S )z
    Serialize a `Path` object to a string.

    .. warning::
        Path("./aaa") serializes to "aaa"

    :param data: [description]
    :type data: pathlib.Path
    ztag:yaml.org,2002:str)Zrepresent_scalarstr)r   r   r   r   r   _represent_path>   s    
r   c             C   s   |  d| S )zu
    Serialize OrderedDict to a yaml map

    :param data: [description]
    :type data: collections.OrderedDict
    ztag:yaml.org,2002:map)Zrepresent_mappingitems)r   r   r   r   r   _represent_ordered_dictK   s    r   )Loader)sreturnc             O   s   t t| f||S )z
    Deserialize ``s`` (a ``str``, ``bytes`` or ``bytearray`` instance containing a YAML document) to a Python dictionary.

    [extended_summary]

    :param s: [description]
    :type s: str
    :return: [description]
    :rtype: Dict
    )r
   ioStringIO)r    argskwargsr   r   r   r   ^   s    r   )Dumper)objr!   c             O   s   t | f||S )z
    Serialize ``obj`` to a YAML formatted ``str``.

    [extended_summary]

    :param obj: [description]
    :type obj: Dict
    :return: [description]
    :rtype: str
    )r   )r'   r&   r$   r%   r   r   r   r   r   s    r   )#__doc__r"   collectionsr   	functoolsr   pathlibr   typingr   yamlZ_yamlZyaml.constructorr   Z_Dumperr   Z_LoaderImportErrorr   r	   __all__r   Zadd_constructorZyaml_constructorsr   r   Zadd_multi_representerZadd_representerr
   r   r   r   r   r   r   r   r   r   r   <module>   s8   
