
    i                          S SK r S SKrS SKrS SKrS SKrS SKrS SKrS SKJr  S SK	J
r
  S SKJrJrJr  S SKrS SKJr  S SKJr  S SKJr  \R(                  " \5      r " S S	5      rg)
    N)md5)PurePath)UnionBinaryIOCallable)StopTransmission)raw)Sessionc                   L    \ rS rSr    SSSS\\\4   S\S\S	\S
\	4S jjr
Srg)SaveFile&   N selfzpyrogram.Clientpathfile_id	file_partprogressprogress_argsc           	        ^#    U R                    ISh  vN   Uc   SSS5      ISh  vN   gU4S jnSn[        U[        [        45      (       a  [	        US5      nO-[        U[
        R                  5      (       a  UnO[        S5      e[        USS5      n	UR                  S[        R                  5        UR                  5       n
UR                  S5        U
S:X  a  [        S	5      eU R                  (       a  U R                  R                  (       a  S
nOSnXS-  S-  :  a  [        SU S35      e[        [         R"                  " X-  5      5      nU
S:  nU(       a  SOSnUSLnU=(       d    U R%                  5       nU(       d  U(       d
  ['        5       OSnU R(                  R+                  5       I Sh  vN nU R-                  USS9I Sh  vN n[/        U5       Vs/ s H$  nU R0                  R3                  U" U5      5      PM&     nn[4        R6                  " S5      m UR                  Xs-  5         UR9                  U5      nU(       d[  U(       dR  U(       dK  SR;                  UR=                  5        Vs/ s H   n[?        U5      SS RA                  S5      PM"     sn5      nGOU(       a+  [B        RD                  RF                  RI                  UUUUS9nO)[B        RD                  RF                  RK                  UUUS9nTRM                  U5      I Sh  vN   U(       az   U H  nTRM                  S5      I Sh  vN   M     [4        RN                  " U6 I Sh  vN   [        U[        [        45      (       a  URQ                  5         SSS5      ISh  vN   gU(       d  U(       d  URS                  U5        US-  nU(       a~  [T        RV                  " U[Y        X7-  U
5      U
/UQ76 n[Z        R\                  " U5      (       a  U" 5       I Sh  vN   O.U R0                  R_                  U R`                  U5      I Sh  vN   GM  U(       a  [B        Rb                  Re                  UUU	S9U H  nTRM                  S5      I Sh  vN   M     [4        RN                  " U6 I Sh  vN   [        U[        [        45      (       a  URQ                  5         sSSS5      ISh  vN   $ [B        Rb                  Rg                  UUU	US9U H  nTRM                  S5      I Sh  vN   M     [4        RN                  " U6 I Sh  vN   [        U[        [        45      (       a  URQ                  5         sSSS5      ISh  vN   $  GNt GNc GN GNs  snf s  snf  GN GN] GNA GN	 GN GNe GN" GN N N Ns N9! [h         a    e [j         a  n[l        Ro                  U5         SnAOSnAff = f U H  nTRM                  S5      I Sh  vN    M     [4        RN                  " U6 I Sh  vN    [        U[        [        45      (       a  URQ                  5         Op! U H  nTRM                  S5      I Sh  vN    M     [4        RN                  " U6 I Sh  vN    [        U[        [        45      (       a  URQ                  5         f f = fSSS5      ISh  vN    g! , ISh  vN  (       d  f       g= f7f)aj  Upload a file onto Telegram servers, without actually sending the message to anyone.
Useful whenever an InputFile type is required.

.. note::

    This is a utility method intended to be used **only** when working with raw
    :obj:`functions <pyrogram.api.functions>` (i.e: a Telegram API method you wish to use which is not
    available yet in the Client class as an easy-to-use method).

.. include:: /_includes/usable-by/users-bots.rst

Parameters:
    path (``str`` | ``BinaryIO``):
        The path of the file you want to upload that exists on your local machine or a binary file-like object
        with its attribute ".name" set for in-memory uploads.

    file_id (``int``, *optional*):
        In case a file part expired, pass the file_id and the file_part to retry uploading that specific chunk.

    file_part (``int``, *optional*):
        In case a file part expired, pass the file_id and the file_part to retry uploading that specific chunk.

    progress (``Callable``, *optional*):
        Pass a callback function to view the file transmission progress.
        The function must take *(current, total)* as positional arguments (look at Other Parameters below for a
        detailed description) and will be called back each time a new file chunk has been successfully
        transmitted.

    progress_args (``tuple``, *optional*):
        Extra custom arguments for the progress callback function.
        You can pass anything you need to be available in the progress callback scope; for example, a Message
        object or a Client instance in order to edit the message with the updated progress status.

Other Parameters:
    current (``int``):
        The amount of bytes transmitted so far.

    total (``int``):
        The total size of the file.

    *args (``tuple``, *optional*):
        Extra custom arguments as defined in the ``progress_args`` parameter.
        You can either keep ``*args`` or add every single extra argument in your function signature.

Returns:
    ``InputFile``: On success, the uploaded file is returned in form of an InputFile object.

Raises:
    RPCError: In case of a Telegram RPC error.
Nc                    >#     TR                  5       I S h  vN nUc  g  U R                  U5      I S h  vN   M8   N$ N! [         a  n[        R	                  U5         S nAN*S nAff = f7f)N)getinvoke	Exceptionlog	exception)sessiondataequeues      P/app/mltbenv/lib/python3.13/site-packages/pyrogram/methods/advanced/save_file.pyworker"SaveFile.save_file.<locals>.workere   sa     !&,D|)%nnT222 , 3$ )a(()sD   A-=A-A ?A A-A 
A*A% A-%A**A-i   rbzPInvalid file. Expected a file path as string or a binary (not text) file pointernamezfile.jpgr   zFile size equals to 0 Bi  i  i   zCan't upload files bigger than z MiBi         T)is_media    )r   r   file_total_partsbytes)r   r   r+   )idpartsr$   )r,   r-   r$   md5_checksum)8save_file_semaphore
isinstancestrr   openioIOBase
ValueErrorgetattrseekosSEEK_ENDtellme
is_premiumintmathceilrnd_idr   storagedc_idget_sessionrangeloopcreate_taskasyncioQueuereadjoindigesthexzfillr	   	functionsuploadSaveBigFilePartSaveFilePartputgathercloseupdate	functoolspartialmininspectiscoroutinefunctionrun_in_executorexecutortypesInputFileBig	InputFiler   r   r   r   )r   r   r   r   r   r   r!   	part_sizefp	file_name	file_sizefile_size_limit_mibr*   is_bigworkers_countis_missing_partmd5_sumrB   r   _workerschunkirpcfuncr   r   s                             @r    	save_fileSaveFile.save_file'   s    t +++| ,++
) #I$h00$%D")),, !sttFJ7IGGAr{{#	IGGAJA~ !:;;ww477--&*#&*#5<< #BCVBWW[!\]]"499Y-B#CD!11F!'AQM%T1O.G#)/cetG,,,,..E ,,UT,BBGGL]G[\G[!tyy,,VG_=G[G\MM!$EI	-.GGI.E %o&(ggGNNL\.]L\qs1vabz/?/?/BL\.]&^G!mm22BB$+&/-="'	 C  "mm22??$+&/"' @   ))C.((&N !A))D/)) ! nng...dS(O44HHJA ,++j "/u-NI(00$	 5yA%  +	  #66x@@"&&LL"&))";";DMM4"PPPW b 9911".& 2  !A))D/)) ! nng...dS(O44HHJA ,++f 99..".&%,	 /  !A))D/)) ! nng...dS(O44HHJA ,++` /B\ /^" )V *.{ ,F )P, *.{ ,v *.{ ,L $  !a  ! " !A))D/)) ! nng...dS(O44HHJ !A))D/)) ! nng...dS(O44HHJ 5 ,+++++s  [<V[<["[<V[<F[":V;["V["$+V["(AV>?'V
&A8V>VV>+["V!["#V$$/["[<V'[<$A5V>V*.V>V-	V>%Y 5["V0
["-V3./["[<)V6*[</Y ["'V8
(["V:/["6[<V<[<[<["["["V>!["$["'[<*V>-V>0["3["6[<8[":["<[<>W1W,'Y ,W11Y 5["X[".X1/1[" [:Y=;[Z
2[["[<[[<"[9([+)[95[<)Nr   Nr   )__name__
__module____qualname____firstlineno__r   r1   r   r=   r   tuplero   __static_attributes__r       r    r   r   &   sc     !!zzCM"z z 	z
 z z zrw   r   )rG   rV   rY   r3   loggingr>   r8   hashlibr   pathlibr   typingr   r   r   pyrogramr   r	   pyrogram.sessionr
   	getLoggerrq   r   r   r   rw   r    <module>r      sP   &    	   	   , ,  %  $!{ {rw   