U
    hL/                     @   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 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                    sx   t  jf | |dkr,tf d|i|p&i }|p2|}| jrH|jsHtd|jrb| j|jkrbt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__ N/var/www/html/venv/lib/python3.8/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>:   s      z'DirFileSystem._join.<locals>.<dictcomp>c                    s   g | ]}  |qS r   r   r   r   r   r   r   
<listcomp>;   s     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r js|S | jks@ j jjrD| jdd  krDdS  j jj } j jjr|| jjs||dd  }||st|t|d  S  fdd|D S )N    c                    s   g | ]}  |qS r   _relpathr   r   r   r   r   L   s     z*DirFileSystem._relpath.<locals>.<listcomp>)r   r   r   
startswithr   r   AssertionError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 d H S r+   )r   set_session)r   argskwargsr   r   r   r,   T   s    zDirFileSystem.set_sessionc                    s   | j j| |f|I d H S r+   )r   _rm_filer   r   r   r.   r   r   r   r/   W   s    zDirFileSystem._rm_filec                 K   s   | j j| |f|S r+   )r   rm_filer   r0   r   r   r   r1   Z   s    zDirFileSystem.rm_filec                    s    | j j| |f||I d H S r+   )r   _rmr   r   r   r-   r.   r   r   r   r2   ]   s    zDirFileSystem._rmc                 O   s   | j j| |f||S r+   )r   rmr   r3   r   r   r   r4   `   s    zDirFileSystem.rmc                    s$   | j j| || |f|I d H S r+   )r   _cp_filer   r   path1path2r.   r   r   r   r5   c   s    zDirFileSystem._cp_filec                 K   s   | j j| || |f|S r+   )r   cp_filer   r6   r   r   r   r9   f   s    zDirFileSystem.cp_filec                    s(   | j j| || |f||I d H S r+   )r   _copyr   r   r7   r8   r-   r.   r   r   r   r:   i   s    zDirFileSystem._copyc                 O   s"   | j j| || |f||S r+   )r   copyr   r;   r   r   r   r<   w   s    zDirFileSystem.copyc                    s    | j j| |f||I d H S r+   )r   _piper   r3   r   r   r   r=      s    zDirFileSystem._pipec                 O   s   | j j| |f||S r+   )r   piper   r3   r   r   r   r>      s    zDirFileSystem.pipec                    s    | j j| |f||I d H S r+   )r   
_pipe_filer   r3   r   r   r   r?      s    zDirFileSystem._pipe_filec                 O   s   | j j| |f||S r+   )r   	pipe_filer   r3   r   r   r   r@      s    zDirFileSystem.pipe_filec                    s    | j j| |f||I d H S r+   )r   	_cat_filer   r3   r   r   r   rA      s    zDirFileSystem._cat_filec                 O   s   | j j| |f||S r+   )r   cat_filer   r3   r   r   r   rB      s    zDirFileSystem.cat_filec                    sD    j j |f||I d H }t|tr@ fdd| D S |S )Nc                    s   i | ]\}}  ||qS r   r%   r   keyr   r   r   r   r      s      z&DirFileSystem._cat.<locals>.<dictcomp>)r   _catr   r   r    r!   r   r   r-   r.   retr   r   r   rE      s    

zDirFileSystem._catc                    s>    j j |f||}t|tr: fdd| D S |S )Nc                    s   i | ]\}}  ||qS r   r%   rC   r   r   r   r      s      z%DirFileSystem.cat.<locals>.<dictcomp>)r   catr   r   r    r!   rF   r   r   r   rH      s    
zDirFileSystem.catc                    s   | j j|| |f|I d H S r+   )r   	_put_filer   r   lpathrpathr.   r   r   r   rI      s    zDirFileSystem._put_filec                 K   s   | j j|| |f|S r+   )r   put_filer   rJ   r   r   r   rM      s    zDirFileSystem.put_filec                    s"   | j j|| |f||I d H S r+   )r   _putr   r   rK   rL   r-   r.   r   r   r   rN      s    zDirFileSystem._putc                 O   s   | j j|| |f||S r+   )r   putr   rO   r   r   r   rP      s    zDirFileSystem.putc                    s   | j j| ||f|I d H S r+   )r   	_get_filer   r   rL   rK   r.   r   r   r   rQ      s    zDirFileSystem._get_filec                 K   s   | j j| ||f|S r+   )r   get_filer   rR   r   r   r   rS      s    zDirFileSystem.get_filec                    s    | j j| |f||I d H S r+   )r   _getr   r   rL   r-   r.   r   r   r   rT      s    zDirFileSystem._getc                 O   s   | j j| |f||S r+   )r   getr   rU   r   r   r   rV      s    zDirFileSystem.getc                    s   | j | |I d H S r+   )r   _isfiler   r"   r   r   r   rW      s    zDirFileSystem._isfilec                 C   s   | j | |S r+   )r   isfiler   r"   r   r   r   rX      s    zDirFileSystem.isfilec                    s   | j | |I d H S r+   )r   _isdirr   r"   r   r   r   rY      s    zDirFileSystem._isdirc                 C   s   | j | |S r+   )r   isdirr   r"   r   r   r   rZ      s    zDirFileSystem.isdirc                    s   | j | |I d H S r+   )r   _sizer   r"   r   r   r   r[      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 d H }| }| |d |d< |S Nname)r   _infor   r<   r&   r   r   r.   infor   r   r   ra      s    zDirFileSystem._infoc                 K   s4   | j j| |f|}| }| |d |d< |S r_   )r   rc   r   r<   r&   rb   r   r   r   rc      s    zDirFileSystem.infoTc                    sl   | j j| |fd|i|I d H  }|rbg }|D ](}| }| |d |d< || q4|S | |S Ndetailr`   )r   _lsr   r<   r&   appendr   r   re   r.   rG   outentryr   r   r   rf      s    (zDirFileSystem._lsc                 K   sf   | j j| |fd|i| }|r\g }|D ](}| }| |d |d< || q.|S | |S rd   )r   lsr   r<   r&   rg   rh   r   r   r   rk     s    "zDirFileSystem.lsc                 O  sF   | j j| |f||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   rl     s    ,zDirFileSystem._walkc                 o   s<   | j j| |f||D ]\}}}| |||fV  qd S r+   )r   walkr   r&   rm   r   r   r   rq     s    $zDirFileSystem.walkc                    sL   | dd} jj |f|I d H }|rB fdd| D S  |S )Nre   Fc                    s   i | ]\}}  ||qS r   r%   r   r   rc   r   r   r   r     s      z'DirFileSystem._glob.<locals>.<dictcomp>)rV   r   _globr   r!   r&   r   r   r.   re   rG   r   r   r   rs     s
    zDirFileSystem._globc                    sF   | dd} jj |f|}|r< fdd| D S  |S )Nre   Fc                    s   i | ]\}}  ||qS r   r%   rr   r   r   r   r      s      z&DirFileSystem.glob.<locals>.<dictcomp>)rV   r   globr   r!   r&   rt   r   r   r   ru     s
    zDirFileSystem.globc                    sJ   | dd} jj |f||I d H }|r4|S  fdd| D S )NtotalTc                    s   i | ]\}}  ||qS r   r%   r   r   r\   r   r   r   r   )  s      z%DirFileSystem._du.<locals>.<dictcomp>)rV   r   _dur   r!   r   r   r-   r.   rv   rG   r   r   r   rx   #  s
     zDirFileSystem._duc                    sD   | dd} jj |f||}|r.|S  fdd| D S )Nrv   Tc                    s   i | ]\}}  ||qS r   r%   rw   r   r   r   r   1  s      z$DirFileSystem.du.<locals>.<dictcomp>)rV   r   dur   r!   ry   r   r   r   rz   +  s
    zDirFileSystem.duc                    sP   | dd} jj |f||I d H }|rF fdd| D S  |S )Nre   Fc                    s   i | ]\}}  ||qS r   r%   rr   r   r   r   r   7  s      z'DirFileSystem._find.<locals>.<dictcomp>)rV   r   _findr   r!   r&   r   r   r-   r.   re   rG   r   r   r   r{   3  s
     zDirFileSystem._findc                    sJ   | dd} jj |f||}|r@ fdd| D S  |S )Nre   Fc                    s   i | ]\}}  ||qS r   r%   rr   r   r   r   r   >  s      z&DirFileSystem.find.<locals>.<dictcomp>)rV   r   findr   r!   r&   r|   r   r   r   r}   :  s
    zDirFileSystem.findc                    s&   |  | jj| |f||I d H S r+   )r&   r   _expand_pathr   r3   r   r   r   r~   A  s    zDirFileSystem._expand_pathc                 O   s    |  | jj| |f||S r+   )r&   r   expand_pathr   r3   r   r   r   r   F  s    zDirFileSystem.expand_pathc                    s    | j j| |f||I d H S r+   )r   _mkdirr   r3   r   r   r   r   I  s    zDirFileSystem._mkdirc                 O   s   | j j| |f||S r+   )r   mkdirr   r3   r   r   r   r   L  s    zDirFileSystem.mkdirc                    s    | j j| |f||I d H S r+   )r   	_makedirsr   r3   r   r   r   r   O  s    zDirFileSystem._makedirsc                 O   s   | j j| |f||S r+   )r   makedirsr   r3   r   r   r   r   R  s    zDirFileSystem.makedirsc                 C   s   | j | |S r+   )r   rmdirr   r"   r   r   r   r   U  s    zDirFileSystem.rmdirc                 K   s   | j j| || |f|S r+   )r   mvr   r6   r   r   r   r   X  s    zDirFileSystem.mvc                 K   s   | j j| |f|S r+   )r   touchr   r0   r   r   r   r   _  s    zDirFileSystem.touchc                 C   s   | j | |S r+   )r   createdr   r"   r   r   r   r   b  s    zDirFileSystem.createdc                 C   s   | j | |S r+   )r   modifiedr   r"   r   r   r   r   e  s    zDirFileSystem.modifiedc                 O   s   | j j| |f||S r+   )r   signr   r3   r   r   r   r   h  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__k  s    zDirFileSystem.__repr__c                 O   s   | j j| |f||S r+   )r   openr   r3   r   r   r   r   n  s    zDirFileSystem.openc                    s    | j j| |f||I d H S r+   )r   
open_asyncr   r3   r   r   r   r   z  s    zDirFileSystem.open_async)NNNNN)T)T)G__name__
__module__r   __doc__r   r   r   r&   propertyr   r,   r/   r1   r2   r4   r5   r9   r:   r<   r=   r>   r?   r@   rA   rB   rE   rH   rI   rM   rN   rP   rQ   rS   rT   rV   rW   rX   rY   rZ   r[   r\   r]   r^   ra   rc   rf   rk   rl   rq   rs   ru   rx   rz   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   