o
                         @   s  d dl mZmZ 	 d dlZd dlZd dlmZmZmZm	Z	 d dl
mZ d dlmZ er8d dlmZmZmZmZ nd dlmZmZmZmZ 	 g d	Zd
ZdZdZdZdZ G dd de!Z"dd Z#G dd de!Z$G dd de!Z%G dd de!Z&G dd de!Z'G dd de	e(e'Z)G dd de*e'Z+G dd  d eZ,G d!d" d"e,eZ-G d#d$ d$e,eZ.G d%d& d&e,Z/G d'd( d(ee'Z0e1d)d* Z2G d+d, d,e'eZ3G d-d. d.e0Z4G d/d0 d0ee'Z5G d1d2 d2e'Z6d3d4ej7fd5d6Z8dS )7    )absolute_importprint_functionN)ordereddictPY2string_typesMutableSliceableSequence)ScalarString)Anchor)
MutableSetSizedSetMappingF)AnyDictOptionalListUnionr   Iterator)CommentedSeqCommentedKeySeqCommentedMapCommentedOrderedMapCommentedSetcomment_attribmerge_attrib_yaml_comment_yaml_format_yaml_line_col_yaml_merge	_yaml_tagc                   @   sd   e Zd ZdZeZdd Zdd Zedd Z	edd	 Z
e
jd
d	 Z
edd Zejdd ZdS )Comment)comment_items_end_startc                 C   s   d | _ i | _g | _d S N)r!   r"   r#   self r(   =/tmp/google-cloud-sdk/lib/third_party/ruamel/yaml/comments.py__init__.   s   
zComment.__init__c                 C   s0   t | jrdt| j }nd}d| j| j|S )Nz,
  end= z$Comment(comment={0},
  items={1}{2}))boolr#   strformatr!   r"   )r'   endr(   r(   r)   __str__8   s   
zComment.__str__c                 C      | j S r%   r"   r&   r(   r(   r)   items@      zComment.itemsc                 C   r1   r%   r#   r&   r(   r(   r)   r/   E   r4   zComment.endc                 C   
   || _ d S r%   r5   r'   valuer(   r(   r)   r/   J      
c                 C   r1   r%   r$   r&   r(   r(   r)   startO   r4   zComment.startc                 C   r6   r%   r:   r7   r(   r(   r)   r;   T   r9   N)__name__
__module____qualname__	__slots__r   attribr*   r0   propertyr3   r/   setterr;   r(   r(   r(   r)   r    (   s    




r    c                   C   s   d S r%   r(   r(   r(   r(   r)   	NoComment[      rC   c                   @   s6   e Zd ZdZeZdd Zdd Zdd Zdd	d
Z	dS )Format_flow_stylec                 C   
   d | _ d S r%   rF   r&   r(   r(   r)   r*   d      
zFormat.__init__c                 C   
   d| _ d S NTrF   r&   r(   r(   r)   set_flow_styleh   rI   zFormat.set_flow_stylec                 C   rJ   NFrF   r&   r(   r(   r)   set_block_stylel   rI   zFormat.set_block_styleNc                 C   s   | j du r|S | j S )a  if default (the flow_style) is None, the flow style tacked on to
        the object explicitly will be taken. If that is None as well the
        default flow style rules the format down the line, or the type
        of the constituent values (simple -> flow, map/list -> block)NrF   )r'   defaultr(   r(   r)   
flow_stylep   s   
zFormat.flow_styler%   )
r<   r=   r>   r?   format_attribr@   r*   rL   rN   rP   r(   r(   r(   r)   rE   `   s    rE   c                   @   sH   e Zd ZeZdd Zdd Zdd Zdd Zd	d
 Z	dd Z
dd ZdS )LineColc                 C   s   d | _ d | _d | _d S r%   )linecoldatar&   r(   r(   r)   r*   ~   s   
zLineCol.__init__c                 C      | j d u ri | _ || j |< d S r%   rU   r'   keyrU   r(   r(   r)   add_kv_line_col      
zLineCol.add_kv_line_colc                 C      |  |ddS Nr      _kvr'   kr(   r(   r)   rY         zLineCol.keyc                 C   r\   )N      r_   ra   r(   r(   r)   r8      rc   zLineCol.valuec                 C   s(   | j d u rd S | j | }|| || fS r%   rW   )r'   rb   x0x1rU   r(   r(   r)   r`      s   

zLineCol._kvc                 C   s*   | j d u rd S | j | d | j | d fS r]   rW   r'   idxr(   r(   r)   item   s   
zLineCol.itemc                 C   rV   r%   rW   rX   r(   r(   r)   add_idx_line_col   r[   zLineCol.add_idx_line_colN)r<   r=   r>   line_col_attribr@   r*   rZ   rY   r8   r`   rj   rk   r(   r(   r(   r)   rR   {   s    rR   c                   @   s(   e Zd ZdZdZeZdd Zdd ZdS )Tagz'store tag information for roundtrippingr8   c                 C   rH   r%   rn   r&   r(   r(   r)   r*      rI   zTag.__init__c                 C   s
   d | S )Nz#{0.__class__.__name__}({0.value!r}))r.   r&   r(   r(   r)   __repr__   rI   zTag.__repr__N)	r<   r=   r>   __doc__r?   
tag_attribr@   r*   ro   r(   r(   r(   r)   rm      s    rm   c                   @   s   e Zd Zedd Zd.ddZd.ddZd.dd	Zd/ddZ	d0ddZ	edd Z
edfddZedd Zdd Zdd Zdd Zedd Zdd Zd.d d!Zed"d# Zd$d% Zd.d&d'Zd(d) Zd*d+ Zd,d- ZdS )1CommentedBasec                 C   (   t | tjst| tjt  t| tjS r%   )hasattrr    r@   setattrgetattrr&   r(   r(   r)   ca      zCommentedBase.caFc                 C   s6   |d u rd S |s| j jd u rg | j _| j j| d S r%   )rw   r/   extend)r'   r!   clearr(   r(   r)   yaml_end_comment_extend   s
   z%CommentedBase.yaml_end_comment_extendc                 C   sr   | j j|g d}|s|d d u r(|d d ur!t|d ts!J |d |d< n	|d |d  |d |d< d S )NNNNNr^   r   rw   r"   
setdefault
isinstancelistry   r'   rY   r!   rz   rr(   r(   r)   yaml_key_comment_extend      z%CommentedBase.yaml_key_comment_extendc                 C   sr   | j j|g d}|s|d d u r(|d d ur!t|d ts!J |d |d< n	|d |d  |d |d< d S )Nr|   re   r^   r   rd   r}   r   r(   r(   r)   yaml_value_comment_extend   r   z'CommentedBase.yaml_value_comment_extendr   c                 C   sn   ddl m} ddlm} |  }|d dkr|dd }||}|dD ]}||d| d |d q%dS )zoverwrites any preceding comment lines on an object
        expects comment to be without `#` and possible have multiple lines
        r^   CommentMarkCommentToken
N# )errorr   tokensr   _yaml_get_pre_commentsplitappend)r'   r!   indentr   r   pre_comments
start_markcomr(   r(   r)   yaml_set_start_comment   s   z$CommentedBase.yaml_set_start_commentNc                    s*  ddl m} ddlm   fdd}|du r|d }|r.t|dkr.|d	 d
kr.|dd	 }|r<|d	 d
kr<|dd	 }||}| jj|dg ddg}	|d
kr[|	d |d| n|ro|	d
D ]}
|	d ||
| qb|r||}|	d du rg |	d< |	d
D ]}
|	d ||
| qdS dS )zc
        expects comment (before/after) to be without `#` and possible have multiple lines
        r   r   r   c                    s    | rdnd|  d |d S )Nr   r+   r   r(   )smarkr   r(   r)   comment_token   s   zFCommentedBase.yaml_set_comment_before_after_key.<locals>.comment_tokenNrd   r^   r   r   r+   re   )
ruamel.yaml.errorr   ruamel.yaml.tokensr   lenrw   r3   r~   r   r   )r'   rY   beforer   afterafter_indentr   r   r   cr   r(   r   r)   !yaml_set_comment_before_after_key   s0   z/CommentedBase.yaml_set_comment_before_after_keyc                 C   rs   )z<format attribute

        set_flow_style()/set_block_style())rt   rE   r@   ru   rv   r&   r(   r(   r)   fa  s   zCommentedBase.fac                 C   s   ddl m} ddlm} |du r#z| |}W n ty"   d}Y nw |d dkr-d| }|du r=|d dkr=d| }d}||}|||ddg}| j||d	 dS )
z
        there is a problem as eol comments should start with ' #'
        (but at the beginning of the line the space doesn't have to be before
        the #. The column index is for the # mark
        r^   r   r   Nr   #r    rY   )r   r   r   r   _yaml_get_columnAttributeError_yaml_add_eol_comment)r'   r!   rY   columnr   r   r   ctr(   r(   r)   yaml_add_eol_comment  s"   z"CommentedBase.yaml_add_eol_commentc                 C   rs   r%   )rt   rR   r@   ru   rv   r&   r(   r(   r)   lc0  rx   zCommentedBase.lcc                 C      || j _|| j _d S r%   )r   rS   rT   )r'   rS   rT   r(   r(   r)   _yaml_set_line_col7     z CommentedBase._yaml_set_line_colc                 C      | j || d S r%   )r   rZ   rX   r(   r(   r)   _yaml_set_kv_line_col<     z#CommentedBase._yaml_set_kv_line_colc                 C   r   r%   )r   rk   rX   r(   r(   r)   _yaml_set_idx_line_col@  r   z$CommentedBase._yaml_set_idx_line_colc                 C   rs   r%   )rt   r	   r@   ru   rv   r&   r(   r(   r)   anchorD  rx   zCommentedBase.anchorc                 C   s   t | tjsd S | jS r%   )rt   r	   r@   r   r&   r(   r(   r)   yaml_anchorK  s   zCommentedBase.yaml_anchorc                 C   r   r%   )r   r8   always_dump)r'   r8   r   r(   r(   r)   yaml_set_anchorQ  r   zCommentedBase.yaml_set_anchorc                 C   rs   r%   )rt   rm   r@   ru   rv   r&   r(   r(   r)   tagV  rx   zCommentedBase.tagc                 C   s   || j _d S r%   )r   r8   r7   r(   r(   r)   yaml_set_tag]     zCommentedBase.yaml_set_tagc              	   C   s^   t jtjtjtjtjtfD ]}t| |r,|r#t||t	
t| | qt||t| | qd S r%   )r    r@   rE   rR   r	   rm   r   rt   ru   copydeepcopyrv   )r'   tdeepar(   r(   r)   copy_attributesa  s   
zCommentedBase.copy_attributesc                 C      t r%   NotImplementedErrorr'   r!   rY   r(   r(   r)   r   m  rD   z#CommentedBase._yaml_add_eol_commentc                 C   r   r%   r   r&   r(   r(   r)   r   q  rD   z#CommentedBase._yaml_get_pre_commentc                 C   r   r%   r   r'   rY   r(   r(   r)   r   u  rD   zCommentedBase._yaml_get_column)Fr   )Nr   NN)r<   r=   r>   rA   rw   r{   r   r   r   r   r   rC   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r(   r(   r(   r)   rr      s8    





#
	




rr   c                   @   s   e Zd ZejdfZdd Zdd Zdd Zd&d	d
Z	dd Z
dd Zdd Zdd ZefddZdd Zdd Zdd Zdd Zdd Zdd  Zd'd"d#Zd$d% ZdS )(r   _lstc                 O   s   t j| g|R i | d S r%   )r   r*   r'   argskwr(   r(   r)   r*   }  s   zCommentedSeq.__init__c                 C      t | |S r%   r   __getitem__rh   r(   r(   r)   __getsingleitem__  r   zCommentedSeq.__getsingleitem__c                 C   sP   |t | k rt|trt|tst| | trt| | |}t| || d S r%   )r   r   r   r   typer   __setitem__)r'   ri   r8   r(   r(   r)   __setsingleitem__  s   zCommentedSeq.__setsingleitem__Nc                 C   sV   t | | | jj|d  t| jjD ]}||k rq| jj|| jj|d < qd S Nr^   )r   __delitem__rw   r3   popsorted)r'   ri   
list_indexr(   r(   r)   __delsingleitem__  s   zCommentedSeq.__delsingleitem__c                 C   
   t | S r%   )r   __len__r&   r(   r(   r)   r     rI   zCommentedSeq.__len__c                 C   sP   t | || t| jjddD ]}||k r dS | jj|| jj|d < qdS )z5the comments after the insertion have to move forwardTreverser^   N)r   insertr   rw   r3   r   )r'   ri   valr   r(   r(   r)   r     s   zCommentedSeq.insertc                 C   s   t | | d S r%   )r   ry   )r'   r   r(   r(   r)   ry        zCommentedSeq.extendc                 C   r   r%   )r   __eq__r'   otherr(   r(   r)   r     r   zCommentedSeq.__eq__c                 C   $   |t ur| || d S || j_d S r%   rC   r   rw   r!   r   r(   r(   r)   _yaml_add_comment     zCommentedSeq._yaml_add_commentc                 C      | j ||d d S Nr   r   r   r(   r(   r)   r     r   z"CommentedSeq._yaml_add_eol_commentc                 C      | j j| d jjS Nr   rw   r3   r   r   r   r(   r(   r)   _yaml_get_columnX     zCommentedSeq._yaml_get_columnXc                 C      d }d }|d |d }}|| j jv r|}n!|| j jv r|}nt| D ]\}}||kr- n
|| j jvr4q#|}q#|d ur@| |}|S r   rw   r3   	enumerater   r'   rY   r   sel_idxprepostrow_idx_k1r(   r(   r)   r         
zCommentedSeq._yaml_get_columnc                 C   0   g }| j jd u rd |g| j _|S || j jd< |S r   rw   r!   r'   r   r(   r(   r)   r        z"CommentedSeq._yaml_get_pre_commentc                 C   s@   |   }||t| < | D ]}|t| | j|dd q|S NT)r   )	__class__idr   r   r   r   r'   memoresrb   r(   r(   r)   __deepcopy__  s   zCommentedSeq.__deepcopy__c                 C   r   r%   )r   __add__r   r(   r(   r)   r    r   zCommentedSeq.__add__Fc                    s   |d u rt t tt |d}t dd |D  n t tt|t tt |d}t  fdd|D   jj	}i  j_
t|D ]\}}|d }||v r]||  jj	|< qId S )Nr   c                 S   s   g | ]}|d  qS r   r(   .0xr(   r(   r)   
<listcomp>  s    z%CommentedSeq.sort.<locals>.<listcomp>c                    s   g | ]
}t  |d  qS )r^   r   r  r&   r(   r)   r    s    r^   )r   zipranger   r   r*   map__iter__rw   r3   r"   r   )r'   rY   r   tmp_lstitmri   r  	old_indexr(   r&   r)   sort  s   zCommentedSeq.sortc                 C   r   r%   )r   ro   r&   r(   r(   r)   ro     rI   zCommentedSeq.__repr__r%   rM   )r<   r=   r>   r    r@   r?   r*   r   r   r   r   r   ry   r   rC   r   r   r   r   r   r  r  r  ro   r(   r(   r(   r)   r   z  s&    

				
r   c                   @   s<   e Zd ZdZefddZdd Zdd Zdd	 Zd
d Z	dS )r   zEThis primarily exists to be able to roundtrip keys that are sequencesc                 C   r   r%   r   r   r(   r(   r)   r     r   z!CommentedKeySeq._yaml_add_commentc                 C   r   r   r   r   r(   r(   r)   r   	  r   z%CommentedKeySeq._yaml_add_eol_commentc                 C   r   r   r   r   r(   r(   r)   r     r   z!CommentedKeySeq._yaml_get_columnXc                 C   r   r   r   r   r(   r(   r)   r     r   z CommentedKeySeq._yaml_get_columnc                 C   r   r   r   r   r(   r(   r)   r   &  r   z%CommentedKeySeq._yaml_get_pre_commentN)
r<   r=   r>   rp   rC   r   r   r   r   r   r(   r(   r(   r)   r     s    r   c                   @       e Zd ZdZdd Zdd ZdS )CommentedMapView_mappingc                 C   r6   r%   r  )r'   mappingr(   r(   r)   r*   3  rI   zCommentedMapView.__init__c                 C   s   t | j}|S r%   )r   r  )r'   countr(   r(   r)   r   7  s   
zCommentedMapView.__len__N)r<   r=   r>   r?   r*   r   r(   r(   r(   r)   r  0  s    r  c                   @   ,   e Zd ZdZedd Zdd Zdd ZdS )	CommentedMapKeysViewr(   c                 C      t |S r%   setr'   itr(   r(   r)   _from_iterable@     z#CommentedMapKeysView._from_iterablec                 C   
   || j v S r%   r  r   r(   r(   r)   __contains__E  rI   z!CommentedMapKeysView.__contains__c                 c       | j D ]}|V  qd S r%   r  r'   r  r(   r(   r)   r  I  s   
zCommentedMapKeysView.__iter__Nr<   r=   r>   r?   classmethodr  r   r  r(   r(   r(   r)   r  =  s    
r  c                   @   r  )	CommentedMapItemsViewr(   c                 C   r  r%   r  r  r(   r(   r)   r  S  r  z$CommentedMapItemsView._from_iterablec                 C   s2   |\}}z
| j | }W ||kS  ty   Y dS w rM   )r  KeyError)r'   rj   rY   r8   vr(   r(   r)   r   X  s   z"CommentedMapItemsView.__contains__c                 c   s&    | j  D ]
}|| j | fV  qd S r%   r  _keysr   r(   r(   r)   r  b  s   zCommentedMapItemsView.__iter__Nr#  r(   r(   r(   r)   r%  P  s    

r%  c                   @   r  )CommentedMapValuesViewr(   c                 C   s$   | j D ]}|| j | kr dS qdS )NTFr  )r'   r8   rY   r(   r(   r)   r   k  s
   
z#CommentedMapValuesView.__contains__c                 c   s"    | j  D ]}| j | V  qd S r%   r(  r   r(   r(   r)   r  r  s   zCommentedMapValuesView.__iter__N)r<   r=   r>   r?   r   r  r(   r(   r(   r)   r*  h  s    r*  c                   @   s  e Zd ZejddfZdd ZeefddZdd Z	d	d
 Z
dd Zdd Zdd ZdTddZdUddZdd Zdd Zdd Zdd ZdTdd Zd!d" Zd#d$ Zd%d& Zd'd( Zd)d* Zd+d, Zd-d. Zersd/d0 Zd1d2 Zd3d4 Znd5d0 Zerd6d7 Z d8d9 Z!d:d; Z"d<d= Z#nd>d9 Z!d?d@ Z$erdAdB Z%dCdD Z&dEdF Z'ndGdB Z%e(dHdI Z)dJdK Z*dLdM Z+dNdO Z,dPdQ Z-dRdS Z.dS )Vr   _ok_refc                 O   s*   t  | _g | _tj| g|R i | d S r%   )r  r+  r,  r   r*   r   r(   r(   r)   r*   {  s   zCommentedMap.__init__c                 C   <   |t ur| || dS |t ur| || dS || j_dS z>values is set to key to indicate a value attachment of commentNrC   r   r   rw   r!   r'   r!   rY   r8   r(   r(   r)   r        zCommentedMap._yaml_add_commentc                 C      | j ||d dS z6add on the value line, with value specified by the keyrn   Nr   r   r(   r(   r)   r        z"CommentedMap._yaml_add_eol_commentc                 C   r   )Nrd   r   r   r(   r(   r)   r     r   zCommentedMap._yaml_get_columnXc           	      C   s   d }d }d\}}}| D ]}|d ur||kr|} n	||kr|}|}q|| j jv r+|}n|| j jv r4|}n| D ]}||kr> n
|| j jvrEq6|}q6|d urQ| |}|S )N)NNN)rw   r3   r   )	r'   rY   r   r   r   r   lastr  k1r(   r(   r)   r     s.   

zCommentedMap._yaml_get_columnc                 C   r   r   r   r   r(   r(   r)   r     r   z"CommentedMap._yaml_get_pre_commentc                 C   s   zt | | W n ty   |D ]}|| | |< qY nw z| j|  W d S  ty?   |D ]
}| j|d  q1Y d S w r   )r   update	TypeErrorr+  keysr   add)r'   valsr  r(   r(   r)   r7    s   zCommentedMap.updateNc                 C   s:   t | ||| | j| |dur| j||d dS dS )zPinsert key value into given position
        attach comment if provided
        Nr   )r   r   r+  r:  r   )r'   posrY   r8   r!   r(   r(   r)   r     s
   zCommentedMap.insertFc              	      sh   t |ts| ||S  fdd z |d| W S  ty$   | Y S  ttfy3   s/ | Y S w )z/multi-level get that expects dicts within dictsc                    sZ   s	t |ts	J |t| kr|t| krt|| |d   S  | |d || |d   S r   )r   dictr   
IndexError)key_listleveldget_one_levellist_okr(   r)   rC    s   z)CommentedMap.mlget.<locals>.get_one_levelr^   )r   r   getr&  r8  r>  )r'   rY   rO   rD  r(   rB  r)   mlget  s   

zCommentedMap.mlgetc                 C   sR   zt | |W S  ty(   t| tg D ]}||d v r&|d |    Y S q w r   )r   r   r&  rv   r   )r'   rY   mergedr(   r(   r)   r     s   zCommentedMap.__getitem__c                 C   sX   || v rt |trt |tst | | trt| | |}t| || | j| d S r%   )r   r   r   r   r   r   r+  r:  )r'   rY   r8   r(   r(   r)   r     s   zCommentedMap.__setitem__c                 C   s   || j v rdS d S rK   )r+  r   r(   r(   r)   _unmerged_contains  s   
zCommentedMap._unmerged_containsc                 C      t t| |S r%   )r,   r   r   r   r(   r(   r)   r   
  r   zCommentedMap.__contains__c                 C   s   z|  |W S    | Y S r%   )r   )r'   rY   rO   r(   r(   r)   rE    s   zCommentedMap.getc                 C   s   t | ddS )Nr   r   )r   ro   replacer&   r(   r(   r)   ro     r   zCommentedMap.__repr__c                 c   s2    t | D ]}|| jv r|t | |fV  qd S r%   )r   r  r+  r   r"  r(   r(   r)   non_merged_items  s   
zCommentedMap.non_merged_itemsc                 C   s2   | j | t| | | jD ]}|| qd S r%   )r+  discardr   r   r,  update_key_value)r'   rY   refererr(   r(   r)   r     s
   
zCommentedMap.__delitem__c                 c       t | D ]}|V  qd S r%   r   r  r"  r(   r(   r)   r  3     zCommentedMap.__iter__c                 c   rO  r%   rP  r"  r(   r(   r)   r)  8  rQ  zCommentedMap._keysc                 C   r   r%   )r   r   r&   r(   r(   r)   r   =  rI   zCommentedMap.__len__c                 C   s   t t| |kS r%   )r,   r=  r   r(   r(   r)   r   A  r   zCommentedMap.__eq__c                 C      t |  S r%   )r   r)  r&   r(   r(   r)   r9  G  r   zCommentedMap.keysc                 C      |   S r%   )r)  r&   r(   r(   r)   iterkeysK     zCommentedMap.iterkeysc                 C      t | S r%   r  r&   r(   r(   r)   viewkeysO  rU  zCommentedMap.viewkeysc                 C   rV  r%   rW  r&   r(   r(   r)   r9  U  rU  c                 c   s$    t | D ]	}t | |V  qd S r%   r   r  r   r"  r(   r(   r)   _values[  s   zCommentedMap._valuesc                 C   rR  r%   )r   rZ  r&   r(   r(   r)   values`  r   zCommentedMap.valuesc                 C   rS  r%   )rZ  r&   r(   r(   r)   
itervaluesd  rU  zCommentedMap.itervaluesc                 C   rV  r%   r*  r&   r(   r(   r)   
viewvaluesh  rU  zCommentedMap.viewvaluesc                 C   rV  r%   r]  r&   r(   r(   r)   r[  n  rU  c                 c   s(    t | D ]}|t | |fV  qd S r%   rY  r"  r(   r(   r)   r"   r  s   zCommentedMap._itemsc                 C   rR  r%   )r   r"   r&   r(   r(   r)   r3   y  r   zCommentedMap.itemsc                 C   rS  r%   r2   r&   r(   r(   r)   	iteritems}  rU  zCommentedMap.iteritemsc                 C   rV  r%   r%  r&   r(   r(   r)   	viewitems  rU  zCommentedMap.viewitemsc                 C   rV  r%   r`  r&   r(   r(   r)   r3     rU  c                 C   s    t | tst| tg  t| tS r%   )rt   r   ru   rv   r&   r(   r(   r)   merge  s   

zCommentedMap.mergec                 C   s2   t |  }|  D ]\}}|||< q	| | |S r%   )r   r"   r   )r'   r  rb   r'  r(   r(   r)   r     s
   


zCommentedMap.copyc                 C   s   || j vr| j | d S d S r%   )r,  r   )r'   cmr(   r(   r)   add_referent  s   
zCommentedMap.add_referentc                 C   sZ   |D ]"}|d  |  |d  D ]\}}t| |rqt| || qq| j| d S r   )rd  r3   r   r   r   rb  ry   )r'   r8   r'  rb   r(   r(   r)   add_yaml_merge  s   zCommentedMap.add_yaml_mergec                 C   sR   || j v rd S | jD ]}||d v r t| ||d |   d S q
t| | d S r   )r+  rb  r   r   r   )r'   rY   r'  r(   r(   r)   rM    s   

zCommentedMap.update_key_valuec                 C   sB   |   }||t| < | D ]}t| | ||< q| j|dd |S r   )r   r   r   r   r   r   r(   r(   r)   r    s   zCommentedMap.__deepcopy__r%   rM   )/r<   r=   r>   r    r@   r?   r*   rC   r   r   r   r   r   r7  r   rF  r   r   rH  r   rE  ro   rK  r   r  r)  r   r   r   r9  rT  rX  rZ  r[  r\  r^  r"   r3   r_  ra  rA   rb  r   rd  re  rM  r  r(   r(   r(   r)   r   x  s^    	










r   c                 O   s   t d| j)Nz{} objects are immutable)r8  r.   r<   )clsr   kwargsr(   r(   r)   raise_immutable     rh  c                   @   s   e Zd ZejdfZ	 dd Ze Z Z	 Z
 Z Z ZZdd Zdd Zdd	 Zd
d Zdd ZedddZefddZdd Zdd Zdd Zdd ZdS )CommentedKeyMap_odc                 O   sV   t | dr	t|  zt|i || _W d S  ty*   tr)t|d  | _Y d S  w )Nrk  r   )rt   rh  r   rk  r8  r   r3   r   r(   r(   r)   r*     s   
zCommentedKeyMap.__init__c                 C   s
   | j | S r%   )rk  )r'   indexr(   r(   r)   r     rI   zCommentedKeyMap.__getitem__c                 c   s    | j  D ]}|V  qd S r%   )rk  r  r"  r(   r(   r)   r    rQ  zCommentedKeyMap.__iter__c                 C   
   t | jS r%   )r   rk  r&   r(   r(   r)   r     rI   zCommentedKeyMap.__len__c                 C   s   t t|  S r%   )hashtupler3   r&   r(   r(   r)   __hash__  r   zCommentedKeyMap.__hash__c                 C   s.   t | ts
| j S dtt| j  d S )Nzordereddict())rt   r   rk  ro   reprr   r3   r&   r(   r(   r)   ro     s   

zCommentedKeyMap.__repr__Nc                 C   rI  r%   )rj  r=  fromkeys)r9  r'  r(   r(   r)   rs    ri  zCommentedKeyMap.fromkeysc                 C   r   r%   r   r   r(   r(   r)   r     r   z!CommentedKeyMap._yaml_add_commentc                 C   r   r   r   r   r(   r(   r)   r     r   z%CommentedKeyMap._yaml_add_eol_commentc                 C   r   r   r   r   r(   r(   r)   r     r   z!CommentedKeyMap._yaml_get_columnXc                 C   r   r   r   r   r(   r(   r)   r     r   z CommentedKeyMap._yaml_get_columnc                 C   r   r   r   r   r(   r(   r)   r     r   z%CommentedKeyMap._yaml_get_pre_commentr%   )r<   r=   r>   r    r@   r?   r*   rh  r   r   rz   r   popitemr~   r7  r   r  r   rp  ro   r$  rs  rC   r   r   r   r   r   r(   r(   r(   r)   rj    s"    
rj  c                   @   s   e Zd ZejfZdS )r   N)r<   r=   r>   r    r@   r?   r(   r(   r(   r)   r   !  s    r   c                   @   sf   e Zd ZejdfZdddZeef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S )r   odictNc                 C   s*   t  | _t|  |d ur| |O } d S d S r%   )r   ru  r
   r*   )r'   r[  r(   r(   r)   r*   (  s
   
zCommentedSet.__init__c                 C   r-  r.  r/  r0  r(   r(   r)   r   /  r1  zCommentedSet._yaml_add_commentc                 C   r2  r3  r   r   r(   r(   r)   r   :  r4  z"CommentedSet._yaml_add_eol_commentc                 C   s   d| j |< dS )zAdd an element.Nru  r7   r(   r(   r)   r:  ?  s   zCommentedSet.addc                 C   s   | j |= dS )z8Remove an element.  Do not raise an exception if absent.Nrv  r7   r(   r(   r)   rL  D  s   zCommentedSet.discardc                 C   r  r%   rv  r"  r(   r(   r)   r   I  rI   zCommentedSet.__contains__c                 c   r!  r%   rv  r"  r(   r(   r)   r  M  s   
zCommentedSet.__iter__c                 C   rm  r%   )r   ru  r&   r(   r(   r)   r   R  rI   zCommentedSet.__len__c                 C   s   d | j S )Nz
set({0!r}))r.   ru  r9  r&   r(   r(   r)   ro   V  r   zCommentedSet.__repr__r%   )r<   r=   r>   r    r@   r?   r*   rC   r   r   r:  rL  r   r  r   ro   r(   r(   r(   r)   r   %  s    

r   c                   @   s   e Zd Zdd Zdd ZdS )TaggedScalarc                 C   s   d | _ d | _d S r%   )r8   styler&   r(   r(   r)   r*   ]  s   
zTaggedScalar.__init__c                 C   r1   r%   rn   r&   r(   r(   r)   r0   b  s   zTaggedScalar.__str__N)r<   r=   r>   r*   r0   r(   r(   r(   r)   rw  [  s    rw  r+   .c                 C   s   t | tr7t| dr7|rtjd| |d| j | D ]}t| | |r.|| | n|||d q dS t | t	rrt| drt|rLtjd| |d| j t
| D ]\}}t||ri|| t| nt|||d qYdS dS dS )zg
    recursively dump comments, all but the toplevel preceded by the path
    in dotted form x.0.a
    rw   z{}
)namesepoutN)r   r=  rt   sysstdoutwriter.   rw   dump_commentsr   r   r-   )rA  rz  r{  r|  rb   ri   r(   r(   r)   r  g  s"   & r  )9
__future__r   r   r}  r   ruamel.yaml.compatr   r   r   r   ruamel.yaml.scalarstringr   ruamel.yaml.anchorr	   collectionsr
   r   r   r   collections.abctypingr   r   r   r   r   r   __all__r   rQ   rl   r   rq   objectr    rC   rE   rR   rm   rr   r   r   ro  r   r  r  r%  r*  r   r$  rh  rj  r   r   rw  r~  r  r(   r(   r(   r)   <module>   sR   3+ F 1  H
]6