o
    _ZhL/                     @   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   ZasynchronousZ
async_impl
ValueError_strip_protocolpathfs)selfr   r   foZtarget_protocolZtarget_optionsZstorage_options	__class__r   K/var/www/auris/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 r.   )r   set_session)r   argskwargsr   r   r   r/   T      zDirFileSystem.set_sessionc                    s"   | j j| |fi |I d H S r.   )r   _rm_filer   r   r   r1   r   r   r   r3   W   s    zDirFileSystem._rm_filec                 K      | j j| |fi |S r.   )r   rm_filer   r4   r   r   r   r6   Z      zDirFileSystem.rm_filec                    (   | j j| |g|R i |I d H S r.   )r   _rmr   r   r   r0   r1   r   r   r   r9   ]      &zDirFileSystem._rmc                 O       | j j| |g|R i |S r.   )r   rmr   r:   r   r   r   r=   `       zDirFileSystem.rmc                    s*   | j j| || |fi |I d H S r.   )r   _cp_filer   r   path1path2r1   r   r   r   r?   c   s   (zDirFileSystem._cp_filec                 K   "   | j j| || |fi |S r.   )r   cp_filer   r@   r   r   r   rD   f   s   "zDirFileSystem.cp_filec                    s0   | j j| || |g|R i |I d H S r.   )r   _copyr   r   rA   rB   r0   r1   r   r   r   rE   i   s   zDirFileSystem._copyc                 O   s(   | j j| || |g|R i |S r.   )r   copyr   rF   r   r   r   rG   w   s   zDirFileSystem.copyc                    r8   r.   )r   _piper   r:   r   r   r   rH      r;   zDirFileSystem._pipec                 O   r<   r.   )r   piper   r:   r   r   r   rI      r>   zDirFileSystem.pipec                    r8   r.   )r   
_pipe_filer   r:   r   r   r   rJ      r;   zDirFileSystem._pipe_filec                 O   r<   r.   )r   	pipe_filer   r:   r   r   r   rK      r>   zDirFileSystem.pipe_filec                    r8   r.   )r   	_cat_filer   r:   r   r   r   rL      r;   zDirFileSystem._cat_filec                 O   r<   r.   )r   cat_filer   r:   r   r   r   rM      r>   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   r0   r1   retr   r   r   rP      s   
zDirFileSystem._catc                    sD    j j |g|R i |}t|tr  fdd| D S |S )Nc                    r   r   r)   rN   r   r   r   r      r   z%DirFileSystem.cat.<locals>.<dictcomp>)r   catr   r    r$   r%   rQ   r   r   r   rS      s   
zDirFileSystem.catc                    s$   | j j|| |fi |I d H S r.   )r   	_put_filer   r   lpathrpathr1   r   r   r   rT         "zDirFileSystem._put_filec                 K   s   | j j|| |fi |S r.   )r   put_filer   rU   r   r   r   rY         zDirFileSystem.put_filec                    s*   | j j|| |g|R i |I d H S r.   )r   _putr   r   rV   rW   r0   r1   r   r   r   r[      s   zDirFileSystem._putc                 O   s"   | j j|| |g|R i |S r.   )r   putr   r\   r   r   r   r]      s   zDirFileSystem.putc                    s$   | j j| ||fi |I d H S r.   )r   	_get_filer   r   rW   rV   r1   r   r   r   r^      rX   zDirFileSystem._get_filec                 K   s   | j j| ||fi |S r.   )r   get_filer   r_   r   r   r   r`      rZ   zDirFileSystem.get_filec                    r8   r.   )r   _getr   r   rW   r0   r1   r   r   r   ra      r;   zDirFileSystem._getc                 O   r<   r.   )r   getr   rb   r   r   r   rc      r>   zDirFileSystem.getc                       | j | |I d H S r.   )r   _isfiler   r&   r   r   r   re      r2   zDirFileSystem._isfilec                 C      | j | |S r.   )r   isfiler   r&   r   r   r   rg         zDirFileSystem.isfilec                    rd   r.   )r   _isdirr   r&   r   r   r   ri      r2   zDirFileSystem._isdirc                 C   rf   r.   )r   isdirr   r&   r   r   r   rj      rh   zDirFileSystem.isdirc                    rd   r.   )r   _sizer   r&   r   r   r   rk      r2   zDirFileSystem._sizec                 C   rf   r.   )r   sizer   r&   r   r   r   rl      rh   zDirFileSystem.sizec                    rd   r.   )r   _existsr   r&   r   r   r   rm      r2   zDirFileSystem._existsc                 C   rf   r.   )r   existsr   r&   r   r   r   rn      rh   zDirFileSystem.existsc                    s@   | j j| |fi |I d H }| }| |d |d< |S Nname)r   _infor   rG   r*   r   r   r1   infor   r   r   rq      s
    zDirFileSystem._infoc                 K   s8   | j j| |fi |}| }| |d |d< |S ro   )r   rs   r   rG   r*   rr   r   r   r   rs      s   zDirFileSystem.infoTc                    sn   | j j| |fd|i|I d H  }|r2g }|D ]}| }| |d |d< || q|S | |S Ndetailrp   )r   _lsr   rG   r*   appendr   r   ru   r1   rR   outentryr   r   r   rv      s   (
zDirFileSystem._lsc                 K   sf   | j j| |fd|i| }|r.g }|D ]}| }| |d |d< || q|S | |S rt   )r   lsr   rG   r*   rw   rx   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   r0   r1   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 )Nru   Fc                    r   r   r)   r   r   rs   r   r   r   r     r   z'DirFileSystem._glob.<locals>.<dictcomp>)rc   r   _globr   r%   r*   r   r   r1   ru   rR   r   r   r   r     s    
zDirFileSystem._globc                    sJ   | dd} jj |fi |}|r  fdd| D S  |S )Nru   Fc                    r   r   r)   r   r   r   r   r      r   z&DirFileSystem.glob.<locals>.<dictcomp>)rc   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   rl   r   r   r   r   )  r   z%DirFileSystem._du.<locals>.<dictcomp>)rc   r   _dur   r%   r   r   r0   r1   r   rR   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>)rc   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 )Nru   Fc                    r   r   r)   r   r   r   r   r   7  r   z'DirFileSystem._find.<locals>.<dictcomp>)rc   r   _findr   r%   r*   r   r   r0   r1   ru   rR   r   r   r   r   3  s   &
zDirFileSystem._findc                    sP   | dd} jj |g|R i |}|r# fdd| D S  |S )Nru   Fc                    r   r   r)   r   r   r   r   r   >  r   z&DirFileSystem.find.<locals>.<dictcomp>)rc   r   findr   r%   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   r:   r   r   r   r   A  s   $zDirFileSystem._expand_pathc                 O   s&   |  | jj| |g|R i |S r.   )r*   r   expand_pathr   r:   r   r   r   r   F  s   &zDirFileSystem.expand_pathc                    r8   r.   )r   _mkdirr   r:   r   r   r   r   I  r;   zDirFileSystem._mkdirc                 O   r<   r.   )r   mkdirr   r:   r   r   r   r   L  r>   zDirFileSystem.mkdirc                    r8   r.   )r   	_makedirsr   r:   r   r   r   r   O  r;   zDirFileSystem._makedirsc                 O   r<   r.   )r   makedirsr   r:   r   r   r   r   R  r>   zDirFileSystem.makedirsc                 C   rf   r.   )r   rmdirr   r&   r   r   r   r   U  rh   zDirFileSystem.rmdirc                 K   rC   r.   )r   mvr   r@   r   r   r   r   X  s   zDirFileSystem.mvc                 K   r5   r.   )r   touchr   r4   r   r   r   r   _  r7   zDirFileSystem.touchc                 C   rf   r.   )r   createdr   r&   r   r   r   r   b  rh   zDirFileSystem.createdc                 C   rf   r.   )r   modifiedr   r&   r   r   r   r   e  rh   zDirFileSystem.modifiedc                 O   r<   r.   )r   signr   r:   r   r   r   r   h  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__k  s   zDirFileSystem.__repr__c                 O   r<   r.   )r   openr   r:   r   r   r   r   n  s   zDirFileSystem.openc                    r8   r.   )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"   r/   r3   r6   r9   r=   r?   rD   rE   rG   rH   rI   rJ   rK   rL   rM   rP   rS   rT   rY   r[   r]   r^   r`   ra   rc   re   rg   ri   rj   rk   rl   rm   rn   rq   rs   rv   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   Zasynr   r   r   r   r   r   <module>   s    