
    obw&                        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$                  r6d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jJ                  dd      Z& ejJ                  dd      Z' ejJ                  ddd      Z(d Z)d Z* G d dee(   ejV                  e(         Z, G d dee(   ejV                  e(         Z-y)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                     t        |       S )zMake a read-only filesystem.

    Arguments:
        fs (FS): A filesystem instance.

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

    )WrapReadOnlyfss    )/usr/lib/python3/dist-packages/fs/wrap.py	read_onlyr'   3   s         c                     t        |       S )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$   s    r&   cache_directoryr+   A   s     r(   c                   F     e Zd ZdZdZ fdZ	 	 ddZd	dZd Zd Z	 x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                 :    t         t        |   |       i | _        y N)superr*   __init___cache)selfwrap_fs	__class__s     r&   r0   zWrapCachedDir.__init__q   s    mT+G4r(   c                 P   t        t        |            }|t        |xs d      f}|| j                  vrG| j                  j                  |||      }|D ci c]  }|j                  | }}|| j                  |<   t        | j                  |   j                               }	|	S c c}w )N )
namespacespage)	r
   r   	frozensetr1   _wrap_fsscandirnameitervalues)
r2   pathr7   r8   _path	cache_key_scan_resultinfo_dirgen_scandirs
             r&   r;   zWrapCachedDir.scandirv   s     'Ij&6B78	DKK'==00*SW0XL0<=DIItO=D=%)DKK	"4;;y188:; >s   B#c                 2   t        t        |            }|dk(  rt        ddddi      S t        |      \  }}|t	        |xs d      f}|| j
                  vr| j                  ||       | j
                  |   }	 ||   }|S # t        $ r t        |      w xY w)N/basic T)r<   is_dirr6   )r7   )	r
   r   r   r   r9   r1   r;   KeyErrorr   )	r2   r?   r7   r@   dir_pathresource_namerA   rD   rC   s	            r&   getinfozWrapCachedDir.getinfo   s    'C<2">?@@"',-y)9r:;	DKK'LLjL9{{9%	)&D   	)"4((	)s   :B Bc                 X    	 | j                  |      j                  S # t        $ r Y yw xY wNFrN   rJ   r   r2   r?   s     r&   isdirzWrapCachedDir.isdir   s.    	<<%,,, 		s    	))c                 Z    	 | j                  |      j                   S # t        $ r Y yw xY wrP   rQ   rR   s     r&   isfilezWrapCachedDir.isfile   s1    	||D)0000 		s    	**NNr.   )__name__
__module____qualname____doc__	wrap_namer0   r;   rN   rS   rU   __classcell__)r4   s   @r&   r*   r*   P   s0    < I 	 $r(   r*   c                       e Zd ZdZdZd Z	 	 	 ddZ	 	 ddZddZddZ	d	 Z
d
 Zd Zd Z	 	 	 ddZddZddZddZ	 	 ddZ	 	 	 	 	 	 ddZd ZddZ	 	 	 d dZd Zd!dZy)"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                 8    | j                          t        |      r.   checkr   )r2   r?   datas      r&   appendbyteszWrapReadOnly.appendbytes       

t$$r(   Nc                 8    | j                          t        |      r.   r_   )r2   r?   textencodingerrorsnewlines         r&   
appendtextzWrapReadOnly.appendtext        	

t$$r(   c                 8    | j                          t        |      r.   r_   r2   r?   permissionsrecreates       r&   makedirzWrapReadOnly.makedir        	

t$$r(   c                 8    | j                          t        |      r.   r_   r2   src_pathdst_path	overwritepreserve_times        r&   movezWrapReadOnly.move       

x((r(   c                     | j                          t        |      rt        |       | j                  j                  |f|dd|S )N)mode	buffering)r`   r	   r   r:   openbin)r2   r?   r{   r|   optionss        r&   r}   zWrapReadOnly.openbin   sA    

$"4(($t}}$$TNNgNNr(   c                 8    | j                          t        |      r.   r_   rR   s     r&   removezWrapReadOnly.remove   rc   r(   c                 8    | j                          t        |      r.   r_   rR   s     r&   	removedirzWrapReadOnly.removedir   rc   r(   c                 8    | j                          t        |      r.   r_   rR   s     r&   
removetreezWrapReadOnly.removetree   rc   r(   c                 8    | j                          t        |      r.   r_   )r2   r?   rC   s      r&   setinfozWrapReadOnly.setinfo   rc   r(   c                 8    | j                          t        |      r.   r_   )r2   r?   contentsrf   rg   rh   s         r&   	writetextzWrapReadOnly.writetext   rj   r(   c                 8    | j                          t        |      r.   r_   )r2   r?   accessedmodifieds       r&   settimeszWrapReadOnly.settimes   rc   r(   c                 8    | j                          t        |      r.   r_   rr   s        r&   copyzWrapReadOnly.copy   rx   r(   c                 8    | j                          t        |      r.   r_   )r2   r?   wipes      r&   createzWrapReadOnly.create  rc   r(   c                 8    | j                          t        |      r.   r_   rl   s       r&   makedirszWrapReadOnly.makedirs  rp   r(   c           
          | j                          t        |      rt        |       | j                  j                  |f||||||d|S )N)r{   r|   rf   rg   rh   line_buffering)r`   r	   r   r:   open)	r2   r?   r{   r|   rf   rg   rh   r   r~   s	            r&   r   zWrapReadOnly.open  s]     	

$"4((!t}}!!	
)	
 	
 		
r(   c                 8    | j                          t        |      r.   r_   )r2   r?   r   s      r&   
writebyteszWrapReadOnly.writebytes+  rc   r(   c                 8    | j                          t        |      r.   r_   )r2   r?   file
chunk_sizer~   s        r&   uploadzWrapReadOnly.upload0  rc   r(   c                 8    | j                          t        |      r.   r_   )r2   r?   r   rf   rg   rh   s         r&   	writefilezWrapReadOnly.writefile5  rj   r(   c                 8    | j                          t        |      r.   r_   rR   s     r&   touchzWrapReadOnly.touchA  rc   r(   c                     | j                          t        | j                         j                  |            }|j	                  dd       |S )N)	namespaceTF)r'   supports_rename)r`   dictdelegate_fsgetmetaupdate)r2   r   metas      r&   r   zWrapReadOnly.getmetaF  sA    

D$$&...CDdE:r(   )zutf-8NrI   rP   )FF)rrz   rV   )F)r   rz   NNrI   Fr.   )NNrI   )standard)rW   rX   rY   rZ   r[   rb   ri   ro   rw   r}   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r6   r(   r&   r#   r#      s     I% 
% 	%)
O%
%
%
% 
%%
)
% 	% 
4%
% 
%%
r(   r#   ).rZ   
__future__r   r   typingrg   r   r   rC   r   r{   r	   r?   r
   r   r   wrapfsr   TYPE_CHECKINGr   r   r   r   r   r   r   r   r   r   r   baser   r   rm   r   subfsr   TypeVarr   r   r    r'   r+   Genericr*   r#   r6   r(   r&   <module>r      s    8  6    * * 	   "( V^^D)V^^D%V^^D5TF2Jr 2 Tnd6":v~~b1 dr(   