o
    hL/                     @   s,   d dl mZ d dlmZ G dd deZdS )   )
filesystem)AsyncFileSystemc                       s0  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 ZDdd ZE  ZFS )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 }|p|}| jr&|js&td|jr3| j|jkr3t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protocolz(can't use asynchronous with non-async fsz7both dirfs and fs should be in the same sync/async mode )	super__init__r   asynchronous
async_impl
ValueError_strip_protocolpathfs)selfr   r   fotarget_protocoltarget_optionsstorage_options	__class__r   p/var/www/html/construction_image-detection-poc/venv/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   2   s   

zDirFileSystem._joinc                    s   t |trM js
|S | jks  j jjr"| jdd  kr"dS  j jj } j jjr>| jjs>|dd  }||sEJ |t|d  S  fdd|D S )N    c                    r!   r   _relpathr"   r   r   r   r#   L   r$   z*DirFileSystem._relpath.<locals>.<listcomp>)r%   r&   r   
startswithr   r'   len)r   r   prefixr   r   r   r/   =   s   

zDirFileSystem._relpathc                 C   s   | j jS N)r   r'   r   r   r   r   r'   P   s   zDirFileSystem.sepc                    s   | j j|i |I d H S r3   )r   set_session)r   argskwargsr   r   r   r4   T      zDirFileSystem.set_sessionc                    s"   | j j| |fi |I d H S r3   )r   _rm_filer   r   r   r6   r   r   r   r8   W   s    zDirFileSystem._rm_filec                 K      | j j| |fi |S r3   )r   rm_filer   r9   r   r   r   r;   Z      zDirFileSystem.rm_filec                    (   | j j| |g|R i |I d H S r3   )r   _rmr   r   r   r5   r6   r   r   r   r>   ]      &zDirFileSystem._rmc                 O       | j j| |g|R i |S r3   )r   rmr   r?   r   r   r   rB   `       zDirFileSystem.rmc                    s*   | j j| || |fi |I d H S r3   )r   _cp_filer   r   path1path2r6   r   r   r   rD   c   s   (zDirFileSystem._cp_filec                 K   "   | j j| || |fi |S r3   )r   cp_filer   rE   r   r   r   rI   f   s   "zDirFileSystem.cp_filec                    s0   | j j| || |g|R i |I d H S r3   )r   _copyr   r   rF   rG   r5   r6   r   r   r   rJ   i   s   zDirFileSystem._copyc                 O   s(   | j j| || |g|R i |S r3   )r   copyr   rK   r   r   r   rL   w   s   zDirFileSystem.copyc                    r=   r3   )r   _piper   r?   r   r   r   rM      r@   zDirFileSystem._pipec                 O   rA   r3   )r   piper   r?   r   r   r   rN      rC   zDirFileSystem.pipec                    r=   r3   )r   
_pipe_filer   r?   r   r   r   rO      r@   zDirFileSystem._pipe_filec                 O   rA   r3   )r   	pipe_filer   r?   r   r   r   rP      rC   zDirFileSystem.pipe_filec                    r=   r3   )r   	_cat_filer   r?   r   r   r   rQ      r@   zDirFileSystem._cat_filec                 O   rA   r3   )r   cat_filer   r?   r   r   r   rR      rC   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   r5   r6   retr   r   r   rU      s   
zDirFileSystem._catc                    sD    j j |g|R i |}t|tr  fdd| D S |S )Nc                    r   r   r.   rS   r   r   r   r      r    z%DirFileSystem.cat.<locals>.<dictcomp>)r   catr   r%   r)   r*   rV   r   r   r   rX      s   
zDirFileSystem.catc                    s$   | j j|| |fi |I d H S r3   )r   	_put_filer   r   lpathrpathr6   r   r   r   rY         "zDirFileSystem._put_filec                 K   s   | j j|| |fi |S r3   )r   put_filer   rZ   r   r   r   r^         zDirFileSystem.put_filec                    s*   | j j|| |g|R i |I d H S r3   )r   _putr   r   r[   r\   r5   r6   r   r   r   r`      s   zDirFileSystem._putc                 O   s"   | j j|| |g|R i |S r3   )r   putr   ra   r   r   r   rb      s   zDirFileSystem.putc                    s$   | j j| ||fi |I d H S r3   )r   	_get_filer   r   r\   r[   r6   r   r   r   rc      r]   zDirFileSystem._get_filec                 K   s   | j j| ||fi |S r3   )r   get_filer   rd   r   r   r   re      r_   zDirFileSystem.get_filec                    r=   r3   )r   _getr   r   r\   r5   r6   r   r   r   rf      r@   zDirFileSystem._getc                 O   rA   r3   )r   getr   rg   r   r   r   rh      rC   zDirFileSystem.getc                       | j | |I d H S r3   )r   _isfiler   r+   r   r   r   rj      r7   zDirFileSystem._isfilec                 C      | j | |S r3   )r   isfiler   r+   r   r   r   rl         zDirFileSystem.isfilec                    ri   r3   )r   _isdirr   r+   r   r   r   rn      r7   zDirFileSystem._isdirc                 C   rk   r3   )r   isdirr   r+   r   r   r   ro      rm   zDirFileSystem.isdirc                    ri   r3   )r   _sizer   r+   r   r   r   rp      r7   zDirFileSystem._sizec                 C   rk   r3   )r   sizer   r+   r   r   r   rq      rm   zDirFileSystem.sizec                    ri   r3   )r   _existsr   r+   r   r   r   rr      r7   zDirFileSystem._existsc                 C   rk   r3   )r   existsr   r+   r   r   r   rs      rm   zDirFileSystem.existsc                    s@   | j j| |fi |I d H }| }| |d |d< |S Nname)r   _infor   rL   r/   r   r   r6   infor   r   r   rv      s
    zDirFileSystem._infoc                 K   s8   | j j| |fi |}| }| |d |d< |S rt   )r   rx   r   rL   r/   rw   r   r   r   rx      s   zDirFileSystem.infoTc                    sn   | j j| |fd|i|I d H  }|r2g }|D ]}| }| |d |d< || q|S | |S Ndetailru   )r   _lsr   rL   r/   appendr   r   rz   r6   rW   outentryr   r   r   r{      s   (
zDirFileSystem._lsc                 K   sf   | j j| |fd|i| }|r.g }|D ]}| }| |d |d< || q|S | |S ry   )r   lsr   rL   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 r3   )r   _walkr   r/   r   r   r5   r6   rootdirsfilesr   r   r   r     s   2zDirFileSystem._walkc                 o   sD    | j j| |g|R i |D ]\}}}| |||fV  qd S r3   )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 )Nrz   Fc                    r   r   r.   r   r   rx   r   r   r   r     r    z'DirFileSystem._glob.<locals>.<dictcomp>)rh   r   _globr   r*   r/   r   r   r6   rz   rW   r   r   r   r     s    
zDirFileSystem._globc                    sJ   | dd} jj |fi |}|r  fdd| D S  |S )Nrz   Fc                    r   r   r.   r   r   r   r   r      r    z&DirFileSystem.glob.<locals>.<dictcomp>)rh   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   rq   r   r   r   r   )  r    z%DirFileSystem._du.<locals>.<dictcomp>)rh   r   _dur   r*   r   r   r5   r6   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                    r   r   r.   r   r   r   r   r   1  r    z$DirFileSystem.du.<locals>.<dictcomp>)rh   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 )Nrz   Fc                    r   r   r.   r   r   r   r   r   7  r    z'DirFileSystem._find.<locals>.<dictcomp>)rh   r   _findr   r*   r/   r   r   r5   r6   rz   rW   r   r   r   r   3  s   &
zDirFileSystem._findc                    sP   | dd} jj |g|R i |}|r# fdd| D S  |S )Nrz   Fc                    r   r   r.   r   r   r   r   r   >  r    z&DirFileSystem.find.<locals>.<dictcomp>)rh   r   findr   r*   r/   r   r   r   r   r   :  s
    
zDirFileSystem.findc                    s.   |  | jj| |g|R i |I d H S r3   )r/   r   _expand_pathr   r?   r   r   r   r   A  s   $zDirFileSystem._expand_pathc                 O   s&   |  | jj| |g|R i |S r3   )r/   r   expand_pathr   r?   r   r   r   r   F  s   &zDirFileSystem.expand_pathc                    r=   r3   )r   _mkdirr   r?   r   r   r   r   I  r@   zDirFileSystem._mkdirc                 O   rA   r3   )r   mkdirr   r?   r   r   r   r   L  rC   zDirFileSystem.mkdirc                    r=   r3   )r   	_makedirsr   r?   r   r   r   r   O  r@   zDirFileSystem._makedirsc                 O   rA   r3   )r   makedirsr   r?   r   r   r   r   R  rC   zDirFileSystem.makedirsc                 C   rk   r3   )r   rmdirr   r+   r   r   r   r   U  rm   zDirFileSystem.rmdirc                 K   rH   r3   )r   mvr   rE   r   r   r   r   X  s   zDirFileSystem.mvc                 K   r:   r3   )r   touchr   r9   r   r   r   r   _  r<   zDirFileSystem.touchc                 C   rk   r3   )r   createdr   r+   r   r   r   r   b  rm   zDirFileSystem.createdc                 C   rk   r3   )r   modifiedr   r+   r   r   r   r   e  rm   zDirFileSystem.modifiedc                 O   rA   r3   )r   signr   r?   r   r   r   r   h  rC   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__k  s   zDirFileSystem.__repr__c                 O   rA   r3   )r   openr   r?   r   r   r   r   n  s   zDirFileSystem.openc                    r=   r3   )r   
open_asyncr   r?   r   r   r   r   z  s   zDirFileSystem.open_async)NNNNN)T)G__name__
__module__r   __doc__r   r	   r   r/   propertyr'   r4   r8   r;   r>   rB   rD   rI   rJ   rL   rM   rN   rO   rP   rQ   rR   rU   rX   rY   r^   r`   rb   rc   re   rf   rh   rj   rl   rn   ro   rp   rq   rr   rs   rv   rx   r{   r   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    