ó
á>_[c           @@ sÙ   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	 e
 r d d l m Z m Z m Z m Z m Z d d l m Z n  d	 e f d
 „  ƒ  YZ e e e j ƒ Z d „  Z d „  Z d d „ Z d S(   s6   
some helper functions that might be generally useful
i    (   t   absolute_importt   print_function(   t   partialNi   (   t	   text_typet   binary_type(   t   Anyt   Dictt   Optionalt   Listt   Text(   t   StreamTextTypet   LazyEvalc           B@ s)   e  Z d  Z d „  Z d „  Z d „  Z RS(   sÈ  
    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 †  } t  j ˆ d | ƒ d  S(   Nc           @ s/   ˆ ˆ ˆ Ž  ‰  t  j ˆ d ‡  f d †  ƒ ˆ  S(   Nt	   lazy_selfc           @ s   ˆ  S(   N(    (    (   t   return_value(    s/   lib/python2.7/site-packages/ruamel_yaml/util.pyt   <lambda>    s    (   t   objectt   __setattr__(    (   t   argst   funct   kwargst   self(   R   s/   lib/python2.7/site-packages/ruamel_yaml/util.pyR      s    R   (   R   R   (   R   R   R   R   R   (    (   R   R   R   R   s/   lib/python2.7/site-packages/ruamel_yaml/util.pyt   __init__   s    c         C@ s2   t  j |  d ƒ } | d k r" | St | ƒ  | ƒ S(   NR   (   R   t   __getattribute__t   getattr(   R   t   nameR   (    (    s/   lib/python2.7/site-packages/ruamel_yaml/util.pyR   $   s    c         C@ s   t  |  j ƒ  | | ƒ d  S(   N(   t   setattrR   (   R   R   t   value(    (    s/   lib/python2.7/site-packages/ruamel_yaml/util.pyR   *   s    (   t   __name__t
   __module__t   __doc__R   R   R   (    (    (    s/   lib/python2.7/site-packages/ruamel_yaml/util.pyR      s   			c         K@ s  d d l  m } d „  } t |  t ƒ r1 |  } n- t |  t ƒ rR |  j d ƒ } n |  j ƒ  } d } d } d } d } d }	 xU| j ƒ  D]G}
 |
 j	 ƒ  } | j
 ƒ  } | j d ƒ r| |
 ƒ } | |	 } | d } x |
 | d k rö | d 7} qÙ W|
 | d k rq‰ n  | |	 } Pn  | d k r|| d k	 r|| r|d } x |
 | d	 k r_| d 7} qBW| | k r|| | } q|n  | j d
 ƒ rÊ| |
 ƒ }	 d } x |
 | d k r½| d 7} q W| } q‰ n  d } q‰ W| d k rõ| d k	 rõ| } n  | | |  | | f S(   st  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
    i   (   t   round_trip_loadc         S@ s=   d } x0 | t  |  ƒ k  r8 |  | d k r8 | d 7} q	 W| S(   Ni    t    i   (   t   len(   t   lt   idx(    (    s/   lib/python2.7/site-packages/ruamel_yaml/util.pyt   leading_spacesB   s    %s   utf-8i    s   - R   t   #s    -t   :N(   t   mainR   t
   isinstanceR   R   t   decodet   readt   Nonet
   splitlinest   rstript   lstript
   startswitht   endswith(   t   streamt   kwR   R#   t   yaml_strt
   map_indentt   indentt   block_seq_indentt   prev_line_key_onlyt
   key_indentt   linet   rlinet   llinet   l_sR"   (    (    s/   lib/python2.7/site-packages/ruamel_yaml/util.pyt   load_yaml_guess_indent6   sT    			



	c         c@ s¤   d d l  m } t |  | ƒ s% t ‚ x% |  j D] } | j ƒ  r/ | Vq/ q/ Wx( t |  ƒ D] } | j ƒ  rZ | VqZ qZ Wx% |  j D] } | j ƒ  r‚ | Vq‚ q‚ Wd S(   sv   
    walks over a ConfigObj (INI file with comments) generating
    corresponding YAML output (including comments
    i    (   t	   ConfigObjN(   t	   configobjR=   R'   t   AssertionErrort   initial_commentt   stript   _walk_sectiont   final_comment(   t   cfgR=   t   ct   s(    (    s/   lib/python2.7/site-packages/ruamel_yaml/util.pyt   configobj_walkert   s    c   
      c@ s¼  d d l  m } t |  | ƒ s% t ‚ d | } xæ |  j D]Û } x$ |  j | D] } | | j ƒ  VqM W|  | } d | k r­ | d } d | | j ƒ  j d d | ƒ } n) d | k rÖ d | j d d ƒ d } n  d	 j | | | ƒ } |  j	 | } | r| d
 | 7} n  | Vq9 Wx |  j
 D]’ } x$ |  j | D] } | | j ƒ  Vq6Wd j | | ƒ } |  j	 | } | r…| d
 | 7} n  | Vx' t |  | d | d ƒD] }	 |	 Vq¥Wq"Wd  S(   Ni    (   t   Sectionu     u   
u   |
R%   u   'u   ''u   {0}{1}: {2}u    u   {0}{1}:t   leveli   (   R>   RH   R'   R?   t   scalarst   commentsRA   t   replacet   formatt   inline_commentst   sectionsRB   (
   RF   RI   RH   R4   R   RE   t   xt   iR8   t   val(    (    s/   lib/python2.7/site-packages/ruamel_yaml/util.pyRB   ‡   s6    


'	!(   R   t
   __future__R    R   t	   functoolsR   t   ret   compatR   R   t   Falset   typingR   R   R   R   R	   R
   R   R   t   compilet   RegExpR<   RG   RB   (    (    (    s/   lib/python2.7/site-packages/ruamel_yaml/util.pyt   <module>   s   (	>	