U
    Æ½„bŸç  ã                   @   s0  d dl Z d dlZd dlZd dlZd dlmZ d dlZd dlm	Z	m
Z
 d dlT d dlT d dlT d dlmZmZmZmZ d dlmZmZmZmZ d dlmZmZmZmZmZ d dlmZm Z  d d	l!m"Z"m#Z#m$Z$m%Z% d d
l&m'Z'm(Z(m)Z)m*Z* d dlmZ+ d dl,m-Z-m.Z.m/Z/ zd dl<m=Z=m>Z> W n   d Z=Z>Y nX G dd„ dƒZ?G dd„ dƒZ@dd„ ZAdKdd„ZBefdd„ZCefdd„ZDefdd„ZEefdd„ZFdLdd „ZGdMd!d"„ZHdNd#d$„ZIdOd%d&„ZJdPd'd(„ZKdQd)d*„ZLdedddddfd+d,„ZMdZNdedddddeNddddfd-d.„ZOdefd/d0„ZPdedddddddeNdddddddfd1d2„ZQdedddddddeNdddddfd3d4„ZRdRd5d6„ZSdSd7d8„ZTdedddddddeNdddddddfd9d:„ZUddde fd;d<„ZVddde fd=d>„ZWde)fd?d@„ZXde)fdAdB„ZYde$fdCdD„ZZde$fdEdF„Z[G dGdH„ dHe\ƒZ]G dIdJ„ dJee]ƒƒZ^dS )Té    N)Úimport_module)ÚUnsafeLoaderWarningÚ	YAMLError)Ú*)Ú
BaseLoaderÚ
SafeLoaderÚLoaderÚRoundTripLoader)Ú
BaseDumperÚ
SafeDumperÚDumperÚRoundTripDumper)ÚStringIOÚBytesIOÚwith_metaclassÚnprintÚnprintf)ÚVersionedResolverÚResolver)ÚBaseRepresenterÚSafeRepresenterÚRepresenterÚRoundTripRepresenter)ÚBaseConstructorÚSafeConstructorÚConstructorÚRoundTripConstructor)r   )ÚCommentedMapÚCommentedSeqÚC_PRE)ÚCParserÚCEmitterc                   @   sˆ  e Zd Zdddddœdd„Zedd„ ƒZedd	„ ƒZed
d„ ƒZedd„ ƒZedd„ ƒZ	edd„ ƒZ
edd„ ƒZedd„ ƒZedd„ ƒZdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ ZdKdd,œd-d.„Zdd,œd/d0„Zdd,œd1d2„Zd3d4„ Zd5d6„ Zd7d8„ Zd9d:„ Zd;d<„ Zd=d>„ Z d?d@„ Z!dLdAdB„Z"edCdD„ ƒZ#e#j$dEdD„ ƒZ#edFdG„ ƒZ%e%j$dHdG„ ƒZ%dMdIdJ„Z&dS )NÚYAMLNF)ÚtypÚpureÚoutputÚplug_insc          
      C   sÎ  |dkrdgnt |tƒr|n|g| _|| _|| _d| _g | _|dkrHg n||  ¡  D ]"}| t	j
d¡}| j t|ƒ¡ qTtjjj| _d| _d| _d| _d| _d| _d| _d| _d| _d}d}d| jkrÎd}�n¶d| jk�r>|sætdkrðtjjjnt| _tjjj| _|�stdk�rtjj j!nt| _!tjj"j#| _#tjj$j%| _�nFd| jk�rœtjjj| _tjjj&| _|�srtdk�r|tjj j!nt| _!tjj"j#| _#tjj$j'| _nèd	| jk�r|�s¸tdk�rÂtjjjnt| _tjjj| _|�sätdk�rîtjj j!nt| _!tjj"j#| _#tjj$j| _nvd
| jk�r|d| _tjjj| _tjj(j| _tjjj)| _tjj*j+| _tjj j,| _!tjj"j#| _#tjj$j-| _t.| _nd}d}|�räd| _tjjj| _tjj(j| _tjjj)| _tjj*j/| _tjj j0| _!tjj"j#| _#tjj$j-| _~d| _1d| _2d| _3d| _4d| _5d| _6d| _7d| _8d| _9d| _:d| _;d| _<d| _=d| _>d| _?d| _@d| _Ad| _Bd| _Cd| _Dd| _Ed| _Fd| _Gd| _H| jD ]2}	tI|	ddƒ| jk�r||d7 }|	 J| ¡  �q°�q||dk�rÊtKd L| j¡ƒ‚dS )ak  
        typ: 'rt'/None -> RoundTripLoader/RoundTripDumper,  (default)
             'safe'    -> SafeLoader/SafeDumper,
             'unsafe'  -> normal/unsafe Loader/Dumper
             'base'    -> baseloader
        pure: if True only use Python modules
        input/output: needed to work as context manager
        plug_ins: a list of plug-in files
        NÚrtÚ.Té   FÚsafeÚbaseZunsafeZrtscr   zutf-8r#   z1typ "{}"not recognised (need to install plug-in?))MÚ
isinstanceÚlistr#   r$   Ú_outputÚ_context_managerr&   Úofficial_plug_insÚreplaceÚosÚsepÚappendr   ÚruamelÚyamlÚresolverr   r   Úallow_unicodeÚReaderr   r   ÚScannerÚ
SerializerÚdefault_flow_styleZcomment_handlingr!   ÚemitterÚEmitterÚrepresenterr   r    ÚparserÚParserÚcomposerÚComposerÚconstructorr   r   r   Ú
serializerr   ÚscannerZRoundTripScannerSCZRoundTripParserSCr   r   ZRoundTripScannerZRoundTripParserÚstreamÚ	canonicalÚ
old_indentÚwidthÚ
line_breakÚ
map_indentÚsequence_indentÚsequence_dash_offsetÚcompact_seq_seqÚcompact_seq_mapÚ sort_base_mapping_type_on_outputÚtop_level_colon_alignÚprefix_colonÚversionÚpreserve_quotesÚallow_duplicate_keysÚencodingÚexplicit_startÚexplicit_endÚtagsÚdefault_styleZ0top_level_block_style_scalar_no_indent_error_1_1Úscalar_after_indicatorÚ+brace_single_entry_mapping_in_flow_sequenceÚgetattrZinit_typÚNotImplementedErrorÚformat)
Úselfr#   r$   r%   r&   ZpuÚ	file_nameZ	typ_foundZsetup_rtÚmodule© rd   ú4/tmp/pip-unpacked-wheel-ctuyz3qg/ruamel/yaml/main.pyÚ__init__6   sÀ    $
ÿ  ÿ 




ÿzYAML.__init__c                 C   s8   z| j W S  tk
r2   | jd | d�| _ | j  Y S X d S ©N©Úloader)Ú_readerÚAttributeErrorr9   ©ra   rd   rd   re   Úreader±   s
    zYAML.readerc                 C   s6   z| j W S  tk
r0   | j| d�| _ | j  Y S X d S rg   )Ú_scannerrk   r:   rl   rd   rd   re   rF   º   s
    zYAML.scannerc                 C   sj   dt  ¡ jj }t| |ƒs`| jtk	r:t| || j| d�ƒ n&t| dd ƒd krNd S t| |t| j	ƒƒ t| |ƒS )NÚ_rh   Ú_stream)
ÚsysÚ	_getframeÚf_codeÚco_nameÚhasattrrA   r    Úsetattrr^   rp   ©ra   Úattrrd   rd   re   r@   Ã   s    

zYAML.parserc                 C   s8   dt  ¡ jj }t| |ƒs.t| || j| d�ƒ t| |ƒS )Nro   rh   )rq   rr   rs   rt   ru   rv   rC   r^   rw   rd   rd   re   rB   Ù   s    
zYAML.composerc                 C   sH   dt  ¡ jj }t| |ƒs>| j| j| d�}| j|_t| ||ƒ t	| |ƒS )Nro   )rU   ri   )
rq   rr   rs   rt   ru   r   rU   rV   rv   r^   )ra   rx   Zcnstrd   rd   re   rD   á   s    
zYAML.constructorc                 C   s<   dt  ¡ jj }t| |ƒs2t| || j| j| d�ƒ t| |ƒS )Nro   )rT   ri   )	rq   rr   rs   rt   ru   rv   r   rT   r^   rw   rd   rd   re   r7   ë   s    
zYAML.resolverc                 C   sØ   dt  ¡ jj }t| |ƒsÎ| jtk	r¶| jd | j| j| j	| j
| j| j| j| d�	}t| ||ƒ | jd k	rl| j|_| jd k	r~| j|_| jd k	r�| j|_| jd k	r¢| j|_| jd k	rÎ| j|_nt| dd ƒd krÊd S d S t| |ƒS )Nro   )rH   ÚindentrJ   r8   rK   rS   r]   Údumperrp   )rq   rr   rs   rt   ru   r>   r!   rH   rI   rJ   r8   rK   rS   r]   rv   rL   Zbest_map_indentrM   Zbest_sequence_indentrN   rO   rP   r^   )ra   rx   Ú_emitterrd   rd   re   r=   ó   s:    

÷





zYAML.emitterc                 C   sL   dt  ¡ jj }t| |ƒsBt| || j| j| j| j	| j
| j| d�ƒ t| |ƒS )Nro   )rW   rX   rY   rT   rZ   rz   )rq   rr   rs   rt   ru   rv   r;   rW   rX   rY   rT   rZ   r^   rw   rd   rd   re   rE     s    
úýzYAML.serializerc                 C   sV   dt  ¡ jj }t| |ƒsL| j| j| j| d�}| jd k	r@| j|_t	| ||ƒ t
| |ƒS )Nro   )r[   r<   rz   )rq   rr   rs   rt   ru   r   r[   r<   rQ   rv   r^   )ra   rx   Zrepresrd   rd   re   r?   *  s    
ý
zYAML.representerc                 c   s¾   t |dƒs<t |dƒr<| d¡�}|  |¡W  5 Q R £ S Q R X |  |¡\}}z| j
 ¡ rd| j
 ¡ V  qLW 5 | ¡  z| j ¡  W n tk
r’   Y nX z| j 	¡  W n tk
r¶   Y nX X dS )zA
        Scan a YAML stream and produce scanning tokens.
        ÚreadÚopenÚrbN)ru   r}   ÚscanÚget_constructor_parserÚdisposerj   Úreset_readerrk   rn   Úreset_scannerrF   Úcheck_tokenÚ	get_token©ra   rG   Úfpro   r@   rd   rd   re   r   9  s     
z	YAML.scanc                 c   sº   t |dƒs<t |dƒr<| d¡�}|  |¡W  5 Q R £ S Q R X |  |¡\}}z| 
¡ r`| ¡ V  qLW 5 | ¡  z| j ¡  W n tk
rŽ   Y nX z| j 	¡  W n tk
r²   Y nX X dS )zA
        Parse a YAML stream and produce parsing events.
        r|   r}   r~   N)ru   r}   Úparser€   r�   rj   r‚   rk   rn   rƒ   Úcheck_eventÚ	get_eventr†   rd   rd   re   rˆ   Q  s     z
YAML.parsec                 C   s°   t |dƒs<t |dƒr<| d¡�}|  |¡W  5 Q R £ S Q R X |  |¡\}}z|j
 ¡ W ¢S | ¡  z| j ¡  W n tk
r„   Y nX z| j 	¡  W n tk
r¨   Y nX X dS )zv
        Parse the first YAML document in a stream
        and produce the corresponding representation tree.
        r|   r}   r~   N)ru   r}   Úcomposer€   r�   rj   r‚   rk   rn   rƒ   rB   Úget_single_node©ra   rG   r‡   rD   r@   rd   rd   re   r‹   i  s    zYAML.composec                 c   s‚   |   |¡\}}z|j ¡ r(|j 	¡ V  qW 5 | ¡  z| j ¡  W n tk
rV   Y nX z| j ¡  W n tk
rz   Y nX X dS )zn
        Parse all YAML documents in a stream
        and produce corresponding representation trees.
        N)
r€   r�   rj   r‚   rk   rn   rƒ   rB   Ú
check_nodeÚget_node)ra   rG   rD   r@   rd   rd   re   Úcompose_all�  s    
zYAML.compose_allc                 C   s®   t |dƒs<t |dƒr<| d¡�}|  |¡W  5 Q R £ S Q R X |  |¡\}}z| 
¡ W ¢S | ¡  z| j ¡  W n tk
r‚   Y nX z| j 	¡  W n tk
r¦   Y nX X dS )a•  
        at this point you either have the non-pure Parser (which has its own reader and
        scanner) or you have the pure Parser.
        If the pure Parser is set, then set the Reader and Scanner, if not already set.
        If either the Scanner or Reader are set, you cannot use the non-pure Parser,
            so reset it to the pure parser and set the Reader resp. Scanner if necessary
        r|   r}   r~   N)ru   r}   Úloadr€   r�   rj   r‚   rk   rn   rƒ   Úget_single_datar�   rd   rd   re   r‘   £  s    	z	YAML.loadc                 c   sÈ   t |dƒsJt |dƒrJ| d¡�&}|  |¡D ]
}|V  q*W 5 Q R £ d S Q R X |  |¡\}}z| 
¡ rn| ¡ V  qZW 5 | ¡  z| j ¡  W n tk
rœ   Y nX z| j 	¡  W n tk
rÀ   Y nX X d S )Nr|   r}   Úr)ru   r}   Úload_allr€   r�   rj   r‚   rk   rn   rƒ   Ú
check_dataÚget_data)ra   rG   r‡   ÚdrD   r@   rd   rd   re   r”   ¾  s$    zYAML.load_allc                    sò   ˆj tk	r@ˆjdkr tjjjˆ_ˆjdkr6tjjjˆ_|ˆj_n¦ˆjdk	rvˆjdkr`tjjjˆ_tjj	j ˆ_ |ˆj_npˆjdk	r¬ˆjdkr–tjjjˆ_tjj	j ˆ_ |ˆj_n:ˆj
‰ G ‡ ‡fdd„dˆj ˆjˆ ƒ}|ˆ_||ƒ}||fS ˆjˆj	fS )zM
        the old cyaml needs special setup, and therefore the stream
        Nc                       s"   e Zd Z”jdf‡ ‡fdd„	ZdS )z,YAML.get_constructor_parser.<locals>.XLoaderNc                    sD   t  | |¡ |  | _| _ˆjj| | d� ˆj| _ˆ j| || d� d S )Nrh   )rT   Z	loadumper)r    rf   Ú_parserÚ	_composerr   rV   )ÚselfxrG   rT   rU   ©Zrslvrra   rd   re   rf   ù  s
    z5YAML.get_constructor_parser.<locals>.XLoader.__init__)Ú__name__Ú
__module__Ú__qualname__rT   rf   rd   r›   rd   re   ÚXLoaderø  s   rŸ   )rA   r    r9   r5   r6   rm   r:   rF   rG   r@   r   r   rp   rD   )ra   rG   rŸ   ri   rd   r›   re   r€   Ù  s,    









	zYAML.get_constructor_parserc                 C   sV   |   |d¡\}}}z|D ]}| |¡ qW 5 z| ¡  W n tk
rN   ‚ Y nX X dS )zx
        Emit YAML parsing events into a stream.
        If stream is None, return the produced string instead.
        N)Ú"get_serializer_representer_emitterr�   rk   Úemit)ra   ÚeventsrG   ro   r=   Úeventrd   rd   re   r¡     s    z	YAML.emitc                 C   s   |   |g|¡ dS )z„
        Serialize a representation tree into a YAML stream.
        If stream is None, return the produced string instead.
        N)Úserialize_all)ra   ÚnoderG   rd   rd   re   Ú	serialize  s    zYAML.serializec                 C   sf   |   |d¡\}}}z(| ¡  |D ]}| |¡ q | ¡  W 5 z| ¡  W n tk
r^   ‚ Y nX X dS )z‘
        Serialize a sequence of representation trees into a YAML stream.
        If stream is None, return the produced string instead.
        N)r    r�   rk   r}   r¦   Úclose)ra   ÚnodesrG   rE   ro   r=   r¥   rd   rd   re   r¤     s    zYAML.serialize_all©Ú	transformc                C   sb   | j r<| jstdƒ‚|d k	r.td | jj¡ƒ‚| j  |¡ n"|d krLtdƒ‚| j|g||d�S d S )Nz8Missing output stream while dumping from context managerz?{}.dump() in the context manager cannot have transform keyword z<Need a stream argument when not dumping from context managerr©   )r/   r.   Ú	TypeErrorr`   Ú	__class__rœ   ÚdumpÚdump_all)ra   ÚdatarG   rª   rd   rd   re   r­   0  s    ÿÿz	YAML.dumpc                C   sN   | j r
t‚|| _t| |d�| _ |D ]}| j  |¡ q"| j  ¡  d | _d | _ d S )Nr©   )r/   r_   r.   ÚYAMLContextManagerr­   Úteardown_output)ra   Ú	documentsrG   rª   r¯   rd   rd   re   r®   @  s    
zYAML.dump_allc                C   sr  t |dƒsBt |dƒrB| d¡�}| j|||d�W  5 Q R £ S Q R X | jdkrdtdd„ |d D ƒƒ}n| j}|d	k	rŽ|}| jd	krˆtƒ }ntƒ }|  ||¡\}}}	zJ| j ¡  |D ],}
z| j |
¡ W q° tk
rÚ   ‚ Y q°X q°| j ¡  W 5 z| j	 
¡  W n tk
�r   ‚ Y nX t| d
ƒ t| dƒ X |�rn| ¡ }| j�rL| | j¡}|d	k�r`||ƒ n| ||ƒ¡ d	S )zL
        Serialize a sequence of Python objects into a YAML stream.
        Úwriter}   Úwr©   Tc                 S   s   g | ]}t t|ƒƒ‘qS rd   ©ÚlenÚstr©Ú.0Úxrd   rd   re   Ú
<listcomp>W  s     z"YAML.Xdump_all.<locals>.<listcomp>r   NÚ_serializerr{   )ru   r}   r®   rR   ÚmaxrW   r   r   r    r=   r�   rk   ÚdelattrrE   r?   Ú	representr§   ÚgetvalueÚdecoder³   )ra   r²   rG   rª   r‡   ÚtlcaZfstreamrE   r?   r=   r¯   Úvalrd   rd   re   Ú	Xdump_allL  sJ    "

 ÿ





zYAML.Xdump_allc                    s*  ˆj tk	rTˆjd kr tjjjˆ_|ˆj_|ˆj_ˆj	d k	rDˆj	ˆj_	ˆjˆj
ˆjfS ˆjd k	ržtjjj ˆ_ |ˆj_|ˆj_ˆj	d k	rŽˆj	ˆj_	ˆjˆj
ˆjfS dˆjkr²tjjjntjjj‰ G ‡ ‡fdd„dtˆjˆ ƒ}|ˆ_||ˆjˆjˆjˆjˆjˆjˆjˆjˆjˆjˆjd�}| ˆ_ˆ_|||fS )Nr+   c                       s   e Zd Zd‡ ‡fdd„	ZdS )z8YAML.get_serializer_representer_emitter.<locals>.XDumperNc                    sT   t j| |||||	|||
|||d� |  | _ | _| _ˆjj| ||d� ˆ  | ¡ d S )N)
rH   ry   rJ   rW   r8   rK   rX   rY   rT   rZ   )r[   r<   )r!   rf   r{   r¼   Ú_representerr   )rš   rG   r[   r<   rH   ry   rJ   r8   rK   rW   rX   rY   rT   rZ   Úblock_seq_indentrR   rS   r›   rd   re   rf   š  s*    ô  ÿzAYAML.get_serializer_representer_emitter.<locals>.XDumper.__init__)NNNNNNNNNNNNNNN)rœ   r�   rž   rf   rd   r›   rd   re   ÚXDumper™  s                   ïrÇ   )r[   r<   rH   ry   rJ   r8   rK   rX   rY   rT   rZ   )r>   r!   r;   r5   r6   rE   r=   rG   rR   r\   r?   r#   r7   ZBaseResolverr   r   rp   r[   r<   rH   rI   rJ   r8   rK   rX   rY   rT   rZ   r{   r¼   )ra   rG   rÂ   rÇ   rz   rd   r›   re   r    ~  sJ    






ÿý)ôz'YAML.get_serializer_representer_emitterc                 K   s"   d| j krtf |ŽS tf |ŽS d S ©Nr'   )r#   r   Údict)ra   Úkwrd   rd   re   ÚmapÕ  s    

zYAML.mapc                 G   s   d| j krt|Ž S t|Ž S d S rÈ   )r#   r   r-   )ra   Úargsrd   rd   re   ÚseqÜ  s    
zYAML.seqc                    s^   zt j t¡}W n tk
r(   g  Y S X t j t j |¡¡‰ ‡ fdd„t |d ¡D ƒ}|S )a˜  search for list of subdirs that are plug-ins, if __file__ is not available, e.g.
        single file installers that are not properly emulating a file-system (issue 324)
        no plug-ins will be found. If any are packaged, you know which file that are
        and you can explicitly provide it during instantiation:
            yaml = ruamel.yaml.YAML(plug_ins=['ruamel/yaml/jinja2/__plug_in__'])
        c                    s    g | ]}|  ˆ d ¡dd… ‘qS )Ú r)   éýÿÿÿ)r1   r¸   ©Zgpbdrd   re   r»   ñ  s     z*YAML.official_plug_ins.<locals>.<listcomp>z/*/__plug_in__.py)r2   ÚpathÚdirnameÚ__file__Ú	NameErrorÚglob)ra   ZbdÚresrd   rÐ   re   r0   ä  s    
zYAML.official_plug_insc                    s    t ˆ ddˆ j ƒ‰z| j ˆ ˆ j¡ W n0 tk
rV   ‡ ‡fdd„}| j ˆ |¡ Y nX z| j ˆˆ j¡ W n. tk
rš   ‡ fdd„}| j ˆ|¡ Y nX ˆ S )zö
        register a class for dumping loading
        - if it has attribute yaml_tag use that to register, else use class name
        - if it has methods to_yaml/from_yaml use those to dump/load else dump attributes
          as mapping
        Úyaml_tagú!c                    s   | j ˆ|ˆ | jd�S ©N©Z
flow_style©Úrepresent_yaml_objectr<   ©r?   r¯   ©ÚclsÚtagrd   re   Út_y  s       ÿz YAML.register_class.<locals>.t_yc                    s   |   |ˆ ¡S ©N©Zconstruct_yaml_object©rD   r¥   ©rß   rd   re   Úf_y  s    z YAML.register_class.<locals>.f_y©	r^   rœ   r?   Úadd_representerÚto_yamlrk   rD   Úadd_constructorÚ	from_yaml)ra   rß   rá   ræ   rd   rÞ   re   Úregister_classô  s    zYAML.register_classc                 C   s   t | ƒ| _| S râ   )r°   r/   rl   rd   rd   re   Ú	__enter__  s    
zYAML.__enter__c                 C   s"   |rt d|ƒ | j ¡  d | _d S )Nr#   )r   r/   r±   )ra   r#   ÚvalueÚ	tracebackrd   rd   re   Ú__exit__  s    

zYAML.__exit__c                 C   s.   |d k	r|| _ |d k	r|| _|d k	r*|| _d S râ   )rL   rM   rN   )ra   ÚmappingÚsequenceÚoffsetrd   rd   re   Ú_indent#  s    zYAML._indentc                 C   s   | j S râ   )rô   rl   rd   rd   re   ry   ,  s    zYAML.indentc                 C   s
   || _ d S râ   )rI   ©ra   rÃ   rd   rd   re   ry   1  s    c                 C   s   | j S râ   ©rN   rl   rd   rd   re   rÆ   6  s    zYAML.block_seq_indentc                 C   s
   || _ d S râ   rö   rõ   rd   rd   re   rÆ   ;  s    c                 C   s   || _ || _d S râ   )rO   rP   )ra   Zseq_seqZseq_maprd   rd   re   Úcompact@  s    zYAML.compact)N)NNN)NN)'rœ   r�   rž   rf   Úpropertyrm   rF   r@   rB   rD   r7   r=   rE   r?   r   rˆ   r‹   r�   r‘   r”   r€   r¡   r¦   r¤   r­   r®   rÄ   r    rË   rÍ   r0   rì   rí   rð   rô   ry   ÚsetterrÆ   r÷   rd   rd   rd   re   r"   5   sb   {




	

#

"-2W!	
	



r"   c                   @   s.   e Zd Zd
dd„Zdd„ Zdd„ Zdd	„ ZdS )r°   Nc                 C   s„   || _ d| _d | _| j j| _|| _t| jdƒsPt| jdƒrP| j| _| j d¡| _| jd k	r€| j| _| j jd krxt	ƒ | _nt
ƒ | _d S )NFr³   r}   r´   )Ú_yamlÚ_output_initedÚ_output_pathr.   Ú
_transformru   r}   Ú_fstreamrW   r   r   )ra   r6   rª   rd   rd   re   rf   G  s    


zYAMLContextManager.__init__c                 C   sì   | j r| jj ¡  nd S z| jj ¡  W n tk
r>   ‚ Y nX zt| jdƒ t| jdƒ W n tk
rr   ‚ Y nX | jrÔ| j	 
¡ }| jjrš| | jj¡}| jd kr°|  |¡ n$| j |  |¡¡ | j ¡  | j| _	| jd k	rè| j	 ¡  d S )Nr¼   r{   )rû   rú   rE   r§   r=   r�   rk   r¾   rý   r.   rÀ   rW   rÁ   rþ   r³   Úflushrü   rõ   rd   rd   re   r±   g  s.    



z"YAMLContextManager.teardown_outputc                 C   sN   | j jdkr tdd„ |D ƒƒ}n| j j}| j  | j|¡ | j j ¡  d| _d S )NTc                 S   s   g | ]}t t|ƒƒ‘qS rd   rµ   r¸   rd   rd   re   r»   ‡  s     z2YAMLContextManager.init_output.<locals>.<listcomp>)rú   rR   r½   r    r.   rE   r}   rû   )ra   Z
first_datarÂ   rd   rd   re   Úinit_output„  s    zYAMLContextManager.init_outputc                 C   s>   | j s|  |¡ z| jj |¡ W n tk
r8   ‚ Y nX d S râ   )rû   r   rú   r?   r¿   rk   )ra   r¯   rd   rd   re   r­   Ž  s    
zYAMLContextManager.dump)N)rœ   r�   rž   rf   r±   r   r­   rd   rd   rd   re   r°   F  s   
 
r°   c                    s   ‡ fdd„}|S )aj   decorator for classes that needs to dump/load objects
    The tag for such objects is taken from the class attribute yaml_tag (or the
    class name in lowercase in case unavailable)
    If methods to_yaml and/or from_yaml are available, these are called for dumping resp.
    loading, default routines (dumping a mapping of the attributes) used otherwise.
    c                    s    t ˆ ddˆ j ƒ‰zˆj ˆ ˆ j¡ W n0 tk
rV   ‡ ‡fdd„}ˆj ˆ |¡ Y nX zˆj ˆˆ j¡ W n. tk
rš   ‡ fdd„}ˆj ˆ|¡ Y nX ˆ S )Nr×   rØ   c                    s   | j ˆ|ˆ | jd�S rÙ   rÛ   rÝ   rÞ   rd   re   rá   Á  s       ÿz)yaml_object.<locals>.yo_deco.<locals>.t_yc                    s   |   |ˆ ¡S râ   rã   rä   rå   rd   re   ræ   Ì  s    z)yaml_object.<locals>.yo_deco.<locals>.f_yrç   )rß   rá   ræ   ©ÚymlrÞ   re   Úyo_decoº  s    zyaml_object.<locals>.yo_decord   )r  r  rd   r  re   Úyaml_object±  s    	r  rÎ   c                 C   s,   ddl m} tj|d| ||d�tdd� d S )Nr   )Ú_FzM
{fun} will be removed, use

  yaml=YAML({arg})
  yaml.{method}(...)

instead)ÚfunÚmethodÚargé   ©Ú
stacklevel)Úruamel.yaml.compatr  ÚwarningsÚwarnÚPendingDeprecationWarning)r  r  r  r  rd   rd   re   Úwarn_deprecation×  s    üør  c                 c   sD   t dddd� || ƒ}z|j ¡ r0|j ¡ V  qW 5 |j ¡  X dS )z9
    Scan a YAML stream and produce scanning tokens.
    r   útyp='unsafe', pure=True©r  N)r  r˜   r�   rF   r„   r…   ©rG   r   ri   rd   rd   re   r   ê  s    
r   c                 c   sD   t dddd� || ƒ}z|j ¡ r0|j ¡ V  qW 5 |j ¡  X dS )z9
    Parse a YAML stream and produce parsing events.
    rˆ   r  r  N)r  r˜   r�   r‰   rŠ   r  rd   rd   re   rˆ   ø  s    
rˆ   c                 C   s2   t dddd� || ƒ}z| ¡ W ¢S | ¡  X dS )zj
    Parse the first YAML document in a stream
    and produce the corresponding representation tree.
    r‹   r  r  N)r  r�   rŒ   r  rd   rd   re   r‹     s
    r‹   c                 c   sB   t dddd� || ƒ}z| ¡ r.|j ¡ V  qW 5 |j ¡  X dS )zb
    Parse all YAML documents in a stream
    and produce corresponding representation trees.
    r‹   r  r  N)r  r˜   r�   rŽ   r™   r�   r  rd   rd   re   r�     s    r�   c                 C   s¢   t dddd� |dkr,tjtjtdd� t}|| ||d�}z|j ¡ W ¢S |j ¡  z|j 	¡  W n t
k
rv   Y nX z|j ¡  W n t
k
rš   Y nX X dS )zd
    Parse the first YAML document in a stream
    and produce the corresponding Python object.
    r‘   r  r  Né   r
  ©rU   )r  r  r  r   ÚtextÚUnsafeLoaderr˜   r�   rj   r‚   rk   rn   rƒ   Ú_constructorr’   ©rG   r   rT   rU   ri   rd   rd   re   r‘   #  s     
r‘   c                 c   s°   t dddd� |dkr,tjtjtdd� t}|| ||d�}z|j ¡ rT|j ¡ V  q<W 5 |j ¡  z|j 	¡  W n t
k
r„   Y nX z|j ¡  W n t
k
r¨   Y nX X dS )z\
    Parse all YAML documents in a stream
    and produce corresponding Python objects.
    r”   r  r  Nr  r
  r  )r  r  r  r   r  r  r˜   r�   rj   r‚   rk   rn   rƒ   r  r•   r–   r  rd   rd   re   r”   <  s"    

r”   c                 C   s   t dddd� t| t|ƒS )ú†
    Parse the first YAML document in a stream
    and produce the corresponding Python object.
    Resolve only basic YAML tags.
    Ú	safe_loadr‘   útyp='safe', pure=Truer  )r  r‘   r   ©rG   rT   rd   rd   re   r  V  s    r  c                 C   s   t dddd� t| t|ƒS )ú~
    Parse all YAML documents in a stream
    and produce corresponding Python objects.
    Resolve only basic YAML tags.
    Úsafe_load_allr”   r  r  )r  r”   r   r  rd   rd   re   r  a  s    r  c                 C   s   t ddƒ t| t||d�S )r  Úround_trip_load_allr‘   r  )r  r‘   r	   ©rG   rT   rU   rd   rd   re   Úround_trip_loadl  s    
r"  c                 C   s   t ddƒ t| t||d�S )r  r   r”   r  )r  r”   r	   r!  rd   rd   re   r   w  s    
r   c                 C   s–   t dddd� d}|dkr&tƒ }|j}|||||||d�}	z| D ]}
|	 |
¡ q@W 5 z|	j ¡  W n tk
r€   ‚ |	 ¡  Y nX X |dk	r’|ƒ S dS )zl
    Emit YAML parsing events into a stream.
    If stream is None, return the produced string instead.
    r¡   r  r  N)rH   ry   rJ   r8   rK   )r  r   rÀ   r{   r�   rk   r¡   )r¢   rG   r   rH   ry   rJ   r8   rK   rÀ   rz   r£   rd   rd   re   r¡   ‚  s.    úr¡   c                 C   sÄ   t dddd� d}|dkr6|dkr*tƒ }ntƒ }|j}|||||||||||	|
d�}z,|j ¡  | D ]}| 	|¡ qd|j 
¡  W 5 z|j ¡  W n tk
r®   ‚ | ¡  Y nX X |dk	rÀ|ƒ S dS )z…
    Serialize a sequence of representation trees into a YAML stream.
    If stream is None, return the produced string instead.
    r¤   r  r  N)
rH   ry   rJ   r8   rK   rW   rT   rZ   rX   rY   )r  r   r   rÀ   r{   r�   rk   r¼   r}   r¦   r§   )r¨   rG   r   rH   ry   rJ   r8   rK   rW   rX   rY   rT   rZ   rÀ   rz   r¥   rd   rd   re   r¤   ®  s@    õ
r¤   c                 K   s&   t dddd� t| g|fd|i|—ŽS )zx
    Serialize a representation tree into a YAML stream.
    If stream is None, return the produced string instead.
    r¦   r  r  r   )r  r¤   )r¥   rG   r   Úkwdsrd   rd   re   r¦   æ  s    r¦   c                 C   s  t dddd� d}|dkr0tdd„ | d D ƒƒ}|dkrT|
dkrHtƒ }ntƒ }|j}|||||||||	|
|||||||d	�}zJ|j 	¡  | D ],}z|j
 |¡ W qŒ tk
r¶   ‚ Y qŒX qŒ|j ¡  W 5 z|j ¡  W n tk
rô   ‚ | ¡  Y nX X |dk	�r|ƒ S dS )
z
    Serialize a sequence of Python objects into a YAML stream.
    If stream is None, return the produced string instead.
    r®   r  r  NTc                 S   s   g | ]}t t|ƒƒ‘qS rd   rµ   r¸   rd   rd   re   r»     s     zdump_all.<locals>.<listcomp>r   )r[   r<   rH   ry   rJ   r8   rK   rW   rX   rY   rT   rZ   rÆ   rR   rS   )r  r½   r   r   rÀ   r{   r�   rk   r¼   r}   rÅ   r¿   r§   )r²   rG   r   r[   r<   rH   ry   rJ   r8   rK   rW   rX   rY   rT   rZ   rÆ   rR   rS   rÀ   rz   r¯   rd   rd   re   r®   ð  sV    ð


r®   c                 C   s8   t dddd� t| g|||||||||	|
|||||d�S )u§   
    Serialize a Python object into a YAML stream.
    If stream is None, return the produced string instead.

    default_style âˆˆ None, '', '"', "'", '|', '>'

    r­   r  r  )r   r[   r<   rH   ry   rJ   r8   rK   rW   rX   rY   rT   rZ   rÆ   ©r  r®   )r¯   rG   r   r[   r<   rH   ry   rJ   r8   rK   rW   rX   rY   rT   rZ   rÆ   rd   rd   re   r­   9  s&    ðr­   c                 K   s$   t dddd� t| |fdti|—ŽS )z¡
    Serialize a sequence of Python objects into a YAML stream.
    Produce only basic YAML tags.
    If stream is None, return the produced string instead.
    Úsafe_dump_allr®   r  r  r   ©r  r®   r   )r²   rG   r#  rd   rd   re   r%  h  s    r%  c                 K   s&   t dddd� t| g|fdti|—ŽS )z”
    Serialize a Python object into a YAML stream.
    Produce only basic YAML tags.
    If stream is None, return the produced string instead.
    Ú	safe_dumpr­   r  r  r   r&  )r¯   rG   r#  rd   rd   re   r'  s  s    r'  c                 C   sH   |d krdn|}t ddƒ t| g|||||||||	|
|||||||d�S )NTÚround_trip_dumpr­   )r   r[   r<   rH   ry   rJ   r8   rK   rW   rX   rY   rT   rZ   rÆ   rR   rS   r$  )r¯   rG   r   r[   r<   rH   ry   rJ   r8   rK   rW   rX   rY   rT   rZ   rÆ   rR   rS   rd   rd   re   r(  ~  s,    
îr(  c                 C   sº   |dkr"|dkr"|  | ||¡ dS |rlt|dƒr@|  | ||¡ n,t|tttjjjt	fƒrht
  | ||¡ nt‚|r¶t|dƒrŠ|  | ||¡ n,t|tttjjjtfƒr²t
  | ||¡ nt‚dS )zÙ
    Add an implicit scalar detector.
    If an implicit scalar value matches the given regexp,
    the corresponding tag is assigned to the scalar.
    first is a sequence of possible initial characters or None.
    NÚadd_implicit_resolver)r)  ru   Ú
issubclassr   r   r5   r6   ri   r   r	   r   r_   r
   r   rz   r   r   )rà   ÚregexpÚfirstr   r   r7   rd   rd   re   r)  ¯  s*    

 ÿ
 ÿr)  c                 C   sº   |dkr"|dkr"|  | ||¡ dS |rlt|dƒr@|  | ||¡ n,t|tttjjjt	fƒrht
  | ||¡ nt‚|r¶t|dƒrŠ|  | ||¡ n,t|tttjjjtfƒr²t
  | ||¡ nt‚dS )zÁ
    Add a path based resolver for the given tag.
    A path is a list of keys that forms a path
    to a node in the representation tree.
    Keys can be string values, integers, or None.
    NÚadd_path_resolver)r-  ru   r*  r   r   r5   r6   ri   r   r	   r   r_   r
   r   rz   r   r   )rà   rÑ   Úkindr   r   r7   rd   rd   re   r-  Ñ  s*    
 ÿ
 ÿr-  c                 C   s˜   |dkr|  | |¡ n~t|dƒr0|  | |¡ dS t|tƒrHt  | |¡ nLt|tƒr`t  | |¡ n4t||ƒrxt  | |¡ nt|tƒr�t	  | |¡ nt
‚dS )z½
    Add an object constructor for the given tag.
    object_onstructor is a function that accepts a Loader instance
    and a node object and produces the corresponding Python object.
    Nrê   )rê   ru   r*  r   r   r   r   r   r	   r   r_   )rà   Zobject_constructorr   rD   rd   rd   re   rê   ð  s    




rê   c                 C   s¢   |dkr|  | |¡ nˆdr4t|dƒr4|  | |¡ dS t|tƒrLt  | |¡ nRt|tƒrdt  | |¡ n:t|tjj	j
ƒr‚t  | |¡ nt|tƒršt  | |¡ nt‚dS )a  
    Add a multi-constructor for the given tag prefix.
    Multi-constructor is called for a node if its tag starts with tag_prefix.
    Multi-constructor accepts a Loader instance, a tag suffix,
    and a node object and produces the corresponding Python object.
    NFÚadd_multi_constructor)r/  ru   r*  r   r   r   r   r5   r6   ri   r   r   r	   r   r_   )Z
tag_prefixZmulti_constructorr   rD   rd   rd   re   r/  	  s    


r/  c                 C   s˜   |dkr|  | |¡ n~t|dƒr0|  | |¡ dS t|tƒrHt  | |¡ nLt|tƒr`t  | |¡ n4t||ƒrxt  | |¡ nt|tƒr�t	  | |¡ nt
‚dS )zÔ
    Add a representer for the given type.
    object_representer is a function accepting a Dumper instance
    and an instance of the given data type
    and producing the corresponding representation node.
    Nrè   )rè   ru   r*  r
   r   r   r   r   r   r   r_   )Ú	data_typeZobject_representerr   r?   rd   rd   re   rè   #  s    




rè   c                 C   s˜   |dkr|  | |¡ n~t|dƒr0|  | |¡ dS t|tƒrHt  | |¡ nLt|tƒr`t  | |¡ n4t||ƒrxt  | |¡ nt|tƒr�t	  | |¡ nt
‚dS )zÞ
    Add a representer for the given type.
    multi_representer is a function accepting a Dumper instance
    and an instance of the given data type or subtype
    and producing the corresponding representation node.
    NÚadd_multi_representer)r1  ru   r*  r
   r   r   r   r   r   r   r_   )r0  Zmulti_representerr   r?   rd   rd   re   r1  >  s    




r1  c                       s    e Zd ZdZ‡ fdd„Z‡  ZS )ÚYAMLObjectMetaclassz'
    The metaclass for YAMLObject.
    c                    sJ   t ƒ  |||¡ d|krF|d d k	rF| j | j| j¡ | j | | j¡ d S )Nr×   )	Úsuperrf   Úyaml_constructorrê   r×   rë   Úyaml_representerrè   ré   )rß   ÚnameÚbasesr#  ©r¬   rd   re   rf   ]  s    zYAMLObjectMetaclass.__init__)rœ   r�   rž   Ú__doc__rf   Ú__classcell__rd   rd   r8  re   r2  X  s   r2  c                   @   s<   e Zd ZdZdZeZeZdZ	dZ
edd„ ƒZedd„ ƒZdS )Ú
YAMLObjectza
    An object that can dump itself to a YAML stream
    and load itself from a YAML stream.
    rd   Nc                 C   s   |  || ¡S )zC
        Convert a representation node to a Python object.
        rã   )rß   rD   r¥   rd   rd   re   rë   s  s    zYAMLObject.from_yamlc                 C   s   |j | j|| | jd�S )zC
        Convert a Python object to a representation node.
        rÚ   )rÜ   r×   Úyaml_flow_style)rß   r?   r¯   rd   rd   re   ré   {  s       ÿzYAMLObject.to_yaml)rœ   r�   rž   r9  Ú	__slots__r   r4  r   r5  r×   r<  Úclassmethodrë   ré   rd   rd   rd   re   r;  e  s   
r;  )rÎ   )NNN)NNN)N)N)NN)NN)N)N)_rq   r2   r  rÕ   Ú	importlibr   Zruamel.yamlr5   Zruamel.yaml.errorr   r   Zruamel.yaml.tokensZruamel.yaml.eventsZruamel.yaml.nodesZruamel.yaml.loaderr   r   r   r	   Zruamel.yaml.dumperr
   r   r   r   r  r   r   r   r   r   Zruamel.yaml.resolverr   r   Zruamel.yaml.representerr   r   r   r   Zruamel.yaml.constructorr   r   r   r   r  Zruamel.yaml.commentsr   r   r   ÚListÚSetÚDictÚUnionÚAnyÚCallableÚOptionalÚTextZ
StreamTypeZStreamTextTypeZVersionTypeÚPathZ_ruamel_yamlr    r!   r"   r°   r  r  r   rˆ   r‹   r�   r‘   r”   r  r  r"  r   r¡   Úencr¤   r¦   r®   r­   r%  r'  r(  r)  r-  rê   r/  rè   r1  Útyper2  r;  rd   rd   rd   re   Ú<module>   s  	      k&






ø
)ó
8î
Kð
/

î
2   ÿ
"