o
    "                     @   s6  d dl mZ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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/ 	 z
d dl<m=Z=m>Z> W n   d Z=Z>Y e? Z@G dd de?ZAG dd de?ZBdd ZCefddZDefddZEefddZFefddZGdMd d!ZHdMd"d#ZIdNd$d%ZJdNd&d'ZKdOd(d)ZLdOd*d+ZMdedddddfd,d-ZNe rdnd.ZOdedddddeOddddfd/d0ZPdefd1d2ZQdedddddddeOdddddddfd3d4ZRdedddddddeOdddddfd5d6ZSdNd7d8ZTdNd9d:ZUdedddddddeOdddddddfd;d<ZVddde$fd=d>ZWddde$fd?d@ZXde-fdAdBZYde-fdCdDZZde(fdEdFZ[de(fdGdHZ\G dIdJ dJe]Z^G dKdL dLee^Z_dS )P    )absolute_importunicode_literalsprint_functionN)import_module)UnsafeLoaderWarning	YAMLError)*)
BaseLoader
SafeLoaderLoaderRoundTripLoader)
BaseDumper
SafeDumperDumperRoundTripDumper)StringIOBytesIOwith_metaclassPY3nprint)VersionedResolverResolver)BaseRepresenterSafeRepresenterRepresenterRoundTripRepresenter)BaseConstructorSafeConstructorConstructorRoundTripConstructor)r   F)ListSetDictUnionAnyCallable)
StreamTypeStreamTextTypeVersionType)Path)CParserCEmitterc                   @   s\  e Zd Zed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dedf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d-d. Zd/d0 Zd1d2 Zd=d3d4Zed5d6 Zejd7d6 Zed8d9 Z e jd:d9 Z d>d;d<Z!dS )?YAMLNFc           	      C   s  |t urtd| jj||du rdn|| _|| _|| _d| _g | _	|du r)g n|| 
  D ]}|tjd}| j	t| q/tjjj| _d| _d| _d| _d| _d| _| jdkrd| _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(| _)n| jdkr|st*du rtjjjnt*| _tjjj+| _|st,du rtjj"j$nt,| _$tjj%j&| _&tjj'j-| _)n| jdkrtjjj| _tjjj.| _|st,du rtjj"j$nt,| _$tjj%j&| _&tjj'j/| _)nW| jd	kr |st*du rtjjjnt*| _tjjj| _|st,du rtjj"j$nt,| _$tjj%j&| _&tjj'j)| _)n | j	D ]}t0|d
d| jkr6|1|   n
q#t2d| jd| _3d| _4d| _5d| _6d| _7d| _8d| _9d| _:d| _;d| _<d| _=d| _>d| _?d| _@d| _Ad| _Bd| _Cd| _Dd| _Ed| _Fd| _Gd| _Hd| _Id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
        input/output: needed to work as context manager
        plug_ins: a list of plug-in files
        L{}.__init__() takes no positional argument but at least one was given ({!r})Nrt.TFsafebaseunsafetypz1typ "{}"not recognised (need to install plug-in?)r   utf-8)Jenforce	TypeErrorformat	__class____name__r3   pure_output_context_manager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   scannerRoundTripScannerparserRoundTripParserParsercomposerComposerconstructorr   r   r+   r   r*   r   r   r   getattrinit_typNotImplementedError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_style0top_level_block_style_scalar_no_indent_error_1_1+brace_single_entry_mapping_in_flow_sequence)	self_kwr3   r:   outputr=   pu	file_namemodule rw   9/tmp/google-cloud-sdk/lib/third_party/ruamel/yaml/main.py__init__=   s   


 



zYAML.__init__c                 C   s2   z| j W S  ty   | jd | d| _ | j  Y S w Nloader)_readerAttributeErrorrG   rq   rw   rw   rx   reader   s   
zYAML.readerc                 C   s0   z| j W S  ty   | j| d| _ | j  Y S w rz   )_scannerr~   rH   r   rw   rw   rx   rO      s   
zYAML.scannerc                 C   sj   dt  jj }t| |s0| jturt| || j| d nt| dd d u r'd S t| |t| j	 t| |S )N_r{   _stream)
sys	_getframef_codeco_namehasattrrS   r*   setattrrW   r   rq   attrrw   rw   rx   rQ      s   


zYAML.parserc                 C   s8   dt  jj }t| |st| || j| d t| |S )Nr   r{   )r   r   r   r   r   r   rU   rW   r   rw   rw   rx   rT      s   

zYAML.composerc                 C   sH   dt  jj }t| |s| j| j| d}| j|_t| || t	| |S )Nr   )rh   r|   )
r   r   r   r   r   r   rh   ri   r   rW   )rq   r   cnstrw   rw   rx   rV      s   

zYAML.constructorc                 C   s<   dt  jj }t| |st| || j| j| d t| |S )Nr   )rg   r|   )	r   r   r   r   r   r   r   rg   rW   r   rw   rw   rx   rE      s   

zYAML.resolverc                 C   s   dt  jj }t| |sg| jtur[| jd | j| j| j	| j
| j| j| j| d	}t| || | jd ur6| j|_| jd ur?| j|_| jd urH| j|_| jd urQ| j|_| jd urZ| j|_nt| dd d u red S d S t| |S )Nr   )r[   indentr]   rF   r^   rf   rp   dumperr   )r   r   r   r   r   rL   r+   r[   r\   r]   rF   r^   rf   rp   r   r_   best_map_indentr`   best_sequence_indentra   rb   rc   rW   )rq   r   _emitterrw   rw   rx   rK      s<   







zYAML.emitterc                 C   sL   dt  jj }t| |s!t| || j| j| j| j	| j
| j| d t| |S )Nr   )rj   rk   rl   rg   rm   r   )r   r   r   r   r   r   rI   rj   rk   rl   rg   rm   rW   r   rw   rw   rx   rM     s   

zYAML.serializerc                 C   sV   dt  jj }t| |s&| j| j| j| d}| jd ur | j|_t	| || t
| |S )Nr   )rn   rJ   r   )r   r   r   r   r   r   rn   rJ   rd   r   rW   )rq   r   represrw   rw   rx   rN      s   


zYAML.representerc                 C   s   t |ds$t |dr$|d}| |W  d   S 1 sw   Y  | |\}}z*| W |  z| j  W n	 tyD   Y nw z| j	
  W S  tyU   Y S w |  z| j  W n	 tyj   Y nw z| j	
  W w  ty{   Y w w )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rbN)r   r   loadget_constructor_parserget_single_datadisposer}   reset_readerr~   r   reset_scanner)rq   rZ   fprV   rQ   rw   rw   rx   r   <  s:   	 z	YAML.loadc                 c   sB   |t urtd| jj|t|ds=t|dr=|d}| j|t dD ]}|V  q&	 W d    d S 1 s8w   Y  | |\}}z6|	 rR|
 V  |	 sIW |  z| j  W n	 tyg   Y nw z| j  W d S  tyz   Y d S w |  z| j  W n	 ty   Y nw z| j  W w  ty   Y w w )Nr-   r   r   r)rr   )r5   r6   r7   r8   r9   r   r   load_allr   
check_dataget_datar   r}   r   r~   r   r   )rq   rZ   rr   r   drV   rQ   rw   rw   rx   r   W  sP    
zYAML.load_allc                    s   j tur jdu rtjjj_jdu rtjjj_|j_nSjdur;jdu r0tjjj_tjj	j _ |j_n8jdurVjdu rKt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 )Nr{   )rg   	loadumper)r*   ry   _parser	_composerr   ri   )selfxrZ   rg   rh   rslvrrq   rw   rx   ry     s
   z5YAML.get_constructor_parser.<locals>.XLoader.__init__)r9   
__module____qualname__rg   ry   rw   r   rw   rx   XLoader  s    r   )rS   r*   rG   rC   rD   r   rH   rO   rZ   rQ   r   r   r   rV   )rq   rZ   r   r|   rw   r   rx   r   w  s,   









	zYAML.get_constructor_parserc                 C   s~   | j r-| js
td|turtd| jj||d ur%td| jj| j | d S |d u r5td| j|g|||dS )Nz8Missing output stream while dumping from context managerzJ{}.dump() takes one positional argument but at least two were given ({!r})z?{}.dump() in the context manager cannot have transform keyword z<Need a stream argument when not dumping from context manager	transform)	r<   r;   r6   r5   r7   r8   r9   dumpdump_all)rq   datarZ   rr   r   rw   rw   rx   r     s"   
z	YAML.dumpc                 C   sj   | j rt|turtd| jj||| _t| |d| _ |D ]}| j 	| q| j 
  d | _d | _ d S )NP{}.dump(_all) takes two positional argument but at least three were given ({!r})r   )r<   rY   r5   r6   r7   r8   r9   r;   YAMLContextManagerr   teardown_output)rq   	documentsrZ   rr   r   r   rw   rw   rx   r     s   

zYAML.dump_allc                 C   s  t |ds(t |dr(|d}| j||||dW  d   S 1 s#w   Y  |tur6td| jj|| jdu rGt	dd	 |d
 D }n| j}|dur\|}| j
du rYt }nt }| ||\}}	}
z;| j  |D ]}z| j| W qm ty    w | j  W z| j  W n ty    w t| d t| d nz| j  W n ty    w t| d t| d w |r| }| j
r|| j
}|du r|| dS ||| dS )zL
        Serialize a sequence of Python objects into a YAML stream.
        writer   wr   Nr   Tc                 S      g | ]}t t|qS rw   lenstr.0xrw   rw   rx   
<listcomp>      z"YAML.Xdump_all.<locals>.<listcomp>r   _serializerr   )r   r   r   r5   r6   r7   r8   r9   re   maxrj   r   r   "get_serializer_representer_emitterrM   rN   	representr~   closerK   r   delattrgetvaluedecoder   )rq   r   rZ   rr   r   r   tlcafstreamrM   rN   rK   r   valrw   rw   rx   	Xdump_all  sh    





zYAML.Xdump_allc                    s  j tur jd u rtjjj_|j_|j_jj	jfS jd ur;tjjj _ |j_|j_jj	jfS j
dkrEt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 )Nr1   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)
r[   r   r]   rj   rF   r^   rk   rl   rg   rm   )rn   rJ   )r+   ry   r   r   _representerr   )r   rZ   rn   rJ   r[   r   r]   rF   r^   rj   rk   rl   rg   rm   block_seq_indentre   rf   r   rw   rx   ry     s&   zAYAML.get_serializer_representer_emitter.<locals>.XDumper.__init__)NNNNNNNNNNNNNNN)r9   r   r   ry   rw   r   rw   rx   XDumper  s"    r   )rn   rJ   r[   r   r]   rF   r^   rk   rl   rg   rm   )rL   r+   rI   rC   rD   rM   rK   rZ   re   rN   r3   rE   BaseResolverr   r   r   rn   rJ   r[   r\   r]   rF   r^   rk   rl   rg   rm   r   r   )rq   rZ   r   r   r   rw   r   rx   r     sB   




)
z'YAML.get_serializer_representer_emitterc                 K   s2   | j dkrddlm} |di |S tdi |S )Nr.   r   )CommentedMaprw   )r3   ruamel.yaml.commentsr   dict)rq   kwr   rw   rw   rx   mapT  s   
zYAML.mapc                 G   s&   | j dkrddlm} || S t| S )Nr.   r   )CommentedSeq)r3   r   r   list)rq   argsr   rw   rw   rx   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   gpbdrw   rx   r   k  s     z*YAML.official_plug_ins.<locals>.<listcomp>z/*/__plug_in__.py)r@   pathdirname__file__glob)rq   bdresrw   r   rx   r>   g  s   zYAML.official_plug_insc                    s   t  dd j z
| j  j W n ty*    fdd}| j | Y nw z| j j W  S  tyM    fdd}| j| Y  S w )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                       | j | | jdS N
flow_stylerepresent_yaml_objectrJ   rN   r   clstagrw   rx   t_y{     
z YAML.register_class.<locals>.t_yc                       |  | S Nconstruct_yaml_objectrV   noder   rw   rx   f_y     z YAML.register_class.<locals>.f_y	rW   r9   rN   add_representerto_yamlr~   rV   add_constructor	from_yaml)rq   r   r   r   rw   r   rx   register_classn  s   	zYAML.register_classc                 c   s    |  |\}}z6| r| V  | sW |  z| j  W n	 ty+   Y nw z| j  W dS  ty>   Y dS w |  z| j  W n	 tyS   Y nw z| j  W w  tyd   Y w w )zA
        Parse a YAML stream and produce parsing events.
        N)	r   check_event	get_eventr   r}   r   r~   r   r   )rq   rZ   r   rQ   rw   rw   rx   parse  s:   
z
YAML.parsec                 C   s   t | | _| S r   )r   r<   r   rw   rw   rx   	__enter__  s   
zYAML.__enter__c                 C   s"   |rt d| | j  d | _d S )Nr3   )r   r<   r   )rq   r3   value	tracebackrw   rw   rx   __exit__  s   


zYAML.__exit__c                 C   s2   |d ur|| _ |d ur|| _|d ur|| _d S d S r   )r_   r`   ra   )rq   mappingsequenceoffsetrw   rw   rx   _indent  s   
zYAML._indentc                 C      | j S r   )r
  r   rw   rw   rx   r        zYAML.indentc                 C   
   || _ d S r   )r\   rq   r   rw   rw   rx   r        
c                 C   r  r   ra   r   rw   rw   rx   r     r  zYAML.block_seq_indentc                 C   r  r   r  r  rw   rw   rx   r     r  c                 C   s   || _ || _d S r   )rb   rc   )rq   seq_seqseq_maprw   rw   rx   compact  s   
zYAML.compactNNNNN)"r9   r   r   r5   ry   propertyr   rO   rQ   rT   rV   rE   rK   rM   rN   r   r   r   r   r   r   r   r   r   r>   r   r  r  r  r
  r   setterr   r  rw   rw   rw   rx   r,   <   sZ    

j




	

#

 -7S	

		



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s(t| jdr(| j| _| jd| _| jd urC| j| _| j jd u r=t	 | _d S t
 | _d S d S )NFr   r   r   )_yaml_output_inited_output_pathr;   
_transformr   r   _fstreamrj   r   r   )rq   rD   r   rw   rw   rx   ry     s   

zYAMLContextManager.__init__c                 C   s   | j r
| jj  nd S z| jj  W n ty    w zt| jd t| jd W n ty3    w | jrd| j	
 }| jjrG|| jj}| jd u rR| | n| j| | | j  | j| _	| jd urp| j	  d S d S )Nr   r   )r  r  rM   r   rK   r   r~   r   r  r;   r   rj   r   r  r   flushr  r  rw   rw   rx   r     s4   



z"YAMLContextManager.teardown_outputc                 C   sN   | j jdu rtdd |D }n| j j}| j | j| | j j  d| _d S )NTc                 S   r   rw   r   r   rw   rw   rx   r     r   z2YAMLContextManager.init_output.<locals>.<listcomp>)r  re   r   r   r;   rM   r   r  )rq   
first_datar   rw   rw   rx   init_output  s   
zYAMLContextManager.init_outputc                 C   s6   | j s| | z
| jj| W d S  ty    w r   )r  r  r  rN   r   r~   )rq   r   rw   rw   rx   r     s   
zYAMLContextManager.dumpr   )r9   r   r   ry   r   r  r   rw   rw   rw   rx   r     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 n ty*    fdd}j | Y nw zj j W  S  tyM    fdd}j| Y  S w )Nr   r   c                    r   r   r   r   r   rw   rx   r   O  r   z)yaml_object.<locals>.yo_deco.<locals>.t_yc                    r   r   r   r   r   rw   rx   r   Z  r   z)yaml_object.<locals>.yo_deco.<locals>.f_yr   )r   r   r   ymlr   rx   yo_decoH  s   	zyaml_object.<locals>.yo_decorw   )r!  r"  rw   r   rx   yaml_object?  s   	r#  c                 c   sX    || }z |j  r|j  V  |j  sW |j  dS W |j  dS |j  w )z9
    Scan a YAML stream and produce scanning tokens.
    N)rO   check_token	get_tokenr   r   rZ   r   r|   rw   rw   rx   scang     
r'  c                 c   sX    || }z |j  r|j  V  |j  sW |j   dS W |j   dS |j   w )z9
    Parse a YAML stream and produce parsing events.
    N)r   r   r  r   r&  rw   rw   rx   r  t  r(  r  c                 C   s&   || }z	|  W |  S |  w )zj
    Parse the first YAML document in a stream
    and produce the corresponding representation tree.
    )get_single_noder   r&  rw   rw   rx   compose  s   r*  c                 c   sT    || }z|  r|j V  |  s
W |j  dS W |j  dS |j  w )zb
    Parse all YAML documents in a stream
    and produce corresponding representation trees.
    N)
check_noder   get_noder   r   r&  rw   rw   rx   compose_all  s   
r-  c                 C   s   |du rt jtjtdd t}|| ||d}z,|j W |j  z|j	
  W n	 ty1   Y nw z|j  W S  tyB   Y S w |j  z|j	
  W n	 tyX   Y nw z|j  W w  tyi   Y w w )zd
    Parse the first YAML document in a stream
    and produce the corresponding Python object.
    N   
stacklevelrh   )warningswarnr   textUnsafeLoader_constructorr   r   r   r}   r   r~   r   r   rZ   r   rg   rh   r|   rw   rw   rx   r     s8   


r   c                 c   s    |du rt jtjtdd t}|| ||d}z:|j r(|j V  |j sW |j	  z|j
  W n	 ty>   Y nw z|j  W dS  tyQ   Y dS w |j	  z|j
  W n	 tyg   Y nw z|j  W w  tyx   Y w w )z\
    Parse all YAML documents in a stream
    and produce corresponding Python objects.
    Nr.  r/  r1  )r2  r3  r   r4  r5  r6  r   r   r   r   r}   r   r~   r   r   r7  rw   rw   rx   r     s@   



r   c                 C      t | t|S )
    Parse the first YAML document in a stream
    and produce the corresponding Python object.
    Resolve only basic YAML tags.
    )r   r
   rZ   rg   rw   rw   rx   	safe_load     r;  c                 C   r8  )~
    Parse all YAML documents in a stream
    and produce corresponding Python objects.
    Resolve only basic YAML tags.
    )r   r
   r:  rw   rw   rx   safe_load_all  r<  r>  c                 C      t | t||dS )r9  r1  )r   r   rZ   rg   rh   rw   rw   rx   round_trip_load     rA  c                 C   r?  )r=  r1  )r   r   r@  rw   rw   rx   round_trip_load_all  rB  rC  c                 C   s   d}|du rt  }|j}|||||||d}	z| D ]}
|	|
 qW z|	j  W n ty1    w z|	j  W w  tyA    w |durI| S dS )zl
    Emit YAML parsing events into a stream.
    If stream is None, return the produced string instead.
    N)r[   r   r]   rF   r^   )r   r   emitr   r   r~   )eventsrZ   r   r[   r   r]   rF   r^   r   r   eventrw   rw   rx   rD    s:   rD  r4   c                 C   s   d}|du r|du rt  }nt }|j}|||||||||||	|
d}z%|j  | D ]}|| q+|j  W z|j  W n t	yH    w z|j  W w  t	yX    w |du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)
r[   r   r]   rF   r^   rj   rg   rm   rk   rl   )
r   r   r   r   r   	serializer   r   r   r~   )nodesrZ   r   r[   r   r]   rF   r^   rj   rk   rl   rg   rm   r   r   r   rw   rw   rx   serialize_all   sJ   
rI  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   )rI  )r   rZ   r   kwdsrw   rw   rx   rG  W  s   rG  c                 C   s  d}|du rt dd | d D }|du r#|
du rt }nt }|j}||f|||||||	|
|||||||d}z0|j  | D ]}z|j| W qA tyS    w |j	  W z|j
  W n tyi    w z|j
  W w  tyy    w |du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   r   rw   r   r   rw   rw   rx   r   {  r   zdump_all.<locals>.<listcomp>r   )rn   rJ   r[   r   r]   rF   r^   rj   rk   rl   rg   rm   r   re   rf   )r   r   r   r   r   r   r   r   r~   r   r   r   )r   rZ   r   rn   rJ   r[   r   r]   rF   r^   rj   rk   rl   rg   rm   r   re   rf   r   r   r   rw   rw   rx   r   `  sb   
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   rn   rJ   r[   r   r]   rF   r^   rj   rk   rl   rg   rm   r   r   )r   rZ   r   rn   rJ   r[   r   r]   rF   r^   rj   rk   rl   rg   rm   r   rw   rw   rx   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   rZ   rJ  rw   rw   rx   safe_dump_all  s   rM  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   rL  )r   rZ   rJ  rw   rw   rx   	safe_dump  s   rN  c                 C   s   |d u rdn|}t | g|fi d|d|d|d|d|d|d|d	|	d
|
d|d|d|d|d|d|d|S )NTr   rn   rJ   r[   r   r]   rF   r^   rj   rk   rl   rg   rm   r   re   rf   rK  )r   rZ   r   rn   rJ   r[   r   r]   rF   r^   rj   rk   rl   rg   rm   r   re   rf   rw   rw   rx   round_trip_dump  sJ   	
rO  c                 C      |du r|du r| | || dS |r6t|dr | | || nt|tttjjjt	fr4t
 | || nt|r]t|drF| | || dS t|tttjjjtfr[t
 | || dS 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)rQ  r   
issubclassr	   r
   rC   rD   r|   r   r   r   rY   r   r   r   r   r   )r   regexpfirstr   r   rE   rw   rw   rx   rQ    s(   


rQ  c                 C   rP  )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)rU  r   rR  r	   r
   rC   rD   r|   r   r   r   rY   r   r   r   r   r   )r   r   kindr   r   rE   rw   rw   rx   rU  <  s(   

rU  c                 C      |du r| | | dS t|dr| | | dS t|tr&t | | dS t|tr3t | | dS t||r@t | | dS t|trMt	 | | dS t
)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   r   rR  r	   r   r
   r   r   r   r   rY   )r   object_constructorr   rV   rw   rw   rx   r   [  s   




r   c                 C   s   |du r| | | dS 	 t|trt | | dS t|tr't | | dS t|tjj	j
r7t | | dS t|trDt | | dS t)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.
    N)add_multi_constructorr   rR  r	   r   r
   r   rC   rD   r|   r   r   r   r   rY   )
tag_prefixmulti_constructorr   rV   rw   rw   rx   rY  t  s   


rY  c                 C   rW  )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   r   rR  r   r   r   r   r   r   r   rY   )	data_typeobject_representerr   rN   rw   rw   rx   r        




r   c                 C   rW  )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_  r   rR  r   r   r   r   r   r   r   rY   )r\  multi_representerr   rN   rw   rw   rx   r_    r^  r_  c                       s    e Zd ZdZ fddZ  ZS )YAMLObjectMetaclassz'
    The metaclass for YAMLObject.
    c                    sV   t t| ||| d|v r'|d d ur)| j| j| j | j| | j	 d S d S d S )Nr   )
superra  ry   yaml_constructorr   r   r   yaml_representerr   r   )r   namebasesrJ  r8   rw   rx   ry     s
   zYAMLObjectMetaclass.__init__)r9   r   r   __doc__ry   __classcell__rw   rw   rg  rx   ra    s    ra  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.
    rw   Nc                 C   s   | || S )zC
        Convert a representation node to a Python object.
        r   )r   rV   r   rw   rw   rx   r     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   rN   r   rw   rw   rx   r     s   zYAMLObject.to_yaml)r9   r   r   rh  	__slots__r   rc  r   rd  r   rk  classmethodr   r   rw   rw   rw   rx   rj    s    
rj  r  r   r  )`
__future__r   r   r   r   r@   r2  r   	importlibr   ruamel.yamlrC   ruamel.yaml.errorr   r   ruamel.yaml.tokensruamel.yaml.eventsruamel.yaml.nodesruamel.yaml.loaderr	   r
   r   r   ruamel.yaml.dumperr   r   r   r   ruamel.yaml.compatr   r   r   r   r   ruamel.yaml.resolverr   r   ruamel.yaml.representerr   r   r   r   ruamel.yaml.constructorr   r   r   r   r5  typingr    r!   r"   r#   r$   r%   r&   r'   r(   pathlibr)   _ruamel_yamlr*   r+   objectr5   r,   r   r#  r'  r  r*  r-  r   r   r;  r>  rA  rC  rD  encrI  rG  r   r   rM  rN  rO  rQ  rU  r   rY  r   r_  typera  rj  rw   rw   rw   rx   <module>   s   	
     k(









(
7
J

.


1
"