Ë
    ùÇ:jª4  ã                  óè   — d dl mZ d dlZd dlZd dlZd dlZd dlZddlmZm	Z	m
Z
 ddlmZ ddlmZmZmZmZ i Z ej&                  d«      Zd„ Zdd	„Z	 	 	 	 	 	 dd
„Z G d„ de«      Z	 dd„Zdd„Zd„ Zy)é    )ÚannotationsNé   )ÚAsyncFileSystemÚ_run_coros_in_chunksÚsync_wrapper)ÚDEFAULT_CALLBACK)Ú
filesystemÚget_filesystem_classÚsplit_protocolÚ	url_to_fszfsspec.genericc                ó*   — t        | fi |¤Žt        | <   y)z4Populate the dict used for method=="generic" lookupsN)r	   Ú_generic_fs)ÚprotocolÚstorage_optionss     úc/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/fsspec/generic.pyÚset_generic_fsr      s   € ä& xÑC°?ÑC„K�Òó    c                óP  — t        | t        t        f«      r| d   n| } |xs t        | «      d   }|xs i }|dk(  rt	        |«      S |dk(  r	t
        |   S |dk(  rt        |«      }|j                  «       S |dk(  r!t        | fi |j                  |i «      ¤Ž\  }}|S t        d|› �«      ‚)zPick instance of backend FSr   ÚdefaultÚgenericÚcurrentÚoptionszUnknown FS resolution method: )Ú
isinstanceÚlistÚtupler   r	   r   r
   r   r   ÚgetÚ
ValueError)ÚurlÚmethodr   r   ÚclsÚfsÚ_s          r   Ú_resolve_fsr#      s¼   € ä˜s¤T¬5 MÔ2ˆ#ˆaŠ&¸€CØÒ1œ>¨#Ó.¨qÑ1€HØ%Ò+¨€OØ�ÒÜ˜(Ó#Ð#Ø�ÒÜ˜8Ñ$Ð$Ø�ÒÜ" 8Ó,ˆØ�{‰{‹}ÐØ�ÒÜ˜#ÑC ×!4Ñ!4°X¸rÓ!BÑC‰ˆˆAØˆ	Ü
Ð5°f°XÐ>Ó
?Ð?r   c           	     óâ  — |xs t        di |xs i ¤Ž}|j                  | «      } |j                  |«      }|j                  | dd¬«      }	|j                  | «      st	        d«      ‚|j                  |dd¬«      }
|	j                  «       D ��cg c]#  \  }}|d   dk(  r|j                  | |«      |
vr|‘Œ% }}}t        j                  t        |«      › d�«       |r1|j                  |D �cg c]  }|j                  | |«      ‘Œ c}d¬«       |	j                  «       D ��ci c]  \  }}|d   dk(  sŒ||“Œ }	}}t        j                  t        |	«      › d	�«       |
j                  «       D ��cg c]#  \  }}|j                  || «      |	vr
|d   dk(  r|‘Œ% }}}|	j                  «       j                  «       D ]š  \  }}|j                  | |«      }||
v rz|d
k(  r||	|<   Œ'|dk(  r|	j                  |«       Œ>|dk(  sŒDt        |«      r ||«      n||   }|
|   }t        |«      r ||«      n||   }||k7  r||	|<   Œ„|	j                  |«       Œ–||	|<   Œœ t        j                  t        |	«      › d�«       |	r-t        |	j                  «       Ž \  }} |j                  ||fi |¤Ž t        j                  t        |«      › d�«       |r|r|j!                  |«       |	S c c}}w c c}w c c}}w c c}}w )aU  Sync 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)ÚwithdirsÚdetailzCan only rsync on a directoryÚtypeÚ	directoryz directories to create©Úexist_okÚfilez files to consider for copyÚalwaysÚneverÚ	differentz files to copyz files to delete© )ÚGenericFileSystemÚ_strip_protocolÚfindÚisdirr   ÚitemsÚreplaceÚloggerÚdebugÚlenÚmake_many_dirsÚcopyÚpopÚcallableÚzipÚcpÚrm)ÚsourceÚdestinationÚdelete_missingÚsource_fieldÚ
dest_fieldÚupdate_condÚinst_kwargsr!   ÚkwargsÚallfilesÚ
otherfilesÚaÚvÚdirsÚdirnÚoÚ	to_deleteÚkÚ	otherfileÚinf1Úv2Úinf2Úsource_filesÚtarget_filess                           r   ÚrsyncrW   (   sñ  € ðh 
Ò	7Ô Ñ7 KÒ$5°2Ñ7€BØ×Ñ Ó'€FØ×$Ñ$ [Ó1€KØ�w‰w�v¨°TˆwÓ:€HØ�8‰8�FÔÜÐ8Ó9Ð9Ø—‘˜¨t¸D�ÓA€Jð —N‘NÓ$÷áˆAˆqØˆV‰9˜Ò#¨¯	©	°&¸+Ó(FÈjÑ(Xò 	
ð€Dñ ô
 ‡L�L”C˜“I�;Ð4Ð5Ô6ÙØ
×ÑØ;?Ö@°4ˆT�\‰\˜& +Õ.Ò@È4ð 	ô 	
ð "*§¡Ó!1×I™˜˜A°Q°v±YÀ&Ó5H��1‘ÐI€HÑIÜ
‡L�L”C˜“M�?Ð"=Ð>Ô?ð ×$Ñ$Ó&÷áˆAˆqØ�9‰9�[ &Ó)°Ñ9¸aÀ¹iÈ6Ò>Qò 	
ð€Iñ ð
 —‘“×%Ñ%Ó'ò $‰ˆˆ1Ø—I‘I˜f kÓ2ˆ	Ø˜
Ñ"Ø˜hÒ&Ø'�˜’Ø Ò'Ø—‘˜Q•Ø Ó+Ü*2°<Ô*@‘| A”ÀaÈÁo�Ø 	Ñ*�Ü)1°*Ô)=‘z "”~À2ÀjÁ>�Ø˜4’<à"+�H˜Q’Kð —L‘L •Oð $ˆH�QŠKð'$ô( ‡L�L”C˜“M�? .Ð1Ô2ÙÜ%(¨(¯.©.Ó*:Ð%;Ñ"ˆ�lØˆ�‰ˆl˜LÑ3¨FÒ3Ü
‡L�L”C˜	“NÐ#Ð#3Ð4Ô5Ù™)Ø
�‰ˆiÔØ€OùóYùò AùãIùós   Â(KÃ*K ÄK%Ä0K%Å,(K+c                  óÄ   ‡ — e Zd ZdZdZdˆ fd„	Z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df	 dd„Zdd„Z ee«      Z	 	 	 	 	 d	 	 	 	 	 	 	 	 	 	 	 	 	 dd„Zˆ xZS )r0   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   Nc                ó@   •— || _         || _        t        ‰| �  di |¤Ž 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/   )r   Úst_optsÚsuperÚ__init__)ÚselfÚdefault_methodr   rG   Ú	__class__s       €r   r\   zGenericFileSystem.__init__¡   s#   ø€ ð  %ˆŒØ&ˆŒÜ‰ÑÑ"˜6Ó"r   c                ó†   — t        || j                  | j                  ¬«      }|j                  |j	                  |«      «      S ©N©r   )r#   r   rZ   Úunstrip_protocolÚ_parent©r]   Úpathr!   s      r   rd   zGenericFileSystem._parentµ   s2   € Ü˜˜tŸ{™{¸D¿L¹LÔIˆØ×"Ñ" 2§:¡:¨dÓ#3Ó4Ð4r   c                ó†   — t        || j                  | j                  ¬«      }|j                  |j	                  |«      «      S ra   )r#   r   rZ   rc   r1   re   s      r   r1   z!GenericFileSystem._strip_protocol¹   s4   € ä˜˜tŸ{™{¸D¿L¹LÔIˆØ×"Ñ" 2×#5Ñ#5°dÓ#;Ó<Ð<r   c              ‹  ó€  K  — t        || j                  | j                  ¬«      }|j                  r  |j                  |f||ddœ|¤Žƒ d {  –—† }n |j
                  |f||ddœ|¤Ž}i }|j                  «       D ]0  \  }	}
|
j                  «       }
|j                  |	«      }||
d<   |
||<   Œ2 |r|S t        |«      S 7 Œp­w)Nrb   T)Úmaxdepthr%   r&   Úname)
r#   r   rZ   Ú
async_implÚ_findr2   r4   r:   rc   r   )r]   rf   ri   r%   r&   rG   r!   ÚoutÚresultrP   rK   rj   s               r   rl   zGenericFileSystem._find¾   sÞ   è ø€ Ü˜˜tŸ{™{¸D¿L¹LÔIˆØ�=Š=Ø ˜Ÿ™ØðØ'°(À4ñØKQñ÷ ‰Cð �"—'‘'ØðØ'°(À4ñØKQñˆCð ˆØ—I‘I“Kò 	‰DˆAˆqØ—‘“ˆAØ×&Ñ& qÓ)ˆDØˆAˆf‰IØˆF�4ŠLð		ñ
 ØˆMÜ�F‹|Ððús   ‚A	B>ÁB<ÁA1B>c              ‹  ó  K  — t        || j                  «      }|j                  r |j                  |fi |¤Žƒ d {  –—† }n |j                  |fi |¤Ž}|j                  «       }|j                  |d   «      |d<   |S 7 ŒA­w)Nrj   )r#   r   rk   Ú_infoÚinfor:   rc   )r]   r   rG   r!   rm   s        r   rp   zGenericFileSystem._infoÒ   sw   è ø€ Ü˜˜dŸk™kÓ*ˆØ�=Š=Ø ˜Ÿ™ Ñ/¨Ñ/×/‰Cà�"—'‘'˜#Ñ( Ñ(ˆCØ�h‰h‹jˆØ×)Ñ)¨#¨f©+Ó6ˆˆF‰Øˆ
ð 0ús   ‚9A?»A=¼AA?c              ‹  óp  K  — t        || j                  «      }|j                  r |j                  |fddi|¤Žƒ d {  –—† }n |j                  |fddi|¤Ž}|D �cg c]  }|j                  «       ‘Œ }}|D ]  }|j                  |d   «      |d<   Œ |r|S |D �cg c]  }|d   ‘Œ	 c}S 7 Œlc c}w c c}w ­w)Nr&   Trj   )r#   r   rk   Ú_lsÚlsr:   rc   )r]   r   r&   rG   r!   rm   rN   s          r   rs   zGenericFileSystem._lsÜ   sÂ   è ø€ ô ˜˜dŸk™kÓ*ˆØ�=Š=Ø˜Ÿ™˜sÑ:¨4Ð:°6Ñ:×:‰Cà�"—%‘%˜Ñ3 DÐ3¨FÑ3ˆCØ!$Ö%˜Aˆq�v‰v�xÐ%ˆÐ%Øò 	7ˆAØ×+Ñ+¨A¨f©IÓ6ˆAˆfŠIð	7áØˆJà'*Ö+ !�A�f“IÒ+Ð+ð ;úò &ùò ,ùs-   ‚;B6½B*¾B6ÁB,Á3(B6ÂB1Â'B6Â,
B6c              ‹  ó®   K  — t        || j                  «      }|j                  r |j                  |fi |¤Žƒ d {  –—† S  |j                  |fi |¤ŽS 7 Œ­w©N)r#   r   rk   Ú	_cat_fileÚcat_file)r]   r   rG   r!   s       r   rw   zGenericFileSystem._cat_fileï   sS   è ø€ ô
 ˜˜dŸk™kÓ*ˆØ�=Š=Ø%˜Ÿ™ cÑ4¨VÑ4×4Ð4à�2—;‘;˜sÑ- fÑ-Ð-ð 5ús   ‚9A»A¼Ac              ‹  óÊ   K  — t        || j                  | j                  ¬«      }|j                  r |j                  ||fi |¤Žƒ d {  –—† S  |j
                  ||fi |¤ŽS 7 Œ­wra   )r#   r   rZ   rk   Ú
_pipe_fileÚ	pipe_file)r]   rf   ÚvaluerG   r!   s        r   rz   zGenericFileSystem._pipe_fileú   s]   è ø€ ô ˜˜tŸ{™{¸D¿L¹LÔIˆØ�=Š=Ø&˜Ÿ™ t¨UÑ=°fÑ=×=Ð=à�2—<‘<  eÑ6¨vÑ6Ð6ð >ús   ‚AA#ÁA!Á	A#c              ‹  óâ   K  — |}t        |t        «      r|g}t        |d   | j                  «      }|j                  r |j
                  |fi |¤Žƒ d {  –—†  y  |j                  |fi |¤Ž y 7 Œ­w)Nr   )r   Ústrr#   r   rk   Ú_rmr?   )r]   r   rG   Úurlsr!   s        r   r   zGenericFileSystem._rm  sh   è ø€ ØˆÜ�dœCÔ Ø�6ˆDÜ˜˜a™ $§+¡+Ó.ˆØ�=Š=Ø�"—&‘&˜Ñ( Ñ(×(Ñ(àˆB�E‰E�#Ñ ˜Ó ð )ús   ‚AA/ÁA-ÁA/c              ƒ  óö   K  — t         j                  d|«       t        || j                  | j                  ¬«      }|j
                  r|j                  ||¬«      ƒ d {  –—†  y |j                  ||¬«       y 7 Œ­w)NzMake dir %srb   r)   )r6   r7   r#   r   rZ   rk   Ú	_makedirsÚmakedirs)r]   rf   r*   r!   s       r   r‚   zGenericFileSystem._makedirs  s\   è ø€ Ü�‰�] DÔ)Ü˜˜tŸ{™{¸D¿L¹LÔIˆØ�=Š=Ø—,‘,˜t¨h�,Ó7×7Ñ7à�K‰K˜ xˆKÕ0ð 8ús   ‚AA9ÁA7ÁA9c                ó"   — t        ||fd| i|¤Ž y)z[Sync files between two directory trees

        See `func:rsync` for more details.
        r!   N)rW   )r]   r@   rA   rG   s       r   rW   zGenericFileSystem.rsync  s   € ô
 	ˆf�kÑ5 dÐ5¨fÓ5r   i   c           	   ‹  ó$  K  — t        || j                  «      }t        || j                  «      }||u r<|j                  r |j                  ||fi |¤Žƒ d {  –—† S  |j                  ||fi |¤ŽS t        ||g||g|dd¬«      ƒ d {  –—†  y 7 Œ57 Œ­w)Nr   Úraise©Úon_error)r#   r   rk   Ú_copyr:   Úcopy_file_op)	r]   r   Úurl2Ú	blocksizeÚcallbackÚtempdirrG   r!   Úfs2s	            r   Ú_cp_filezGenericFileSystem._cp_file  s“   è ø€ ô ˜˜dŸk™kÓ*ˆÜ˜$ §¡Ó,ˆØ�‰9à�}Š}Ø%˜RŸX™X c¨4Ñ:°6Ñ:×:Ð:à�r—w‘w˜s DÑ3¨FÑ3Ð3Ü˜2 ˜u c¨D¨6°7¸AÈÔP×PÑPð ;øð 	Qús$   ‚ABÁBÁ/BÂBÂBÂBc              ƒ  ó   K  — t        |d   | j                  «      }|j                  r4|D �cg c]  }|j                  ||¬«      ‘Œ }}t	        |«      ƒ d {  –—†  y |D ]  }|j                  ||¬«       Œ y c c}w 7 Œ%­w)Nr   r)   )r#   r   rk   r‚   r   rƒ   )r]   r€   r*   r!   ÚuÚcoross         r   Ú_make_many_dirsz!GenericFileSystem._make_many_dirs2  sw   è ø€ Ü˜˜a™ $§+¡+Ó.ˆØ�=Š=ØAEÖF¸A�R—\‘\ !¨h�\Õ7ÐFˆEÐFÜ& uÓ-×-Ñ-àò 2�Ø—‘˜A¨�Õ1ñ2ùò GØ-ús   ‚*A>¬A7ÁA>ÁA<Á&A>c           	   ‹  óŽ  K  — |rt        d«      ‚t        |t        «      r|gn|}t        |t        «      r|gn|}t        || j                  «      }	t        || j                  «      }
|	|
u r<|	j
                  r |	j                  ||fi |¤Žƒ d {  –—† S  |	j                  ||fi |¤ŽS t        |	||
||||¬«      ƒ d {  –—†  y 7 Œ37 Œ­w)NzPlease use fsspec.generic.rsyncr‡   )	ÚNotImplementedErrorr   r~   r#   r   rk   r‰   r:   rŠ   )r]   Úpath1Úpath2Ú	recursiverˆ   ri   Ú
batch_sizerŽ   rG   r!   r�   s              r   r‰   zGenericFileSystem._copy=  sÈ   è ø€ ñ Ü%Ð&GÓHÐHÜ% e¬SÔ1�‘°uˆÜ% e¬SÔ1�‘°uˆä˜ §¡Ó,ˆÜ˜% §¡Ó-ˆà�‰9Ø�}Š}Ø%˜RŸX™X e¨UÑ=°fÑ=×=Ð=à�r—w‘w˜u eÑ6¨vÑ6Ð6äØ��s˜E 7¨JÀô
÷ 	
ñ 	
ð	 >øð	
ús$   ‚BCÂCÂ-CÂ;CÂ<CÃC)r   N)NFF)T)F)rŽ   ú
str | None)FÚignoreNNN)r—   ú	list[str]r˜   r�   r™   Úboolrˆ   r~   ri   ú
int | Nonerš   rŸ   rŽ   r›   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r\   rd   r1   rl   rp   rs   rw   rz   r   r‚   rW   r   r�   r”   r   r9   r‰   Ú__classcell__)r_   s   @r   r0   r0   ’   sÒ   ø„ ñ
ð €Hõ#ò(5ò=ó
ò(ð ó,ò&	.ò
7ò!ó1ò6ð Ø!Ø"ðQð óQó&2ñ " /Ó2€Nð  Ø Ø#Ø!%Ø"ð
àð
ð ð
ð ð	
ð
 ð
ð ð
ð ð
ð ÷
r   r0   c              ƒ  óî  K  — dd l }|xs |j                  «       }	 t        ||«      D ��	cg c]N  \  }}	t        | |||	t        j
                  j                  |t        j                  «       j                  «      «      ‘ŒP }
}}	t        |
|d¬«      ƒ d {  –—† }t        j                  |«       |dk(  r|S |dk(  r|D ]  }t        |t        «      sŒ|‚ y y c c}	}w 7 ŒF# t        j                  |«       w xY w­w)Nr   T)rš   Úreturn_exceptionsÚreturnr†   )ÚtempfileÚmkdtempr=   Ú_copy_file_opÚosrf   ÚjoinÚuuidÚuuid4Úhexr   ÚshutilÚrmtreer   Ú	Exception)Úfs1Úurl1r�   r‹   rŽ   rš   rˆ   r¨   Úu1Úu2r“   rm   rN   s                r   rŠ   rŠ   ]  sô   è ø€ ó àÒ+˜×)Ñ)Ó+€Gðô ˜d D›/÷	
ñ ��Bô ØØØØÜ—‘—‘˜W¤d§j¡j£l×&6Ñ&6Ó7õð	
ˆñ 	
ô )Ø˜j¸Dô
÷ 
ˆô 	�‰�gÔØ�8ÒØˆ
Ø	�WÒ	Øò 	ˆAÜ˜!œYÕ'Ø�ñ	ð 
ùó#	
ð
ùô 	�‰�gÕüs@   ‚C5œC «ACÁ>C ÂCÂC Â6C5ÃC5ÃC ÃC2Ã2C5c              ƒ  óP  K  — | j                   r| j                  ||«      ƒ d {  –—†  n| j                  ||«       |j                   r|j                  ||«      ƒ d {  –—†  n|j	                  ||«       t        j                  |«       t        j                  d||«       y 7 Œ}7 ŒF­w)NzCopy %s -> %s; done)	rk   Ú	_get_fileÚget_fileÚ	_put_fileÚput_filer«   Úunlinkr6   r7   )r³   r´   r�   r‹   Úlocalrˆ   s         r   rª   rª   {  s€   è ø€ Ø
‡~‚~Ø�m‰m˜D %Ó(×(Ñ(à�‰�T˜5Ô!Ø
‡~‚~Ø�m‰m˜E 4Ó(×(Ñ(à�‰�U˜DÔ!Ü‡I�IˆeÔÜ
‡L�LÐ&¨¨dÕ3ð 	)øð 	)ús"   ‚"B&¤B"¥8B&ÁB$ÁAB&Â$B&c              ƒ  óP   K  — t        j                  | «      r
| ƒ d {  –—† S | S 7 Œ­wrv   )ÚinspectÚiscoroutine)Úcors    r   Úmaybe_awaitrÂ   ˆ  s&   è ø€ Ü×Ñ˜3ÔØ�yÐàˆ
ð ús   ‚&�$ž&)NN)FÚsizerÃ   r.   NN)Né   rœ   )rœ   )Ú
__future__r   r¿   Úloggingr«   r°   r­   Úasynr   r   r   Ú	callbacksr   Úcorer	   r
   r   r   r   Ú	getLoggerr6   r   r#   rW   r0   rŠ   rª   rÂ   r/   r   r   ú<module>rË      sŠ   ðÝ "ã Û Û 	Û Û ç EÑ EÝ 'ß MÓ Mà€Ø	ˆ×	Ñ	Ð+Ó	,€òDó
@ð* ØØØØØógôTH
˜ô H
ðX AIóó<
4ór   