
"·T`k  ã               @   s   Gd  d „  d e  ƒ Z d S)c               @   sj   e  Z d  Z 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)ÚSimpleTablezRA minimal implementation of PrettyTable
    for distribution with cloud-init.
    c             C   s<   | |  _  g  |  _ d g t |  j  ƒ |  _ |  j | ƒ d  S)Né    )ÚfieldsÚrowsÚlenÚcolumn_widthsÚupdate_column_widths)Úselfr   © r	   ú7/usr/lib/python3/dist-packages/cloudinit/simpletable.pyÚ__init__   s    		zSimpleTable.__init__c             C   sD   x= t  | ƒ D]/ \ } } t t | ƒ |  j | ƒ |  j | <q Wd  S)N)Ú	enumerateÚmaxr   r   )r   ÚvaluesÚiÚvaluer	   r	   r
   r      s    	z SimpleTable.update_column_widthsc             C   s[   t  | ƒ t  |  j ƒ k r' t d ƒ ‚ d d „  | Dƒ } |  j j | ƒ |  j | ƒ d  S)Nztoo many valuesc             S   s   g  |  ] } t  | ƒ ‘ q Sr	   )Ústr)Ú.0r   r	   r	   r
   ú
<listcomp>    s   	 z'SimpleTable.add_row.<locals>.<listcomp>)r   r   Ú	TypeErrorr   Úappendr   )r   r   r	   r	   r
   Úadd_row   s
    zSimpleTable.add_rowc             C   s%   d d j  d d „  |  j Dƒ ƒ d S)z+Returns a horizontal divider for the table.ú+c             S   s   g  |  ] } d  | d ‘ q S)ú-é   r	   )r   Úwr	   r	   r
   r   '   s   	 z%SimpleTable._hdiv.<locals>.<listcomp>)Újoinr   )r   r	   r	   r
   Ú_hdiv$   s    zSimpleTable._hdivc                s.   d d j  ‡  f d d †  t | ƒ Dƒ ƒ d S)zReturns a formatted row.ú|c                s0   g  |  ]& \ } } | j  ˆ  j | d  ƒ ‘ q S)r   )Úcenterr   )r   r   Úcol)r   r	   r
   r   ,   s   	z$SimpleTable._row.<locals>.<listcomp>)r   r   )r   Úrowr	   )r   r
   Ú_row)   s    zSimpleTable._rowc                sa   ˆ  j  ƒ  ˆ  j ˆ  j ƒ ˆ  j  ƒ  g } | ‡  f d d †  ˆ  j Dƒ ˆ  j  ƒ  g 7} d j | ƒ S)zÍReturns a string representation of the table with lines around.

        +-----+-----+
        | one | two |
        +-----+-----+
        |  1  |  2  |
        |  01 |  10 |
        +-----+-----+
        c                s   g  |  ] } ˆ  j  | ƒ ‘ q Sr	   )r!   )r   Úr)r   r	   r
   r   :   s   	 z'SimpleTable.__str__.<locals>.<listcomp>Ú
)r   r!   r   r   r   )r   Úlinesr	   )r   r
   Ú__str__/   s    
'-zSimpleTable.__str__c             C   s
   |  j  ƒ  S)N)r%   )r   r	   r	   r
   Ú
get_string=   s    zSimpleTable.get_stringN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r!   r%   r&   r	   r	   r	   r
   r   	   s   	r   N)Úobjectr   r	   r	   r	   r
   Ú<module>	   s    