L i4ddlmZddlZddlZddlZddlZddlZddlmZm Z m Z ddl m Z ddl mZmZmZmZiZej&dZdZdd Z dd ZGd d eZ dd ZddZdZy)) annotationsN)AsyncFileSystem_run_coros_in_chunks sync_wrapper)DEFAULT_CALLBACK) filesystemget_filesystem_classsplit_protocol url_to_fszfsspec.genericc *t|fi|t|<y)z4Populate the dict used for method=="generic" lookupsN)r _generic_fs)protocolstorage_optionss T/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/fsspec/generic.pyset_generic_fsrs&xC?CKcPt|ttfr|dn|}|xst|d}|xsi}|dk(r t |S|dk(r t |S|dk(rt |}|jS|dk(r!t|fi|j|i\}}|Std|)zPick instance of backend FSrdefaultgenericcurrentoptionszUnknown FS resolution method: ) isinstancelisttupler r rr rr get ValueError)urlmethodrrclsfs_s r _resolve_fsr#ssT5M2#a&C1>#.q1H%+O (## 8$$ "8,{{} #C!4!4Xr!BCA 5fX> ??rc |xstdi|xsi}|j|}|j|}|j|dd} |j|s t d|j|dd} | j D cgc]#\} } | ddk(r| j ||| vr| %} } } tjt| d| r1|j| Dcgc]}|j ||c}d| j D cic]\} } | ddk(s| | } } } tjt| d | j D cgc]#\}} |j ||| vr | ddk(r|%}}} | jj D]\}} |j ||}|| vrz|d k(r|| |<'|d k(r| j|>|d k(sDt|r|| n| |}| |}t|r||n||}||k7r|| |<| j||| |<tjt| d | r-t| j \}}|j||fi|tjt|d|r|r|j!|| Scc} } wcc}wcc} } wcc} }w)aUSync files between two directory trees (experimental) Parameters ---------- source: str Root of the directory tree to take files from. This must be a directory, but do not include any terminating "/" character destination: str Root path to copy into. The contents of this location should be identical to the contents of ``source`` when done. This will be made a directory, and the terminal "/" should not be included. 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 | callable If ``update_field`` is "different", this is the key in the info of source files to consider for difference. Maybe a function of the info dict. dest_field: str | callable If ``update_field`` is "different", this is the key in the info of destination files to consider for difference. May be a function of the info dict. 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. Returns ------- dict of the copy operations that were performed, {source: destination} T)withdirsdetailzCan only rsync on a directorytype directoryz directories to createexist_okfilez files to consider for copyalwaysnever differentz files to copyz files to delete)GenericFileSystem_strip_protocolfindisdirritemsreplaceloggerdebuglenmake_many_dirscopypopcallablezipcprm)source destinationdelete_missing source_field dest_field update_cond inst_kwargsr!kwargsallfiles otherfilesavdirsdirno to_deletek otherfileinf1v2inf2 source_files target_filess rrsyncrW(sh 7 7K$527B    'F$$[1KwwvTw:H 88F 899tDAJNN$  Aq V9 # &+(Fj(X  D   LLCI;456  ;? @4T\\&+ . @4  "*!1IAQvY&5H1IHI LLCM?"=>?$$& Aq 99[& ) 9ai6>Q I  %%'$1IIfk2  "h&' ' Q +*2<*@|Aa o *)1*)=z"~2j>4<"+HQKLLO$HQK'$( LLCM?.12%((..*:%;" l lL3F3 LLC N##345) i OY  AIs (K*K K%0K%,(K+ceZdZdZdZdfd ZdZdZddZdZ dd Z d Z d Z d Z dd ZdZdedf ddZddZeeZ d ddZxZS)r0a^Wrapper over all other FS types 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. rNc @||_||_t| di|y)a 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 - "options": expects storage_options, a dict mapping protocol to kwargs to use when constructing the filesystem - "current": takes the most recently instantiated version of each FS Nr/)rst_optssuper__init__)selfdefault_methodrrG __class__s rr\zGenericFileSystem.__init__s# % &  "6"rct||j|j}|j|j |SNr)r#rrZunstrip_protocol_parentr]pathr!s rrdzGenericFileSystem._parents2 t{{DLL I""2::d#344rct||j|j}|j|j |Sra)r#rrZrcr1res rr1z!GenericFileSystem._strip_protocols4 t{{DLL I""2#5#5d#;< B< A1B>cKt||j}|jr|j|fi|d{}n|j|fi|}|j }|j |d|d<|S7Aw)Nrj)r#rrk_infoinfor:rc)r]rrGr!rms rrpzGenericFileSystem._infosw dkk * == ///C"''#((Chhj))#f+6F  0s9A?A=AA?cpKt||j}|jr|j|fddi|d{}n|j|fddi|}|Dcgc]}|j }}|D]}|j |d|d<|r|S|Dcgc]}|d c}S7lcc}wcc}ww)Nr&Trj)r#rrk_lslsr:rc)r]rr&rGr!rmrNs rrszGenericFileSystem._lss dkk * ==s:4:6::C"%%3D3F3C!$%Aqvvx%% 7A++AfI6AfI 7 J'*+!AfI+ +;& ,s-;B6B*B6B,3(B6 B1'B6, B6cKt||j}|jr|j|fi|d{S|j|fi|S7wN)r#rrk _cat_filecat_file)r]rrGr!s rrwzGenericFileSystem._cat_filesS dkk * ==%c4V44 42;;s-f- -5s9AAAcKt||j|j}|jr|j||fi|d{S|j ||fi|S7wra)r#rrZrk _pipe_file pipe_file)r]rfvaluerGr!s rrzzGenericFileSystem._pipe_files] t{{DLL I ==&tU=f== =2<<e6v6 6>sAA#A! A#cK|}t|tr|g}t|d|j}|jr|j |fi|d{y|j |fi|y7w)Nr)rstrr#rrk_rmr?)r]rrGurlsr!s rrzGenericFileSystem._rmsh dC 6D a$++ . =="&&(( ( ( BEE#   )sAA/A-A/cKtjd|t||j|j}|j r|j ||d{y|j||y7w)Nz Make dir %srbr))r6r7r#rrZrk _makedirsmakedirs)r]rfr*r!s rrzGenericFileSystem._makedirss\ ]D) t{{DLL I ==,,th,7 7 7 KKxK 0 8sAA9A7A9c "t||fd|i|y)z[Sync files between two directory trees See `func:rsync` for more details. r!N)rW)r]r@rArGs rrWzGenericFileSystem.rsyncs fk5d5f5ric $Kt||j}t||j}||ur<|jr|j||fi|d{S|j||fi|St ||g||g|ddd{y757w)Nrraiseon_error)r#rrk_copyr: copy_file_op) r]rurl2 blocksizecallbacktempdirrGr!fs2s r_cp_filezGenericFileSystem._cp_filesdkk *$ , 9}}%RXXc4:6:::rwwsD3F332ucD67APPP; Qs$ABB /BBBBcKt|d|j}|jr4|Dcgc]}|j||}}t |d{y|D]}|j ||ycc}w7%w)Nrr))r#rrkrrr)r]rr*r!ucoross r_make_many_dirsz!GenericFileSystem._make_many_dirs2sw a$++ . ==AEFAR\\!h\7FEF&u- - - 2 A 1 2G -s*A>A7A>A<&A>c K|r tdt|tr|gn|}t|tr|gn|}t||j} t||j} | | ur<| j r| j ||fi|d{S| j||fi|St| || ||||d{y737w)NzPlease use fsspec.generic.rsyncr) NotImplementedErrorrr~r#rrkrr:r) r]path1path2 recursiverri batch_sizerrGr!rs rrzGenericFileSystem._copy=s %&GH H%eS1u%eS1u  ,%- 9}}%RXXeU=f===rwwue6v66 sE7J   > s$B C C-C;C<CC)rN)NFF)T)F)r str | None)FignoreNNN)r list[str]rrrboolrr~ri int | Nonerrrr)__name__ __module__ __qualname____doc__rr\rdr1rlrprsrwrzrrrWrrrrr9r __classcell__)r_s@rr0r0s H#(5= (,& . 7!16!" Q  Q&2"/2N   #!%"           rr0cKddl}|xs|j} t||D cgc]N\}} t|||| tj j |tjjP} }} t| |dd{} tj||dk(r| S|dk(r| D]} t| ts| yycc} }w7F#tj|wxYww)NrT)rreturn_exceptionsreturnr)tempfilemkdtempr= _copy_file_oposrfjoinuuiduuid4hexrshutilrmtreer Exception) fs1url1rrrrrru1u2rrmrNs rrr]s+))+GdD/  B  Wdjjl&6&67      ) jD    g8 W  A!Y'  #     gs@C5CAC>CCC6C5C5CC22C5cPK|jr|j||d{n|j|||jr|j||d{n|j ||t j |tjd||y7}7Fw)NzCopy %s -> %s; done) rk _get_fileget_file _put_fileput_filerunlinkr6r7)rrrrlocalrs rrr{s ~~mmD%((( T5! ~~mmE4((( UD!IIe LL&d3 ) )s""B&B"8B&B$AB&$B&cPKtj|r |d{S|S7wrv)inspect iscoroutine)cors r maybe_awaitrs&3y s &$&)NN)Fsizerr.NN)Nr)r) __future__rrloggingrrrasynrrr callbacksrcorer r r r r getLoggerr6rr#rWr0rrrr/rrrs" EE'MM   + ,D @* gTH H XAI< 4r