B
    |?_[}                 @   s  d dl mZmZ 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
T 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 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* yd dl+m,Z,m-Z- W n   d Z,Z-Y nX e. Z/G dd de.Z0dd Z1efddZ2efddZ3efddZ4efddZ5dFddZ6dGddZ7dHddZ8dIdd Z9dJd!d"Z:dKd#d$Z;dedddddfd%d&Z<erdnd'Z=deddddde=ddddfd(d)Z>defd*d+Z?deddddddde=dddddddfd,d-Z@deddddddde=dddddfd.d/ZAdLd0d1ZBdMd2d3ZCdeddddddde=dddddddfd4d5ZDdddefd6d7ZEdddefd8d9ZFde(fd:d;ZGde(fd<d=ZHde#fd>d?ZIde#fd@dAZJG dBdC dCeKZLG dDdE dEeeLZMdS )N    )absolute_importunicode_literalsN)import_module)*)
BaseLoader
SafeLoaderLoaderRoundTripLoader)
BaseDumper
SafeDumperDumperRoundTripDumper)StringIOBytesIOwith_metaclassPY3)VersionedResolverResolver)BaseRepresenterSafeRepresenterRepresenterRoundTripRepresenter)BaseConstructorSafeConstructorConstructorRoundTripConstructor)r   )CParserCEmitterc               @   s(  e Zd Zedddf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efddZdd ZedfddZedfdd Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd3d+d,Zed-d. Zejd/d. Zed0d1 Zejd2d1 ZdS )4YAMLNFc             C   s  |t k	rtd| jj||dkr(dn|| _|| _g | _x>|dkrHg n||   D ]"}|	t
jd}| jt| qTW tjj| _d| _d| _d| _d| _d| _| jdkrd| _tjj| _tjj| _tjj| _tjj| _tjj | _!tj"j#| _#tj$j%| _&nf| jdkrd|st'dkr tjjnt'| _tjj(| _|s@t)dkrHtjj!nt)| _!tj"j#| _#tj$j*| _&n| jdkrtjj| _tjj+| _|st)dkrtjj!nt)| _!tj"j#| _#tj$j,| _&n| jd	kr |st'dkrtjjnt'| _tjj| _|st)dkrtjj!nt)| _!tj"j#| _#tj$j&| _&nBx@| jD ]&}t-|d
d| jkr(|.|  P q(W t/d| jd| _0d| _1d| _2d| _3d| _4d| _5d| _6d| _7d| _8d| _9d| _:d| _;d| _<d| _=d| _>d| _?d| _@d| _Ad| _BdS )a  
        _kw: not used, forces keyword arguments in 2.7 (in 3 you can do (*, safe_load=..)
        typ: 'rt'/None -> RoundTripLoader/RoundTripDumper,  (default)
             'safe'    -> SafeLoader/SafeDumper,
             'unsafe'  -> normal/unsafe Loader/Dumper
             'base'    -> baseloader
        pure: if True only use Python modules
        plug_ins: a list of plug-in files
        zL{}.__init__() takes no positional argument but at least one was given ({!r})Nrt.TFZsafebaseZunsafetypz1typ "{}"not recognised (need to install plug-in?)r   zutf-8)Cenforce	TypeErrorformat	__class____name__r"   pureplug_insofficial_plug_insreplaceossepappendr   ruamel_yamlresolverr   r   allow_unicodeReaderScanner
Serializerdefault_flow_styleemitterEmitter
serializerrepresenterr   r   scannerZRoundTripScannerparserZRoundTripParserParsercomposerComposerconstructorr   r   r   r   r   r   r   r   getattrZinit_typNotImplementedErrorstream	canonical
old_indentwidth
line_break
map_indentsequence_indentsequence_dash_offset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)self_kwr"   r(   r)   Zpu	file_namemodule rX   /lib/python3.7/site-packages/ruamel_yaml/main.py__init__/   s    















zYAML.__init__c             C   s:   dt  jj }t| |s0t| || jd | d t| |S )N_)loader)sys	_getframef_codeco_namehasattrsetattrr2   r@   )rT   attrrX   rX   rY   reader   s    
zYAML.readerc             C   s8   dt  jj }t| |s.t| || j| d t| |S )Nr[   )r\   )r]   r^   r_   r`   ra   rb   r3   r@   )rT   rc   rX   rX   rY   r:      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 )Nr[   )r\   _stream)
r]   r^   r_   r`   ra   r<   r   rb   r@   re   )rT   rc   rX   rX   rY   r;      s    

zYAML.parserc             C   s8   dt  jj }t| |s.t| || j| d t| |S )Nr[   )r\   )r]   r^   r_   r`   ra   rb   r>   r@   )rT   rc   rX   rX   rY   r=      s    
zYAML.composerc             C   sH   dt  jj }t| |s>| j| j| d}| j|_t| || t	| |S )Nr[   )rM   r\   )
r]   r^   r_   r`   ra   r   rM   rN   rb   r@   )rT   rc   ZcnstrX   rX   rY   r?      s    
zYAML.constructorc             C   s<   dt  jj }t| |s2t| || j| j| d t| |S )Nr[   )rL   r\   )	r]   r^   r_   r`   ra   rb   r   rL   r@   )rT   rc   rX   rX   rY   r0      s
    

zYAML.resolverc          
   C   s   dt  jj }t| |s| jtk	r| jd | j| j| j	| j
| j| j| d}t| || | jd k	rh| j|_| jd k	rz| j|_| jd k	r| j|_nt| dd d krd S d S t| |S )Nr[   )rC   indentrE   r1   rF   rK   dumperre   )r]   r^   r_   r`   ra   r7   r   rC   rD   rE   r1   rF   rK   rb   rG   Zbest_map_indentrH   Zbest_sequence_indentrI   r@   )rT   rc   _emitterrX   rX   rY   r6      s(    





zYAML.emitterc             C   sL   dt  jj }t| |sBt| || j| j| j| j	| j
| j| d t| |S )Nr[   )rO   rP   rQ   rL   rR   rg   )r]   r^   r_   r`   ra   rb   r4   rO   rP   rQ   rL   rR   r@   )rT   rc   rX   rX   rY   r8      s    

zYAML.serializerc             C   s@   dt  jj }t| |s6t| || j| j| j| d t	| |S )Nr[   )rS   r5   rg   )
r]   r^   r_   r`   ra   rb   r   rS   r5   r@   )rT   rc   rX   rX   rY   r9      s    


zYAML.representerc             C   s   t |ds0t |dr0|d}| |S Q R X | |\}}z| S |  y| j  W n tk
rr   Y nX y| 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
        readopenrN)ra   rj   loadget_constructor_parserget_single_datadispose_readerreset_readerAttributeError_scannerreset_scanner)rT   rB   fpr?   r;   rX   rX   rY   rl      s    	z	YAML.loadc             c   s   |t k	rtd| jj|t|dsdt|drd|d$}x| j|t dD ]
}|V  qLW d S Q R X | |\}}zx|	 r|
 V  qvW W d |  y| j  W n tk
r   Y nX y| j  W n tk
r   Y nX X d S )NzL{}.__init__() takes no positional argument but at least one was given ({!r})ri   rj   rk   )rU   )r#   r$   r%   r&   r'   ra   rj   load_allrm   
check_dataget_dataro   rp   rq   rr   rs   rt   )rT   rB   rU   ru   dr?   r;   rX   rX   rY   rv     s*    


zYAML.load_allc                s   j tk	r<jdkrtjj_jdkr2tjj_|j_njdk	rnjdkrZtjj_tjj _ |j_njdk	rjdkrtjj_tjj _ |j_nNj	  tj
jkrtj
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d fdd	ZdS )z,YAML.get_constructor_parser.<locals>.XLoaderNc                sB   t | | |  | _| _jj| | d j| _ j| | d d S )N)r\   )Z	loadumper)r   rZ   _parser	_composerr   rN   )selfxrB   rL   rM   )rslvrrT   rX   rY   rZ   T  s
    z5YAML.get_constructor_parser.<locals>.XLoader.__init__)NN)r'   
__module____qualname__rZ   rX   )r}   rT   rX   rY   XLoaderS  s   r   )r<   r   r2   r/   rd   r3   r:   rB   r;   r   r0   r   r   re   r?   )rT   rB   r   r\   rX   )r}   rT   rY   rm   4  s0    















zYAML.get_constructor_parserc             C   s   | j |g|||dS )N)	transform)dump_all)rT   datarB   rU   r   rX   rX   rY   dump`  s    z	YAML.dumpc             C   s  t |ds8t |dr8|d}| j||||dS Q R X |tk	rTtd| jj|| jdkrvt	dd	 |d
 D }n| j}|dk	r|}| j
dkrt }nt }| ||\}}	}
zN| j  x4|D ],}y| j| W q tk
r    Y qX qW | j  W dy| j  W n tk
r(    Y nX t| d t| d X |r| }| j
rb|| j
}|dkrv|| n||| dS )zL
        Serialize a sequence of Python objects into a YAML stream.
        writerj   w)r   NzP{}.dump(_all) takes two positional argument but at least three were given ({!r})Tc             S   s   g | ]}t t|qS rX   )lenstr).0xrX   rX   rY   
<listcomp>r  s    z!YAML.dump_all.<locals>.<listcomp>r   _serializerrh   )ra   rj   r   r#   r$   r%   r&   r'   rJ   maxrO   r   r   "get_serializer_representer_emitterr8   r9   	representrr   closer6   ro   delattrgetvaluedecoder   )rT   	documentsrB   rU   r   ru   tlcaZfstreamr8   r9   r6   r   valrX   rX   rY   r   d  sJ    






zYAML.dump_allc                s   j tk	r>jd krtjj_|j_|j_jjjfS jd k	rrtjj _ |j_|j_jjjfS j	dkrtj
jnt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)
rC   rf   rE   rO   r1   rF   rP   rQ   rL   rR   )rS   r5   )r   rZ   rh   r   _representerr   )r|   rB   rS   r5   rC   rf   rE   r1   rF   rO   rP   rQ   rL   rR   block_seq_indentrJ   rK   )r}   rT   rX   rY   rZ     s    


zAYAML.get_serializer_representer_emitter.<locals>.XDumper.__init__)NNNNNNNNNNNNNNN)r'   r~   r   rZ   rX   )r}   rT   rX   rY   XDumper  s        r   )rS   r5   rC   rf   rE   r1   rF   rP   rQ   rL   rR   )r7   r   r4   r/   r8   r6   rB   rJ   r9   r"   r0   ZBaseResolverr   r   re   rS   r5   rC   rD   rE   r1   rF   rP   rQ   rL   rR   rh   r   )rT   rB   r   r   rg   rX   )r}   rT   rY   r     s0    




z'YAML.get_serializer_representer_emitterc             K   s.   | j dkr ddlm} |f |S tf |S d S )Nr   r   )CommentedMap)r"   ruamel_yaml.commentsr   dict)rT   kwr   rX   rX   rY   map  s    

zYAML.mapc             G   s*   | j dkrddlm} || S t| S d S )Nr   r   )CommentedSeq)r"   r   r   list)rT   argsr   rX   rX   rY   seq  s    
zYAML.seqc                s@   t jt}t jt j|  fddt|d D }|S )Nc                s    g | ]}|  d dd qS )    )r+   )r   r   )gpbdrX   rY   r     s    z*YAML.official_plug_ins.<locals>.<listcomp>z/*/__plug_in__.py)r,   pathdirname__file__glob)rT   ZbdZresrX   )r   rY   r*     s    zYAML.official_plug_insc                s   t  dd j y| j  j W n0 tk
rV    fdd}| j | Y nX y| 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)
flow_style)represent_yaml_objectr5   )r9   r   )clstagrX   rY   t_y  s    z YAML.register_class.<locals>.t_yc                s   |  | S )N)construct_yaml_object)r?   node)r   rX   rY   f_y  s    z YAML.register_class.<locals>.f_y)	r@   r'   r9   add_representerto_yamlrr   r?   add_constructor	from_yaml)rT   r   r   r   rX   )r   r   rY   register_class  s    zYAML.register_classc             C   s.   |d k	r|| _ |d k	r|| _|d k	r*|| _d S )N)rG   rH   rI   )rT   mappingZsequenceoffsetrX   rX   rY   _indent   s    zYAML._indentc             C   s   | j S )N)r   )rT   rX   rX   rY   rf   	  s    zYAML.indentc             C   s
   || _ d S )N)rD   )rT   r   rX   rX   rY   rf     s    c             C   s   | j S )N)rI   )rT   rX   rX   rY   r     s    zYAML.block_seq_indentc             C   s
   || _ d S )N)rI   )rT   r   rX   rX   rY   r     s    )NNN)r'   r~   r   r#   rZ   propertyrd   r:   r;   r=   r?   r0   r6   r8   r9   rl   rv   rm   r   r   r   r   r   r*   r   r   rf   setterr   rX   rX   rX   rY   r   .   s2   X
	,43	
	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 yj  j W n0 tk
rV    fdd}j | Y nX yj j W n. tk
r    fdd}j| Y nX  S )Nr   r   c                s   | j | | jdS )N)r   )r   r5   )r9   r   )r   r   rX   rY   r   ,  s    z)yaml_object.<locals>.yo_deco.<locals>.t_yc                s   |  | S )N)r   )r?   r   )r   rX   rY   r   5  s    z)yaml_object.<locals>.yo_deco.<locals>.f_y)	r@   r'   r9   r   r   rr   r?   r   r   )r   r   r   )yml)r   r   rY   yo_deco&  s    zyaml_object.<locals>.yo_decorX   )r   r   rX   )r   rY   yaml_object  s    r   c             c   s:   || }z x|j  r$|j  V  qW W d|j  X dS )z9
    Scan a YAML stream and produce scanning tokens.
    N)r:   Zcheck_tokenZ	get_tokenrz   ro   )rB   r   r\   rX   rX   rY   scan@  s
    r   c             c   s:   || }z x|j  r$|j  V  qW W d|j   X dS )z9
    Parse a YAML stream and produce parsing events.
    N)rz   Zcheck_eventZ	get_eventro   )rB   r   r\   rX   rX   rY   parseM  s
    r   c             C   s    || }z|  S |  X dS )zj
    Parse the first YAML document in a stream
    and produce the corresponding representation tree.
    N)Zget_single_nodero   )rB   r   r\   rX   rX   rY   composeZ  s    r   c             c   s8   || }zx|  r"|j V  qW W d|j  X dS )zb
    Parse all YAML documents in a stream
    and produce corresponding representation trees.
    N)Z
check_noder{   Zget_noderz   ro   )rB   r   r\   rX   rX   rY   compose_allg  s
    
r   c             C   sH   |dkrt jtjtdd t}|| ||d}z
|j S |j  X dS )zd
    Parse the first YAML document in a stream
    and produce the corresponding Python object.
    N   )
stacklevel)rM   )	warningswarnUnsafeLoaderWarningtextUnsafeLoader_constructorrn   rz   ro   )rB   r   rL   rM   r\   rX   rX   rY   rl   u  s    
rl   c             c   s^   |dkrt jtjtdd t}|| ||d}z x|j rH|j V  q0W W d|j	  X dS )z\
    Parse all YAML documents in a stream
    and produce corresponding Python objects.
    Nr   )r   )rM   )
r   r   r   r   r   r   rw   rx   rz   ro   )rB   r   rL   rM   r\   rX   rX   rY   rv     s    rv   c             C   s   t | t|S )z
    Parse the first YAML document in a stream
    and produce the corresponding Python object.
    Resolve only basic YAML tags.
    )rl   r   )rB   rL   rX   rX   rY   	safe_load  s    r   c             C   s   t | t|S )z~
    Parse all YAML documents in a stream
    and produce corresponding Python objects.
    Resolve only basic YAML tags.
    )rv   r   )rB   rL   rX   rX   rY   safe_load_all  s    r   c             C   s   t | t||dS )z
    Parse the first YAML document in a stream
    and produce the corresponding Python object.
    Resolve only basic YAML tags.
    )rM   )rl   r	   )rB   rL   rM   rX   rX   rY   round_trip_load  s    r   c             C   s   t | t||dS )z~
    Parse all YAML documents in a stream
    and produce corresponding Python objects.
    Resolve only basic YAML tags.
    )rM   )rv   r	   )rB   rL   rM   rX   rX   rY   round_trip_load_all  s    r   c             C   s   d}|dkrt  }|j}|||||||d}	zx| D ]}
|	|
 q4W W dy|	j  W n tk
rv    |	  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.
    N)rC   rf   rE   r1   rF   )r   r   emitrh   ro   rr   )ZeventsrB   r   rC   rf   rE   r1   rF   r   rg   ZeventrX   rX   rY   r     s     


r   zutf-8c             C   s   d}|dkr(|dkrt  }nt }|j}|||||||||||	|
d}z0|j  x| D ]}|| qXW |j  W dy|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.
    N)
rC   rf   rE   r1   rF   rO   rL   rR   rP   rQ   )
r   r   r   r   rj   	serializer   rh   ro   rr   )ZnodesrB   r   rC   rf   rE   r1   rF   rO   rP   rQ   rL   rR   r   rg   r   rX   rX   rY   serialize_all  s,    




r   c             K   s   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   rB   r   kwdsrX   rX   rY   r      s    r   c             C   s   d}|dkr"t dd | d D }|dkrF|
dkr:t }nt }|j}|||||||||	|
|||||||d}zN|j  x4| D ],}y|j| W q tk
r    Y qX qW |j	  W dy|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.
    NTc             S   s   g | ]}t t|qS rX   )r   r   )r   r   rX   rX   rY   r     s    zdump_all.<locals>.<listcomp>r   )rS   r5   rC   rf   rE   r1   rF   rO   rP   rQ   rL   rR   r   rJ   rK   )r   r   r   r   r   rj   r   r   rr   r   rh   ro   )r   rB   r   rS   r5   rC   rf   rE   r1   rF   rO   rP   rQ   rL   rR   r   rJ   rK   r   rg   r   rX   rX   rY   r   	  s@    


r   c             C   s*   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   rS   r5   rC   rf   rE   r1   rF   rO   rP   rQ   rL   rR   r   )r   )r   rB   r   rS   r5   rC   rf   rE   r1   rF   rO   rP   rQ   rL   rR   r   rX   rX   rY   r   ;  s    
r   c             K   s   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.
    r   )r   r   )r   rB   r   rX   rX   rY   safe_dump_allU  s    r   c             K   s   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.
    r   )r   r   )r   rB   r   rX   rX   rY   	safe_dump_  s    r   c             C   s>   |d krdn|}t | g|||||||||	|
|||||||dS )NT)r   rS   r5   rC   rf   rE   r1   rF   rO   rP   rQ   rL   rR   r   rJ   rK   )r   )r   rB   r   rS   r5   rC   rf   rE   r1   rF   rO   rP   rQ   rL   rR   r   rJ   rK   rX   rX   rY   round_trip_dumpi  s    
r   c             C   s   |dkr"|dkr"| | || dS |rjt|dr@| | || n*t|tttjjtfrft	 | || nt
|rt|dr| | || n*t|tttjjtfrt	 | || 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   ra   
issubclassr   r   r/   r\   r   r	   r   rA   r
   r   rg   r   r   )r   Zregexpfirstr   r   r0   rX   rX   rY   r     s"    	

r   c             C   s   |dkr"|dkr"| | || dS |rjt|dr@| | || n*t|tttjjtfrft	 | || nt
|rt|dr| | || n*t|tttjjtfrt	 | || 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   ra   r   r   r   r/   r\   r   r	   r   rA   r
   r   rg   r   r   )r   r   Zkindr   r   r0   rX   rX   rY   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rt	 | | 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   ra   r   r   r   r   r   r   r	   r   rA   )r   Zobject_constructorr   r?   rX   rX   rY   r     s    




r   c             C   s   |dkr| | | ndr4t|dr4| | | dS t|trLt | | nPt|trdt | | n8t|tjj	rt
 | | nt|trt | | 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   ra   r   r   r   r   r   r/   r\   r   r   r	   r   rA   )Z
tag_prefixZmulti_constructorr   r?   rX   rX   rY   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rt	 | | 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   ra   r   r
   r   r   r   r   r   r   rA   )	data_typeZobject_representerr   r9   rX   rX   rY   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rt	 | | 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)r   ra   r   r
   r   r   r   r   r   r   rA   )r   Zmulti_representerr   r9   rX   rX   rY   r     s    




r   c                   s    e Zd ZdZ fddZ  ZS )YAMLObjectMetaclassz'
    The metaclass for YAMLObject.
    c                sN   t t| ||| d|krJ|d d k	rJ| j| j| j | j| | j	 d S )Nr   )
superr   rZ   yaml_constructorr   r   r   yaml_representerr   r   )r   namebasesr   )r&   rX   rY   rZ   ,  s    zYAMLObjectMetaclass.__init__)r'   r~   r   __doc__rZ   __classcell__rX   rX   )r&   rY   r   (  s   r   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.
    rX   Nc             C   s   | || S )zC
        Convert a representation node to a Python object.
        )r   )r   r?   r   rX   rX   rY   r   A  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   r9   r   rX   rX   rY   r   I  s    zYAMLObject.to_yaml)r'   r~   r   r   	__slots__r   r   r   r   r   r   classmethodr   r   rX   rX   rX   rY   r   4  s   r   )NNN)NNN)N)N)NN)NN)N)N)NZ
__future__r   r   r]   r,   r   r   	importlibr   r/   Zruamel_yaml.errorZruamel_yaml.tokensZruamel_yaml.eventsZruamel_yaml.nodesZruamel_yaml.loaderr   r   r   r	   Zruamel_yaml.dumperr
   r   r   r   Zruamel_yaml.compatr   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_yamlr   r   objectr#   r   r   r   r   r   r   rl   rv   r   r   r   r   r   encr   r   r   r   r   r   r   r   r   r   r   r   r   typer   r   rX   rX   rX   rY   <module>   s      s"









 	,



