o
    h!                     @   s*  d Z ddlZddlZddlmZ ddlmZmZmZ ddlm	Z	 ddl
mZ ddlmZmZmZmZ 	 g d
ZdZdZdZdZG dd dZe Ze  ZZ e Z!e  Z"Z#e  Z$Z%e Z&e Z'e Z(e Z)e Z*e Z+e Z,e Z-dZ.dZ/dZ0dZ1dZ2G dd dZ3dd Z4G dd dZ5G dd dZ6G dd dZ7G dd  d Z8G d!d" d"ee9e8Z:G d#d$ d$e;e8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e8ZAeBd/d0 ZCG d1d2 d2e8eZDG d3d4 d4eAZEG d5d6 d6ee8ZFG d7d8 d8e8ZGd9d:ejHfd;d<ZIdS )=z
stuff to deal with comments and formatting on dict/list/ordereddict/set
these are not really related, formatting could be factored out as
a separate base
    N)ordereddict)MutableSliceableSequence_Fnprintf)ScalarString)Anchor)
MutableSetSizedSetMappingF)AnyDictOptionalListUnionr   Iterator)CommentedSeqCommentedKeySeqCommentedMapCommentedOrderedMapCommentedSetcomment_attribmerge_attribC_POSTC_PREC_SPLIT_ON_FIRST_BLANKC_BLANK_LINE_PRESERVE_SPACE         c                   @   s$   e Zd Zdd Zdd Zdd ZdS )IDXc                 C   
   d| _ d S Nr   _idxself r'   \/var/www/html/magazine_api/magazine_env/lib/python3.10/site-packages/ruamel/yaml/comments.py__init__1      
zIDX.__init__c                 C   s   | j }|  j d7  _ |S Nr   r#   r&   xr'   r'   r(   __call__5   s   zIDX.__call__c                 C   
   t | jS N)strr$   r%   r'   r'   r(   __str__;   r*   zIDX.__str__N)__name__
__module____qualname__r)   r.   r2   r'   r'   r'   r(   r    /   s    r    Z_yaml_commentZ_yaml_formatZ_yaml_line_colZ_yaml_mergeZ	_yaml_tagc                   @   s   e Zd ZdZeZdddZdd 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d Zdd Zdd ZdS )Comment)comment_items_post_preTc                 C   s$   |rd ng | _ d | _i | _g | _d S r0   )r:   r7   r8   r9   )r&   oldr'   r'   r(   r)   _   s   
zComment.__init__c                 C   s0   t | jrdt| j }nd}d| j| j|S )N,
  end= z$Comment(comment={0},
  items={1}{2}))boolr9   r1   formatr7   r8   )r&   endr'   r'   r(   r2   j   s   
zComment.__str__c                    s   t | jrdt| j }nd}ztdd | jD d  W n ty(   d Y nw d fdd| j D }|r@d| d	 }d
| j	||S )Nr<   r=   c                 S      g | ]}t t|qS r'   lenr1   .0kr'   r'   r(   
<listcomp>y       z(Comment._old__repr__.<locals>.<listcomp>r       c                    &   g | ]\}}d  t|d  |qS z	{:{}} {}
:r?   r1   rE   rF   vlnr'   r(   rG   }      & 
      z&Comment(
  start={},
  items={{{}}}{}))
r>   r9   r1   maxr8   
ValueErrorjoinitemsr?   r7   r&   r@   itr'   rP   r(   _old__repr__r   s   
zComment._old__repr__c                    s   | j d u r	|  S t| jrdt| j }nd}ztdd | jD d  W n ty1   d Y nw d fdd| j	 D }|rId| d	 }d

| j||S )Nr<   r=   c                 S   rA   r'   rB   rD   r'   r'   r(   rG      rH   z$Comment.__repr__.<locals>.<listcomp>r   rI   c                    rJ   rK   rM   rN   rP   r'   r(   rG      rR   rS   rT   z$Comment(
  pre={},
  items={{{}}}{}))r:   r[   r>   r9   reprrU   r8   rV   rW   rX   r?   prerY   r'   rP   r(   __repr__   s    

zComment.__repr__c                 C      | j S r0   )r8   r%   r'   r'   r(   rX         zComment.itemsc                 C   r_   r0   r9   r%   r'   r'   r(   r@      r`   zComment.endc                 C   
   || _ d S r0   ra   r&   valuer'   r'   r(   r@         
c                 C   r_   r0   r:   r%   r'   r'   r(   r]      r`   zComment.prec                 C   rb   r0   rf   rc   r'   r'   r(   r]      re   c                 C   s,   | j |}|d u st||k rd S || S r0   )r8   getrC   )r&   itemposr-   r'   r'   r(   rg      s   zComment.getc                 C   sl   | j |}|d u rd g|d   | j |< }nt||kr(|d  t||ks|| d u s0J |||< d S r+   )r8   rg   rC   append)r&   rh   ri   rd   r-   r'   r'   r(   set   s   
zComment.setc                 C   s   | j r'| j d r|| j d jv rdS | j d r'| j d D ]
}||jv r& dS q| j D ]}|s1q,|D ]}|r@||jv r@  dS q3q,| jrS| jD ]
}||jv rR dS qHdS )Nr   Tr   F)r7   rd   rX   valuesr@   )r&   r-   crd   r'   r'   r(   __contains__   s,   



zComment.__contains__N)T)r3   r4   r5   	__slots__r   attribr)   r2   r[   r^   propertyrX   r@   setterr]   rg   rk   rn   r'   r'   r'   r(   r6   Y   s(    





r6   c                   C   s   d S r0   r'   r'   r'   r'   r(   	NoComment      rs   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Z_flow_stylec                 C   
   d | _ d S r0   rv   r%   r'   r'   r(   r)      r*   zFormat.__init__c                 C   r!   NTrv   r%   r'   r'   r(   set_flow_style   r*   zFormat.set_flow_stylec                 C   r!   NFrv   r%   r'   r'   r(   set_block_style   r*   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)Nrv   )r&   defaultr'   r'   r(   
flow_style   s   
zFormat.flow_styler0   )
r3   r4   r5   ro   format_attribrp   r)   ry   r{   r}   r'   r'   r'   r(   ru      s    ru   c                   @   sT   e Zd 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d ZdS )LineColzL
    line and column information wrt document, values start at zero (0)
    c                 C   s   d | _ d | _d | _d S r0   )linecoldatar%   r'   r'   r(   r)      s   
zLineCol.__init__c                 C      | j d u ri | _ || j |< d S r0   r   r&   keyr   r'   r'   r(   add_kv_line_col     
zLineCol.add_kv_line_colc                 C      |  |ddS Nr   r   _kvr&   rF   r'   r'   r(   r        zLineCol.keyc                 C   r   )Nr      r   r   r'   r'   r(   rd     r   zLineCol.valuec                 C   s(   | j d u rd S | j | }|| || fS r0   r   )r&   rF   Zx0x1r   r'   r'   r(   r     s   

zLineCol._kvc                 C   s*   | j d u rd S | j | d | j | d fS r   r   r&   idxr'   r'   r(   rh     s   
zLineCol.itemc                 C   r   r0   r   r   r'   r'   r(   add_idx_line_col!  r   zLineCol.add_idx_line_colc                 C   s   t d| j| jdS )NzLineCol({line}, {col}))r   r   )r   r   r   r%   r'   r'   r(   r^   '     zLineCol.__repr__N)r3   r4   r5   __doc__line_col_attribrp   r)   r   r   rd   r   rh   r   r^   r'   r'   r'   r(   r      s    r   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rd   c                 C   rw   r0   r   r%   r'   r'   r(   r)   2  r*   zTag.__init__c                 C   s
   d | S )Nz#{0.__class__.__name__}({0.value!r}))r?   r%   r'   r'   r(   r^   6  r*   zTag.__repr__N)	r3   r4   r5   r   ro   
tag_attribrp   r)   r^   r'   r'   r'   r(   r   ,  s    r   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d1d&d'Zd(d) Zd*d+ Zd,d- ZdS )2CommentedBasec                 C   (   t | tjst| tjt  t| tjS r0   )hasattrr6   rp   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 r0   )r   r@   extend)r&   r7   clearr'   r'   r(   yaml_end_comment_extendC  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   r   r8   
setdefault
isinstancelistr   r&   r   r7   r   rr'   r'   r(   yaml_key_comment_extendK     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   r   r   r   r   r   r   r'   r'   r(   yaml_value_comment_extendV  r   z'CommentedBase.yaml_value_comment_extendr   c           	      C   s   ddl m} ddlm} |  }|d dkr|dd }||}|dD ] }| }t|dkr;|d dkr;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
Nr   ## )	errorr   tokensr   _yaml_clear_pre_commentsplitstriprC   rj   )	r&   r7   indentr   r   pre_comments
start_markcomrm   r'   r'   r(   yaml_set_start_commenta  s   z$CommentedBase.yaml_set_start_commentNc                    sB  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ur{|	d du rZg |	d< |d
kri|	d |d| n|	d
D ]}
|	d ||
| qn|r||}|	d du rg |	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 |S )Nr   r=   r   r'   )smarkr   r'   r(   comment_token}  s   zFCommentedBase.yaml_set_comment_before_after_key.<locals>.comment_tokenNr   r   r   r   r=   r   )
Zruamel.yaml.errorr   Zruamel.yaml.tokensr   rC   r   rX   r   rj   r   )r&   r   beforer   afterZafter_indentr   r   r   rm   r   r'   r   r(   !yaml_set_comment_before_after_keys  s4   z/CommentedBase.yaml_set_comment_before_after_keyc                 C   r   )z<format attribute

        set_flow_style()/set_block_style())r   ru   rp   r   r   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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   r    r   )r   r   r   r   _yaml_get_columnAttributeError_yaml_add_eol_comment)r&   r7   r   columnr   r   r   ctr'   r'   r(   yaml_add_eol_comment  s"   z"CommentedBase.yaml_add_eol_commentc                 C   r   r0   )r   r   rp   r   r   r%   r'   r'   r(   lc  r   zCommentedBase.lcc                 C      || j _|| j _d S r0   )r   r   r   )r&   r   r   r'   r'   r(   _yaml_set_line_col     z CommentedBase._yaml_set_line_colc                 C      | j || d S r0   )r   r   r   r'   r'   r(   _yaml_set_kv_line_col  r   z#CommentedBase._yaml_set_kv_line_colc                 C   r   r0   )r   r   r   r'   r'   r(   _yaml_set_idx_line_col  r   z$CommentedBase._yaml_set_idx_line_colc                 C   r   r0   )r   r   rp   r   r   r%   r'   r'   r(   anchor  r   zCommentedBase.anchorc                 C   s   t | tjsd S | jS r0   )r   r   rp   r   r%   r'   r'   r(   yaml_anchor  s   zCommentedBase.yaml_anchorc                 C   r   r0   )r   rd   always_dump)r&   rd   r   r'   r'   r(   yaml_set_anchor  r   zCommentedBase.yaml_set_anchorc                 C   r   r0   )r   r   rp   r   r   r%   r'   r'   r(   tag  r   zCommentedBase.tagc                 C   s   || j _d S r0   )r   rd   rc   r'   r'   r(   yaml_set_tag     zCommentedBase.yaml_set_tagc              
   C   sd   t jtjtjtjtjtfD ]"}t| |r/|d ur&t||t	
t| || qt||t| | qd S r0   )r6   rp   ru   r   r   r   r   r   r   copydeepcopyr   )r&   tmemoar'   r'   r(   copy_attributes  s   
zCommentedBase.copy_attributesc                 C      t r0   NotImplementedErrorr&   r7   r   r'   r'   r(   r     rt   z#CommentedBase._yaml_add_eol_commentc                 C   r   r0   r   r%   r'   r'   r(   _yaml_get_pre_comment  rt   z#CommentedBase._yaml_get_pre_commentc                 C   r   r0   r   r&   r   r'   r'   r(   r     rt   zCommentedBase._yaml_get_column)Fr   )Nr   NNr0   )r3   r4   r5   rq   r   r   r   r   r   r   r   rs   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r'   r'   r'   r(   r   ;  s8    





&
	




r   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" Zd)d$d%Zd&d' ZdS )*r   Z_lstc                 O   s   t j| g|R i | d S r0   )r   r)   r&   argskwr'   r'   r(   r)   	  s   zCommentedSeq.__init__c                 C      t | |S r0   r   __getitem__r   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 r0   )rC   r   r1   r   typer   __setitem__)r&   r   rd   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 r+   )r   __delitem__r   rX   popsorted)r&   r   
list_indexr'   r'   r(   __delsingleitem__  s   zCommentedSeq.__delsingleitem__c                 C   
   t | S r0   )r   __len__r%   r'   r'   r(   r   &  r*   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   r   rX   r   )r&   r   valr   r'   r'   r(   r   *  s   zCommentedSeq.insertc                 C   s   t | | d S r0   )r   r   )r&   r   r'   r'   r(   r   3     zCommentedSeq.extendc                 C   r   r0   )r   __eq__r&   otherr'   r'   r(   r   7  r   zCommentedSeq.__eq__c                 C   $   |t ur| || d S || j_d S r0   rs   r   r   r7   r   r'   r'   r(   _yaml_add_comment;     zCommentedSeq._yaml_add_commentc                 C      | j ||d d S Nr   r  r   r'   r'   r(   r   B  r   z"CommentedSeq._yaml_add_eol_commentc                 C      | j j| d jjS r"   r   rX   r   r   r   r'   r'   r(   _yaml_get_columnXF     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+   r   rX   	enumerater  r&   r   r   sel_idxr]   postZrow_idxZ_k1r'   r'   r(   r   J      
zCommentedSeq._yaml_get_columnc                 C   0   g }| j jd u rd |g| j _|S | j jd }|S r+   r   r7   r&   r   r'   r'   r(   r   _     z"CommentedSeq._yaml_get_pre_commentc                 C   0   g }| j jd u rd |g| j _|S || j jd< |S r+   r  r  r'   r'   r(   r   h  r  z$CommentedSeq._yaml_clear_pre_commentc                 C   sB   |   }||t| < | D ]}|t|| | j||d q|S N)r   )	__class__idrj   r   r   r   r&   r   resrF   r'   r'   r(   __deepcopy__q  s   zCommentedSeq.__deepcopy__c                 C   r   r0   )r   __add__r  r'   r'   r(   r   z  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'   rE   r-   r'   r'   r(   rG     s    z%CommentedSeq.sort.<locals>.<listcomp>c                    s   g | ]
}t  |d  qS )r   r   r!  r%   r'   r(   rG     s    r   )r   ziprangerC   r   r)   map__iter__r   rX   r8   r  )r&   r   r   Ztmp_lstZitmr   r-   Z	old_indexr'   r%   r(   sort~  s   zCommentedSeq.sortc                 C   r   r0   )r   r^   r%   r'   r'   r(   r^     r*   zCommentedSeq.__repr__r0   rz   )r3   r4   r5   r6   rp   ro   r)   r   r   r   r   r   r   r   rs   r  r   r  r   r   r   r  r   r&  r^   r'   r'   r'   r(   r     s(    

					
r   c                   @   sD   e Zd ZdZefddZ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  r0   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_commentc                 C   r  r+   r  r  r'   r'   r(   r     r  z'CommentedKeySeq._yaml_clear_pre_commentN)r3   r4   r5   r   rs   r  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   rb   r0   r)  )r&   mappingr'   r'   r(   r)     r*   zCommentedMapView.__init__c                 C   s   t | j}|S r0   )rC   r*  )r&   countr'   r'   r(   r     s   
zCommentedMapView.__len__N)r3   r4   r5   ro   r)   r   r'   r'   r'   r(   r(    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 r0   rk   r&   rZ   r'   r'   r(   _from_iterable     z#CommentedMapKeysView._from_iterablec                 C   
   || j v S r0   r)  r   r'   r'   r(   rn     r*   z!CommentedMapKeysView.__contains__c                 c       | j D ]}|V  qd S r0   r)  r,   r'   r'   r(   r%    s   
zCommentedMapKeysView.__iter__Nr3   r4   r5   ro   classmethodr2  rn   r%  r'   r'   r'   r(   r.    s    
r.  c                   @   r-  )	CommentedMapItemsViewr'   c                 C   r/  r0   r0  r1  r'   r'   r(   r2    r3  z$CommentedMapItemsView._from_iterablec                 C   s2   |\}}z
| j | }W ||kS  ty   Y dS w rz   )r*  KeyError)r&   rh   r   rd   rO   r'   r'   r(   rn     s   z"CommentedMapItemsView.__contains__c                 c   s&    | j  D ]
}|| j | fV  qd S r0   r*  _keysr   r'   r'   r(   r%     s   zCommentedMapItemsView.__iter__Nr6  r'   r'   r'   r(   r8    s    

r8  c                   @   r'  )CommentedMapValuesViewr'   c                 C   s$   | j D ]}|| j | kr dS qdS )NTFr)  )r&   rd   r   r'   r'   r(   rn   	  s
   
z#CommentedMapValuesView.__contains__c                 c   s"    | j  D ]}| j | V  qd S r0   r:  r   r'   r'   r(   r%    s   zCommentedMapValuesView.__iter__N)r3   r4   r5   ro   rn   r%  r'   r'   r'   r(   r<    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dd ZdEddZdFddZdd Zdd Zdd Zdd  ZdEd!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d3d4 Zd5d6 Zd7d8 Z e!d9d: Z"d;d< Z#d=d> Z$d?d@ Z%dAdB Z&dCdD Z'dS )Gr   _ok_refc                 O   s*   t  | _g | _tj| g|R i | d S r0   )rk   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rs   r   r   r   r7   r&   r7   r   rd   r'   r'   r(   r       zCommentedMap._yaml_add_commentc                 C      | j ||d dS z6add on the value line, with value specified by the keyr   Nr	  r   r'   r'   r(   r   *     z"CommentedMap._yaml_add_eol_commentc                 C   r
  )Nr   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)r   rX   r  )	r&   r   r   r  r]   r  lastr-   Zk1r'   r'   r(   r   3  s.   

zCommentedMap._yaml_get_columnc                 C   r  r+   r  r  r'   r'   r(   r   O  r  z"CommentedMap._yaml_get_pre_commentc                 C   r  r+   r  r  r'   r'   r(   r   X  r  z$CommentedMap._yaml_clear_pre_commentc                 O   s   zt j| g|R i | W n ty&   |d D ]
}|d | | |< qY nw |rNz| j|d   W n tyM   |d D ]
}| j|d  q@Y nw |rZ| jj|   d S d S r"   )r   update	TypeErrorr=  keysr   add)r&   valsr   r-   r'   r'   r(   rI  a  s$   zCommentedMap.updateNc                 C   sv   t |  |g }t| ||| |D ]}| j| q| jD ]}|D ]}|| q#q|dur9| j||d dS dS )zPinsert key value into given position
        attach comment if provided
        Nr   )	r   rK  r   r   r=  rL  r>  update_key_valuer   )r&   ri   r   rd   r7   rK  Zkeytmprefererr'   r'   r(   r   s  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   dictrC   
IndexError)Zkey_listleveldget_one_levellist_okr'   r(   rU    s   z)CommentedMap.mlget.<locals>.get_one_levelr   )r   r   rg   r9  rJ  rQ  )r&   r   r|   rV  r'   rT  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   r9  r   r   )r&   r   Z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 r0   )r   r1   r   r   r   r   r=  rL  )r&   r   rd   r'   r'   r(   r     s   zCommentedMap.__setitem__c                 C   s   || j v rdS d S rx   )r=  r   r'   r'   r(   _unmerged_contains  s   
zCommentedMap._unmerged_containsc                 C      t t| |S r0   )r>   r   rn   r   r'   r'   r(   rn     r   zCommentedMap.__contains__c                 C   s   z|  |W S    | Y S r0   )r   )r&   r   r|   r'   r'   r(   rg     s   zCommentedMap.getc                 C   s   t | ddS )Nr   r   )r   r^   replacer%   r'   r'   r(   r^     r   zCommentedMap.__repr__c                 c   s2    t | D ]}|| jv r|t | |fV  qd S r0   )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 r0   )r=  discardr   r   r>  rN  )r&   r   rO  r'   r'   r(   r     s
   
zCommentedMap.__delitem__c                 c       t | D ]}|V  qd S r0   r   r%  r,   r'   r'   r(   r%       zCommentedMap.__iter__c                 c   r]  r0   r^  r,   r'   r'   r(   r;    r_  zCommentedMap._keysc                 C   s   t t| S r0   )intr   r   r%   r'   r'   r(   r     r   zCommentedMap.__len__c                 C   s   t t| |kS r0   )r>   rP  r  r'   r'   r(   r     r   zCommentedMap.__eq__c                 C      t | S r0   )r.  r%   r'   r'   r(   rK       zCommentedMap.keysc                 C   ra  r0   )r<  r%   r'   r'   r(   rl     rb  zCommentedMap.valuesc                 c   s(    t | D ]}|t | |fV  qd S r0   )r   r%  r   r,   r'   r'   r(   r8     s   zCommentedMap._itemsc                 C   ra  r0   )r8  r%   r'   r'   r(   rX     rb  zCommentedMap.itemsc                 C   s    t | tst| tg  t| tS r0   )r   r   r   r   r%   r'   r'   r(   merge  s   

zCommentedMap.mergec                 C   s2   t |  }|  D ]\}}|||< q	| | |S r0   )r   r8   r   )r&   r-   rF   rO   r'   r'   r(   r     s
   


zCommentedMap.copyc                 C   s   || j vr| j | d S d S r0   )r>  rj   )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+   )re  rX   r   rn   r   rc  r   )r&   rd   rO   rF   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=  rc  r   r   r   )r&   r   rO   r'   r'   r(   rN  #  s   

zCommentedMap.update_key_valuec                 C   sD   |   }||t| < | D ]}t| | |||< q| j||d |S r  )r  r  r   r   r   r  r'   r'   r(   r  -  s   zCommentedMap.__deepcopy__r0   rz   )(r3   r4   r5   r6   rp   ro   r)   rs   r  r   r  r   r   r   rI  r   rW  r   r   rX  rn   rg   r^   r[  r   r%  r;  r   r   rK  rl   r8   rX   rq   rc  r   re  rf  rN  r  r'   r'   r'   r(   r     sF    		






r   c                 O   s   t d| j)Nz{} objects are immutable)rJ  r?   r3   )clsr   kwargsr'   r'   r(   raise_immutable8     ri  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   s:   t | dr	t|  zt|i || _W d S  ty    w )Nrl  )r   ri  r   rl  rJ  r   r'   r'   r(   r)   B  s   
zCommentedKeyMap.__init__c                 C   s
   | j | S r0   )rl  )r&   indexr'   r'   r(   r   N  r*   zCommentedKeyMap.__getitem__c                 c   s    | j  D ]}|V  qd S r0   )rl  r%  r,   r'   r'   r(   r%  R  r_  zCommentedKeyMap.__iter__c                 C   r/   r0   )rC   rl  r%   r'   r'   r(   r   W  r*   zCommentedKeyMap.__len__c                 C   s   t t|  S r0   )hashtuplerX   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())r   r   rl  r^   r\   r   rX   r%   r'   r'   r(   r^   _  s   

zCommentedKeyMap.__repr__Nc                 C   rY  r0   )rk  rP  fromkeys)rK  rO   r'   r'   r(   rr  e  rj  zCommentedKeyMap.fromkeysc                 C   r  r0   r  r   r'   r'   r(   r  j  r  z!CommentedKeyMap._yaml_add_commentc                 C   r  r  r	  r   r'   r'   r(   r   q  r   z%CommentedKeyMap._yaml_add_eol_commentc                 C   r
  r"   r  r   r'   r'   r(   r  u  r  z!CommentedKeyMap._yaml_get_columnXc                 C   r  r+   r  r  r'   r'   r(   r   y  r  z CommentedKeyMap._yaml_get_columnc                 C   r  r+   r  r  r'   r'   r(   r     r  z%CommentedKeyMap._yaml_get_pre_commentr0   )r3   r4   r5   r6   rp   ro   r)   ri  r   r   r   r   popitemr   rI  r   r%  r   rp  r^   r7  rr  rs   r  r   r  r   r   r'   r'   r'   r(   rk  >  s"    
	rk  c                   @   s   e Zd ZejfZdS )r   N)r3   r4   r5   r6   rp   ro   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 r0   )r   rt  r   r)   )r&   rl   r'   r'   r(   r)     s
   
zCommentedSet.__init__c                 C   r?  r@  rA  rB  r'   r'   r(   r    rC  zCommentedSet._yaml_add_commentc                 C   rD  rE  r	  r   r'   r'   r(   r     rF  z"CommentedSet._yaml_add_eol_commentc                 C   s   d| j |< dS )zAdd an element.Nrt  rc   r'   r'   r(   rL    s   zCommentedSet.addc                 C   s   | j |= dS )z8Remove an element.  Do not raise an exception if absent.Nru  rc   r'   r'   r(   r\    s   zCommentedSet.discardc                 C   r4  r0   ru  r,   r'   r'   r(   rn     r*   zCommentedSet.__contains__c                 c   r5  r0   ru  r,   r'   r'   r(   r%    s   
zCommentedSet.__iter__c                 C   r/   r0   )rC   rt  r%   r'   r'   r(   r     r*   zCommentedSet.__len__c                 C   s   d | j S )Nz
set({0!r}))r?   rt  rK  r%   r'   r'   r(   r^     r   zCommentedSet.__repr__r0   )r3   r4   r5   r6   rp   ro   r)   rs   r  r   rL  r\  rn   r%  r   r^   r'   r'   r'   r(   r     s    

r   c                   @   s   e Zd ZdddZdd ZdS )TaggedScalarNc                 C   s&   || _ || _|d ur| | d S d S r0   )rd   styler   )r&   rd   rw  r   r'   r'   r(   r)     s
   zTaggedScalar.__init__c                 C   r_   r0   r   r%   r'   r'   r(   r2     s   zTaggedScalar.__str__rG  )r3   r4   r5   r)   r2   r'   r'   r'   r(   rv    s    
rv  r=   .c                 C   s   t | tr;t| dr;|r|d|t|  |d| j | D ]}t| | |r2|| t| n|||d q"dS t | t	rxt| drz|rR|d|t|  |d| j t
| D ]\}}t||ro|| t| nt|||d q_dS dS dS )zg
    recursively dump comments, all but the toplevel preceded by the path
    in dotted form x.0.a
    r   z{} {}
z{!r}
)namesepoutN)r   rP  r   writer?   r   r   dump_commentsr1   r   r  )rS  ry  rz  r{  rF   r   r'   r'   r(   r}    s"   * r}  )Jr   sysr   Zruamel.yaml.compatr   r   r   r   Zruamel.yaml.scalarstringr   Zruamel.yaml.anchorr   collections.abcr   r	   r
   r   typingr   r   r   r   r   r   __all__r   r   r   r   r    ZcidxZC_VALUE_EOLZ
C_ELEM_EOLZ	C_KEY_EOLZ	C_KEY_PREZ
C_ELEM_PREZC_VALUE_POSTZC_ELEM_POSTZC_VALUE_PREZ
C_KEY_POSTZ	C_TAG_EOLZ
C_TAG_POSTZ	C_TAG_PREZC_ANCHOR_EOLZC_ANCHOR_POSTZC_ANCHOR_PREr   r~   r   r   r   r6   rs   ru   r   r   r   r   r   ro  r   r(  r.  r8  r<  r   r7  ri  rk  r   r   rv  stdoutr}  r'   r'   r'   r(   <module>   st   


 3 L :  $
Z6