a
    yn„fà,  ã                   @   s,   d dl mZ d dlmZ G dd„ deƒZdS )é   )Ú
filesystem)ÚAsyncFileSystemc                       s  e Zd ZdZdZdƒ‡ fdd„	Zdd„ Zdd	„ Zed
d„ ƒZ	dd„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zd d!„ Zd"d#„ Zd$d%„ Zd&d'„ Zd(d)„ Zd*d+„ Zd,d-„ Zd.d/„ Zd0d1„ Zd2d3„ Zd4d5„ Zd6d7„ Zd8d9„ Z d:d;„ Z!d<d=„ Z"d>d?„ Z#d@dA„ Z$dBdC„ Z%dDdE„ Z&dFdG„ Z'dHdI„ Z(dJdK„ Z)dLdM„ Z*dNdO„ Z+dPdQ„ Z,d„dSdT„Z-d…dUdV„Z.dWdX„ Z/dYdZ„ Z0d[d\„ Z1d]d^„ Z2d_d`„ Z3dadb„ Z4dcdd„ Z5dedf„ Z6dgdh„ Z7didj„ Z8dkdl„ Z9dmdn„ Z:dodp„ Z;dqdr„ Z<dsdt„ Z=dudv„ Z>dwdx„ Z?dydz„ Z@d{d|„ ZAd}d~„ ZBdd€„ ZCd�d‚„ ZD‡  ZES )†ÚDirFileSystemzþDirectory prefix filesystem

    The DirFileSystem is a filesystem-wrapper. It assumes every path it is dealing with
    is relative to the `path`. After performing the necessary paths operation it
    delegates everything to the wrapped filesystem.
    ÚdirNc                    s˜   t ƒ jf i |¤Ž |du r0tf d|i|p*i ¤Ž}|du|duA du rLtdƒ‚|pR|}| jrh|jshtdƒ‚|jr‚| j|jkr‚tdƒ‚| |¡| _|| _dS )aS  
        Parameters
        ----------
        path: str
            Path to the directory.
        fs: AbstractFileSystem
            An instantiated filesystem to wrap.
        target_protocol, target_options:
            if fs is none, construct it from these
        fo: str
            Alternate for path; do not provide both
        NÚprotocolFzProvide path or fo, not bothz(can't use asynchronous with non-async fsz7both dirfs and fs should be in the same sync/async mode)	ÚsuperÚ__init__r   Ú
ValueErrorZasynchronousZ
async_implÚ_strip_protocolÚpathÚfs)Úselfr   r   ÚfoZtarget_protocolZtarget_optionsZstorage_options©Ú	__class__© ú_/home/yuhw/wc/wire-cell-python/wcpy/lib/python3.9/site-packages/fsspec/implementations/dirfs.pyr      s    zDirFileSystem.__init__c                    sj   t |tƒr8ˆ js|S |sˆ jS ˆ jj ˆ jˆ  |¡f¡S t |tƒrX‡ fdd„| ¡ D ƒS ‡ fdd„|D ƒS )Nc                    s   i | ]\}}ˆ   |¡|“qS r   ©Ú_join)Ú.0Ú_pathÚvalue©r   r   r   Ú
<dictcomp><   ó    z'DirFileSystem._join.<locals>.<dictcomp>c                    s   g | ]}ˆ   |¡‘qS r   r   ©r   r   r   r   r   Ú
<listcomp>=   r   z'DirFileSystem._join.<locals>.<listcomp>)	Ú
isinstanceÚstrr   r   ÚsepÚjoinr
   ÚdictÚitems©r   r   r   r   r   r   4   s    

zDirFileSystem._joinc                    s`   t |tƒrNˆ js|S |ˆ jkr"dS ˆ jˆ jj }| |¡s>J ‚|t|ƒd … S ‡ fdd„|D ƒS )NÚ c                    s   g | ]}ˆ   |¡‘qS r   ©Ú_relpathr   r   r   r   r   H   r   z*DirFileSystem._relpath.<locals>.<listcomp>)r   r   r   r   r   Ú
startswithÚlen)r   r   Úprefixr   r   r   r&   ?   s    

zDirFileSystem._relpathc                 C   s   | j jS ©N)r   r   r   r   r   r   r   L   s    zDirFileSystem.sepc                 Ï   s   | j j|i |¤ŽI d H S r*   )r   Úset_session)r   ÚargsÚkwargsr   r   r   r+   P   s    zDirFileSystem.set_sessionc                 Ë   s    | j j|  |¡fi |¤ŽI d H S r*   )r   Ú_rm_filer   ©r   r   r-   r   r   r   r.   S   s    zDirFileSystem._rm_filec                 K   s   | j j|  |¡fi |¤ŽS r*   )r   Úrm_filer   r/   r   r   r   r0   V   s    zDirFileSystem.rm_filec                 Ï   s&   | j j|  |¡g|¢R i |¤ŽI d H S r*   )r   Ú_rmr   ©r   r   r,   r-   r   r   r   r1   Y   s    zDirFileSystem._rmc                 O   s    | j j|  |¡g|¢R i |¤ŽS r*   )r   Úrmr   r2   r   r   r   r3   \   s    zDirFileSystem.rmc                 Ë   s(   | j j|  |¡|  |¡fi |¤ŽI d H S r*   )r   Ú_cp_filer   ©r   Úpath1Úpath2r-   r   r   r   r4   _   s    zDirFileSystem._cp_filec                 K   s"   | j j|  |¡|  |¡fi |¤ŽS r*   )r   Úcp_filer   r5   r   r   r   r8   b   s    zDirFileSystem.cp_filec                 Ï   s.   | j j|  |¡|  |¡g|¢R i |¤ŽI d H S r*   )r   Ú_copyr   ©r   r6   r7   r,   r-   r   r   r   r9   e   s    þýüzDirFileSystem._copyc                 O   s(   | j j|  |¡|  |¡g|¢R i |¤ŽS r*   )r   Úcopyr   r:   r   r   r   r;   s   s    þýüzDirFileSystem.copyc                 Ï   s&   | j j|  |¡g|¢R i |¤ŽI d H S r*   )r   Ú_piper   r2   r   r   r   r<   {   s    zDirFileSystem._pipec                 O   s    | j j|  |¡g|¢R i |¤ŽS r*   )r   Úpiper   r2   r   r   r   r=   ~   s    zDirFileSystem.pipec                 Ï   s&   | j j|  |¡g|¢R i |¤ŽI d H S r*   )r   Ú
_pipe_filer   r2   r   r   r   r>   �   s    zDirFileSystem._pipe_filec                 O   s    | j j|  |¡g|¢R i |¤ŽS r*   )r   Ú	pipe_filer   r2   r   r   r   r?   „   s    zDirFileSystem.pipe_filec                 Ï   s&   | j j|  |¡g|¢R i |¤ŽI d H S r*   )r   Ú	_cat_filer   r2   r   r   r   r@   ‡   s    zDirFileSystem._cat_filec                 O   s    | j j|  |¡g|¢R i |¤ŽS r*   )r   Úcat_filer   r2   r   r   r   rA   Š   s    zDirFileSystem.cat_filec                 �   sJ   ˆ j jˆ  |¡g|¢R i |¤ŽI d H }t|tƒrF‡ fdd„| ¡ D ƒS |S )Nc                    s   i | ]\}}ˆ   |¡|“qS r   r%   ©r   Úkeyr   r   r   r   r   •   r   z&DirFileSystem._cat.<locals>.<dictcomp>)r   Ú_catr   r   r!   r"   ©r   r   r,   r-   Úretr   r   r   rD   �   s    ÿþý
zDirFileSystem._catc                    sD   ˆ j jˆ  |¡g|¢R i |¤Ž}t|tƒr@‡ fdd„| ¡ D ƒS |S )Nc                    s   i | ]\}}ˆ   |¡|“qS r   r%   rB   r   r   r   r   ¡   r   z%DirFileSystem.cat.<locals>.<dictcomp>)r   Úcatr   r   r!   r"   rE   r   r   r   rG   ™   s    ÿþý
zDirFileSystem.catc                 Ë   s"   | j j||  |¡fi |¤ŽI d H S r*   )r   Ú	_put_filer   ©r   ÚlpathÚrpathr-   r   r   r   rH   ¥   s    zDirFileSystem._put_filec                 K   s   | j j||  |¡fi |¤ŽS r*   )r   Úput_filer   rI   r   r   r   rL   ¨   s    zDirFileSystem.put_filec                 Ï   s(   | j j||  |¡g|¢R i |¤ŽI d H S r*   )r   Ú_putr   ©r   rJ   rK   r,   r-   r   r   r   rM   «   s    þýüzDirFileSystem._putc                 O   s"   | j j||  |¡g|¢R i |¤ŽS r*   )r   Úputr   rN   r   r   r   rO   ¹   s    þýüzDirFileSystem.putc                 Ë   s"   | j j|  |¡|fi |¤ŽI d H S r*   )r   Ú	_get_filer   ©r   rK   rJ   r-   r   r   r   rP   Á   s    zDirFileSystem._get_filec                 K   s   | j j|  |¡|fi |¤ŽS r*   )r   Úget_filer   rQ   r   r   r   rR   Ä   s    zDirFileSystem.get_filec                 Ï   s&   | j j|  |¡g|¢R i |¤ŽI d H S r*   )r   Ú_getr   ©r   rK   r,   r-   r   r   r   rS   Ç   s    zDirFileSystem._getc                 O   s    | j j|  |¡g|¢R i |¤ŽS r*   )r   Úgetr   rT   r   r   r   rU   Ê   s    zDirFileSystem.getc                 Ã   s   | j  |  |¡¡I d H S r*   )r   Ú_isfiler   r#   r   r   r   rV   Í   s    zDirFileSystem._isfilec                 C   s   | j  |  |¡¡S r*   )r   Úisfiler   r#   r   r   r   rW   Ð   s    zDirFileSystem.isfilec                 Ã   s   | j  |  |¡¡I d H S r*   )r   Ú_isdirr   r#   r   r   r   rX   Ó   s    zDirFileSystem._isdirc                 C   s   | j  |  |¡¡S r*   )r   Úisdirr   r#   r   r   r   rY   Ö   s    zDirFileSystem.isdirc                 Ã   s   | j  |  |¡¡I d H S r*   )r   Ú_sizer   r#   r   r   r   rZ   Ù   s    zDirFileSystem._sizec                 C   s   | j  |  |¡¡S r*   )r   Úsizer   r#   r   r   r   r[   Ü   s    zDirFileSystem.sizec                 Ã   s   | j  |  |¡¡I d H S r*   )r   Ú_existsr   r#   r   r   r   r\   ß   s    zDirFileSystem._existsc                 C   s   | j  |  |¡¡S r*   )r   Úexistsr   r#   r   r   r   r]   â   s    zDirFileSystem.existsc                 Ë   s    | j j|  |¡fi |¤ŽI d H S r*   )r   Ú_infor   r/   r   r   r   r^   å   s    zDirFileSystem._infoc                 K   s   | j j|  |¡fi |¤ŽS r*   )r   Úinfor   r/   r   r   r   r_   è   s    zDirFileSystem.infoTc                 Ë   sl   | j j|  |¡fd|i|¤ŽI d H  ¡ }|rbg }|D ](}| ¡ }|  |d ¡|d< | |¡ q4|S |  |¡S ©NÚdetailÚname)r   Ú_lsr   r;   r&   Úappend©r   r   ra   r-   rF   ÚoutÚentryr   r   r   rc   ë   s    (zDirFileSystem._lsc                 K   sf   | j j|  |¡fd|i|¤Ž ¡ }|r\g }|D ](}| ¡ }|  |d ¡|d< | |¡ q.|S |  |¡S r`   )r   Úlsr   r;   r&   rd   re   r   r   r   rh   ÷   s    "zDirFileSystem.lsc                 O  sL   | j j|  |¡g|¢R i |¤Ž2 z$3 d H W \}}}|  |¡||fV  q 6 d S r*   )r   Ú_walkr   r&   ©r   r   r,   r-   ÚrootÚdirsÚfilesr   r   r   ri     s    2zDirFileSystem._walkc                 o   sB   | j j|  |¡g|¢R i |¤ŽD ]\}}}|  |¡||fV  q d S r*   )r   Úwalkr   r&   rj   r   r   r   rn     s    *zDirFileSystem.walkc                 ‹   sP   |  dd¡}ˆ jjˆ  |¡fi |¤ŽI d H }|rF‡ fdd„| ¡ D ƒS ˆ  |¡S )Nra   Fc                    s   i | ]\}}ˆ   |¡|“qS r   r%   ©r   r   r_   r   r   r   r     r   z'DirFileSystem._glob.<locals>.<dictcomp>)rU   r   Ú_globr   r"   r&   ©r   r   r-   ra   rF   r   r   r   rp     s
     zDirFileSystem._globc                    sJ   |  dd¡}ˆ jjˆ  |¡fi |¤Ž}|r@‡ fdd„| ¡ D ƒS ˆ  |¡S )Nra   Fc                    s   i | ]\}}ˆ   |¡|“qS r   r%   ro   r   r   r   r     r   z&DirFileSystem.glob.<locals>.<dictcomp>)rU   r   Úglobr   r"   r&   rq   r   r   r   rr     s
    zDirFileSystem.globc                 �   sP   |  dd¡}ˆ jjˆ  |¡g|¢R i |¤ŽI d H }|r:|S ‡ fdd„| ¡ D ƒS )NÚtotalTc                    s   i | ]\}}ˆ   |¡|“qS r   r%   ©r   r   r[   r   r   r   r     r   z%DirFileSystem._du.<locals>.<dictcomp>)rU   r   Ú_dur   r"   ©r   r   r,   r-   rs   rF   r   r   r   ru     s
    &zDirFileSystem._duc                    sJ   |  dd¡}ˆ jjˆ  |¡g|¢R i |¤Ž}|r4|S ‡ fdd„| ¡ D ƒS )Nrs   Tc                    s   i | ]\}}ˆ   |¡|“qS r   r%   rt   r   r   r   r   '  r   z$DirFileSystem.du.<locals>.<dictcomp>)rU   r   Údur   r"   rv   r   r   r   rw   !  s
     zDirFileSystem.duc                 �   sV   |  dd¡}ˆ jjˆ  |¡g|¢R i |¤ŽI d H }|rL‡ fdd„| ¡ D ƒS ˆ  |¡S )Nra   Fc                    s   i | ]\}}ˆ   |¡|“qS r   r%   ro   r   r   r   r   -  r   z'DirFileSystem._find.<locals>.<dictcomp>)rU   r   Ú_findr   r"   r&   ©r   r   r,   r-   ra   rF   r   r   r   rx   )  s
    &zDirFileSystem._findc                    sP   |  dd¡}ˆ jjˆ  |¡g|¢R i |¤Ž}|rF‡ fdd„| ¡ D ƒS ˆ  |¡S )Nra   Fc                    s   i | ]\}}ˆ   |¡|“qS r   r%   ro   r   r   r   r   4  r   z&DirFileSystem.find.<locals>.<dictcomp>)rU   r   Úfindr   r"   r&   ry   r   r   r   rz   0  s
     zDirFileSystem.findc                 Ï   s,   |   | jj|  |¡g|¢R i |¤ŽI d H ¡S r*   )r&   r   Ú_expand_pathr   r2   r   r   r   r{   7  s    $ÿzDirFileSystem._expand_pathc                 O   s&   |   | jj|  |¡g|¢R i |¤Ž¡S r*   )r&   r   Úexpand_pathr   r2   r   r   r   r|   <  s    zDirFileSystem.expand_pathc                 Ï   s&   | j j|  |¡g|¢R i |¤ŽI d H S r*   )r   Ú_mkdirr   r2   r   r   r   r}   ?  s    zDirFileSystem._mkdirc                 O   s    | j j|  |¡g|¢R i |¤ŽS r*   )r   Úmkdirr   r2   r   r   r   r~   B  s    zDirFileSystem.mkdirc                 Ï   s&   | j j|  |¡g|¢R i |¤ŽI d H S r*   )r   Ú	_makedirsr   r2   r   r   r   r   E  s    zDirFileSystem._makedirsc                 O   s    | j j|  |¡g|¢R i |¤ŽS r*   )r   Úmakedirsr   r2   r   r   r   r€   H  s    zDirFileSystem.makedirsc                 C   s   | j  |  |¡¡S r*   )r   Úrmdirr   r#   r   r   r   r�   K  s    zDirFileSystem.rmdirc                 K   s"   | j j|  |¡|  |¡fi |¤ŽS r*   )r   Úmvr   r5   r   r   r   r‚   N  s    þýzDirFileSystem.mvc                 K   s   | j j|  |¡fi |¤ŽS r*   )r   Útouchr   r/   r   r   r   rƒ   U  s    zDirFileSystem.touchc                 C   s   | j  |  |¡¡S r*   )r   Úcreatedr   r#   r   r   r   r„   X  s    zDirFileSystem.createdc                 C   s   | j  |  |¡¡S r*   )r   Úmodifiedr   r#   r   r   r   r…   [  s    zDirFileSystem.modifiedc                 O   s    | j j|  |¡g|¢R i |¤ŽS r*   )r   Úsignr   r2   r   r   r   r†   ^  s    zDirFileSystem.signc                 C   s   | j j› d| j› d| j› d�S )Nz(path='z', fs=ú))r   Ú__qualname__r   r   r   r   r   r   Ú__repr__a  s    zDirFileSystem.__repr__c                 O   s    | j j|  |¡g|¢R i |¤ŽS r*   )r   Úopenr   r2   r   r   r   rŠ   d  s    ÿþýzDirFileSystem.open)NNNNN)T)T)FÚ__name__Ú
__module__rˆ   Ú__doc__r   r   r   r&   Úpropertyr   r+   r.   r0   r1   r3   r4   r8   r9   r;   r<   r=   r>   r?   r@   rA   rD   rG   rH   rL   rM   rO   rP   rR   rS   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   rc   rh   ri   rn   rp   rr   ru   rw   rx   rz   r{   r|   r}   r~   r   r€   r�   r‚   rƒ   r„   r…   r†   r‰   rŠ   Ú__classcell__r   r   r   r   r      sŽ        ú%


r   N)r$   r   Zasynr   r   r   r   r   r   Ú<module>   s   