o
    pfw&                     @   sN  d Z ddlmZmZ ddlZddlmZmZ ddlm	Z	 ddl
mZ ddlmZmZmZ dd	lmZ ejrkdd
lmZmZmZmZmZmZmZmZmZmZ ddlmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ej%dddZ&ej%dddZ'ej%ddddZ(dd Z)dd Z*G dd dee( ej+e( Z,G dd dee( ej+e( Z-dS ) aw  Collection of useful `~fs.wrapfs.WrapFS` subclasses.

Here's an example that opens a filesystem then makes it *read only*::

    >>> home_fs = fs.open_fs('~')
    >>> read_only_home_fs = fs.wrap.read_only(home_fs)
    >>> read_only_home_fs.removedir('Desktop')
    Traceback (most recent call last):
      ...
    fs.errors.ResourceReadOnly: resource 'Desktop' is read only

    )print_functionunicode_literalsN   )ResourceNotFoundResourceReadOnly)Info)check_writable)abspathnormpathsplit)WrapFS)
IOAnyBinaryIO
CollectionDictIteratorMappingOptionalTextTuple)datetime)FS)RawInfo)Permissions)SubFS_Wr   )bound_Tr   _FT)r   	covariantc                 C      t | S )zMake a read-only filesystem.

    Arguments:
        fs (FS): A filesystem instance.

    Returns:
        FS: A read only version of ``fs``

    )WrapReadOnlyfs r%   @/home/ertert/spirit/venv/lib/python3.10/site-packages/fs/wrap.py	read_only3   s   r'   c                 C   r!   )a  Make a filesystem that caches directory information.

    Arguments:
        fs (FS): A filesystem instance.

    Returns:
        FS: A filesystem that caches results of `~FS.scandir`, `~FS.isdir`
        and other methods which read directory information.

    )WrapCachedDirr#   r%   r%   r&   cache_directoryA   s   r)   c                       sL   e Zd ZdZdZ fddZ		dddZddd	Zd
d Zdd Z	  Z
S )r(   a  Caches filesystem directory information.

    This filesystem caches directory information retrieved from a
    scandir call. This *may* speed up code that calls `~FS.isdir`,
    `~FS.isfile`, or `~FS.gettype` too frequently.

    Note:
        Using this wrap will prevent changes to directory information
        being visible to the filesystem object. Consequently it is best
        used only in a fairly limited scope where you don't expected
        anything on the filesystem to change.

    z
cached-dirc                    s   t t| | i | _d S N)superr(   __init___cache)selfwrap_fs	__class__r%   r&   r,   q   s   
zWrapCachedDir.__init__Nc           	      C   sf   t t|}|t|pdf}|| jvr(| jj|||d}dd |D }|| j|< t| j|  }|S )Nr%   )
namespacespagec                 S   s   i | ]}|j |qS r%   )name).0infor%   r%   r&   
<dictcomp>   s    z)WrapCachedDir.scandir.<locals>.<dictcomp>)r	   r
   	frozensetr-   _wrap_fsscandiritervalues)	r.   pathr2   r3   _path	cache_key_scan_result_dirgen_scandirr%   r%   r&   r:   v   s   

zWrapCachedDir.scandirc           	      C   s   t t|}|dkrtddddiS t|\}}|t|pdf}|| jvr-| j||d | j| }z|| }W |S  tyD   t|w )N/basic T)r4   is_dirr%   )r2   )	r	   r
   r   r   r8   r-   r:   KeyErrorr   )	r.   r=   r2   r>   dir_pathresource_namer?   rA   r6   r%   r%   r&   getinfo   s   


zWrapCachedDir.getinfoc                 C   s$   z|  |jW S  ty   Y dS w NFrJ   rF   r   r.   r=   r%   r%   r&   isdir   s
   zWrapCachedDir.isdirc                 C   s&   z|  |j W S  ty   Y dS w rK   rL   rM   r%   r%   r&   isfile   s
   zWrapCachedDir.isfileNNr*   )__name__
__module____qualname____doc__	wrap_namer,   r:   rJ   rN   rO   __classcell__r%   r%   r0   r&   r(   P   s    

r(   c                   @   s   e Zd ZdZdZdd Z			d2dd	Z		
d3ddZd4ddZd5ddZ	dd Z
dd Zdd Zdd Z			d2ddZd6ddZd4dd Zd7d!d"Z		
d3d#d$Z						
d8d%d&Zd'd( Zd9d)d*Z			d:d+d,Zd-d. Zd;d0d1ZdS )<r"   zMakes a Filesystem read-only.

    Any call that would would write data or modify the filesystem in any way
    will raise a `~fs.errors.ResourceReadOnly` exception.

    z	read-onlyc                 C      |    t|r*   checkr   )r.   r=   datar%   r%   r&   appendbytes      zWrapReadOnly.appendbytesutf-8NrE   c                 C   rW   r*   rX   )r.   r=   textencodingerrorsnewliner%   r%   r&   
appendtext      	zWrapReadOnly.appendtextFc                 C   rW   r*   rX   r.   r=   permissionsrecreater%   r%   r&   makedir      zWrapReadOnly.makedirc                 C      |    t|r*   rX   r.   src_pathdst_path	overwritepreserve_timer%   r%   r&   move   r\   zWrapReadOnly.moverc                 K   s2   |    t|rt|| jj|f|dd|S )Nrq   )mode	buffering)rY   r   r   r9   openbin)r.   r=   rr   rs   optionsr%   r%   r&   rt      s   zWrapReadOnly.openbinc                 C   rW   r*   rX   rM   r%   r%   r&   remove   r\   zWrapReadOnly.removec                 C   rW   r*   rX   rM   r%   r%   r&   	removedir   r\   zWrapReadOnly.removedirc                 C   rW   r*   rX   rM   r%   r%   r&   
removetree   r\   zWrapReadOnly.removetreec                 C   rW   r*   rX   )r.   r=   r6   r%   r%   r&   setinfo   r\   zWrapReadOnly.setinfoc                 C   rW   r*   rX   )r.   r=   contentsr_   r`   ra   r%   r%   r&   	writetext   rc   zWrapReadOnly.writetextc                 C   rW   r*   rX   )r.   r=   accessedmodifiedr%   r%   r&   settimes   r\   zWrapReadOnly.settimesc                 C   ri   r*   rX   rj   r%   r%   r&   copy   r\   zWrapReadOnly.copyc                 C   rW   r*   rX   )r.   r=   wiper%   r%   r&   create  r\   zWrapReadOnly.createc                 C   rW   r*   rX   rd   r%   r%   r&   makedirs  rh   zWrapReadOnly.makedirsc           	   	   K   s:   |    t|rt|| jj|f||||||d|S )N)rr   rs   r_   r`   ra   line_buffering)rY   r   r   r9   open)	r.   r=   rr   rs   r_   r`   ra   r   ru   r%   r%   r&   r     s   zWrapReadOnly.openc                 C   rW   r*   rX   )r.   r=   rz   r%   r%   r&   
writebytes+  r\   zWrapReadOnly.writebytesc                 K   rW   r*   rX   )r.   r=   file
chunk_sizeru   r%   r%   r&   upload0  r\   zWrapReadOnly.uploadc                 C   rW   r*   rX   )r.   r=   r   r_   r`   ra   r%   r%   r&   	writefile5  rc   zWrapReadOnly.writefilec                 C   rW   r*   rX   rM   r%   r%   r&   touchA  r\   zWrapReadOnly.touchstandardc                 C   s.   |    t|  j|d}|jddd |S )N)	namespaceTF)r'   supports_rename)rY   dictdelegate_fsgetmetaupdate)r.   r   metar%   r%   r&   r   F  s   zWrapReadOnly.getmeta)r]   NrE   rK   )FF)rp   rq   rP   )F)rp   rq   NNrE   Fr*   )NNrE   )r   )rQ   rR   rS   rT   rU   r[   rb   rg   ro   rt   rv   rw   rx   ry   r{   r~   r   r   r   r   r   r   r   r   r   r%   r%   r%   r&   r"      sT    	




	






	
r"   ).rT   
__future__r   r   typingr`   r   r   r6   r   rr   r   r=   r	   r
   r   wrapfsr   TYPE_CHECKINGr   r   r   r   r   r   r   r   r   r   r   baser   r   re   r   subfsr   TypeVarr   r   r   r'   r)   Genericr(   r"   r%   r%   r%   r&   <module>   s,    0 W