§
    }ŠtjB±  ã                   óØ  — d 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 ddlm	Z	m
Z
 ddlmZ ddlmZ ddlmZmZ ddlmZ dd	lmZmZ dd
l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%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3 ddl(m4Z5 ddl6m7Z7 erddl8m9Z9m:Z:  e0j;        e<¦  «        Z=ed         Z>dZ?dZ@dZAe G d„ d¦  «        ¦   «         ZBe G d„ d¦  «        ¦   «         ZCe G d„ d¦  «        ¦   «         ZDdeEdeEfd„ZFeeDeCeBf         ZGd eHeG         ddfd!„ZIe3dd"ddd#œd$eHeD         d%eEd&eEd'eJeEeEf         d(eEdz  d)eKd*eEdz  d+eLdz  fd,„¦   «         ZMd$eHeD         d)eKddfd-„ZNe3dd"d.œd/eHeJeEef                  d0eJeEeDf         d'eJeEeEf         d(eEdz  d)eKf
d1„¦   «         ZOe3dddd2œd$eHeD         d%eEd&eEd'eJeEeEf         d(eEdz  d*eEdz  d+eLdz  fd3„¦   «         ZPd4eJfd5„ZQe3	 	 	 dHd$e	eD         d%eEd&eEd'eJeEeEf         d*eEd(eEdz  d+eLd7eEdz  ddfd8„¦   «         ZR G d9„ d:e¦  «        ZSe3	 dId;e	eC         d%eEd&eEd'eJeEeEf         d*eEd(eEdz  deJeSed<eTf         f         fd=„¦   «         ZU	 	 dJd e	eG         d>eJeSed<eTf         f         d?eEd@eEdz  dAeEdz  de	eJeEef                  fdB„ZVddd6d6d6dCœd e	eG         d>eJeSed<eTf         f         d?eEd@eEd%eEd&eEd'eJeEeEf         d*eEd(eEdz  dAeEdz  d+eLdDeLdEeLddFfdG„ZWdS )Kz<
Type definitions and utilities for the `create_commit` API
é    N)Údefaultdict)ÚIterableÚIterator)ÚThreadPoolExecutor)Úcontextmanager)Ú	dataclassÚfield)Úgroupby)ÚPathÚPurePosixPath)ÚTYPE_CHECKINGÚAnyÚBinaryIOÚLiteralÚ
NamedTupleÚUnioné   )Ú	constants)ÚEntryNotFoundError)Ú
hf_hub_url)Ú
UploadInfoÚ
lfs_uploadÚpost_lfs_batch_info)ÚFORBIDDEN_FOLDERSÚare_progress_bars_disabledÚchunk_iterableÚget_sessionÚhf_raise_for_statusÚhf_thread_mapÚhttp_backoffÚloggingÚshaÚtqdm_stream_fileÚvalidate_hf_hub_args)Útqdm)Úis_xet_available)Ú
CommitInfoÚRepoFile©ÚlfsÚregulariô  é   c                   óD   — e Zd ZU dZeed<   dZeed         z  ed<   d„ Z	dS )ÚCommitOperationDeletea«  
    Data structure holding necessary info to delete a file or a folder from a repository
    on the Hub.

    Args:
        path_in_repo (`str`):
            Relative filepath in the repo, for example: `"checkpoints/1fec34a/weights.bin"`
            for a file or `"checkpoints/1fec34a/"` for a folder.
        is_folder (`bool` or `Literal["auto"]`, *optional*)
            Whether the Delete Operation applies to a folder or not. If "auto", the path
            type (file or folder) is guessed automatically by looking if path ends with
            a "/" (folder) or not (file). To explicitly set the path type, you can set
            `is_folder=True` or `is_folder=False`.
    Úpath_in_repoÚautoÚ	is_folderc                 óð   — t          | j        ¦  «        | _        | j        dk    r| j                             d¦  «        | _        t	          | j        t
          ¦  «        st          d| j        › d�¦  «        ‚d S )Nr0   ú/zNWrong value for `is_folder`. Must be one of [`True`, `False`, `'auto'`]. Got 'z'.)Ú_validate_path_in_repor/   r1   ÚendswithÚ
isinstanceÚboolÚ
ValueError©Úselfs    úY/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/huggingface_hub/_commit_api.pyÚ__post_init__z#CommitOperationDelete.__post_init__O   s|   € Ý2°4Ô3DÑEÔEˆÔàŒ>˜VÒ#Ð#Ø!Ô.×7Ò7¸Ñ<Ô<ˆDŒNÝ˜$œ.­$Ñ/Ô/ð 	ÝØsÐaeÔaoÐsÐsÐsñô ð ð	ð 	ó    N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__ÚstrÚ__annotations__r1   r7   r   r<   © r=   r;   r.   r.   ;   sV   € € € € € € ðð ð ÐÐÑØ(.€Iˆt�g˜f”oÑ%Ð.Ð.Ñ.ðð ð ð ð r=   r.   c                   ó    — e Zd ZU dZeed<   eed<   dZedz  ed<   dZedz  ed<   dZedz  ed<   dZ	edz  ed<   dZ
edz  ed	<   d
Zeed<   d„ ZdS )ÚCommitOperationCopyax  
    Data structure holding necessary info to copy a file in a repository on the Hub.

    Both LFS files and regular files are supported. LFS files are copied server-side while regular files are
    downloaded and re-uploaded as part of the commit.

    Cross-repository copies are supported by setting `src_repo_id` and `src_repo_type`. For cross-repo LFS copies,
    the LFS objects are duplicated to the destination repository before the commit is created. This is handled
    automatically by [`create_commit`]. Note that cross-repository copies only work within the same
    [storage region](https://huggingface.co/docs/hub/storage-regions); copying across regions is not supported.

    Note: you can combine a [`CommitOperationCopy`] and a [`CommitOperationDelete`] to rename an LFS file on the Hub.

    Args:
        src_path_in_repo (`str`):
            Relative filepath in the repo of the file to be copied, e.g. `"checkpoints/1fec34a/weights.bin"`.
        path_in_repo (`str`):
            Relative filepath in the repo where to copy the file, e.g. `"checkpoints/1fec34a/weights_copy.bin"`.
        src_revision (`str`, *optional*):
            The git revision of the file to be copied. Can be any valid git revision.
            Default to the target commit revision.
        src_repo_id (`str`, *optional*):
            The source repository to copy from (e.g. `"username/source-model"`).
            Default to the destination repository (intra-repo copy).
        src_repo_type (`str`, *optional*):
            The type of the source repository (`"model"`, `"dataset"` or `"space"`).
            Required when `src_repo_id` is set.
    Úsrc_path_in_repor/   NÚsrc_revisionÚsrc_repo_idÚsrc_repo_typeÚ_src_oidÚ	_dest_oidFÚ_is_duplicatedc                 óâ   — t          | j        ¦  «        | _        t          | j        ¦  «        | _        | j        �| j        €t          d¦  «        ‚| j        �| j        €t          d¦  «        ‚d S d S )Nz6`src_repo_type` is required when `src_repo_id` is set.z6`src_repo_id` is required when `src_repo_type` is set.)r4   rG   r/   rI   rJ   r8   r9   s    r;   r<   z!CommitOperationCopy.__post_init__‡   sv   € Ý 6°tÔ7LÑ MÔ MˆÔÝ2°4Ô3DÑEÔEˆÔØÔÐ'¨DÔ,>Ð,FÝÐUÑVÔVÐVØÔÐ)¨dÔ.>Ð.FÝÐUÑVÔVÐVð *Ð)Ð.FÐ.Fr=   )r>   r?   r@   rA   rB   rC   rH   rI   rJ   rK   rL   rM   r7   r<   rD   r=   r;   rF   rF   Z   sÆ   € € € € € € ðð ð: ÐÐÑØÐÐÑØ#€L�#˜‘*Ð#Ð#Ñ#Ø"€K��t‘Ð"Ð"Ñ"Ø $€M�3˜‘:Ð$Ð$Ñ$ð  €Hˆc�D‰jÐÐÑð !€Iˆs�T‰zÐ Ð Ñ à €N�DÐ Ð Ñ ðWð Wð Wð Wð Wr=   rF   c                   ó’  — e Zd ZU dZeed<   eez  ez  ez  ed<    e	dd¬¦  «        Z
eed<    e	ddd¬¦  «        Zedz  ed	<    e	ddd¬¦  «        Zedz  ed
<    e	ddd¬¦  «        Zedz  ed<    e	ddd¬¦  «        Zeed<    e	ddd¬¦  «        Zeed<   dd„Zeddedee         fd„¦   «         Zdefd„Zededz  fd„¦   «         ZdS )ÚCommitOperationAdda¿  
    Data structure holding necessary info to upload a file to a repository on the Hub.

    Args:
        path_in_repo (`str`):
            Relative filepath in the repo, for example: `"checkpoints/1fec34a/weights.bin"`
        path_or_fileobj (`str`, `Path`, `bytes`, or `BinaryIO`):
            Either:
            - a path to a local file (as `str` or `pathlib.Path`) to upload
            - a buffer of bytes (`bytes`) holding the content of the file to upload
            - a "file object" (subclass of `io.BufferedIOBase`), typically obtained
                with `open(path, "rb")`. It must support `seek()` and `tell()` methods.

    Raises:
        [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
            If `path_or_fileobj` is not one of `str`, `Path`, `bytes` or `io.BufferedIOBase`.
        [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
            If `path_or_fileobj` is a `str` or `Path` but not a path to an existing file.
        [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
            If `path_or_fileobj` is a `io.BufferedIOBase` but it doesn't support both
            `seek()` and `tell()`.
    r/   Úpath_or_fileobjF)ÚinitÚreprÚupload_infoN)rR   rS   ÚdefaultÚ_upload_modeÚ_should_ignoreÚ_remote_oidÚ_is_uploadedÚ_is_committedÚreturnc                 óv  — t          | j        ¦  «        | _        t          | j        t          ¦  «        rt          | j        ¦  «        | _        t          | j        t
          ¦  «        rƒt          j                             t          j         	                    | j        ¦  «        ¦  «        | _        t          j         
                    | j        ¦  «        st          d| j        › d�¦  «        ‚n5t          | j        t          j        t          f¦  «        st          d¦  «        ‚t          | j        t          j        ¦  «        ri	 | j                             ¦   «          | j                             dt          j        ¦  «         n)# t$          t&          f$ r}t          d¦  «        |‚d}~ww xY wt          | j        t
          ¦  «        r t)          j        | j        ¦  «        | _        dS t          | j        t          ¦  «        r t)          j        | j        ¦  «        | _        dS t)          j        | j        ¦  «        | _        dS )z6Validates `path_or_fileobj` and compute `upload_info`.zProvided path: 'z(' is not a file on the local file systemz�path_or_fileobj must be either an instance of str, bytes or io.BufferedIOBase. If you passed a file-like object, make sure it is in binary mode.r   zNpath_or_fileobj is a file-like object but does not implement seek() and tell()N)r4   r/   r6   rQ   r   rB   ÚosÚpathÚnormpathÚ
expanduserÚisfiler8   ÚioÚBufferedIOBaseÚbytesÚtellÚseekÚSEEK_CURÚOSErrorÚAttributeErrorr   Ú	from_pathrT   Ú
from_bytesÚfrom_fileobj)r:   Úexcs     r;   r<   z CommitOperationAdd.__post_init__À   s   € å2°4Ô3DÑEÔEˆÔõ �dÔ*­DÑ1Ô1ð 	=Ý#& tÔ';Ñ#<Ô#<ˆDÔ Ý�dÔ*­CÑ0Ô0ð 
	Ý#%¤7×#3Ò#3µB´G×4FÒ4FÀtÔG[Ñ4\Ô4\Ñ#]Ô#]ˆDÔ Ý”7—>’> $Ô"6Ñ7Ô7ð tÝ Ð!r°DÔ4HÐ!rÐ!rÐ!rÑsÔsÐsðtå˜DÔ0µ2Ô3DÅeÐ2LÑMÔMð 	åð#ñô ð õ
 �dÔ*­BÔ,=Ñ>Ô>ð 	ðØÔ$×)Ò)Ñ+Ô+Ð+ØÔ$×)Ò)¨!­R¬[Ñ9Ô9Ð9Ð9øÝ�^Ð,ð ð ð Ý Ødñô àðøøøøðøøøõ �dÔ*­CÑ0Ô0ð 	MÝ)Ô3°DÔ4HÑIÔIˆDÔÐÐÝ˜Ô,­eÑ4Ô4ð 	MÝ)Ô4°TÔ5IÑJÔJˆDÔÐÐå)Ô6°tÔ7KÑLÔLˆDÔÐÐs   Ä?>E> Å>F$ÆFÆF$Ú	with_tqdmc              #   ó‚  K  — t          | j        t          ¦  «        st          | j        t          ¦  «        ri|r3t	          | j        ¦  «        5 }|V — ddd¦  «         dS # 1 swxY w Y   dS t          | j        d¦  «        5 }|V — ddd¦  «         dS # 1 swxY w Y   dS t          | j        t          ¦  «        rt          j        | j        ¦  «        V — dS t          | j        t          j	        ¦  «        rI| j         
                    ¦   «         }| j        V — | j                             |t          j        ¦  «         dS dS )uŠ  
        A context manager that yields a file-like object allowing to read the underlying
        data behind `path_or_fileobj`.

        Args:
            with_tqdm (`bool`, *optional*, defaults to `False`):
                If True, iterating over the file object will display a progress bar. Only
                works if the file-like object is a path to a file. Pure bytes and buffers
                are not supported.

        Example:

        ```python
        >>> operation = CommitOperationAdd(
        ...        path_in_repo="remote/dir/weights.h5",
        ...        path_or_fileobj="./local/weights.h5",
        ... )
        CommitOperationAdd(path_in_repo='remote/dir/weights.h5', path_or_fileobj='./local/weights.h5')

        >>> with operation.as_file() as file:
        ...     content = file.read()

        >>> with operation.as_file(with_tqdm=True) as file:
        ...     while True:
        ...         data = file.read(1024)
        ...         if not data:
        ...              break
        config.json: 100%|â–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆ| 8.19k/8.19k [00:02<00:00, 3.72kB/s]

        >>> with operation.as_file(with_tqdm=True) as file:
        ...     httpx.put(..., data=file)
        config.json: 100%|â–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆâ–ˆ| 8.19k/8.19k [00:02<00:00, 3.72kB/s]
        ```
        NÚrb)r6   rQ   rB   r   r#   Úopenrd   rb   ÚBytesIOrc   re   rf   ÚSEEK_SET)r:   rn   ÚfileÚprev_poss       r;   Úas_filezCommitOperationAdd.as_fileã   sÏ  è è € õH �dÔ*­CÑ0Ô0ð 	=µJ¸tÔ?SÕUYÑ4ZÔ4Zð 	=Øð Ý% dÔ&:Ñ;Ô;ð ¸tØ�J�J�Jðð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð õ ˜$Ô.°Ñ5Ô5ð ¸Ø�J�J�Jðð ð ñ ô ð ð ð ð ð ð ð øøøð ð ð ð ð ð å˜Ô,­eÑ4Ô4ð 	=Ý”*˜TÔ1Ñ2Ô2Ð2Ð2Ð2Ð2Ð2Ý˜Ô,­bÔ.?Ñ@Ô@ð 	=ØÔ+×0Ò0Ñ2Ô2ˆHØÔ&Ð&Ð&Ð&ØÔ ×%Ò% hµ´Ñ<Ô<Ð<Ð<Ð<ð	=ð 	=s$   ÁAÁA#Á&A#ÂBÂBÂBc                 óª   — |                       ¦   «         5 }t          j        |                     ¦   «         ¦  «        cddd¦  «         S # 1 swxY w Y   dS )z[
        The base64-encoded content of `path_or_fileobj`

        Returns: `bytes`
        N)rv   Úbase64Ú	b64encodeÚread©r:   rt   s     r;   Ú
b64contentzCommitOperationAdd.b64content  s‰   € ð �\Š\‰^Œ^ð 	1˜tÝÔ# D§I¢I¡K¤KÑ0Ô0ð	1ð 	1ð 	1ð 	1ñ 	1ô 	1ð 	1ð 	1ð 	1ð 	1ð 	1ð 	1øøøð 	1ð 	1ð 	1ð 	1ð 	1ð 	1s   •&AÁAÁAc                 ó  — | j         €dS | j         dk    r| j        j                             ¦   «         S |                      ¦   «         5 }t          j        |                     ¦   «         ¦  «        cddd¦  «         S # 1 swxY w Y   dS )aÊ  Return the OID of the local file.

        This OID is then compared to `self._remote_oid` to check if the file has changed compared to the remote one.
        If the file did not change, we won't upload it again to prevent empty commits.

        For LFS files, the OID corresponds to the SHA256 of the file content (used a LFS ref).
        For regular files, the OID corresponds to the SHA1 of the file content.
        Note: this is slightly different to git OID computation since the oid of an LFS file is usually the git-SHA1 of the
              pointer file content (not the actual file content). However, using the SHA256 is enough to detect changes
              and more convenient client-side.
        Nr*   )rV   rT   Úsha256Úhexrv   r"   Úgit_hashrz   r{   s     r;   Ú
_local_oidzCommitOperationAdd._local_oid  s¾   € ð ÔÐ$Ø�4ØÔ %Ò'Ð'ØÔ#Ô*×.Ò.Ñ0Ô0Ð0ð —’‘”ð 1 4Ý”| D§I¢I¡K¤KÑ0Ô0ð1ð 1ð 1ð 1ñ 1ô 1ð 1ð 1ð 1ð 1ð 1ð 1øøøð 1ð 1ð 1ð 1ð 1ð 1s   Á&A:Á:A>ÂA>©r[   N)F)r>   r?   r@   rA   rB   rC   r   rd   r   r	   rT   r   rV   Ú
UploadModerW   r7   rX   rY   rZ   r<   r   r   rv   r|   Úpropertyr�   rD   r=   r;   rP   rP   �   s»  € € € € € € ðð ð. ÐÐÑØ˜4‘Z %Ñ'¨(Ñ2Ð2Ð2Ñ2Ø#˜e¨°UÐ;Ñ;Ô;€K�Ð;Ð;Ñ;ð
 ', e°¸UÈDÐ&QÑ&QÔ&Q€L�*˜tÑ#ÐQÐQÑQð #( %¨U¸ÈÐ"MÑ"MÔ"M€N�D˜4‘KÐMÐMÑMð $˜e¨°UÀDÐIÑIÔI€K��t‘ÐIÐIÑIð ˜ E°¸uÐEÑEÔE€L�$ÐEÐEÑEð  ˜% U°ÀÐFÑFÔF€M�4ÐFÐFÑFð!Mð !Mð !Mð !MðF ð/=ð /= ð /=°(¸8Ô2Dð /=ð /=ð /=ñ „^ð/=ðb1˜Eð 1ð 1ð 1ð 1ð ð1˜C $™Jð 1ð 1ð 1ñ „Xð1ð 1ð 1r=   rP   r/   r[   c                 óˆ  ‡— |                       d¦  «        r
| dd …         } | dk    s| dk    s|                       d¦  «        rt          d| › d�¦  «        ‚|                       d¦  «        r
| d	d …         } t          D ]FŠt          ˆfd
„|                      d¦  «        D ¦   «         ¦  «        rt          d‰› d| › d�¦  «        ‚ŒG| S )Nr3   r   ú.z..z../z,Invalid `path_in_repo` in CommitOperation: 'ú'z./é   c              3   ó$   •K  — | ]
}|‰k    V — Œd S ©NrD   )Ú.0ÚpartÚ	forbiddens     €r;   ú	<genexpr>z)_validate_path_in_repo.<locals>.<genexpr>?  s(   øè è € ÐEÐE Tˆt�yÒ ÐEÐEÐEÐEÐEÐEr=   zHInvalid `path_in_repo` in CommitOperation: cannot update files under a 'z/' folder (path: 'z').)Ú
startswithr8   r   ÚanyÚsplit)r/   r�   s    @r;   r4   r4   6  s  ø€ à×Ò˜sÑ#Ô#ð (Ø# A B BÔ'ˆØ�sÒÐ˜l¨dÒ2Ð2°l×6MÒ6MÈeÑ6TÔ6TÐ2ÝÐWÈÐWÐWÐWÑXÔXÐXØ×Ò˜tÑ$Ô$ð (Ø# A B BÔ'ˆÝ&ð ð ˆ	ÝÐEÐEÐEÐE¨\×-?Ò-?ÀÑ-DÔ-DÐEÑEÔEÑEÔEð 	Ýð'Ð[dð 'ð 'Ø!ð'ð 'ð 'ñô ð ð	ð
 Ðr=   Ú
operationsc                 ó&  — t          t          ¦  «        }| D ]ù}|j        }t          |t          ¦  «        rh||         dk    rt          j        d|› d�¦  «         ||xx         dz  cc<   t          |¦  «        j        D ]}|t          |¦  «        xx         dz  cc<   Œ t          |t          ¦  «        r^|t          t          |¦  «        ¦  «                 dk    r8|j        rt          j        d|› d�¦  «         Œát          j        d|› d�¦  «         ŒúdS )a’  
    Warn user when a list of operations is expected to overwrite itself in a single
    commit.

    Rules:
    - If a filepath is updated by multiple `CommitOperationAdd` operations, a warning
      message is triggered.
    - If a filepath is updated at least once by a `CommitOperationAdd` and then deleted
      by a `CommitOperationDelete`, a warning is triggered.
    - If a `CommitOperationDelete` deletes a filepath that is then updated by a
      `CommitOperationAdd`, no warning is triggered. This is usually useless (no need to
      delete before upload) but can happen if a user deletes an entire folder and then
      add new files to it.
    r   zBAbout to update multiple times the same file in the same commit: 'z9'. This can cause undesired inconsistencies in your repo.r   z_About to delete a folder containing files that have just been updated within the same commit: 'zLAbout to delete a file that have just been updated within the same commit: 'N)r   Úintr/   r6   rP   ÚwarningsÚwarnr   ÚparentsrB   r.   r1   )r’   Únb_additions_per_pathÚ	operationr/   Úparents        r;   Ú_warn_on_overwriting_operationsr›   J  s€  € õ -8½Ñ,<Ô,<ÐØð ð ˆ	Ø Ô-ˆÝ�iÕ!3Ñ4Ô4ð 	8Ø$ \Ô2°QÒ6Ð6Ý”ð"Ø%ð"ð "ð "ñô ð ð
 " ,Ð/Ð/Ô/°1Ñ4Ð/Ð/Ñ/Ý'¨Ñ5Ô5Ô=ð 8ð 8�ð &¥c¨&¡k¤kÐ2Ð2Ô2°aÑ7Ð2Ð2Ñ2Ð2Ý�iÕ!6Ñ7Ô7ð 	Ø$¥S­°|Ñ)DÔ)DÑ%EÔ%EÔFÈÒJÐJØÔ&ð Ý”MðIØ=IðIð Ið Iñô ð ð õ ”Mð9Ø*6ð9ð 9ð 9ñô ð øð/ð r=   é   )ÚendpointÚnum_threadsÚrevisionÚ	create_prÚ	additionsÚ	repo_typeÚrepo_idÚheadersr�   rž   rŸ   r    c                 ó¬  — t          d„ | D ¦   «         ¦  «        }t          ¦   «         r4|st          | ||||||¬¦  «         dS t                               d¦  «         t          | |¬¦  «         g }	i }
t          | t          ¬¦  «        D ]£}d„ |D ¦   «         }t          d„ |D ¦   «         |||||dd	d
g¬¦  «        \  }}}|r1d 	                    d„ |D ¦   «         ¦  «        }t          d|› �¦  «        ‚|	                     |¦  «         |D ]#}||
|j        j                             ¦   «         <   Œ$Œ¤t          |	¦  «        dk    rt!          |	|
|||¬¦  «         dS dS )a3  
    Uploads the files through the Xet protocol if possible, otherwise through the legacy LFS protocol.

    The Xet path does not require any Python-side sha256 computation: hashing happens inside `hf_xet`
    while chunking the files (single read pass) and is backfilled on the operations afterwards.
    c              3   óT   K  — | ]#}t          |j        t          j        ¦  «        V — Œ$d S rŠ   )r6   rQ   rb   rc   ©r‹   Úops     r;   rŽ   z _upload_files.<locals>.<genexpr>Š  s3   è è € ÐeÐeÐUW�z¨"Ô*<½bÔ>OÑPÔPÐeÐeÐeÐeÐeÐer=   )r¡   r¢   r£   r¤   r�   rŸ   r    NzcUploading files as a binary IO buffer is not supported by Xet Storage. Falling back to HTTP upload.)rž   )Ú
chunk_sizec                 ó   — g | ]}|‘ŒS rD   rD   r§   s     r;   ú
<listcomp>z!_upload_files.<locals>.<listcomp>¡  s   € Ð)Ð)Ð)˜R�bÐ)Ð)Ð)r=   c                 ó   — g | ]	}|j         ‘Œ
S rD   )rT   r§   s     r;   r«   z!_upload_files.<locals>.<listcomp>£  s   € Ð>Ð>Ð>¨R˜"œ.Ð>Ð>Ð>r=   ÚbasicÚ	multipart)Úupload_infosr£   r¢   rŸ   r�   r¤   ÚtokenÚ	transfersú
c           	      ó’   — g | ]D}d |                      d¦  «        › d|                      di ¦  «                              d¦  «        › �‘ŒES )z$Encountered error for file with OID Úoidz: `ÚerrorÚmessage©Úget)r‹   Úerrs     r;   r«   z!_upload_files.<locals>.<listcomp>®  sb   € ð ð ð àð t¸3¿7º7À5¹>¼>ÐsÐsÈcÏgÊgÐV]Ð_aÑNbÔNb×NfÒNfÐgpÑNqÔNqÐsÐsðð ð r=   zLFS batch API returned errors:
r   )ÚactionsÚ	oid2addopr¤   r�   rž   )r�   r&   Ú_upload_xet_filesÚloggerÚwarningÚ_compute_missing_sha256sr   ÚUPLOAD_BATCH_MAX_NUM_FILESr   Újoinr8   ÚextendrT   r~   r   ÚlenÚ_upload_lfs_files)r¡   r¢   r£   r¤   r�   rž   rŸ   r    Úhas_buffered_io_dataÚlfs_actionsÚlfs_oid2addopÚchunkÚ
chunk_listÚactions_chunkÚerrors_chunkÚ_r¶   r¨   s                     r;   Ú_upload_filesrÍ   x  sÿ  € õ$ ÐeÐeÐ[dÐeÑeÔeÑeÔeÐÝÑÔð 
Ø#ð 
	ÝØ#Ø#ØØØ!Ø!Ø#ðñ ô ð ð ˆFÝ�ŠØqñ	
ô 	
ð 	
õ
 ˜Y°KÐ@Ñ@Ô@Ð@à(*€KØ35€MÝ 	Õ6PÐQÑQÔQð <ð <ˆØ)Ð) 5Ð)Ñ)Ô)ˆ
Ý)<Ø>Ð>°:Ð>Ñ>Ô>ØØØØØØØ Ð,ð	*
ñ 	*
ô 	*
Ñ&ˆ�| Qð ð 	KØ—i’iðð à+ðñ ô ñô ˆGõ ÐIÀÐIÐIÑJÔJÐJØ×Ò˜=Ñ)Ô)Ð)Øð 	<ð 	<ˆBØ9;ˆM˜"œ.Ô/×3Ò3Ñ5Ô5Ñ6Ð6ð	<õ ˆ;ÑÔ˜!ÒÐÝØØ#ØØØ#ð	
ñ 	
ô 	
ð 	
ð 	
ð 	
ð Ðr=   c                 ó†  — d„ | D ¦   «         }t          |¦  «        dk    rdS t                               dt          |¦  «        › d�¦  «         t          |¦  «        dk    r|d         j        j        }dS t          |¬¦  «        5 }t          |                     d„ |¦  «        ¦  «         ddd¦  «         dS # 1 swxY w Y   dS )	zJCompute the sha256 of the operations that don't have one yet, in parallel.c                 ó*   — g | ]}|j         j        °|‘ŒS rD   )rT   Ú	is_hashedr§   s     r;   r«   z,_compute_missing_sha256s.<locals>.<listcomp>Ä  s"   € ÐIÐIÐI˜°´Ô0HÐI�"ÐIÐIÐIr=   r   NzComputing sha256 for z files.r   )Úmax_workersc                 ó   — | j         j        S rŠ   )rT   r~   ©r¨   s    r;   ú<lambda>z*_compute_missing_sha256s.<locals>.<lambda>Ì  s   €  R¤^Ô%:€ r=   )rÃ   r½   ÚinforT   r~   r   ÚlistÚmap)r¡   rž   Ú
not_hashedrÌ   Úexecutors        r;   r¿   r¿   Â  s  € àIÐI˜yÐIÑIÔI€JÝ
ˆ:�„˜!ÒÐØˆÝ
‡K‚KÐ@­¨J©¬Ð@Ð@Ð@ÑAÔAÐAÝ
ˆ:�„˜!ÒÐØ�qŒMÔ%Ô,ˆØˆÝ	¨Ð	4Ñ	4Ô	4ð I¸ÝˆX�\Š\Ð:Ð:¸JÑGÔGÑHÔHÐHðIð Ið Iñ Iô Ið Ið Ið Ið Ið Ið Ið Iøøøð Ið Ið Ið Ið Ið Is   Â%B6Â6B:Â=B:)r�   rž   rº   r»   c                 ó  ‡‡‡— g }| D ]\}|                      d¦  «        €0t                               d‰|d                  j        › d�¦  «         ŒG|                     |¦  «         Œ]dˆˆˆfd„}t          |¦  «        dk    r-t                               d	¦  «          ||d
         ¦  «         dS t                               dt          |¦  «        › d|› d�¦  «         t          ||dt          |¦  «        › d�|t          ¬¦  «         dS )aã  
    Uploads the content of `additions` to the Hub using the large file storage protocol.

    Relevant external documentation:
        - LFS Batch API: https://github.com/git-lfs/git-lfs/blob/main/docs/api/batch.md

    Args:
        actions (`list[dict[str, Any]]`):
            LFS batch actions returned by the server.
        oid2addop (`dict[str, CommitOperationAdd]`):
            A dictionary mapping the OID of the file to the corresponding `CommitOperationAdd` object.
        headers (`dict[str, str]`):
            Headers to use for the request, including authorization headers and user agent.
        endpoint (`str`, *optional*):
            The endpoint to use for the request. Defaults to `constants.ENDPOINT`.
        num_threads (`int`, *optional*):
            The number of concurrent threads to use when uploading. Defaults to 5.

    Raises:
        [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
            If an upload failed for any reason
        [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
            Type of the repo to upload to: `"model"`, `"dataset"` or `"space"`.
        repo_id (`str`):
            A namespace (user or an organization) and a repo name separated
            by a `/`.
        headers (`dict[str, str]`):
            Headers to use for the request, including authorization headers and user agent.
        num_threads (`int`, *optional*):
            The number of concurrent threads to use when uploading. Defaults to 5.
        revision (`str`, *optional*):
            The git revision to upload to.

    Raises:
        [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
            If an upload failed for any reason
        [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
            If the server returns malformed responses
        [`HfHubHTTPError`]
            If the LFS batch endpoint returned an HTTP error.
    rº   NzContent of file r´   z/ is already present upstream - skipping upload.r[   c                 ó¢   •— 	 ‰| d                  }t          || ‰‰¬¦  «         d S # t          $ r}t          d|j        › d�¦  «        |‚d }~ww xY w)Nr´   )r™   Úlfs_batch_actionr¤   r�   zError while uploading 'z' to the Hub.)r   Ú	ExceptionÚRuntimeErrorr/   )Úbatch_actionr™   rm   r�   r¤   r»   s      €€€r;   Ú_wrapped_lfs_uploadz._upload_lfs_files.<locals>._wrapped_lfs_upload  sz   ø€ ð	iØ! ,¨uÔ"5Ô6ˆIÝ ¸\ÐSZÐemÐnÑnÔnÐnÐnÐnøÝð 	ið 	ið 	iÝÐ^¸Ô9OÐ^Ð^Ð^Ñ_Ô_ÐehÐhøøøøð	iøøøs   ƒ!& ¦
A°A	Á	Ar   zUploading 1 LFS file to the Hubr   z
Uploading z" LFS files to the Hub using up to z threads concurrentlyzUpload z
 LFS files)ÚdescrÑ   Ú
tqdm_classr‚   )r¸   r½   Údebugr/   ÚappendrÃ   r   Úhf_tqdm)rº   r»   r¤   r�   rž   Úfiltered_actionsÚactionrà   s    ```    r;   rÄ   rÄ   Ï  so  øøø€ ðf ÐØð ,ð ,ˆØ�:Š:�iÑ Ô Ð(Ý�LŠLØy 9¨V°E¬]Ô#;Ô#HÐyÐyÐyñô ð ð ð ×#Ò# FÑ+Ô+Ð+Ð+ðið ið ið ið ið ið ið iõ ÐÑÔ Ò!Ð!Ý�ŠÐ6Ñ7Ô7Ð7ØÐÐ,¨QÔ/Ñ0Ô0Ð0Ð0Ð0å�ŠØt�Ð-Ñ.Ô.ÐtÐtÐR]ÐtÐtÐtñ	
ô 	
ð 	
õ 	ØØØ<�3Ð/Ñ0Ô0Ð<Ð<Ð<Ø#Ýð	
ñ 	
ô 	
ð 	
ð 	
ð 	
r=   )r�   rŸ   r    c                 ó  ‡— t          | ¦  «        dk    rdS ddlm}m}m}	m}
m} ddlm}  |
|j	        ||||¬¦  «        }|r|dz  } ||¦  «        }ddl
Š |	¦   «         }d}dt          fˆfd	„}	 t          ¦   «         s |¦   «         }|j        }nd}d
„ | D ¦   «         }d„ | D ¦   «         }g }|                     ||||¬¦  «        5 }|D ]I}|                     ||                     t#          |j        ¦  «         ||¦  «        ¬¦  «        f¦  «         ŒJ|D ]<}|                     ||                     |j         ||¦  «        ¬¦  «        f¦  «         Œ=	 ddd¦  «         n# 1 swxY w Y   |D ]Q\  }}|j        j        s@t,                               |                     ¦   «         j        j        ¦  «        |j        _        ŒRn# t6          $ r  |¦   «          ‚ w xY w	 |�|                     ¦   «          dS dS # |�|                     ¦   «          w w xY w)aŽ  
    Uploads the content of `additions` to the Hub using the xet storage protocol.
    This chunks the files and deduplicates the chunks before uploading them to xetcas storage.

    Args:
        additions (`` of `CommitOperationAdd`):
            The files to be uploaded.
        repo_type (`str`):
            Type of the repo (e.g. `"model"`, `"dataset"`, `"space"`).
        repo_id (`str`):
            A namespace (user or an organization) and a repo name separated
            by a `/`.
        headers (`dict[str, str]`):
            Headers to use for the request, including authorization headers and user agent.
        endpoint: (`str`, *optional*):
            The endpoint to use for the xetcas service. Defaults to `constants.ENDPOINT`.
        revision (`str`, *optional*):
            The git revision to upload to.
        create_pr (`bool`, *optional*):
            Whether or not to create a Pull Request with that commit.

    Raises:
        [`EnvironmentError`](https://docs.python.org/3/library/exceptions.html#EnvironmentError)
            If an upload failed for any reason.
        [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
            If the server returns malformed responses or if the user is unauthorized to upload to xet storage.
        [`HfHubHTTPError`]
            If the LFS batch endpoint returned an HTTP error.

    **How it works:**
        The file upload system uses Xet storage, which is a content-addressable storage system that breaks files into chunks
        for efficient storage and transfer.

        ``session.new_upload_commit()`` manages uploading files by:
            - Registering upload tasks and starting upload immediately in the background
            - Breaking files into smaller chunks for efficient storage
            - Avoiding duplicate storage by recognizing identical chunks across files
            - Connecting to a storage server (CAS server) that manages these chunks

        Authentication works transparently: the upload commit accepts a ``token_refresh_url``
        that is used to refresh the short-lived xet write token as needed.

        The upload process works like this:
        1. Upload tasks run in parallel:
            1.1. Read the file content from a path, bytes array, or a stream.
            1.2. Split the file content into smaller chunks based on content patterns: each chunk gets a unique ID based on what's in it.
            1.3. For each chunk:
                - Check if it already exists in storage.
                - Skip uploading chunks that already exist.
            1.4. Group chunks into larger blocks for efficient transfer.
            1.5. Upload these blocks to the storage server.
            1.6. Assemble the file manifest locally and send it to the server for validation.
        2. Return reference files that contain information about the uploaded files, which can be used later to download them.
    r   Nr   )ÚXetTokenTypeÚabort_xet_sessionÚget_xet_sessionÚxet_connection_info_refresh_urlÚxet_headers_without_auth)ÚXetUploadProgressReporter)Ú
token_typer£   r¢   rŸ   r�   z?create_pr=1r¨   c                 óf   •— | j         j        r| j         j                             ¦   «         n‰j        S rŠ   )rT   rÐ   r~   r   ÚCOMPUTE_SHA256)r¨   Úhf_xets    €r;   Ú_sha256_argz&_upload_xet_files.<locals>._sha256_arg‚  s.   ø€ ð /1¬nÔ.FÐaˆrŒ~Ô$×(Ò(Ñ*Ô*Ð*ÈFÔLaÐar=   c                 óF   — g | ]}t          |j        t          ¦  «        ¯|‘ŒS rD   )r6   rQ   rd   r§   s     r;   r«   z%_upload_xet_files.<locals>.<listcomp>Ž  s+   € ÐYÐYÐY µ:¸bÔ>PÕRWÑ3XÔ3XÐY˜ÐYÐYÐYr=   c                 óT   — g | ]%}t          |j        t          t          f¦  «        ¯#|‘Œ&S rD   )r6   rQ   rB   r   r§   s     r;   r«   z%_upload_xet_files.<locals>.<listcomp>�  s1   € Ð_Ð_Ð_ µ:¸bÔ>PÕSVÕX\ÐR]Ñ3^Ô3^Ð_˜Ð_Ð_Ð_r=   )Útoken_refresh_urlÚtoken_refresh_headersÚcustom_headersÚprogress_callback)r~   )rÃ   Ú
utils._xetré   rê   rë   rì   rí   Úutils._xet_progress_reportingrî   ÚWRITErò   rP   r   Úupdate_progressÚnew_upload_commiträ   Ústart_upload_filerB   rQ   Ústart_upload_bytesrT   rÐ   rd   ÚfromhexÚresultÚxet_infor~   ÚKeyboardInterruptÚclose)r¡   r¢   r£   r¤   r�   rŸ   r    ré   rê   rë   rì   rí   rî   Úrefresh_urlÚxet_headersÚsessionÚprogressró   rù   Úall_bytes_opsÚall_paths_opsÚhandlesÚcommitr¨   Úhandlerò   s                            @r;   r¼   r¼   #  sl  ø€ õB ˆ9�~„~˜ÒÐØˆðð ð ð ð ð ð ð ð ð ð ð ð ð ð IÐHÐHÐHÐHÐHà1Ð1ØÔ%ØØØØðñ ô €Kð ð &Ø�~Ñ%ˆà*Ð*¨7Ñ3Ô3€Kà€M€M€MàˆoÑÔ€GØ€HðbÕ*ð bð bð bð bð bð bð
Ý)Ñ+Ô+ð 	%Ø0Ð0Ñ2Ô2ˆHØ (Ô 8ÐÐà $ÐàYÐY iÐYÑYÔYˆØ_Ð_ iÐ_Ñ_Ô_ˆà8:ˆØ×&Ò&Ø)Ø")Ø&Ø/ð	 'ñ 
ô 
ð 		lð
 Ø#ð pð p�Ø—’  F×$<Ò$<½SÀÔASÑ=TÔ=TÐ]hÐ]hÐikÑ]lÔ]lÐ$<Ñ$mÔ$mÐnÑoÔoÐoÐoØ#ð lð l�Ø—’  F×$=Ò$=¸bÔ>PÐYdÐYdÐegÑYhÔYhÐ$=Ñ$iÔ$iÐjÑkÔkÐkÐkðlð		lð 		lð 		lñ 		lô 		lð 		lð 		lð 		lð 		lð 		lð 		løøøð 		lð 		lð 		lð 		lð "ð 	Wð 	W‰JˆB�Ø”>Ô+ð WÝ(-¯ª°f·m²m±o´oÔ6NÔ6UÑ(VÔ(V�”Ô%øð	Wøõ ð ð ð ØÐÑÔÐØðøøøð	Wð ÐØ�NŠNÑÔÐÐÐð  Ðøˆ8ÐØ�NŠNÑÔÐÐð  øøøsE   Á0AF> ÃBEÅF> ÅE"Å"F> Å%E"Å&AF> Æ=G2 Æ>GÇG2 Ç2HÚpreupload_infoc                 ó~  — |                       d¦  «        }t          |t          ¦  «        st          d¦  «        ‚|D ]€}t          |t          ¦  «        rZt          |                      d¦  «        t
          ¦  «        r2t          |                      d¦  «        t
          ¦  «        r
|d         dv st          d¦  «        ‚Œ�| S )NÚfilesz&preupload_info is improperly formattedr^   Ú
uploadModer)   z'preupload_info is improperly formatted:)r¸   r6   rÖ   r8   ÚdictrB   )r  r  Ú	file_infos      r;   Ú_validate_preupload_infor  ©  sÊ   € Ø×Ò˜wÑ'Ô'€EÝ�e�TÑ"Ô"ð CÝÐAÑBÔBÐBØð Hð Hˆ	å�y¥$Ñ'Ô'ð	Hå˜9Ÿ=š=¨Ñ0Ô0µ#Ñ6Ô6ð	Hõ ˜9Ÿ=š=¨Ñ6Ô6½Ñ<Ô<ð	Hð ˜<Ô(Ð,>Ð>Ð>åÐFÑGÔGÐGð ?ð Ðr=   FÚgitignore_contentc                 óˆ  — |�|nt           j        }i }i }	i }
t          | d¦  «        D ]Ã}dd„ |D ¦   «         i}|�||d<   t          d|› d|› d|› d	|› �|||rd
dind¬¦  «        }t	          |¦  «         t          |                     ¦   «         ¦  «        } |j        di d„ |d         D ¦   «         ¤Ž  |	j        di d„ |d         D ¦   «         ¤Ž  |
j        di d„ |d         D ¦   «         ¤Ž ŒÄ| D ]8}||j                 |_	        |	|j                 |_
        |
|j                 |_        Œ9| D ]}|j        j        dk    rd|_	        ŒdS )aï  
    Requests the Hub "preupload" endpoint to determine whether each input file should be uploaded as a regular git blob,
    as a git LFS blob, or as a XET file. Input `additions` are mutated in-place with the upload mode.

    Args:
        additions (`Iterable` of :class:`CommitOperationAdd`):
            Iterable of :class:`CommitOperationAdd` describing the files to
            upload to the Hub.
        repo_type (`str`):
            Type of the repo to upload to: `"model"`, `"dataset"` or `"space"`.
        repo_id (`str`):
            A namespace (user or an organization) and a repo name separated
            by a `/`.
        headers (`dict[str, str]`):
            Headers to use for the request, including authorization headers and user agent.
        revision (`str`):
            The git revision to upload the files to. Can be any valid git revision.
        gitignore_content (`str`, *optional*):
            The content of the `.gitignore` file to know which files should be ignored. The order of priority
            is to first check if `gitignore_content` is passed, then check if the `.gitignore` file is present
            in the list of files to commit and finally default to the `.gitignore` file already hosted on the Hub
            (if any).
    Raises:
        [`~utils.HfHubHTTPError`]
            If the Hub API returned an error.
        [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
            If the Hub API response is improperly formatted.
    Nr,   r  c                 ó–   — g | ]F}|j         t          j        |j        j        ¦  «                             d ¦  «        |j        j        dœ‘ŒGS )Úascii)r^   ÚsampleÚsize)r/   rx   ry   rT   r  Údecoder  r§   s     r;   r«   z'_fetch_upload_modes.<locals>.<listcomp>è  s_   € ð ð ð ð ð	 œOÝ$Ô.¨r¬~Ô/DÑEÔE×LÒLÈWÑUÔUØœNÔ/ðð ðð ð r=   Ú	gitIgnoreÚPOSTú/api/ús/z/preupload/r    Ú1)Újsonr¤   Úparamsc                 ó,   — i | ]}|d          |d         “ŒS )r^   r  rD   ©r‹   rt   s     r;   ú
<dictcomp>z'_fetch_upload_modes.<locals>.<dictcomp>ý  s#   € ÐdÐdÐdÀD˜t Fœ|¨T°,Ô-?ÐdÐdÐdr=   c                 ó,   — i | ]}|d          |d         “ŒS )r^   ÚshouldIgnorerD   r%  s     r;   r&  z'_fetch_upload_modes.<locals>.<dictcomp>þ  s#   € Ð$lÐ$lÐ$lÈD T¨&¤\°4¸Ô3GÐ$lÐ$lÐ$lr=   c                 óF   — i | ]}|d          |                      d¦  «        “ŒS )r^   r´   r·   r%  s     r;   r&  z'_fetch_upload_modes.<locals>.<dictcomp>ÿ  s(   € Ð]Ð]Ð]¸T˜4 œ<¨¯ª°%©¬Ð]Ð]Ð]r=   r   r+   rD   )r   ÚENDPOINTr   r    r   r  r"  Úupdater/   rV   rW   rX   rT   r  )r¡   r¢   r£   r¤   rŸ   r�   r    r  Úupload_modesÚshould_ignore_infoÚoid_inforÈ   ÚpayloadÚrespr  Úadditions                   r;   Ú_fetch_upload_modesr2  ¸  sù  € ðN $Ð/ˆxˆxµYÔ5G€Hð +-€LØ*,ÐØ&(€Hå 	¨3Ñ/Ô/ð _ð _ˆàð ð ð  ðñ ô ð	
ˆð Ð(Ø#4ˆG�KÑ åØØÐIÐI˜iÐIÐI¨7ÐIÐI¸xÐIÐIØØØ)2Ð<�K Ð%Ð%¸ð
ñ 
ô 
ˆõ 	˜DÑ!Ô!Ð!Ý1°$·)²)±+´+Ñ>Ô>ˆØˆÔÐeÐeÐdÐdÈNÐ[bÔLcÐdÑdÔdÐeÐeÐeØ!ÐÔ!ÐmÐmÐ$lÐ$lÐTbÐcjÔTkÐ$lÑ$lÔ$lÐmÐmÐmØˆŒÐ^Ð^Ð]Ð]À^ÐT[ÔE\Ð]Ñ]Ô]Ð^Ð^Ð^Ð^ð ð ?ð ?ˆØ ,¨XÔ-BÔ CˆÔØ"4°XÔ5JÔ"KˆÔØ'¨Ô(=Ô>ˆÔÐð ð .ð .ˆØÔÔ$¨Ò)Ð)Ø$-ˆHÔ!øð.ð .r=   c                   óJ   — e Zd ZU edz  ed<   edz  ed<   eed<   edz  ed<   dS )Ú_CopySourceNrI   rJ   r^   rŸ   )r>   r?   r@   rB   rC   rD   r=   r;   r4  r4    sK   € € € € € € Ø�t‘ÐÐÑØ˜‘:ÐÐÑØ
€I€I�IØ�D‰jÐÐÑÐÐr=   r4  Úcopiesr(   c           
      óþ  — ddl m}m}  |||¬¦  «        }t          | ¦  «        } i }	i }
d„ | D ¦   «         }t	          |t
          ¦  «        D ]N}|                     |t          |¦  «        ||¬¦  «        }|D ]#}t          ||¦  «        s|j        |
|j	        |f<   Œ$ŒO|  
                    d„ ¬¦  «         t          | d„ ¬¦  «        D �]¹\  \  }}}}t          |¦  «        }|d	u}|p|}|p|}|p|rd
n|}d„ |D ¦   «         }t	          |t
          ¦  «        D ]Ø}|                     |t          |¦  «        ||¬¦  «        }|D ]­}t          ||¦  «        rt          d¦  «        ‚t          |||j	        |¦  «        }|j        r||	|<   nUt          |||||j	        ¬¦  «        }t!          ¦   «                              ||¬¦  «        }t%          |¦  «         |j        |	|<   |s|j        |
|j	        |f<   Œ®ŒÙ|D ]�}t          |||j        |¦  «        } | |	vr)|rd|› d|› �nd}!t+          d|j        › d|› |!› d�¦  «        ‚|
                     |j        |f¦  «        |_        |s&|
                     |j        |j        f¦  «        |_        Œ��Œ»|	S )az  
    Fetch information about the files to copy.

    For LFS files, we only need their metadata (file size and sha256) while for regular files
    we need to download the raw content from the Hub.

    Args:
        copies (`Iterable` of :class:`CommitOperationCopy`):
            Iterable of :class:`CommitOperationCopy` describing the files to
            copy on the Hub.
        repo_type (`str`):
            Type of the repo to upload to: `"model"`, `"dataset"` or `"space"`.
        repo_id (`str`):
            A namespace (user or an organization) and a repo name separated
            by a `/`.
        headers (`dict[str, str]`):
            Headers to use for the request, including authorization headers and user agent.
        revision (`str`):
            The git revision to upload the files to. Can be any valid git revision.

    Returns: `dict[_CopySource, Union[RepoFile, bytes]]]`
        Key is `(src_repo_id, src_repo_type, path, revision)`. For intra-repo copies,
        `src_repo_id` and `src_repo_type` are `None`.
        Value is the raw content as bytes (for regular files) or the file information as a RepoFile (for LFS files).

    Raises:
        [`~utils.HfHubHTTPError`]
            If the Hub API returned an error.
        [`ValueError`](https://docs.python.org/3/library/exceptions.html#ValueError)
            If the Hub API response is improperly formatted.
    r   )ÚHfApiÚ
RepoFolder)r�   r¤   c                 ó   — g | ]	}|j         ‘Œ
S rD   )r/   r§   s     r;   r«   z(_fetch_files_to_copy.<locals>.<listcomp>E  s   € Ð3Ð3Ð3 b�"”/Ð3Ð3Ð3r=   )r£   ÚpathsrŸ   r¢   c                 ó6   — | j         pd| j        pd| j        pdfS )NÚ ©rI   rJ   rH   rÓ   s    r;   rÔ   z&_fetch_files_to_copy.<locals>.<lambda>R  s$   €  ¤Ð 4°"°bÔ6FÐ6LÈ"ÈbÌoÐNcÐacÐd€ r=   )Úkeyc                 ó*   — | j         | j        | j        fS rŠ   r=  rÓ   s    r;   rÔ   z&_fetch_files_to_copy.<locals>.<lambda>T  s   €  ¤°Ô0@À"Ä/ÐR€ r=   NÚmainc                 ó   — g | ]	}|j         ‘Œ
S rD   )rG   r§   s     r;   r«   z(_fetch_files_to_copy.<locals>.<listcomp>\  s   € Ð>Ð>Ð>¨R�RÔ(Ð>Ð>Ð>r=   z$Copying a folder is not implemented.)r�   r¢   r£   rŸ   Úfilename)r¤   z from r   r<  zCannot copy z at revision z: file is missing on repo.)Úhf_apir7  r8  rÖ   r   ÚFETCH_LFS_BATCH_SIZEÚget_paths_infor6   Úblob_idr^   Úsortr
   ÚNotImplementedErrorr4  r*   r   r   r¸   r   ÚcontentrG   r   r/   rL   rH   rK   )"r5  r¢   r£   r¤   rŸ   r�   r7  r8  rC  Úfiles_to_copyr.  Ú
dest_pathsÚbatchÚdest_repo_filesrt   Úsrc_repo_id_keyÚsrc_repo_type_keyÚsrc_revision_keyÚgroupr’   Úis_cross_repoÚeff_repo_idÚeff_repo_typeÚeff_revisionÚ	src_pathsÚpaths_batchÚsrc_repo_filesÚsrc_repo_fileÚsourceÚurlÚresponser™   r>  Úsource_descs"                                     r;   Ú_fetch_files_to_copyr^    s©  € ðP *Ð)Ð)Ð)Ð)Ð)Ð)Ð)àˆU˜H¨gÐ6Ñ6Ô6€FÝ�&‰\Œ\€FØAC€MØ9;€Hð 4Ð3¨FÐ3Ñ3Ô3€JÝ 
Õ,@ÑAÔAð 	?ð 	?ˆØ ×/Ò/ØÝ�u‘+”+ØØð	 0ñ 
ô 
ˆð $ð 	?ð 	?ˆDÝ˜d JÑ/Ô/ð ?Ø26´,�˜$œ) XÐ.Ñ/øð	?ð
 ‡K‚KÐdÐd€KÑeÔeÐeÝIPØÐRÐRðJñ Jô Jð /hñ /hÑEÑ>ˆÐ+Ð-=Àõ ˜%‘[”[ˆ
Ø'¨tÐ3ˆØ%Ð0¨ˆØ)Ð6¨YˆØ'ÐR°mÐ,Q¨F¨FÈˆà>Ð>°:Ð>Ñ>Ô>ˆ	Ý)¨)Õ5IÑJÔJð 	]ð 	]ˆKØ#×2Ò2Ø#Ý˜;Ñ'Ô'Ø%Ø'ð	 3ñ ô ˆNð "0ð ]ð ]�Ý˜m¨ZÑ8Ô8ð VÝ-Ð.TÑUÔUÐUÝ$ _Ð6GÈÔI[Ð]mÑnÔn�Ø Ô$ð =Ø,9�M &Ñ)Ð)å$Ø!)Ø"/Ø +Ø!-Ø!.Ô!3ðñ ô �Cõ  +™}œ}×0Ò0°¸gÐ0ÑFÔF�HÝ'¨Ñ1Ô1Ð1Ø,4Ô,<�M &Ñ)Ø$ð ]ØGTÔG\�H˜mÔ0Ð2BÐCÑDøð%]ð( $ð 
	hð 
	hˆIÝ˜oÐ/@À)ÔB\Ð^nÑoÔoˆCØ˜-Ð'Ð'ØIVÐ^ÐE }ÐEÐE¸ÐEÐEÐEÐ\^�Ý(ðM 9Ô#=ð Mð MØ#ðMØ%0ðMð Mð Mñô ð ð #+§,¢,°	Ô0FÈÐ/QÑ"RÔ"RˆIÔØ ð hØ%-§\¢\°9Ô3MÈyÔOeÐ2fÑ%gÔ%g�	Ô"øñ
	hð Ðr=   rJ  Úcommit_messageÚcommit_descriptionÚparent_commitc              #   óž  K  — |�|nd}||dœ}|�||d<   d|dœV — d}| D �]}t          |t          ¦  «        r0|j        r)t                               d|j        › d	�¦  «         |d
z  }ŒHt          |t          ¦  «        r@|j        dk    r5d|                     ¦   «                              ¦   «         |j        ddœdœV — Œ�t          |t          ¦  «        rC|j        dk    r8d|j        d|j	        j
                             ¦   «         |j	        j        dœdœV — Œõt          |t          ¦  «        r|j        rdndd|j        idœV — �Œ#t          |t          ¦  «        r«t!          |j        |j        |j        |j        ¦  «        }||         }	t          |	t*          ¦  «        r6dt-          j        |	¦  «                             ¦   «         |j        ddœdœV — �Œ±|	j        rd|j        d|	j        j
        dœdœV — �ŒÔt3          d¦  «        ‚t3          d|› dt5          |dd¦  «        › �¦  «        ‚|dk    r t                               d|› d�¦  «         dS dS )aG  
    Builds the payload to POST to the `/commit` API of the Hub.

    Payload is returned as an iterator so that it can be streamed as a ndjson in the
    POST request.

    For more information, see:
        - https://github.com/huggingface/huggingface_hub/issues/1085#issuecomment-1265208073
        - http://ndjson.org/
    Nr<  )ÚsummaryÚdescriptionÚparentCommitÚheader)r>  Úvaluer   zSkipping file 'z(' in commit (ignored by gitignore file).r   r+   rt   rx   )rI  r^   Úencodingr*   ÚlfsFiler~   )r^   Úalgor´   r  ÚdeletedFolderÚdeletedFiler^   )r^   rj  r´   z_Malformed files_to_copy (should be raw file content as bytes or RepoFile objects with LFS info.z(Unknown operation to commit. Operation: z. Upload mode: rV   zSkipped z/ file(s) in commit (ignored by gitignore file).)r6   rP   rW   r½   rã   r/   rV   r|   r  rT   r~   r   r  r.   r1   rF   r4  rI   rJ   rG   rH   rd   rx   ry   r*   r8   ÚgetattrrÕ   )
r’   rJ  r_  r`  ra  Úheader_valueÚnb_ignored_filesr™   rZ  Úfile_to_copys
             r;   Ú_prepare_commit_payloadrq  ‡  si  è è € ð" 0BÐ/MÐ+Ð+ÐSUÐð  .Ð>PÐQÐQ€LØÐ Ø'4ˆ�^Ñ$Ø \Ð
2Ð
2Ð2Ð2Ð2àÐð  ð Fñ Fˆ	å�iÕ!3Ñ4Ô4ð 	¸Ô9Qð 	Ý�LŠLÐk¨9Ô+AÐkÐkÐkÑlÔlÐlØ Ñ!ÐØõ �iÕ!3Ñ4Ô4ð >	¸Ô9OÐS\Ò9\Ð9\àà(×3Ò3Ñ5Ô5×<Ò<Ñ>Ô>Ø%Ô2Ø (ðð ðð ð ð ð ð õ ˜	Õ#5Ñ6Ô6ð 4	¸9Ô;QÐUZÒ;ZÐ;Zà à%Ô2Ø$Ø$Ô0Ô7×;Ò;Ñ=Ô=Ø%Ô1Ô6ð	ð ðð ð ð ð ð õ ˜	Õ#8Ñ9Ô9ð )	à*3Ô*=ÐP��À=Ø  )Ô"8Ð9ðð ð ð ð ñ õ
 ˜	Õ#6Ñ7Ô7ð #	Ý ØÔ%ØÔ'ØÔ*ØÔ&ñ	ô ˆFð )¨Ô0ˆLÝ˜,­Ñ.Ô.ð à!å#)Ô#3°LÑ#AÔ#A×#HÒ#HÑ#JÔ#JØ )Ô 6Ø$,ðð ðð ð ð ð ñ ð Ô!ð à$à )Ô 6Ø (Ø+Ô/Ô6ðð ðð ð ð ð ñ õ !Øuñô ð õ
 ð?¸9ð ?ð ?Ý˜I ~°tÑ<Ô<ð?ð ?ñô ð ð
 ˜!ÒÐÝ�ŠÐ`Ð/Ð`Ð`Ð`ÑaÔaÐaÐaÐað Ðr=   )r�   ra  r    Ú
hot_reloadÚretry_on_errorrr  rs  r'   c                 óê  — |�|nt           j        }t          | ||||	¬¦  «        }d                     d„ |D ¦   «         ¦  «        }ddi|¥}|› d|› d|› d	|› �}i }|
rd
|d<   |rd
|d<   |rt	          d||||¬¦  «        }n%t          ¦   «                              ||||¬¦  «        }t          |d¬¦  «         |                     ¦   «         }ddl	m
}  ||d         |||d         |
r|d         nd|¬¦  «        S )u·  
    Build the ndjson payload for `operations` and POST it to the `/commit` endpoint of the Hub.

    `revision` must already be URL-quoted. Operations must be ready to commit: upload modes fetched
    and LFS/Xet content uploaded.

    If `retry_on_error` is `True`, the POST is retried with exponential backoff on transient errors.
    Caution: if a commit succeeds but its response is lost, the retry will create a duplicate commit
    (and a duplicate pull request if `create_pr` is set) â€” only enable it when this is acceptable.

    Returns a [`CommitInfo`] built from the server response.

    Raises:
        [`~utils.HfHubHTTPError`]
            If the Hub API returned an error.
    N)r’   rJ  r_  r`  ra  r=   c              3   óh   K  — | ]-}t          j        |¦  «                             ¦   «         d z   V — Œ.dS )ó   
N)r"  ÚdumpsÚencode)r‹   Úitems     r;   rŽ   z_send_commit.<locals>.<genexpr>  s=   è è € ÐJÐJ¸$•D”J˜tÑ$Ô$×+Ò+Ñ-Ô-°Ñ5ÐJÐJÐJÐJÐJÐJr=   zContent-Typezapplication/x-ndjsonr  r   z/commit/r!  r    rr  r  )r¤   rI  r#  r  )Úendpoint_namer   )r'   Ú	commitUrlÚ	commitOidÚpullRequestUrl)Ú
commit_urlr_  r`  r´   Úpr_urlÚ	_endpoint)r   r*  rq  rÁ   r    r   Úpostr   r"  rC  r'   )r’   rJ  r_  r`  r¢   r£   r¤   rŸ   r�   ra  r    rr  rs  r/  Údatar[  r#  r\  Úcommit_datar'   s                       r;   Ú_send_commitr„  ï  ss  € ð@ $Ð/ˆxˆxµYÔ5G€HÝ%ØØ#Ø%Ø-Ø#ðñ ô €Gð �8Š8ÐJÐJÀ'ÐJÑJÔJÑJÔJ€DàÐ5ÐA¸ÐA€GØÐ
DÐ
D˜IÐ
DÐ
D¨Ð
DÐ
D¸(Ð
DÐ
D€Cà€FØð "Ø!ˆˆ{ÑØð #Ø"ˆˆ|Ñàð YÝ ¨°WÀdÐSYÐZÑZÔZˆˆå‘=”=×%Ò% c°7ÀDÐQWÐ%ÑXÔXˆÝ˜°Ð9Ñ9Ô9Ð9à—-’-‘/”/€KØ"Ð"Ð"Ð"Ð"Ð"àˆ:Ø˜{Ô+Ø%Ø-Ø˜Ô$Ø09ÐCˆ{Ð+Ô,Ð,¸tØðñ ô ð r=   )NFNrŠ   )NN)XrA   rx   rb   r"  r]   r•   Úcollectionsr   Úcollections.abcr   r   Úconcurrent.futuresr   Ú
contextlibr   Údataclassesr   r	   Ú	itertoolsr
   Úpathlibr   r   Útypingr   r   r   r   r   r   r<  r   Úerrorsr   Úfile_downloadr   r*   r   r   r   Úutilsr   r   r   r   r   r   r    r!   r"   r#   r$   r%   rå   Úutils._runtimer&   rC  r'   r(   Ú
get_loggerr>   r½   rƒ   rD  ÚDUPLICATE_LFS_BATCH_SIZErÀ   r.   rF   rP   rB   r4   ÚCommitOperationrÖ   r›   r  r”   r7   rÍ   r¿   rÄ   r¼   r  r2  r4  rd   r^  rq  r„  rD   r=   r;   ú<module>r”     s¬  ððð ð €€€Ø 	€	€	€	Ø €€€Ø 	€	€	€	Ø €€€Ø #Ð #Ð #Ð #Ð #Ð #Ø .Ð .Ð .Ð .Ð .Ð .Ð .Ð .Ø 1Ð 1Ð 1Ð 1Ð 1Ð 1Ø %Ð %Ð %Ð %Ð %Ð %Ø (Ð (Ð (Ð (Ð (Ð (Ð (Ð (Ø Ð Ð Ð Ð Ð Ø 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ð 'Ø KÐ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KÐ KÐ Kà Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &Ø %Ð %Ð %Ð %Ð %Ð %Ø <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <Ð <ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð #Ð "Ð "Ð "Ð "Ð "Ø ,Ð ,Ð ,Ð ,Ð ,Ð ,ð ð -Ø,Ð,Ð,Ð,Ð,Ð,Ð,Ð,ð 
ˆÔ	˜HÑ	%Ô	%€ð Ð%Ô&€
ð Ð ØÐ à Ð ð ðð ð ð ð ñ ô ñ „ðð< ð2Wð 2Wð 2Wð 2Wð 2Wñ 2Wô 2Wñ „ð2Wðj ðb1ð b1ð b1ð b1ð b1ñ b1ô b1ñ „ðb1ðJ¨ð °ð ð ð ð ð" Ð*Ð,?ÐAVÐVÔW€ð+°°_Ô0Eð +È$ð +ð +ð +ð +ð\ ð  ØØØ!ðF
ð F
ð F
àÐ&Ô'ðF
ð ðF
ð ð	F
ð
 �#�s�(Œ^ðF
ð �D‰jðF
ð ðF
ð �D‰jðF
ð �d‰{ðF
ð F
ð F
ñ ÔðF
ðR
I¨Ð-?Ô(@ð 
IÈsð 
IÐW[ð 
Ið 
Ið 
Ið 
Ið ð  ØðP
ð P
ð P
à�$�s˜C�x”.Ô!ðP
ð �CÐ+Ð+Ô,ðP
ð �#�s�(Œ^ð	P
ð
 �D‰jðP
ð ðP
ð P
ð P
ñ ÔðP
ðf ð  ØØ!ðBð Bð BàÐ&Ô'ðBð ðBð ð	Bð
 �#�s�(Œ^ðBð �D‰jðBð �D‰jðBð �d‰{ðBð Bð Bñ ÔðBðJ¨Tð ð ð ð ð ð  ØØ$(ðR.ð R.ØÐ*Ô+ðR.àðR.ð ðR.ð �#�s�(Œ^ð	R.ð
 ðR.ð �D‰jðR.ð ðR.ð ˜T‘zðR.ð 
ðR.ð R.ð R.ñ ÔðR.ðjð ð ð ð �*ñ ô ð ð ð  ðnð nØÐ(Ô)ðnàðnð ðnð �#�s�(Œ^ð	nð
 ðnð �D‰jðnð 
ˆ+�u˜Z¨Ð.Ô/Ð
/Ô0ðnð nð nñ Ôðnðj &*Ø $ðebð ebØ˜Ô)ðebà˜ U¨:°uÐ+<Ô%=Ð=Ô>ðebð ðebð ˜d™
ð	ebð
 ˜‘:ðebð ˆd�3˜�8ŒnÔðebð ebð ebð ebðd  Ø $ØØØ ðCð Cð Cà˜Ô)ðCð ˜ U¨:°uÐ+<Ô%=Ð=Ô>ðCð ð	Cð
 ðCð ðCð ðCð �#�s�(Œ^ðCð ðCð �D‰jðCð ˜‘:ðCð ðCð ðCð ðCð ðCð Cð Cð Cð Cð Cr=   