o
    "ifx,                     @   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   U/var/www/html/corbot_env/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  fdd|D S )Nc                       g | ]}  |qS r   )_join.0_pathr   r   r   
<listcomp>;       z'DirFileSystem._join.<locals>.<listcomp>)
isinstancestrr   r   sepjoinr   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   F   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"   J   s   zDirFileSystem.sepc                    s   | j j|i |I d H S r+   )r   set_session)r   argskwargsr   r   r   r,   N      zDirFileSystem.set_sessionc                    "   | j j| |fi |I d H S r+   )r   _rm_filer   r   r   r.   r   r   r   r1   Q       zDirFileSystem._rm_filec                 K      | j j| |fi |S r+   )r   rm_filer   r2   r   r   r   r5   T      zDirFileSystem.rm_filec                    (   | j j| |g|R i |I d H S r+   )r   _rmr   r   r   r-   r.   r   r   r   r8   W      &zDirFileSystem._rmc                 O       | j j| |g|R i |S r+   )r   rmr   r9   r   r   r   r<   Z       zDirFileSystem.rmc                    s*   | j j| || |fi |I d H S r+   )r   _cp_filer   r   path1path2r.   r   r   r   r>   ]   s   (zDirFileSystem._cp_filec                 K   "   | j j| || |fi |S r+   )r   cp_filer   r?   r   r   r   rC   `   s   "zDirFileSystem.cp_filec                    s0   | j j| || |g|R i |I d H S r+   )r   _copyr   r   r@   rA   r-   r.   r   r   r   rD   c   s   zDirFileSystem._copyc                 O   s(   | j j| || |g|R i |S r+   )r   copyr   rE   r   r   r   rF   q   s   zDirFileSystem.copyc                    r7   r+   )r   _piper   r9   r   r   r   rG   y   r:   zDirFileSystem._pipec                 O   r;   r+   )r   piper   r9   r   r   r   rH   |   r=   zDirFileSystem.pipec                    r7   r+   )r   
_pipe_filer   r9   r   r   r   rI      r:   zDirFileSystem._pipe_filec                 O   r;   r+   )r   	pipe_filer   r9   r   r   r   rJ      r=   zDirFileSystem.pipe_filec                    r7   r+   )r   	_cat_filer   r9   r   r   r   rK      r:   zDirFileSystem._cat_filec                 O   r;   r+   )r   cat_filer   r9   r   r   r   rL      r=   zDirFileSystem.cat_filec                    sL    j j |g|R i |I d H }t|tr$ fdd| D S |S )Nc                       i | ]
\}}  ||qS r   r&   r   keyvaluer   r   r   
<dictcomp>       z&DirFileSystem._cat.<locals>.<dictcomp>)r   _catr   r    dictitemsr   r   r-   r.   retr   r   r   rS      s   
zDirFileSystem._catc                    sD    j j |g|R i |}t|tr  fdd| D S |S )Nc                    rM   r   r&   rN   r   r   r   rQ      rR   z%DirFileSystem.cat.<locals>.<dictcomp>)r   catr   r    rT   rU   rV   r   r   r   rX      s   
zDirFileSystem.catc                    s$   | j j|| |fi |I d H S r+   )r   	_put_filer   r   lpathrpathr.   r   r   r   rY         "zDirFileSystem._put_filec                 K   s   | j j|| |fi |S r+   )r   put_filer   rZ   r   r   r   r^         zDirFileSystem.put_filec                    s*   | j j|| |g|R i |I d H S r+   )r   _putr   r   r[   r\   r-   r.   r   r   r   r`      s   zDirFileSystem._putc                 O   s"   | j j|| |g|R i |S r+   )r   putr   ra   r   r   r   rb      s   zDirFileSystem.putc                    s$   | j j| ||fi |I d H S r+   )r   	_get_filer   r   r\   r[   r.   r   r   r   rc      r]   zDirFileSystem._get_filec                 K   s   | j j| ||fi |S r+   )r   get_filer   rd   r   r   r   re      r_   zDirFileSystem.get_filec                    r7   r+   )r   _getr   r   r\   r-   r.   r   r   r   rf      r:   zDirFileSystem._getc                 O   r;   r+   )r   getr   rg   r   r   r   rh      r=   zDirFileSystem.getc                       | j | |I d H S r+   )r   _isfiler   r$   r   r   r   rj      r/   zDirFileSystem._isfilec                 C      | j | |S r+   )r   isfiler   r$   r   r   r   rl         zDirFileSystem.isfilec                    ri   r+   )r   _isdirr   r$   r   r   r   rn      r/   zDirFileSystem._isdirc                 C   rk   r+   )r   isdirr   r$   r   r   r   ro      rm   zDirFileSystem.isdirc                    ri   r+   )r   _sizer   r$   r   r   r   rp      r/   zDirFileSystem._sizec                 C   rk   r+   )r   sizer   r$   r   r   r   rq      rm   zDirFileSystem.sizec                    ri   r+   )r   _existsr   r$   r   r   r   rr      r/   zDirFileSystem._existsc                 C   rk   r+   )r   existsr   r$   r   r   r   rs      rm   zDirFileSystem.existsc                    r0   r+   )r   _infor   r2   r   r   r   rt      r3   zDirFileSystem._infoc                 K   r4   r+   )r   infor   r2   r   r   r   ru      r6   zDirFileSystem.infoTc                    sn   | j j| |fd|i|I d H  }|r2g }|D ]}| }| |d |d< || q|S | |S Ndetailname)r   _lsr   rF   r'   appendr   r   rw   r.   rW   outentryr   r   r   ry      s   (
zDirFileSystem._lsc                 K   sf   | j j| |fd|i| }|r.g }|D ]}| }| |d |d< || q|S | |S rv   )r   lsr   rF   r'   rz   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 r+   )r   _walkr   r'   r   r   r-   r.   rootdirsfilesr   r   r   r     s   2zDirFileSystem._walkc                 o   sD    | j j| |g|R i |D ]\}}}| |||fV  qd S r+   )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 )Nrw   Fc                    rM   r   r&   r   r   ru   r   r   r   rQ     rR   z'DirFileSystem._glob.<locals>.<dictcomp>)rh   r   _globr   rU   r'   r   r   r.   rw   rW   r   r   r   r   	  s    
zDirFileSystem._globc                    sJ   | dd} jj |fi |}|r  fdd| D S  |S )Nrw   Fc                    rM   r   r&   r   r   r   r   rQ     rR   z&DirFileSystem.glob.<locals>.<dictcomp>)rh   r   globr   rU   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                    rM   r   r&   r   r   rq   r   r   r   rQ     rR   z%DirFileSystem._du.<locals>.<dictcomp>)rh   r   _dur   rU   r   r   r-   r.   r   rW   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                    rM   r   r&   r   r   r   r   rQ   %  rR   z$DirFileSystem.du.<locals>.<dictcomp>)rh   r   dur   rU   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 )Nrw   Fc                    rM   r   r&   r   r   r   r   rQ   +  rR   z'DirFileSystem._find.<locals>.<dictcomp>)rh   r   _findr   rU   r'   r   r   r-   r.   rw   rW   r   r   r   r   '  s   &
zDirFileSystem._findc                    sP   | dd} jj |g|R i |}|r# fdd| D S  |S )Nrw   Fc                    rM   r   r&   r   r   r   r   rQ   2  rR   z&DirFileSystem.find.<locals>.<dictcomp>)rh   r   findr   rU   r'   r   r   r   r   r   .  s
    
zDirFileSystem.findc                    s.   |  | jj| |g|R i |I d H S r+   )r'   r   _expand_pathr   r9   r   r   r   r   5  s   $zDirFileSystem._expand_pathc                 O   s&   |  | jj| |g|R i |S r+   )r'   r   expand_pathr   r9   r   r   r   r   :  s   &zDirFileSystem.expand_pathc                    r7   r+   )r   _mkdirr   r9   r   r   r   r   =  r:   zDirFileSystem._mkdirc                 O   r;   r+   )r   mkdirr   r9   r   r   r   r   @  r=   zDirFileSystem.mkdirc                    r7   r+   )r   	_makedirsr   r9   r   r   r   r   C  r:   zDirFileSystem._makedirsc                 O   r;   r+   )r   makedirsr   r9   r   r   r   r   F  r=   zDirFileSystem.makedirsc                 C   rk   r+   )r   rmdirr   r$   r   r   r   r   I  rm   zDirFileSystem.rmdirc                 K   rB   r+   )r   mv_filer   r?   r   r   r   r   L  s   zDirFileSystem.mv_filec                 K   r4   r+   )r   touchr   r2   r   r   r   r   S  r6   zDirFileSystem.touchc                 C   rk   r+   )r   createdr   r$   r   r   r   r   V  rm   zDirFileSystem.createdc                 C   rk   r+   )r   modifiedr   r$   r   r   r   r   Y  rm   zDirFileSystem.modifiedc                 O   r;   r+   )r   signr   r9   r   r   r   r   \  r=   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___  s   zDirFileSystem.__repr__c                 O   r;   r+   )r   openr   r9   r   r   r   r   b  s   zDirFileSystem.open)NNNNN)T)F__name__
__module__r   __doc__r   r	   r   r'   propertyr"   r,   r1   r5   r8   r<   r>   rC   rD   rF   rG   rH   rI   rJ   rK   rL   rS   rX   rY   r^   r`   rb   rc   re   rf   rh   rj   rl   rn   ro   rp   rq   rr   rs   rt   ru   ry   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    