o
    h,                     @   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,ddSdTZ-ddUdV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 ZCdd ZD  ZES )DirFileSystemzDirectory 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di | |du rtdd|i|pi }|du|duA du r&td|p)|}| jr4|js4td|jrA| j|jkrAt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   
ValueErrorasynchronous
async_impl_strip_protocolpathfs)selfr   r   fotarget_protocoltarget_optionsstorage_options	__class__r   W/var/www/html/env_mimamsha/lib/python3.10/site-packages/fsspec/implementations/dirfs.pyr	      s   
zDirFileSystem.__init__c                    sj   t |tr js
|S |s jS  jj j |fS t |tr, fdd| D S  fdd|D S )Nc                       i | ]
\}}  ||qS r   _join).0_pathvaluer   r   r   
<dictcomp><       z'DirFileSystem._join.<locals>.<dictcomp>c                       g | ]}  |qS r   r   r   r   r   r   r   
<listcomp>=       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r' js
|S | jkrdS  j jj }||sJ |t|d  S  fdd|D S )N c                    r!   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 r2   )r   set_session)r   argskwargsr   r   r   r3   P      zDirFileSystem.set_sessionc                    "   | j j| |fi |I d H S r2   )r   _rm_filer   r   r   r5   r   r   r   r8   S       zDirFileSystem._rm_filec                 K      | j j| |fi |S r2   )r   rm_filer   r9   r   r   r   r<   V      zDirFileSystem.rm_filec                    (   | j j| |g|R i |I d H S r2   )r   _rmr   r   r   r4   r5   r   r   r   r?   Y      &zDirFileSystem._rmc                 O       | j j| |g|R i |S r2   )r   rmr   r@   r   r   r   rC   \       zDirFileSystem.rmc                    s*   | j j| || |fi |I d H S r2   )r   _cp_filer   r   path1path2r5   r   r   r   rE   _   s   (zDirFileSystem._cp_filec                 K   "   | j j| || |fi |S r2   )r   cp_filer   rF   r   r   r   rJ   b   s   "zDirFileSystem.cp_filec                    s0   | j j| || |g|R i |I d H S r2   )r   _copyr   r   rG   rH   r4   r5   r   r   r   rK   e   s   zDirFileSystem._copyc                 O   s(   | j j| || |g|R i |S r2   )r   copyr   rL   r   r   r   rM   s   s   zDirFileSystem.copyc                    r>   r2   )r   _piper   r@   r   r   r   rN   {   rA   zDirFileSystem._pipec                 O   rB   r2   )r   piper   r@   r   r   r   rO   ~   rD   zDirFileSystem.pipec                    r>   r2   )r   
_pipe_filer   r@   r   r   r   rP      rA   zDirFileSystem._pipe_filec                 O   rB   r2   )r   	pipe_filer   r@   r   r   r   rQ      rD   zDirFileSystem.pipe_filec                    r>   r2   )r   	_cat_filer   r@   r   r   r   rR      rA   zDirFileSystem._cat_filec                 O   rB   r2   )r   cat_filer   r@   r   r   r   rS      rD   zDirFileSystem.cat_filec                    sL    j j |g|R i |I d H }t|tr$ fdd| D S |S )Nc                    r   r   r-   r   keyr   r   r   r   r      r    z&DirFileSystem._cat.<locals>.<dictcomp>)r   _catr   r%   r)   r*   r   r   r4   r5   retr   r   r   rV      s   
zDirFileSystem._catc                    sD    j j |g|R i |}t|tr  fdd| D S |S )Nc                    r   r   r-   rT   r   r   r   r      r    z%DirFileSystem.cat.<locals>.<dictcomp>)r   catr   r%   r)   r*   rW   r   r   r   rY      s   
zDirFileSystem.catc                    s$   | j j|| |fi |I d H S r2   )r   	_put_filer   r   lpathrpathr5   r   r   r   rZ         "zDirFileSystem._put_filec                 K   s   | j j|| |fi |S r2   )r   put_filer   r[   r   r   r   r_         zDirFileSystem.put_filec                    s*   | j j|| |g|R i |I d H S r2   )r   _putr   r   r\   r]   r4   r5   r   r   r   ra      s   zDirFileSystem._putc                 O   s"   | j j|| |g|R i |S r2   )r   putr   rb   r   r   r   rc      s   zDirFileSystem.putc                    s$   | j j| ||fi |I d H S r2   )r   	_get_filer   r   r]   r\   r5   r   r   r   rd      r^   zDirFileSystem._get_filec                 K   s   | j j| ||fi |S r2   )r   get_filer   re   r   r   r   rf      r`   zDirFileSystem.get_filec                    r>   r2   )r   _getr   r   r]   r4   r5   r   r   r   rg      rA   zDirFileSystem._getc                 O   rB   r2   )r   getr   rh   r   r   r   ri      rD   zDirFileSystem.getc                       | j | |I d H S r2   )r   _isfiler   r+   r   r   r   rk      r6   zDirFileSystem._isfilec                 C      | j | |S r2   )r   isfiler   r+   r   r   r   rm         zDirFileSystem.isfilec                    rj   r2   )r   _isdirr   r+   r   r   r   ro      r6   zDirFileSystem._isdirc                 C   rl   r2   )r   isdirr   r+   r   r   r   rp      rn   zDirFileSystem.isdirc                    rj   r2   )r   _sizer   r+   r   r   r   rq      r6   zDirFileSystem._sizec                 C   rl   r2   )r   sizer   r+   r   r   r   rr      rn   zDirFileSystem.sizec                    rj   r2   )r   _existsr   r+   r   r   r   rs      r6   zDirFileSystem._existsc                 C   rl   r2   )r   existsr   r+   r   r   r   rt      rn   zDirFileSystem.existsc                    r7   r2   )r   _infor   r9   r   r   r   ru      r:   zDirFileSystem._infoc                 K   r;   r2   )r   infor   r9   r   r   r   rv      r=   zDirFileSystem.infoTc                    sn   | j j| |fd|i|I d H  }|r2g }|D ]}| }| |d |d< || q|S | |S Ndetailname)r   _lsr   rM   r.   appendr   r   rx   r5   rX   outentryr   r   r   rz      s   (
zDirFileSystem._lsc                 K   sf   | j j| |fd|i| }|r.g }|D ]}| }| |d |d< || q|S | |S rw   )r   lsr   rM   r.   r{   r|   r   r   r   r      s   "
zDirFileSystem.lsc                 O  sN   | j j| |g|R i |2 z3 d H W \}}}| |||fV  q6 d S r2   )r   _walkr   r.   r   r   r4   r5   rootdirsfilesr   r   r   r     s   2zDirFileSystem._walkc                 o   sD    | j j| |g|R i |D ]\}}}| |||fV  qd S r2   )r   walkr   r.   r   r   r   r   r     s   *zDirFileSystem.walkc                    sR   | dd} jj |fi |I d H }|r$ fdd| D S  |S )Nrx   Fc                    r   r   r-   r   r   rv   r   r   r   r     r    z'DirFileSystem._glob.<locals>.<dictcomp>)ri   r   _globr   r*   r.   r   r   r5   rx   rX   r   r   r   r     s    
zDirFileSystem._globc                    sJ   | dd} jj |fi |}|r  fdd| D S  |S )Nrx   Fc                    r   r   r-   r   r   r   r   r     r    z&DirFileSystem.glob.<locals>.<dictcomp>)ri   r   globr   r*   r.   r   r   r   r   r     s
   
zDirFileSystem.globc                    sR   | dd} jj |g|R i |I d H }|r|S  fdd| D S )NtotalTc                    r   r   r-   r   r   rr   r   r   r   r     r    z%DirFileSystem._du.<locals>.<dictcomp>)ri   r   _dur   r*   r   r   r4   r5   r   rX   r   r   r   r     s   &zDirFileSystem._duc                    sJ   | dd} jj |g|R i |}|r|S  fdd| D S )Nr   Tc                    r   r   r-   r   r   r   r   r   '  r    z$DirFileSystem.du.<locals>.<dictcomp>)ri   r   dur   r*   r   r   r   r   r   !  s
    zDirFileSystem.duc                    sX   | dd} jj |g|R i |I d H }|r' fdd| D S  |S )Nrx   Fc                    r   r   r-   r   r   r   r   r   -  r    z'DirFileSystem._find.<locals>.<dictcomp>)ri   r   _findr   r*   r.   r   r   r4   r5   rx   rX   r   r   r   r   )  s   &
zDirFileSystem._findc                    sP   | dd} jj |g|R i |}|r# fdd| D S  |S )Nrx   Fc                    r   r   r-   r   r   r   r   r   4  r    z&DirFileSystem.find.<locals>.<dictcomp>)ri   r   findr   r*   r.   r   r   r   r   r   0  s
    
zDirFileSystem.findc                    s.   |  | jj| |g|R i |I d H S r2   )r.   r   _expand_pathr   r@   r   r   r   r   7  s   $zDirFileSystem._expand_pathc                 O   s&   |  | jj| |g|R i |S r2   )r.   r   expand_pathr   r@   r   r   r   r   <  s   &zDirFileSystem.expand_pathc                    r>   r2   )r   _mkdirr   r@   r   r   r   r   ?  rA   zDirFileSystem._mkdirc                 O   rB   r2   )r   mkdirr   r@   r   r   r   r   B  rD   zDirFileSystem.mkdirc                    r>   r2   )r   	_makedirsr   r@   r   r   r   r   E  rA   zDirFileSystem._makedirsc                 O   rB   r2   )r   makedirsr   r@   r   r   r   r   H  rD   zDirFileSystem.makedirsc                 C   rl   r2   )r   rmdirr   r+   r   r   r   r   K  rn   zDirFileSystem.rmdirc                 K   rI   r2   )r   mvr   rF   r   r   r   r   N  s   zDirFileSystem.mvc                 K   r;   r2   )r   touchr   r9   r   r   r   r   U  r=   zDirFileSystem.touchc                 C   rl   r2   )r   createdr   r+   r   r   r   r   X  rn   zDirFileSystem.createdc                 C   rl   r2   )r   modifiedr   r+   r   r   r   r   [  rn   zDirFileSystem.modifiedc                 O   rB   r2   )r   signr   r@   r   r   r   r   ^  rD   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   rB   r2   )r   openr   r@   r   r   r   r   d  s   zDirFileSystem.open)NNNNN)T)F__name__
__module__r   __doc__r   r	   r   r.   propertyr'   r3   r8   r<   r?   rC   rE   rJ   rK   rM   rN   rO   rP   rQ   rR   rS   rV   rY   rZ   r_   ra   rc   rd   rf   rg   ri   rk   rm   ro   rp   rq   rr   rs   rt   ru   rv   rz   r   r   r   r   r   r   r   r   r   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   asynr   r   r   r   r   r   <module>   s    