a
    `DÌf’  ã                   @   s"   d dl mZ ddd„Zdd„ ZdS )	é    )ÚunitsÚ c                    s”   t | tƒr‡ fdd„| D ƒS t | tƒr<t‡ fdd„| D ƒƒS t | tƒr\‡ fdd„|  ¡ D ƒS t | tƒsxtdt| ƒ› �ƒ‚ˆ rˆ| dˆ  7 } t| t	j
ƒS )a;  
    Convert val into WCT system of units.

    When val is a string it is evaluated in the context of the WCT
    unit definitions and if unit is given it is multiplied resulting
    in a number.

    When val is a list, tuple, or dict of unit values, the same
    structure is returned with strings evaluted.
    c                    s   g | ]}t |ˆ ƒ‘qS © ©Úunitify©Ú.0Zone©Úunitr   ú9/home/yuhw/wc/wire-cell-python/wirecell/util/functions.pyÚ
<listcomp>   ó    zunitify.<locals>.<listcomp>c                    s   g | ]}t |ˆ ƒ‘qS r   r   r   r	   r   r   r      r   c                    s   i | ]\}}|t |ˆ ƒ“qS r   r   )r   ÚkÚvr	   r   r   Ú
<dictcomp>   r   zunitify.<locals>.<dictcomp>zunsupported value type: Ú*)Ú
isinstanceÚlistÚtupleÚdictÚitemsÚstrÚ	TypeErrorÚtypeÚevalr   Ú__dict__)Úvalr
   r   r	   r   r      s    



r   c                 C   s&   dd„ |   d¡D ƒ}dd„ |D ƒ}|S )z¡
    Parse a string with unit expressions and return its value.  String
    assumed to be a comman separated list of scalar values.  A list is
    returned.
    c                 S   s   g | ]}|  ¡ r|  ¡ ‘qS r   )Ústrip©r   r   r   r   r   r   $   r   z!unitify_parse.<locals>.<listcomp>ú,c                 S   s   g | ]}t |tjƒ‘qS r   )r   r   r   r   r   r   r   r   &   r   )Úsplit)ÚstringZvalsr   r   r   Úunitify_parse   s    r"   N)r   )Úwirecellr   r   r"   r   r   r   r   Ú<module>   s   
