
                             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e      Z eeej&                        Zd	 Zd
 ZddZy)z6
some helper functions that might be generally useful
    )absolute_importprint_function)partialN   )	text_typebinary_typec                   "    e Zd ZdZd Zd Zd Zy)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                 J      fd}t         j                   d|       y )Nc                  N      i  t         j                  d fd        S )N	lazy_selfc                       S N )return_values   #lib/third_party/ruamel/yaml/util.py<lambda>z6LazyEval.__init__.<locals>.lazy_self.<locals>.<lambda>#   s    ,    object__setattr__)r   argsfunckwargsselfs   @r   r   z$LazyEval.__init__.<locals>.lazy_self    s+    00Lt[2FGr   r   r   )r   r   r   r   r   s   ```` r   __init__zLazyEval.__init__   s    	  	4i8r   c                 ^    t         j                  | d      }|dk(  r|S t         |       |      S )Nr   )r   __getattribute__getattr)r   namer   s      r   r   zLazyEval.__getattribute__(   s1    ++D+>	;y{D))r   c                 :    t        | j                         ||       y r   )setattrr   )r   r    values      r   r   zLazyEval.__setattr__/   s     $.r   N)__name__
__module____qualname____doc__r   r   r   r   r   r   r
   r
      s    9*/r   r
   c                    ddl m} d }t        | t              r| }n2t        | t              r| j                  d      }n| j                         }d}d}d}d}d}	|j                         D ]  }
|
j                         }|j                         }|j                  d      r8 ||
      }||	z
  }|dz   }|
|   dk(  r|dz  }|
|   dk(  r|
|   d	k(  re||	z
  } n^|$|"|r d}|
|   d
v r|dz  }|
|   d
v r||kD  r||z
  }|j                  d      r# ||
      }	d}|
|   dk(  r|dz  }|
|   dk(  r|}d} |||} ||fi |||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                 n    d}|t        |       k  r$| |   dk(  r|dz  }|t        |       k  r	| |   dk(  r|S )Nr    r   )len)lidxs     r   leading_spacesz.load_yaml_guess_indent.<locals>.leading_spacesH   sA    CFlqv}1HC CFlqv}
r   zutf-8Nr   z- r+   #z -:)mainr)   
isinstancer   r   decoderead
splitlinesrstriplstrip
startswithendswith)streamkwr)   r/   yaml_str
map_indentindentblock_seq_indentprev_line_key_only
key_indentlinerlinellinel_sr.   s                  r   load_yaml_guess_indentrG   <   s    & &)$	FK	(==);;=JFJ##%D! &C"Z/'Cs)s"q s)s"CyC:%F"4"@UCs)t#q s)t#'' #55
>>#'-JCs)s"q s)s"!$!5 &6 ~*08*r*F4DDDr   c              #     K   ddl m} t        | |      sJ | j                  D ]  }|j	                         s|  t        |       D ]  }|j	                         s|  | j                  D ]  }|j	                         s|  yw)zv
    walks over a ConfigObj (INI file with comments) generating
    corresponding YAML output (including comments
    r   )	ConfigObjN)	configobjrI   r3   initial_commentstrip_walk_sectionfinal_comment)cfgrI   css       r   configobj_walkerrR   z   sx      $c9%%%  779G ! 3779G   779G s   4B	$B	%B	B	c              #     K   ddl m} t        | |      sJ d|z  }| j                  D ]  }| j                  |   D ]  }||j                         z     | |   }d|v r/|dz   }d|z   |j                         j                  dd|z         z   }nd|v rd|j                  dd      z   dz   }d	j                  |||      }| j                  |   }|r|d
|z   z  }|  | j                  D ]v  }| j                  |   D ]  }||j                         z     dj                  ||      }| j                  |   }|r|d
|z   z  }| t        | |   |dz         D ]  }	|	  x y w)Nr   )Sectionz  
z|
r1   'z''z{0}{1}: {2}r+   z{0}{1}:r   )level)rJ   rT   r3   scalarscommentsrL   replaceformatinline_commentssectionsrM   )
rQ   rW   rT   r?   r    rP   xirC   vals
             r   rM   rM      sw    !a!!!U]F		D!A1779$$ "dGA:A
QWWY..ueai@@AAXqyyu--4A$$VT15d#D1HD
  

D!A1779$$ "  .d#D1HD
 4	:CI ; s   EE )r   )r'   
__future__r   r   	functoolsr   recompatr   r   typingAnyDictOptionalListTextStreamTextTyper   r
   compileRegExprG   rR   rM   r   r   r   <module>rn      sK    7  	 *
/v /B 
2::	&;E|(r   