§
    l¬¸j  ã                  ór   — d Z ddlmZ ddlZddlmZ ddlmZ ddlm	Z	m
Z
  G d„ d¦  «        Z	 	 	 	 ddd„ZdS )zBUpload utilities for Ultralytics, mirroring downloads.py patterns.é    )ÚannotationsN)ÚPath)Úsleep)ÚLOGGERÚTQDMc                  ó,   — e Zd ZdZd„ Zdd„Zd„ Zd„ ZdS )	Ú_ProgressReaderz>File wrapper that reports read progress for upload monitoring.c                ó†   — t          |d¦  «        | _        || _        t          j                             |¦  «        | _        d S )NÚrb)ÚopenÚfileÚpbarÚosÚpathÚgetsizeÚ_size)ÚselfÚ	file_pathr   s      úi/root/private/project/pallet_detection_v2/.venv/lib/python3.11/site-packages/ultralytics/utils/uploads.pyÚ__init__z_ProgressReader.__init__   s3   € Ý˜ DÑ)Ô)ˆŒ	ØˆŒ	Ý”W—_’_ YÑ/Ô/ˆŒ
ˆ
ˆ
ó    éÿÿÿÿc                óš   — | j                              |¦  «        }|r.| j        r'| j                             t	          |¦  «        ¦  «         |S )z"Read data and update progress bar.)r   Úreadr   ÚupdateÚlen)r   ÚsizeÚdatas      r   r   z_ProgressReader.read   sG   € àŒy�~Š~˜dÑ#Ô#ˆØð 	(�D”Ið 	(ØŒI×Ò�S ™YœYÑ'Ô'Ð'Øˆr   c                ó   — | j         S )z+Return file size for Content-Length header.)r   ©r   s    r   Ú__len__z_ProgressReader.__len__   s
   € àŒzÐr   c                ó8   — | j                              ¦   «          dS )zClose the file.N)r   Úcloser    s    r   r#   z_ProgressReader.close    s   € àŒ	�ŠÑÔÐÐÐr   N)r   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r!   r#   © r   r   r	   r	      s[   € € € € € ØHÐHð0ð 0ð 0ð
ð ð ð ðð ð ðð ð ð ð r   r	   é   éX  Fr   ú
str | PathÚurlÚstrÚheadersúdict | NoneÚretryÚintÚtimeoutÚprogressÚboolÚreturnc                óö  — ddl }t          | ¦  «        } |                      ¦   «         st          d| › �¦  «        ‚|                      ¦   «         j        }d| j        › �}ddi}	|r|	                     |¦  «         d}
t          |dz   ¦  «        D �]L}d}d}	 |rt          ||dd	d
¬¦  «        }t          | |¦  «        }|                     |||	|¬¦  «        }|                     ¦   «          |                     ¦   «          d}|r|                     ¦   «          d}t          j        d| j        › d�¦  «         	 |r|                     ¦   «          |r|                     ¦   «           d	S  d	S # |j        j        $ rž}|j        �|j        j        nd}d|cxk    rdk     rmn nj|dvrft          j        |› d|› dt+          |j        dd¦  «        › �¦  «         Y d}~|r|                     ¦   «          |r|                     ¦   «           dS  dS d|› �}
Y d}~n)d}~wt,          $ r}t/          |¦  «        }
Y d}~nd}~ww xY w|r|                     ¦   «          |r|                     ¦   «          n2# |r|                     ¦   «          |r|                     ¦   «          w w xY w||k     r=d|dz   z  }t          j        |› d|
› d|dz   › d|› d|› d�
¦  «         t1          |¦  «         �ŒNt          j        |› d|dz   › d|
› �¦  «         dS ) a  Upload a file to a URL with retry logic and optional progress bar.

    Args:
        file (str | Path): Path to the file to upload.
        url (str): The URL endpoint to upload the file to (e.g., signed GCS URL).
        headers (dict, optional): Additional headers to include in the request.
        retry (int, optional): Number of retry attempts on failure (default: 2 for 3 total attempts).
        timeout (int, optional): Request timeout in seconds.
        progress (bool, optional): Whether to display a progress bar during upload.

    Returns:
        (bool): True if upload succeeded, False otherwise.

    Examples:
        >>> from ultralytics.utils.uploads import safe_upload
        >>> success = safe_upload("model.pt", "https://storage.googleapis.com/...", progress=True)
    r   NzFile not found: z
Uploading zContent-Typezapplication/octet-streamé   ÚBTi   )ÚtotalÚdescÚunitÚ
unit_scaleÚunit_divisor)r   r.   r2   z	Uploaded u    âœ…i�  iô  >   é˜  é­  z	 failed: ú ÚreasonÚ FzHTTP r)   z	 failed (z), retrying ú/z in zs...z failed after z attempts: )Úrequestsr   ÚexistsÚFileNotFoundErrorÚstatÚst_sizeÚnamer   Úranger   r	   ÚputÚraise_for_statusr#   r   ÚinfoÚ
exceptionsÚ	HTTPErrorÚresponseÚstatus_codeÚwarningÚgetattrÚ	Exceptionr-   r   )r   r,   r.   r0   r2   r3   rD   Ú	file_sizer:   Úupload_headersÚ
last_errorÚattemptr   ÚreaderÚrÚeÚstatusÚ	wait_times                     r   Úsafe_uploadr^   %   sÆ  € ð2 €O€O€Oå�‰:Œ:€DØ�;Š;‰=Œ=ð ;ÝÐ 9°4Ð 9Ð 9Ñ:Ô:Ð:à—	’	‘”Ô#€IØ#˜œ	Ð#Ð#€Dð %Ð&@ÐA€NØð 'Ø×Ò˜gÑ&Ô&Ð&à€JÝ˜ ™Ñ#Ô#ð #ñ #ˆØˆØˆð	Øð fÝ )°$¸SÈTÐ`dÐeÑeÔe�Ý$ T¨4Ñ0Ô0ˆFà—’˜S v°~Èw�ÑWÔWˆAØ×ÒÑ Ô Ð Ø�LŠL‰NŒNˆNØˆFØð Ø—
’
‘”�Ø�ÝŒKÐ3 D¤IÐ3Ð3Ð3Ñ4Ô4Ð4Øð ð Ø—’‘”�Øð Ø—
’
‘”����ðð ð øð Ô"Ô,ð 	*ð 	*ð 	*Ø/0¬zÐ/E�Q”ZÔ+Ð+È1ˆFØ�fÐ"Ð"Ò"Ð"˜sÒ"Ð"Ð"Ð"Ð" v°ZÐ'?Ð'?Ý” $Ð]Ð]°Ð]Ð]½'À!Ä*ÈhÐXZÑ:[Ô:[Ð]Ð]Ñ^Ô^Ð^Ø�u�u�uð
 ð Ø—’‘”�Øð Ø—
’
‘”����ðð ð ð * Ð)Ð)ˆJˆJˆJˆJˆJˆJøøøøÝð 	 ð 	 ð 	 Ý˜Q™œˆJˆJˆJˆJˆJˆJøøøøð	 øøøð ð Ø—’‘”�Øð Ø—
’
‘”�øøð ð Ø—’‘”�Øð Ø—
’
‘”��ðøøøð �UŠ?ˆ?Ø˜g¨™kÑ*ˆIÝŒN˜dÐmÐm¨ZÐmÐmÀWÈqÁ[ÐmÐmÐSXÐmÐmÐ^gÐmÐmÐmÑnÔnÐnÝ�)ÑÔÐùå
„N�dÐLÐL¨%°!©)ÐLÐLÀ
ÐLÐLÑMÔMÐMØˆ5sJ   ÂBE%Å%H3Å4AHÇI#ÈHÈI#ÈH3ÈH.È)I#È.H3È3I#É#/J)Nr)   r*   F)r   r+   r,   r-   r.   r/   r0   r1   r2   r1   r3   r4   r5   r4   )r'   Ú
__future__r   r   Úpathlibr   Útimer   Úultralytics.utilsr   r   r	   r^   r(   r   r   ú<module>rc      sÂ   ðà HÐ Hà "Ð "Ð "Ð "Ð "Ð "à 	€	€	€	Ø Ð Ð Ð Ð Ð Ø Ð Ð Ð Ð Ð à *Ð *Ð *Ð *Ð *Ð *Ð *Ð *ðð ð ð ð ñ ô ð ð6  ØØØðNð Nð Nð Nð Nð Nð Nr   