§
    +P„j[*  ã                  ój  — d Z 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	Z	ddl
Z
ddlZddlZddl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 dd
lmZ  ed¦  «        ZdZ  e!d¦  «        Z"dddddœZ#d&d„Z$ej%        ej%        ej%        ej%        ej&        dœZ' e!ej%        ej(        h¦  «        Z)dZ* G d„ dej+        ¦  «        Z, ej-        e ¦  «         G d„ de,¦  «        ¦   «         Z.ej-         G d„ dej/        e,¦  «        ¦   «         Z0ej1        d&d„¦   «         Z2d'd!„Z3d(d%„Z4dS ))z#GPath wrapper around the gfile API.é    )ÚannotationsN)ÚAnyÚCallableÚClassVarÚIteratorÚOptionalÚTypeÚTypeVarÚUnion)Úepy)Úabstract_path)Úbackend)Úregister)Ú
stat_utils)ÚPathLikeÚ_P)zgs://zs3://zaz://zhf://)ÚgsÚs3ÚazÚhfz/gs/z/s3/z/az/z/hf/ÚreturnÚboolc                 ój   — t           j                             dd¦  «                             ¦   «         dvS )NÚEPATH_USE_TFÚ )ÚfalseÚnoÚfÚ0)ÚosÚenvironÚgetÚlower© ó    úV/root/disk_3tb/conda_envs/Huy-visual/lib/python3.11/site-packages/etils/epath/gpath.pyÚ_epath_use_tfr'   2   s0   € Ý	Œ�Š˜¨Ñ	+Ô	+×	1Ò	1Ñ	3Ô	3ð <ð 
ð r%   )r   r   r   r   N)ÚrÚwÚac                  óx  ‡ — e Zd ZU dZded<   ej        dk     rdHˆ fd„ZndIˆ fd„ZdJd„Z	e
dKd„¦   «         Ze
dLd„¦   «         Ze
dMd„¦   «         ZdMd„ZdMd„ZdMd„ZdMˆ fd„ZdNd„ZdNd„ZdOd„ZdPd„ZdQdRd"„ZdSd$„Zd%d&d'œdTd,„Z	 	 	 dUdVd1„ZdWd2„ZdQdXd4„ZdQdXd5„Z	 dYd&d&d7œdZd=„Zd[ˆ fd?„Zd\dA„Zd\dB„Z dQd]dE„Z!d^dG„Z"ˆ xZ#S )_Ú_GPathz9Pathlib like api with gs://, s3://, az://, hf:// support.zClassVar[types.ModuleType]Ú_PATH)é   é   ÚclsúType[_P]Úpartsr   r   r   c                óF   •—  t          ¦   «         j        | gt          |Ž ¢R Ž S ©N)ÚsuperÚ__new__Ú_process_parts)r0   r2   Ú	__class__s     €r&   r6   z_GPath.__new__V   s&   ø€ Ø�U‰WŒWŒ_˜SÐ:¥>°5Ð#9Ð:Ð:Ð:Ð:r%   ÚNonec                óB   •—  t          ¦   «         j        t          |Ž Ž  d S r4   )r5   Ú__init__r7   )Úselfr2   r8   s     €r&   r;   z_GPath.__init__[   s"   ø€ Ø…e�g„gÔ�¨Ð.Ð/Ð/Ð/Ð/r%   r<   c                ó&   —  t          | ¦  «        |Ž S )z'Create a new `Path` child of same type.)Útype)r<   r2   s     r&   Ú_newz_GPath._new^   s   € à�4�‰:Œ:�uÐÐr%   úOptional[str]c                óš   — t          | j        ¦  «        dk    r2| j        d         dk    r!| j        d         t          v r| j        d         S d S )Né   r   ú/é   )Úlenr2   Ú_URI_SCHEMES©r<   s    r&   Ú_uri_schemez_GPath._uri_schemed   sJ   € õ 	ˆDŒJ‰Œ˜1ÒÐØŒJ�qŒM˜SÒ Ð ØŒJ�qŒM�\Ð)Ð)àŒZ˜Œ]ÐàˆTr%   úbackend_lib.Backendc                ó
  — 	 t           | j                 }t          ¦   «         r| j        �t          j        S |S # t
          $ rA d                     d„ t           D ¦   «         ¦  «        }t          d| j        › d|› d�¦  «        d ‚w xY w)Nz, c              3  ó"   K  — | ]
}d |› d�V — ŒdS )ú`z://`Nr$   )Ú.0Úks     r&   ú	<genexpr>z"_GPath._backend.<locals>.<genexpr>z   s*   è è € ÐDÐD¨A˜K ˜K˜K˜KÐDÐDÐDÐDÐDÐDr%   zUnsuported scheme `z://` (supported: ú))Ú_PREFIX_TO_BACKENDrH   Ú_is_tf_installedÚbackend_libÚ
tf_backendÚKeyErrorÚjoinÚNotImplementedError)r<   r   Ú	supporteds      r&   Ú_backendz_GPath._backendo   s¤   € ðÝ" 4Ô#3Ô4€gõ 
Ñ	Ô	ð & Ô 0Ð <ÝÔ%Ð%Ø€nøÝð ð ð Ø—)’)ÐDÐDÕ1CÐDÑDÔDÑDÔD€iÝØ
O Ô 0Ð
OÐ
OÀ9Ð
OÐ
OÐ
Oñô àððøøøs   ‚27 µ7 ·ABÚstrc                ó”   — | j         }|r# | j        j        |› d�g| j        dd…         ¢R Ž S | j        r | j        j        | j        Ž ndS )z/Returns the `__fspath__` string representation.ú://rB   Nú.)rH   r-   rV   r2   )r<   Ú
uri_schemes     r&   Ú	_path_strz_GPath._path_str   sc   € ð Ô!€JØð AØˆTŒZŒ_ 
Ð/Ð/Ð/ÐA°$´*¸Q¸R¸R´.ÐAÐAÐAÐAà-1¬ZÐ@ˆ_ˆTŒZŒ_˜dœjÐ)Ð)¸SÐ@r%   c                ó   — | j         S r4   ©r_   rG   s    r&   Ú
__fspath__z_GPath.__fspath__ˆ   ó
   € ØŒ>Ðr%   c                ó   — | j         S r4   ra   rG   s    r&   Ú__str__z_GPath.__str__‹   rc   r%   c                ó@   — t          | ¦  «        j        › d| j        ›d�S )Nú(rP   )r>   Ú__name__r_   rG   s    r&   Ú__repr__z_GPath.__repr__Ž   s$   € Ý�4‰jŒjÔ!Ð7Ð7 D¤NÐ7Ð7Ð7Ð7r%   c                ó`   •— | j         r| j        S t          ¦   «                              ¦   «         S r4   )rH   r_   r5   Úas_uri)r<   r8   s    €r&   rk   z_GPath.as_uri‘   s*   ø€ ØÔð ØŒ^ÐÝ‰7Œ7�>Š>ÑÔÐr%   r   c                ó@   — | j                              | j        ¦  «        S )zReturns True if self exists.)rY   Úexistsr_   rG   s    r&   rm   z_GPath.exists–   s   € àŒ=×Ò ¤Ñ/Ô/Ð/r%   c                ó@   — | j                              | j        ¦  «        S )z$Returns True if self is a directory.)rY   Úisdirr_   rG   s    r&   Úis_dirz_GPath.is_dirš   s   € àŒ=×Ò˜tœ~Ñ.Ô.Ð.r%   úIterator[_P]c              #  ó~   K  — | j                              | j        ¦  «        D ]}|                      | |¦  «        V — ŒdS )zIterates over the directory.N)rY   Úlistdirr_   r?   )r<   r   s     r&   Úiterdirz_GPath.iterdirž   sN   è è € àŒ]×"Ò" 4¤>Ñ2Ô2ð ð ˆØ�IŠI�d˜AÑÔÐÐÐÐðð r%   c                óf   — |                       | j                             | j        ¦  «        ¦  «        S )z<Returns a new path with expanded `~` and `~user` constructs.)r?   r-   Ú
expanduserr_   rG   s    r&   rv   z_GPath.expanduser£   s&   € à�9Š9�T”Z×*Ò*¨4¬>Ñ:Ô:Ñ;Ô;Ð;r%   FÚstrictc                óf   — |                       | j                             | j        ¦  «        ¦  «        S )zReturns the abolute path.)r?   r-   Úabspathr_   )r<   rw   s     r&   Úresolvez_GPath.resolve§   s(   € ð �9Š9�T”Z×'Ò'¨¬Ñ7Ô7Ñ8Ô8Ð8r%   Úpatternc              #  óÞ   K  — | j                              | j        |¦  «        }d|v rt          d|›�¦  «        ‚| j                             |¦  «        D ]}|                      |¦  «        V — ŒdS )z*Yielding all matching files (of any kind).z**zsRecursive `**` pattern not supported as this could trigger thousands of RPC requests on GCS. Use `*` instead. Got: N)r-   rV   r_   rW   rY   Úglobr?   )r<   r{   r   s      r&   r}   z_GPath.glob¬   sŽ   è è € àŒj�oŠo˜dœn¨gÑ6Ô6€Gàˆw€€Ýðàðð ñô ð ð Œ]×Ò Ñ(Ô(ð ð ˆØ�IŠI�a‰LŒLÐÐÐÐðð r%   TN©Útop_downÚon_errorr   r€   ú"Callable[[OSError], object] | Noneú)Iterator[tuple[_P, list[str], list[str]]]c             #  ó�   K  — | j                              | j        ||¬¦  «        D ] \  }}}|                      |¦  «        ||fV — Œ!d S )Nr~   )rY   Úwalkr_   r?   )r<   r   r€   ÚrootÚdirsÚfiless         r&   r„   z_GPath.walkº   sl   è è € ð "œ]×/Ò/ØŒØØð 0ñ ô ð )ð )Ñˆˆd�Eð
 �IŠI�d‰OŒO˜T 5Ð(Ð(Ð(Ð(Ð(ð)ð )r%   ÚmodeúOptional[int]ÚparentsÚexist_okc                ó–   — |r$| j                              | j        ||¬¦  «         dS | j                              | j        ||¬¦  «         dS )z*Create a new directory at this given path.)r‹   rˆ   N)rY   Úmakedirsr_   Úmkdir)r<   rˆ   rŠ   r‹   s       r&   rŽ   z_GPath.mkdirÇ   sW   € ð ð HØ
„m×Ò˜Tœ^°hÀTÐÑJÔJÐJÐJÐJà
„m×Ò˜$œ.°8À$ÐÑGÔGÐGÐGÐGr%   c                ó  — |                       ¦   «         st          | j        › d�¦  «        ‚t          |                      ¦   «         ¦  «        rt          d| j        › d�¦  «        ‚| j                             | j        ¦  «         dS )zRemove the empty directory.z is not a directory.z
Directory z is not emptyN)rp   ÚNotADirectoryErrorr_   Úlistrt   Ú
ValueErrorrY   ÚrmtreerG   s    r&   Úrmdirz_GPath.rmdirÓ   s   € à�;Š;‰=Œ=ð HÝ $¤.ÐFÐFÐFÑGÔGÐGÝˆD�LŠL‰NŒNÑÔð CÝÐA D¤NÐAÐAÐAÑBÔBÐBØ„M×Ò˜œÑ(Ô(Ð(Ð(Ð(r%   Ú
missing_okc                ón   — 	 | j                              | j        ¦  «         dS # t          $ r |s‚ Y dS w xY w)zRemove the directory.N)rY   r“   r_   ÚFileNotFoundError©r<   r•   s     r&   r“   z_GPath.rmtreeÛ   óZ   € ðØ
„m×Ò˜4œ>Ñ*Ô*Ð*Ð*Ð*øÝð ð ð Øð Øðð ð ðøøøó   ‚# £4³4c                ón   — 	 | j                              | j        ¦  «         dS # t          $ r |s‚ Y dS w xY w)z"Remove this file or symbolic link.N)rY   Úremover_   r—   r˜   s     r&   Úunlinkz_GPath.unlinkã   r™   rš   r(   )ÚencodingÚerrorsrž   rŸ   Úkwargsr   útyping.IO[Union[str, bytes]]c               ó  — |rt          d¦  «        ‚|r9|                     ¦   «                              d¦  «        st          d|› �¦  «        ‚|                     dd¦  «        }|t
          vrt          d|›dt
          › �¦  «        ‚|r t          dt          |¦  «        › d	�¦  «        ‚| j                             | j	        |¦  «        }t          j        t          j        t          t          t          f                  |¦  «        }|S )
zOpens the file.z$`errors=` not supported in `open()`.)Úutf8zutf-8z$Only UTF-8 encoding supported. Not: Úbr   zmode=z is not one of zkwargs z` not supported in `open()`.)rW   r#   Ú
startswithr’   ÚreplaceÚ_OPEN_MODESr‘   rY   Úopenr_   ÚtypingÚcastÚIOr   rZ   Úbytes)r<   rˆ   rž   rŸ   r    Úmode_without_bÚgfiles          r&   r¨   z_GPath.openë   s  € ð ð HÝÐ FÑGÔGÐGØð J˜ŸšÑ(Ô(×3Ò3Ð4EÑFÔFð JÝÐH¸hÐHÐHÑIÔIÐIð —\’\ # rÑ*Ô*€NØ�[Ð(Ð(ÝÐM˜~ÐMÐMÅÐMÐMÑNÔNÐNØð ÝØ
>•D˜‘L”LÐ
>Ð
>Ð
>ñô ð ð ŒM×Ò˜tœ~¨tÑ4Ô4€EÝŒK�œ	¥%­­U¨
Ô"3Ô4°eÑ<Ô<€EØ€Lr%   Úotherc                óp   •— |                       |¦  «        }t          ¦   «                              |¦  «        S )z-Returns the current path relative to `other`.)r?   r5   Úrelative_to)r<   r¯   Ú
other_pathr8   s      €r&   r±   z_GPath.relative_to  s,   ø€ à—’˜5Ñ!Ô!€JÝ‰7Œ7×Ò˜zÑ*Ô*Ð*r%   Útargetc                óª   — |                       |¦  «        }t          | |¦  «        }|                     | j        t	          j        |¦  «        ¦  «         |S )z-Rename file or directory to the given target.)r?   Ú_get_backendÚrenamer_   r    Úfspath©r<   r³   r   s      r&   r¶   z_GPath.rename
  sI   € ð
 �YŠY�vÑÔ€FÝ˜4 Ñ(Ô(€GØ‡N‚N�4”>¥2¤9¨VÑ#4Ô#4Ñ5Ô5Ð5Ø€Mr%   c                óª   — |                       |¦  «        }t          | |¦  «        }|                     | j        t	          j        |¦  «        ¦  «         |S )z.Replace file or directory to the given target.)r?   rµ   r¦   r_   r    r·   r¸   s      r&   r¦   z_GPath.replace  sG   € à�YŠY�vÑÔ€FÝ˜4 Ñ(Ô(€GØ‡O‚O�D”N¥B¤I¨fÑ$5Ô$5Ñ6Ô6Ð6Ø€Mr%   ÚdstÚ	overwritec                ó®   — |                       |¦  «        }t          | |¦  «        }|                     | j        t	          j        |¦  «        |¬¦  «         |S )z+Copy file or directory to the given target.)r»   )r?   rµ   Úcopyr_   r    r·   )r<   rº   r»   r   s       r&   r½   z_GPath.copy  sI   € ð �)Š)�C‰.Œ.€CÝ˜4 Ñ%Ô%€GØ‡L‚L�”¥¤¨3¡¤¸9€LÑEÔEÐEØ€Jr%   ústat_utils.StatResultc                ó@   — | j                              | j        ¦  «        S )z(Returns metadata for the file/directory.)rY   Ústatr_   rG   s    r&   rÀ   z_GPath.stat#  s   € àŒ=×Ò˜dœnÑ-Ô-Ð-r%   )r0   r1   r2   r   r   r   )r2   r   r   r9   )r<   r   r2   r   r   r   )r   r@   )r   rI   )r   rZ   ©r   r   )r<   r   r   rq   )r<   r   r   r   )F)r<   r   rw   r   r   r   )r<   r   r{   rZ   r   rq   )r<   r   r   r   r€   r�   r   r‚   )NFF)rˆ   r‰   rŠ   r   r‹   r   r   r9   )r   r9   )r•   r   r   r9   )r(   )
rˆ   rZ   rž   r@   rŸ   r@   r    r   r   r¡   )r<   r   r¯   r   r   r   )r<   r   r³   r   r   r   )r<   r   rº   r   r»   r   r   r   )r   r¾   )$rh   Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__ÚsysÚversion_infor6   r;   r?   ÚpropertyrH   rY   r_   rb   re   ri   rk   rm   rp   rt   rv   rz   r}   r„   rŽ   r”   r“   r�   r¨   r±   r¶   r¦   r½   rÀ   Ú__classcell__)r8   s   @r&   r,   r,   K   s  ø€ € € € € € ØAÐAð $Ð#Ð#Ñ#àÔ˜ÒÐð;ð ;ð ;ð ;ð ;ð ;ð ;ð
0ð 0ð 0ð 0ð 0ð 0ðð ð ð ð ðð ð ñ „8ðð ðð ð ñ „8ðð ðAð Að Añ „8ðAðð ð ð ðð ð ð ð8ð 8ð 8ð 8ðð ð ð ð ð ð
0ð 0ð 0ð 0ð/ð /ð /ð /ðð ð ð ð
<ð <ð <ð <ð9ð 9ð 9ð 9ð 9ð
ð ð ð ð" Ø59ð	)ð )ð )ð )ð )ð )ð !ØØð	
Hð 
Hð 
Hð 
Hð 
Hð)ð )ð )ð )ðð ð ð ð ðð ð ð ð ð ðð !%Ø"ðð ð ð ð ð ð4+ð +ð +ð +ð +ð +ð
ð ð ð ðð ð ð ðð ð ð ð ð.ð .ð .ð .ð .ð .ð .ð .r%   r,   c                  ó   — e Zd ZdZeZdS )Ú
PosixGPathú+Pathlib like api with gs://, s3:// support.N)rh   rÂ   rÃ   rÄ   Ú	posixpathr-   r$   r%   r&   rË   rË   (  s   € € € € € à3Ð3à
€%€%€%r%   rË   c                  ó   — e Zd ZdZeZdS )ÚWindowsGPathrÌ   N)rh   rÂ   rÃ   rÄ   Úntpathr-   r$   r%   r&   rÏ   rÏ   /  s   € € € € € à3Ð3à
€%€%€%r%   rÏ   c                 ód   — t          ¦   «         sdS t          j                             d¦  «        duS )z'Checks whether TensorFlow is installed.FÚ
tensorflowN)r'   Ú	importlibÚutilÚ	find_specr$   r%   r&   rR   rR   6  s0   € õ 
‰Œð Øˆ5Ý	Œ×	!Ò	! ,Ñ	/Ô	/°tÐ	;Ð;r%   r2   r   útuple[PathLike, ...]c                 ó   — d                      d„ | D ¦   «         ¦  «        }|                     t          ¦  «        rD|                     dd¬¦  «        \  }}|› d�}t          |         }|                     ||d¦  «        fS | S )zSupports the `xx://` prefix.rC   c              3  ó>   K  — | ]}t          j        |¦  «        V — Œd S r4   )r    r·   )rM   Úps     r&   rO   z!_process_parts.<locals>.<genexpr>@  s*   è è € Ð3Ð3¨•r”y ‘|”|Ð3Ð3Ð3Ð3Ð3Ð3r%   r\   rD   )Úmaxsplit)rV   r¥   Ú_URI_PREFIXESÚsplitÚ_URI_MAP_ROOTr¦   )r2   Ú	full_pathÚprefixÚ_Ú
new_prefixs        r&   r7   r7   >  s†   € à�hŠhÐ3Ð3¨UÐ3Ñ3Ô3Ñ3Ô3€)Ø×Ò�-Ñ(Ô(ð Ø—’ °�Ñ2Ô2�I€FˆAØˆ^ˆ^ˆ^€FÝ˜vÔ&€JØ×Ò˜f j°!Ñ4Ô4Ð6Ð6à€Lr%   Úp0Úp1rI   c                ód   — | j         t          v r| j         S |j         t          v r|j         S | j         S )zÜWhen composing with another backend, GCS win.

  To allow `Path('.').replace('gs://')`

  Args:
    p0: Path to compare
    p1: Path to compare

  Returns:
    GCS backend if one of the 2 path is GCS, else p0 backend.
  )rY   Ú_GCS_BACKENDS)râ   rã   s     r&   rµ   rµ   J  s6   € ð „[•MÐ!Ð!ØŒ;ÐØ	„{•mÐ#Ð#ØŒ;ÐàŒ;Ðr%   rÁ   )r2   r   r   rÖ   )râ   r,   rã   r,   r   rI   )5rÄ   Ú
__future__r   Ú	functoolsÚimportlib.utilrÓ   rÐ   r    ÚpathlibrÍ   rÆ   Útypesr©   r   r   r   r   r   r	   r
   r   Úetilsr   Úetils.epathr   r   rS   r   r   Úetils.epath.typingr   r   rÛ   Ú	frozensetrF   rÝ   r'   Úfsspec_backendÚ
os_backendrQ   rT   rå   r§   ÚPathr,   Úregister_path_clsrË   ÚPureWindowsPathrÏ   ÚcacherR   r7   rµ   r$   r%   r&   ú<module>rõ      sÖ  ðð *Ð )à "Ð "Ð "Ð "Ð "Ð "à Ð Ð Ð Ø Ð Ð Ð Ø €€€Ø 	€	€	€	Ø €€€Ø Ð Ð Ð Ø 
€
€
€
Ø €€€Ø €€€Ø TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ TÐ Tà Ð Ð Ð Ð Ð Ø %Ð %Ð %Ð %Ð %Ð %Ø .Ð .Ð .Ð .Ð .Ð .Ø  Ð  Ð  Ð  Ð  Ð  Ø "Ð "Ð "Ð "Ð "Ð "Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'à€WˆT�]„]€à4€ØˆyÐ1Ñ2Ô2€ð ØØØð	ð €ðð ð ð ð Ô
$Ø
Ô
$Ø
Ô
$Ø
Ô
$Ø
Ô
 ðð Ð ð �	ØÔØÔðñ ô €ð €ðZ.ð Z.ð Z.ð Z.ð Z.ˆ]Ôñ Z.ô Z.ð Z.ðz €Ô˜MÑ*Ô*ðð ð ð ð �ñ ô ñ +Ô*ðð 
Ôðð ð ð ð �7Ô*¨Fñ ô ñ Ôðð „ð<ð <ð <ñ „ð<ð	ð 	ð 	ð 	ðð ð ð ð ð r%   