
    Li?{              	       P   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 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 ddlmZmZ  ej0                  d      Z	 ddeeeef   ef   deeeef      deeef   fdZ	 ddeeeef   ef   deeeef      deeef   fdZ	 ddeeeef   ef   deeeef      deeef   fdZ	 ddeeeef   ef   deeeef      deeef   fdZ 	 ddeeeef   ef   deeeef      deeef   fdZ!	 ddeeeef   ef   deeeef      deeef   fdZ"	 ddeeeef   ef   deeeef      deeef   fdZ#	 ddeeeef   ef   deeeef      deeef   fdZ$ G d dejJ                        Z& G d dejJ                        Z'y)    N)AnyOptionalUnion)	urlencode   )_api_module)_common)_extra_utils)_transformers)types)get_value_by_path)set_value_by_path)
AsyncPagerPagerzgoogle_genai.filesfrom_objectparent_objectreturnc                 V    i }t        | dg      t        |dgt        | dg             |S )Nfilegetvsetvr   r   	to_objects      P/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/google/genai/files.py_CreateFileParameters_to_mldevr   &   s5     !)	+x ,VHd;9:	    c                 V    i }t        | dg      t        |dgt        | dg             |S NsdkHttpResponsesdk_http_responser   r   s      r   _CreateFileResponse_from_mldevr"   1   @     !)	+)*+7'(${=N<O*P 
r   c           
      ~    i }t        | dg      -t        |ddgt        j                  t        | dg                   |S Nname_urlr   r   r   tt_file_namer   s      r   _DeleteFileParameters_to_mldevr+   >   F     !)	+x ,FF#Q]]4fX3N%O 
r   c                 V    i }t        | dg      t        |dgt        | dg             |S r   r   r   s      r   _DeleteFileResponse_from_mldevr.   K   r#   r   c           
      ~    i }t        | dg      -t        |ddgt        j                  t        | dg                   |S r%   r(   r   s      r   _GetFileParameters_to_mldevr0   X   r,   r   c                     i }t        | dg      t        |ddgt        | dg             t        | dg      t        |ddgt        | dg             |S )N	page_size_querypageSize
page_token	pageTokenr   r   s      r   _ListFilesConfig_to_mldevr7   e   sm     !)	+}%1*-tK+/O 
+~&2	;[<.) 
r   c                 R    i }t        | dg      t        t        | dg      |       |S )Nconfig)r   r7   r   s      r   _ListFilesParameters_to_mldevr:   z   s1     !)	+z".d;
;YG	r   c                    i }t        | dg      t        |dgt        | dg             t        | dg      t        |dgt        | dg             t        | dg      't        |dgt        | dg      D cg c]  }| c}       |S c c}w )Nr    r!   nextPageTokennext_page_tokenfilesr   )r   r   r   items       r   _ListFilesResponse_from_mldevr@      s     !)	+)*+7'(${=N<O*P 
+()5&'kO;L)MN	+y!-WIkG91MNNO	  Os   3	Bc                      e Zd Zdddeej
                     dej                  fdZdddej                  deej                     dej                  fdZdddedeej                     dej                  fd	Zdddedeej                      dej"                  fd
Zdddeeej*                  e   ej.                  f   deej0                     dej                  fdZdddeej
                     deej                     fdZdddeeej                  ej8                  ej:                  f   deej<                     defdZ y)FilesNr9   r9   r   c                   t        j                  |      }| j                  j                  rt	        d      t        |      }|j                  d      }|rdj                  |      }nd}|j                  d      }|r| dt        |       }|j                  dd       d}|j                  ,|j                  j                  |j                  j                  }t        j                  |      }t        j                  |      }| j                  j                  d	|||      }|j                   si nt#        j$                  |j                         }	| j                  j                  st'        |	      }	t         j(                  j+                  |	|j-                         
      }
t        j.                  |j0                        |
_        | j                  j5                  |
       |
S )aa  Lists all files from the service.

    Args:
      config (ListFilesConfig): Optional, configuration for the list method.

    Returns:
      ListFilesResponse: The response for the list method.

    Usage:

    .. code-block:: python

      pager = client.files.list(config={'page_size': 10})
      for file in pager.page:
        print(file.name)
    rC   =This method is only supported in the Gemini Developer client.r'   r>   r3   ?r9   Ngetresponsekwargsheaders)r   _ListFilesParameters_api_clientvertexai
ValueErrorr:   rG   
format_mapr   popr9   http_optionsr	   convert_to_dictencode_unserializable_typesrequestbodyjsonloadsr@   ListFilesResponse_from_response
model_dumpHttpResponserL   r!   _verify_responseselfr9   parameter_modelrequest_dictrequest_url_dictpathquery_paramsrS   rI   response_dictreturn_values              r   _listzFiles._list   s   ( 00O
   
I  3?Cl%))&1	!!"23##H-LvQy./0dXt$04L*""//;$++88l**<8L66|DL''t\<PH&mmBHMM1JM$$3MBm**99'A'A'C : L &+%7%7  &L" 	%%l3r   r   c                   t        j                  ||      }| j                  j                  rt	        d      t        |      }|j                  d      }|rdj                  |      }nd}|j                  d      }|r| dt        |       }|j                  dd        d }|j                  ,|j                  j                  |j                  j                  }t        j                  |      }t        j                  |      }| j                  j                  d|||      }	|@t!        |d	d       r3t        j"                  |	
      }
| j                  j%                  |
       |
S |	j&                  si nt)        j*                  |	j&                        }| j                  j                  st-        |      }t         j"                  j/                  ||j1                               }
| j                  j%                  |
       |
S Nr   r9   rE   r'   zupload/v1beta/filesr3   rF   r9   postshould_return_http_response)r!   rH   )r   _CreateFileParametersrN   rO   rP   r   rG   rQ   r   rR   r9   rS   r	   rT   rU   rV   getattrCreateFileResponser^   rW   rX   rY   r"   r[   r\   r`   r   r9   ra   rb   rc   rd   re   rS   rI   rg   rf   s               r   _createzFiles._create   s    11O   
I  4ODl%))&1	$//0@A$##H-LvQy./0dXt$04L*""//;$++88l**<8L66|DL''lLH g-t --Il
''5&mmBHMM1JM$$4]Cm++::'A'A'C ; L 	%%l3r   r&   c                6   t        j                  ||      }| j                  j                  rt	        d      t        |      }|j                  d      }|rdj                  |      }nd}|j                  d      }|r| dt        |       }|j                  dd       d}|j                  ,|j                  j                  |j                  j                  }t        j                  |      }t        j                  |      }| j                  j                  d	|||      }	|	j                   si nt#        j$                  |	j                         }
t         j&                  j)                  |
|j+                         
      }| j                  j-                  |       |S )ai  Retrieves the file information from the service.

    Args:
      name (str): The name identifier for the file to retrieve.
      config (GetFileConfig): Optional, configuration for the get method.

    Returns:
      File: The file information.

    Usage:

    .. code-block:: python

      file = client.files.get(name='files/...')
      print(file.uri)
    r&   r9   rE   r'   files/{file}r3   rF   r9   NrG   rH   )r   _GetFileParametersrN   rO   rP   r0   rG   rQ   r   rR   r9   rS   r	   rT   rU   rV   rW   rX   rY   Filer[   r\   r^   r`   r&   r9   ra   rb   rc   rd   re   rS   rI   rf   rg   s               r   rG   z	Files.get  sw   ( ..O   
I  1Al%))&1	(()9:##H-LvQy./0dXt$04L*""//;$++88l**<8L66|DL''t\<PH&mmBHMM1JM::,,'A'A'C - L 	%%l3r   c                   t        j                  ||      }| j                  j                  rt	        d      t        |      }|j                  d      }|rdj                  |      }nd}|j                  d      }|r| dt        |       }|j                  dd       d}|j                  ,|j                  j                  |j                  j                  }t        j                  |      }t        j                  |      }| j                  j                  d	|||      }	|	j                   si nt#        j$                  |	j                         }
| j                  j                  st'        |
      }
t         j(                  j+                  |
|j-                         
      }t        j.                  |	j0                        |_        | j                  j5                  |       |S )a]  Deletes a remotely stored file.

    Args:
      name (str): The name identifier for the file to delete.
      config (DeleteFileConfig): Optional, configuration for the delete method.

    Returns:
      DeleteFileResponse: The response for the delete method

    Usage:

    .. code-block:: python

      client.files.delete(name='files/...')
    rt   rE   r'   ru   r3   rF   r9   NdeleterH   rK   )r   _DeleteFileParametersrN   rO   rP   r+   rG   rQ   r   rR   r9   rS   r	   rT   rU   rV   rW   rX   rY   r.   DeleteFileResponser[   r\   r]   rL   r!   r^   rx   s               r   rz   zFiles.delete_  s   & 11O   
I  4ODl%))&1	(()9:##H-LvQy./0dXt$04L*""//;$++88l**<8L66|DL''$lH 'mmBHMM1JM$$4]Cm++::'A'A'C ; L &+%7%7  &L" 	%%l3r   c                   | j                   j                  rt        d      t        j                         }|r_t        |t              rt        j                  di |}n|}t        j                  |j                  |j                  |j                        }nt        j                         }|j                  /|j                  j                  d      sd|j                   |_	        t        j                  ||j                  |j                        \  }}}||_        ||_        | j!                  |t        j"                  |d            }|j$                  .|j$                  j&                  d|j$                  j&                  vrt)        d	      |j$                  j&                  d   }	t        |t*        j,                        r*| j                   j/                  ||	|j                  |
      }
n>t1        j2                  |      }| j                   j/                  ||	|j                  |
      }
t        j                  j5                  |
j6                  d   |r|j9                               S i       S )a  Calls the API to upload a file using a supported file service.

    Args:
      file: A path to the file or an `IOBase` object to be uploaded. If it's an
        IOBase object, it must be opened in blocking (the default) mode and
        binary mode. In other words, do not use non-blocking mode or text mode.
        The given stream must be seekable, that is, it must be able to call
        `seek()` on 'path'.
      config: Optional parameters to set `diplay_name`, `mime_type`, and `name`.
    rE   	mime_typer&   display_namefiles/user_http_optionsuser_mime_typeTrS   rm   rk   x-goog-upload-urlPFailed to create file. Upload URL did not returned from the create file request.rS   r   rH    )rN   rO   rP   r   UploadFileConfig
isinstancedictrw   r   r&   r   
startswithr
   prepare_resumable_uploadrS   
size_bytesrr   CreateFileConfigr!   rL   KeyErrorioIOBaseupload_fileosfspathr[   rX   r\   r`   r   r9   config_modelfile_objrS   r   r   rI   
upload_urlreturn_filefs_paths               r   uploadzFiles.upload  s>       
I  ))+L	FD	!--77 **  #00h h}} )A)A()Kx}}o.hm*6*O*O&33#--+'L*i
 %H"H||%%%4
  H 	""*%%--5h&@&@&H&HH  ++334GHJ$		"$$00

H//l 1 k 		$g$$00
:x22 1 k ::$$!!&),2|&&( %  8: %  r   c                R    t        d| j                  | j                  |      |      S Nr>   rC   )r   rh   r`   r9   s     r   listz
Files.list  s,     



&
!	 r   c                   | j                   j                  rt        d      d}|r(t        |t              rt        j                  di |}n|}t        |t
        j                        r|j                  t        d      t        j                  |      }d| d}ddi}| dt        |       }d}t        |d	g      t        |d	g      }| j                   j                  ||
      }t        |t
        j                        r	||_        |S t        |t
        j                         r|j"                  ||j"                  _        |S )ar  Downloads a file's data from storage.

    Files created by `upload` can't be downloaded. You can tell which files are
    downloadable by checking the `source` or `download_uri` property.

    Note: This method returns the data as bytes. For `Video` and
    `GeneratedVideo` objects there is an additional side effect, that it also
    sets the `video_bytes` property on the `Video` object.

    Args:
      file (str): A file name, uri, or file object. Identifying which file to
        download.
      config (DownloadFileConfigOrDict): Optional, configuration for the get
        method.

    Returns:
      File: The file data as bytes.

    Usage:

    .. code-block:: python

      for file client.files.list():
        if file.download_uri is not None:
          break
      else:
        raise ValueError('No files found with a `download_uri`.')
      data = client.files.download(file=file)
      # data = client.files.download(file=file.name)
      # data = client.files.download(file=file.download_uri)

      video = types.Video(uri=file.uri)
      video_bytes = client.files.download(file=video)
      video.video_bytes
    rE   NzOnly generated files can be downloaded, uploaded files can't be downloaded. You can tell which files are downloadable by checking the `source` or `download_uri` property.r   	:downloadaltmediarF   rS   r   r   )rN   rO   rP   r   r   r   DownloadFileConfigrw   download_urir)   r*   r   r   download_fileVideovideo_bytesGeneratedVideovideo)	r`   r   r9   r   r&   rd   re   rS   datas	            r   downloadzFiles.download  sI   R   
I  L	FD	!//9&9$

#(9(9(A5 
 ==DD6#D7#LV1Y|,-.DLL>*+7,(89l))! * D
 $$d K 
D%..	/DJJ4J#djjKr   )!__name__
__module____qualname__r   r   ListFilesConfigOrDictrZ   rh   
FileOrDictCreateFileConfigOrDictrp   rr   strGetFileConfigOrDictrw   rG   DeleteFileConfigOrDictr|   rz   r   r   PathLiker   r   UploadFileConfigOrDictr   r   r   r   r   DownloadFileConfigOrDictbytesr   r   r   r   rB   rB      s    @DC ; ;<CCR 8<	= = u334	=
 =@ IM??"*5+D+D"E?zz?D LPEE"*5+G+G"HEEV 8<	J #r{{3'23J u334	J
 zzJZ @D ; ;<UZZ :>	O #uzz5;;0D0DDEO u556	O
 Or   rB   c                   Z   e Zd Zdddeej
                     dej                  fdZdddej                  deej                     dej                  fdZdddedeej                     dej                  fd	Zdddedeej                      dej"                  fd
Zdddeeej*                  e   ej.                  f   deej0                     dej                  fdZdddeej
                     deej                     fdZdddeeej                  f   deej8                     defdZy)
AsyncFilesNrC   r9   r   c                  K   t        j                  |      }| j                  j                  rt	        d      t        |      }|j                  d      }|rdj                  |      }nd}|j                  d      }|r| dt        |       }|j                  dd       d}|j                  ,|j                  j                  |j                  j                  }t        j                  |      }t        j                  |      }| j                  j                  d	|||       d{   }|j                   si nt#        j$                  |j                         }	| j                  j                  st'        |	      }	t         j(                  j+                  |	|j-                         
      }
t        j.                  |j0                        |
_        | j                  j5                  |
       |
S 7 íw)ak  Lists all files from the service.

    Args:
      config (ListFilesConfig): Optional, configuration for the list method.

    Returns:
      ListFilesResponse: The response for the list method.

    Usage:

    .. code-block:: python

      pager = await client.aio.files.list(config={'page_size': 10})
      for file in pager.page:
        print(file.name)
    rC   rE   r'   r>   r3   rF   r9   NrG   rH   rK   )r   rM   rN   rO   rP   r:   rG   rQ   r   rR   r9   rS   r	   rT   rU   async_requestrW   rX   rY   r@   rZ   r[   r\   r]   rL   r!   r^   r_   s              r   rh   zAsyncFiles._listP  s    ( 00O
   
I  3?Cl%))&1	!!"23##H-LvQy./0dXt$04L*""//;$++88l**<8L66|DL%%33t\< H 'mmBHMM1JM$$3MBm**99'A'A'C : L &+%7%7  &L" 	%%l3!s   D$G,&G*'CG,r   c                  K   t        j                  ||      }| j                  j                  rt	        d      t        |      }|j                  d      }|rdj                  |      }nd}|j                  d      }|r| dt        |       }|j                  dd        d }|j                  ,|j                  j                  |j                  j                  }t        j                  |      }t        j                  |      }| j                  j                  d|||       d {   }	|@t!        |d	d       r3t        j"                  |	
      }
| j                  j%                  |
       |
S |	j&                  si nt)        j*                  |	j&                        }| j                  j                  st-        |      }t         j"                  j/                  ||j1                               }
| j                  j%                  |
       |
S 7 wrj   )r   rn   rN   rO   rP   r   rG   rQ   r   rR   r9   rS   r	   rT   rU   r   ro   rp   r^   rW   rX   rY   r"   r[   r\   rq   s               r   rr   zAsyncFiles._create  s     11O   
I  4ODl%))&1	$//0@A$##H-LvQy./0dXt$04L*""//;$++88l**<8L66|DL%%33lL H g-t --Il
''5&mmBHMM1JM$$4]Cm++::'A'A'C ; L 	%%l3+s   D%H
'H(C!H
r&   c                R  K   t        j                  ||      }| j                  j                  rt	        d      t        |      }|j                  d      }|rdj                  |      }nd}|j                  d      }|r| dt        |       }|j                  dd       d}|j                  ,|j                  j                  |j                  j                  }t        j                  |      }t        j                  |      }| j                  j                  d	|||       d{   }	|	j                   si nt#        j$                  |	j                         }
t         j&                  j)                  |
|j+                         
      }| j                  j-                  |       |S 7 }w)as  Retrieves the file information from the service.

    Args:
      name (str): The name identifier for the file to retrieve.
      config (GetFileConfig): Optional, configuration for the get method.

    Returns:
      File: The file information.

    Usage:

    .. code-block:: python

      file = await client.aio.files.get(name='files/...')
      print(file.uri)
    rt   rE   r'   ru   r3   rF   r9   NrG   rH   )r   rv   rN   rO   rP   r0   rG   rQ   r   rR   r9   rS   r	   rT   rU   r   rW   rX   rY   rw   r[   r\   r^   rx   s               r   rG   zAsyncFiles.get  s    ( ..O   
I  1Al%))&1	(()9:##H-LvQy./0dXt$04L*""//;$++88l**<8L66|DL%%33t\< H 'mmBHMM1JM::,,'A'A'C - L 	%%l3s   D%F''F%(A>F'c                  K   t        j                  ||      }| j                  j                  rt	        d      t        |      }|j                  d      }|rdj                  |      }nd}|j                  d      }|r| dt        |       }|j                  dd       d}|j                  ,|j                  j                  |j                  j                  }t        j                  |      }t        j                  |      }| j                  j                  d	|||       d{   }	|	j                   si nt#        j$                  |	j                         }
| j                  j                  st'        |
      }
t         j(                  j+                  |
|j-                         
      }t        j.                  |	j0                        |_        | j                  j5                  |       |S 7 íw)ag  Deletes a remotely stored file.

    Args:
      name (str): The name identifier for the file to delete.
      config (DeleteFileConfig): Optional, configuration for the delete method.

    Returns:
      DeleteFileResponse: The response for the delete method

    Usage:

    .. code-block:: python

      await client.aio.files.delete(name='files/...')
    rt   rE   r'   ru   r3   rF   r9   Nrz   rH   rK   )r   r{   rN   rO   rP   r+   rG   rQ   r   rR   r9   rS   r	   rT   rU   r   rW   rX   rY   r.   r|   r[   r\   r]   rL   r!   r^   rx   s               r   rz   zAsyncFiles.delete  s    & 11O   
I  4ODl%))&1	(()9:##H-LvQy./0dXt$04L*""//;$++88l**<8L66|DL%%33$l H 'mmBHMM1JM$$4]Cm++::'A'A'C ; L &+%7%7  &L" 	%%l3!s   D%G-'G+(CG-c                  K   | j                   j                  rt        d      t        j                         }|r_t        |t              rt        j                  di |}n|}t        j                  |j                  |j                  |j                        }nt        j                         }|j                  /|j                  j                  d      sd|j                   |_	        t        j                  ||j                  |j                        \  }}}||_        ||_        | j!                  |t        j"                  |d             d{   }|j$                  F|j$                  j&                  0d	|j$                  j&                  vr#d
|j$                  j&                  vrt)        d      d	|j$                  j&                  v r|j$                  j&                  d	   }	n|j$                  j&                  d
   }	t        |t*        j,                        r2| j                   j/                  ||	|j                  |       d{   }
nFt1        j2                  |      }| j                   j/                  ||	|j                  |       d{   }
t        j                  j5                  |
j6                  d   |r|j9                               S i       S 7 7 7 Nw)a  Calls the API to upload a file asynchronously using a supported file service.

    Args:
      file: A path to the file or an `IOBase` object to be uploaded. If it's an
        IOBase object, it must be opened in blocking (the default) mode and
        binary mode. In other words, do not use non-blocking mode or text mode.
        The given stream must be seekable, that is, it must be able to call
        `seek()` on 'path'.
      config: Optional parameters to set `diplay_name`, `mime_type`, and `name`.
    rE   r~   Nr   r   Tr   rk   r   zX-Goog-Upload-URLr   r   r   rH   r   )rN   rO   rP   r   r   r   r   rw   r   r&   r   r   r
   r   rS   r   rr   r   r!   rL   r   r   r   async_upload_filer   r   r[   rX   r\   r   s               r   r   zAsyncFiles.upload`  s        
I  ))+L	FD	!--77 **  #00h h}} )A)A()Kx}}o.hm*6*O*O&33#--+'L*i
 %H"H\\%%%4
 "  H 	""*%%--5x'A'A'I'II#8+E+E+M+MM   
 : : B B	B--556IJj--556IJj$		"**<<

H//l =  k 		$g**<<
:x22 =  k ::$$!!&),2|&&( %  8: %  C0
s9   EKKC2KKAKKA
KKKc                n   K   t        d| j                  | j                  |       d {   |      S 7 	wr   )r   rh   r   s     r   r   zAsyncFiles.list  s8      

jjj''	  	(s   '53
5c                  K   | j                   j                  rt        d      d}|r(t        |t              rt        j                  d
i |}n|}t        j                  |      }d| d}d}t        |dg      t        |dg      }ddi}|r| dt        |       }| j                   j                  ||	       d{   }|S 7 w)at  Downloads a file's data from the file service.

    The Vertex-AI implementation of the API foes not include the file service.

    Files created by `upload` can't be downloaded. You can tell which files are
    downloadable by checking the `download_uri` property.

    Args:
      File (str): A file name, uri, or file object. Identifying which file to
        download.
      config (DownloadFileConfigOrDict): Optional, configuration for the get
        method.

    Returns:
      File: The file data as bytes.

    Usage:

    .. code-block:: python

      for file client.files.list():
        if file.download_uri is not None:
          break
      else:
        raise ValueError('No files found with a `download_uri`.')
      data = client.files.download(file=file)
      # data = client.files.download(file=file.name)
      # data = client.files.download(file=file.uri)
    rE   Nr   r   rS   r   r   rF   r   r   )rN   rO   rP   r   r   r   r   r)   r*   r   r   async_download_file)	r`   r   r9   r   r&   rd   rS   re   r   s	            r   r   zAsyncFiles.download  s     F   
I  L	FD	!//9&9==DD6#DLL>*+7,(89l7#LvQy./0d!!55! 6  D
 Ks   B;C=C>C)r   r   r   r   r   r   rZ   rh   r   r   rp   rr   r   r   rw   rG   r   r|   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   N  s    @DE ; ;<EEV 8<	= = u334	=
 =@ IMAA"*5+D+D"EAzzAH LPEE"*5+G+G"HEEV 8<	O #r{{3'23O u334	O
 zzOd @D ; ;<%** :>	@ #uzz/"@ u556	@
 @r   r   )N)(r   rX   loggingr   typingr   r   r   urllib.parser    r   r	   r
   r   r)   r   r   r   r   r   pagersr   r   	getLoggerloggerr   r   objectr   r"   r+   r.   r0   r7   r:   r@   
BaseModulerB   r   r   r   r   <module>r      s  $ 
   	 ' ' "       . . % 
		/	0
 /3tCH~v-.DcN+ 
#s(^ /3
tCH~v-.
DcN+
 
#s(^
 /3
tCH~v-.
DcN+
 
#s(^
 /3
tCH~v-.
DcN+
 
#s(^
 /3
tCH~v-.
DcN+
 
#s(^
 /3tCH~v-.DcN+ 
#s(^. /3tCH~v-.DcN+ 
#s(^ /3tCH~v-.DcN+ 
#s(^&sK"" slm'' mr   