a
    �Ï?eÖ  ã                   @   sv   d Z ddlZddlZddlZddlZddlmZmZ ejej	eje
f dœdd„Zefeje
ejej dœd	d
„ZdS )z%Utility funtions for anyconfig.ionfo.é    Né   )ÚGLOB_MARKERÚPATH_SEP)ÚpathÚreturnc              
   C   sx   z|   ¡  ¡ }W nB ttfyR } z&t d| ›d|›�¡ | }W Y d}~n
d}~0 0 | j}|| d¡rr|dd… ndfS )z9Normaliez path objects and retunr it with file extension.zFailed to resolve z, exc=NÚ.r   Ú )Ú
expanduserÚresolveÚRuntimeErrorÚOSErrorÚwarningsÚwarnÚsuffixÚ
startswith)r   Úabs_pathÚexcZfile_ext© r   úY/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/anyconfig/ioinfo/utils.pyÚget_path_and_ext   s    þr   )r   Úmarkerr   c                 #   s¸   |   ¡ s|  ¡ } ttt ‡ fdd„| j¡ƒƒd }|sDtd| ›�ƒ‚|d d }t| jƒ|kr®t	 
| jd ¡j| jd|… Ž }t | j|d… ¡}t| |¡ƒD ]
}|V  q n| V  dS )z-Expand ``path`` contains '*' in its path str.c                    s   ˆ | vS )Nr   )Úp©r   r   r   Ú<lambda>&   ó    z"expand_from_path.<locals>.<lambda>éÿÿÿÿzIt should not happen: r   r   N)Úis_absoluter
   ÚlistÚ	enumerateÚ	itertoolsÚ	takewhileÚpartsÚ
ValueErrorÚlenÚpathlibÚPathÚjoinpathr   ÚjoinÚsortedÚglob)r   r   Zidx_partÚidxÚbaseÚpatternZepathr   r   r   Úexpand_from_path   s     ÿþ 
r-   )Ú__doc__r   r$   Útypingr   Ú	constantsr   r   r%   ÚTupleÚstrr   ÚIteratorr-   r   r   r   r   Ú<module>   s   ÿ
þ