
    OOId'                         d dl Z d dlZddlmZ ddlmZ ddlmZmZm	Z	 i Z
 ej        d          Zd ZdZdd	Z	 	 	 	 	 	 ddZ G d de          Zd ZdS )    N   )AsyncFileSystem)_DEFAULT_CALLBACK)
filesystemget_filesystem_classsplit_protocolzfsspec.genericc                 0    t          | fi |t          | <   d S N)r   _generic_fs)protocolstorage_optionss     .lib/python3.11/site-packages/fsspec/generic.pyset_generic_fsr      s"    &xCC?CCK    defaultc                 ^   |pt           }|pt          |           d         }|pi }|dk    rt          |          S |dk    rt          |         S |dk    r#t	          |          }|                                S |dk    r!t          |fi |                    |i           S t          d|           )zPick instance of backend FSr   r   genericcurrentoptionszUnknown FS resolution method: )default_methodr   r   r   r   r   get
ValueError)urlmethodr   r   clss        r   _resolve_fsr      s    %~F1>#..q1H%+O(###8$$"8,,{{}}(HHo&9&9(B&G&GHHH
>f>>
?
??r   Fsize	differentc                 P    |pt          di |pi }|                                |                              |                     dd          |                               st	          d          |                    dd           fd                                D             }	t                              t          |	           d           |	D ]-}
|	                    |

                               d           .d                                 D             t                              t                     d            fd	                                D             }                                                                D ]j\  }}|
                               }|v rF|d
k    r||<   +|dk    r3||         |         |         k    r||<   O                    |           e||<   krWt                                           \  }}t                              t          |           d            |j        ||fi | |rAt                              t          |           d           |                    |           dS dS )a  Sync files between two directory trees

    (experimental)

    Parameters
    ----------
    source: str
        Root of the directory tree to take files from.
    destination: str
        Root path to copy into. The contents of this location should be
        identical to the contents of ``source`` when done.
    delete_missing: bool
        If there are paths in the destination that don't exist in the
        source and this is True, delete them. Otherwise, leave them alone.
    source_field: str
        If ``update_field`` is "different", this is the key in the info
        of source files to consider for difference.
    dest_field: str
        If ``update_field`` is "different", this is the key in the info
        of destination files to consider for difference.
    update_cond: "different"|"always"|"never"
        If "always", every file is copied, regardless of whether it exists in
        the destination. If "never", files that exist in the destination are
        not copied again. If "different" (default), only copy if the info
        fields given by ``source_field`` and ``dest_field`` (usually "size")
        are different. Other comparisons may be added in the future.
    inst_kwargs: dict|None
        If ``fs`` is None, use this set of keyword arguments to make a
        GenericFileSystem instance
    fs: GenericFileSystem|None
        Instance to use if explicitly given. The instance defines how to
        to make downstream file system instances from paths.
    T)withdirsdetailzCan only rsync on a directoryc                 b    g | ]+\  }}|d          dk    |                               v)|,S )type	directoryreplace).0avdestination
otherfilessources      r   
<listcomp>zrsync.<locals>.<listcomp>W   sN       AqV9##		&+(F(Fj(X(X 	
(X(X(Xr   z directories to createexist_okc                 2    i | ]\  }}|d          dk    ||S r#   file )r'   r(   r)   s      r   
<dictcomp>zrsync.<locals>.<dictcomp>`   s,    IIIAQvY&5H5H15H5H5Hr   z files to consider for copyc                 b    g | ]+\  }}|                               v|d          dk    )|,S r1   r%   )r'   or)   allfilesr*   r,   s      r   r-   zrsync.<locals>.<listcomp>b   sN       Aq99[&))99ai6>Q>Q 	
>Q>Q>Qr   alwaysr   z files to copyz files to deleteNr3   )GenericFileSystem_strip_protocolfindisdirr   itemsloggerdebuglenmkdirsr&   copypopzipcprm)r,   r*   delete_missingsource_field
dest_fieldupdate_condinst_kwargsfskwargsdirsdirn	to_deletekr)   	otherfilesource_filestarget_filesr7   r+   s   ``               @@r   rsyncrU   $   s   X 
	7 77K$5277B''F$$[11KwwvTw::H88F :8999tDAAJ     NN$$  D
 LLCII555666 D D
		$,,v{33d	CCCCII!1!1IIIH
LLCMM>>>???     $$&&  I
 %%'' $ $1IIfk22	
""h&&'++\?j&;J&GGG"+HQKK LLOOO $HQKK 4%((..*:*:%;"lL))999:::lL33F333 I888999
i r   c                   r     e Zd ZdZdZd fd	Zd ZddZd	 Z	 ddZ	d Z
d Zd ZddZd ZdefdZ xZS )r9   a^  Wrapper over all other FS types

    <experimental!>

    This implementation is a single unified interface to be able to run FS operations
    over generic URLs, and dispatch to the specific implementations using the URL
    protocol prefix.

    Note: instances of this FS are always async, even if you never use it with any async
    backend.
    r   r   c                 V    || _          t          t          |           j        di | dS )aK  

        Parameters
        ----------
        default_method: str (optional)
            Defines how to configure backend FS instances. Options are:
            - "default": instantiate like FSClass(), with no
              extra arguments; this is the default instance of that FS, and can be
              configured via the config system
            - "generic": takes instances from the `_generic_fs` dict in this module,
              which you must populate before use. Keys are by protocol
            - "current": takes the most recently instantiated version of each FS
        Nr3   )r   superr9   __init__)selfr   rM   	__class__s      r   rY   zGenericFileSystem.__init__   s6     %/&&/99&99999r   c                 |    t          || j                  }|                    |                    |                    S r
   )r   r   unstrip_protocolr:   )rZ   pathrL   s      r   r:   z!GenericFileSystem._strip_protocol   s5    t{++""2#5#5d#;#;<<<r   NFc                 0  K   t          || j                  }|j        r |j        |f|||d| d {V }n |j        |f|||d|}i }|                                D ]$\  }	}
|                    |	          }||
d<   |
||<   %|r|S t          |          S )N)maxdepthr    r!   name)r   r   
async_impl_findr;   r=   r]   list)rZ   r^   r`   r    r!   rM   rL   outresultrQ   r)   ra   s               r   rc   zGenericFileSystem._find   s     t{++= 	 '(6 MS       CC "''(6 MS C IIKK 	 	DAq&&q))DAfIF4LL 	MF||r   c                    K   t          || j                  }|j        r |j        |fi | d {V }n |j        |fi |}|                    |d                   |d<   |S )Nra   )r   r   rb   _infoinfor]   )rZ   r   rM   rL   re   s        r   rh   zGenericFileSystem._info   s      dk**= 	) //////////CC"'#((((C))#f+66F
r   Tc                    K   t          || j                  }|j        r |j        |fddi| d {V }n |j        |fddi|}|D ] }|                    |d                   |d<   !|r|S d |D             S )Nr!   Tra   c                     g | ]
}|d          S )ra   r3   )r'   r6   s     r   r-   z)GenericFileSystem._ls.<locals>.<listcomp>   s    +++!AfI+++r   )r   r   rb   _lslsr]   )rZ   r   r!   rM   rL   re   r6   s          r   rl   zGenericFileSystem._ls   s       dk**= 	4s::4:6::::::::CC"%33D3F33C 	7 	7A++AfI66AfII 	,J++s++++r   c                    K   t          || j                  }|j        r |j        |fi | d {V S  |j        |fi |S r
   )r   r   rb   	_cat_filecat_filerZ   r   rM   rL   s       r   ro   zGenericFileSystem._cat_file   si      
 dk**= 	.%c44V4444444442;s--f---r   c                    K   t          || j                  }|j        r |j        ||fi | d {V S  |j        ||fi |S r
   )r   r   rb   
_pipe_file	pipe_file)rZ   r^   valuerM   rL   s        r   rs   zGenericFileSystem._pipe_file   sm       t{++= 	7&tU==f=========2<e66v666r   c                    K   t          || j                  }|j        r |j        |fi | d {V  d S  |j        |fi | d S r
   )r   r   rb   _rmrF   rq   s       r   rw   zGenericFileSystem._rm   ss      dk**= 	!"&'''''''''''''BE#       r   c                    K   t          || j                  }|j        r|                    ||           d {V  d S |                    ||           d S )Nr.   )r   r   rb   	_makedirsmakedirs)rZ   r^   r/   rL   s       r   ry   zGenericFileSystem._makedirs   sk      t{++= 	1,,th,77777777777KKxK00000r   c                 &    t          ||fd| i| dS )z[Sync files between two directory trees

        See `func:rsync` for more details.
        rL   N)rU   )rZ   r,   r*   rM   s       r   rU   zGenericFileSystem.rsync   s'    
 	fk55d5f55555r   i   c                 (  K   t          || j                  }t          || j                  }||u r+|j        r |j        ||fi | d {V S  |j        ||fi |S ddd}	 t          |d          r|                    |d           d {V n |j        |dfi |}	|                    t          |	j
                   d {V            t          |d          r|                    |d           d {V n |j        |dfi |}
|	j
        |
                                |	j
        k     rt          |	                    |                     d {V }|	j
        |snst          |
                    |                     d {V  |                    |
                                           |	j
        |
                                |	j
        k     	 t          |
                                           d {V  t          |	                                           d {V  d S # t           $ r Y d S w xY w# 	 t          |
                                           d {V  t          |	                                           d {V  w # t           $ r Y w w xY wxY w)Nr   none)	blocksize
cache_type
open_asyncrbwb)r   r   rb   _cp_filecp_filehasattrr   openset_sizemaybe_awaitr   tellreadwriteabsolute_updateclose	NameError)rZ   r   url2r~   callbackrM   rL   fs2kwf1f2datas               r   r   zGenericFileSystem._cp_file   s+      dk**$,,99} 7(R[d==f=========!rz#t66v666F33	 2|,,.bmmC.........RWS$--"-- 
 K$8$8888888999 3--0cnnT4000000000SXdD//B// 
 '/RWWYY%8%8(););<<<<<<<<7?4?!"((4..111111111((333 '/RWWYY%8%8!"((**---------!"((**-----------   !"((**---------!"((**----------   sE   "E,H0 AH 
H-,H-0J2AJ J
JJJJ)r   )NFF)T)F)__name__
__module____qualname____doc__r   rY   r:   rc   rh   rl   ro   rs   rw   ry   rU   r   r   __classcell__)r[   s   @r   r9   r9      s       
 
 H: : : : : :"= = =
   &   , , , ,$	. 	. 	.
7 
7 
7! ! !1 1 1 16 6 6 ") ) ) ) ) ) ) )r   r9   c                 B   K   t          j        |           r|  d {V S | S r
   )inspectiscoroutine)cors    r   r   r   *  s0      3 yyyyyy
r   )NNN)Fr   r   r   NN)r   loggingasynr   	callbacksr   corer   r   r   r   	getLoggerr>   r   r   r   rU   r9   r   r3   r   r   <module>r      s     ! ! ! ! ! ! ( ( ( ( ( ( B B B B B B B B B B		+	,	,D D D @ @ @ @( X X X Xvh h h h h h h hV    r   