B
    |?_[6                 @   sr   d Z ddlmZmZ ddlmZ ddlZddlmZm	Z	 G dd de
ZeeejZd	d
 Zdd ZdddZdS )z6
some helper functions that might be generally useful
    )absolute_importprint_function)partialN   )	text_typebinary_typec               @   s(   e Zd ZdZdd Zdd Zdd ZdS )	LazyEvala  
    Lightweight wrapper around lazily evaluated func(*args, **kwargs).

    func is only evaluated when any attribute of its return value is accessed.
    Every attribute access is passed through to the wrapped value.
    (This only excludes special cases like method-wrappers, e.g., __hash__.)
    The sole additional attribute is the lazy_self function which holds the
    return value (or, prior to evaluation, func and arguments), in its closure.
    c                s$    fdd}t d| d S )Nc                  s$    t d fdd  S )N	lazy_selfc                  s    S )N r
   )return_valuer
   /lib/python3.7/site-packages/ruamel_yaml/util.py<lambda>    s    z6LazyEval.__init__.<locals>.lazy_self.<locals>.<lambda>)object__setattr__r
   )argsfunckwargsself)r   r   r	      s    
z$LazyEval.__init__.<locals>.lazy_selfr	   )r   r   )r   r   r   r   r	   r
   )r   r   r   r   r   __init__   s    zLazyEval.__init__c             C   s$   t | d}|dkr|S t| |S )Nr	   )r   __getattribute__getattr)r   namer	   r
   r
   r   r   $   s    zLazyEval.__getattribute__c             C   s   t |  || d S )N)setattrr	   )r   r   valuer
   r
   r   r   *   s    zLazyEval.__setattr__N)__name__
__module____qualname____doc__r   r   r   r
   r
   r
   r   r      s   	r   c             K   s  ddl m} dd }t| tr$| }nt| tr:| d}n|  }d}d}d}d}d}	x| D ]}
|
 }|	 }|
dr||
}||	 }|d }x|
| d	kr|d7 }qW |
| d
krq`||	 }P |dkr|dk	r|rd}x|
| dkr|d7 }qW ||kr|| }|drN||
}	d}x|
| d	krF|d7 }q,W |}q`d}q`W |dkrn|dk	rn|}||f|||fS )at  guess the indent and block sequence indent of yaml stream/string

    returns round_trip_loaded stream, indent level, block sequence indent
    - block sequence indent is the number of spaces before a dash relative to previous indent
    - if there are no block sequences, indent is taken from nested mappings, block sequence
      indent is unset (None) in that case
    r   )round_trip_loadc             S   s.   d}x$|t | k r(| | dkr(|d7 }qW |S )Nr    r   )len)lidxr
   r
   r   leading_spacesB   s    z.load_yaml_guess_indent.<locals>.leading_spaceszutf-8Nr   z- r   #z -:)mainr   
isinstancer   r   decoderead
splitlinesrstriplstrip
startswithendswith)streamkwr   r#   Zyaml_strZ
map_indentindentZblock_seq_indentZprev_line_key_onlyZ
key_indentlineZrlineZllineZl_sr"   r
   r
   r   load_yaml_guess_indent6   sT    	



r3   c             c   sz   ddl m} t| |stx| jD ]}| r"|V  q"W xt| D ]}| rB|V  qBW x| jD ]}| r`|V  q`W dS )zv
    walks over a ConfigObj (INI file with comments) generating
    corresponding YAML output (including comments
    r   )	ConfigObjN)	configobjr4   r'   AssertionErrorZinitial_commentstrip_walk_sectionZfinal_comment)Zcfgr4   csr
   r
   r   configobj_walkert   s    

r;   c       
      c   s^  ddl m} t| |std| }x| jD ]}x | j| D ]}||  V  q:W | | }d|kr|d }d| | dd|  }nd|krd|dd d }d	|||}| j	| }|r|d
| 7 }|V  q*W x| j
D ]z}x | j| D ]}||  V  qW d||}| j	| }|r*|d
| 7 }|V  x$t| | |d dD ]}	|	V  qFW qW d S )Nr   )Sectionz  
z|
r%   'z''z{0}{1}: {2}r   z{0}{1}:r   )level)r5   r<   r'   r6   ZscalarsZcommentsr7   replaceformatZinline_commentsZsectionsr8   )
r:   r?   r<   r1   r   r9   xir2   valr
   r
   r   r8      s6    


r8   )r   )r   Z
__future__r   r   	functoolsr   recompatr   r   r   r   compileZRegExpr3   r;   r8   r
   r
   r
   r   <module>   s   >