o
    Zh                     @  s   U d dl mZ d dlmZ d dlm  mZ d dlm	Z	 d dlm
Z
 d dlmZ ddddd	Zd
ed< d)ddZd*ddZd+ddZd,ddZ				d-d.ddZ	d/ddddd d0d$d%Z	d/ddddd d1d'd(ZdS )2    )annotations)CallableN)permission_types)retriever_types)model_typescorporatunedModels)Zcorpusr   Z
tunedmodelZtunedmodelszdict[str, str]_RESOURCE_TYPExstrreturnc                 C  s6   t | tr	|  } t| d }|std|  d|S )Nz!Unsupported resource type. Got: `
` instead.)
isinstancer   lowerr	   get
ValueErrorr
   resource_type r   U/var/www/html/lang_env/lib/python3.10/site-packages/google/generativeai/permission.py_to_resource_type"   s   
r   r   Nonec                 C  sj   |dkrt | stt jjt| | dd S |dkr.t| s,ttjjt| | dd S td| )Nr   )lengthnamer   zUnsupported resource type: )	r   Z
valid_namer   ZNAME_ERROR_MSGformatlenr   Zvalid_tuned_model_nameZTUNED_MODEL_NAME_ERROR_MSGr   r   r   r   _validate_resource_name,   s   

r   c                 C  s    t | stt jj| dd S )N)permission_id)r   Zvalid_idr   ZINVALID_PERMISSION_ID_MSGr   )r
   r   r   r   _validate_permission_id9   s   
r   r   c                 C  sj   |  d}t|dkrtd|  d|\}}}}t|}d||g}t|| t| d|||gS )N/   zyInvalid name format. Expected format:                 `resource_type/<resource_name>/permissions/<permission_id>`. Got: `r   )splitr   r   r   joinr   r   )r   Zname_path_componentsr   resource_nameZpermission_placeholderr   r   r   r   _get_valid_name_components>   s   

r$   
str | Noner#   r   str | int | Nonec                 C  s   | sc|r|st d|  d| d| d|rt|}n|d}t|dkr3t d| dt| d	t|d
 }| d|v rF| d} n| d| d} t|tsWd|vr_| d| 7 } n| |7 } t| } | S )NznInvalid arguments: Either `name` or both `resource_name` and `permission_id` must be provided. Received name: z, resource_name: z, permission_id: .r      zlInvalid `resource_name` format: Expected format is `resource_type/resource_name` (2 components). Received: `z` with z components.r   zpermissions/)r   r   r!   r   r   intr$   )r   r#   r   r   Zresource_path_componentsr   r   r   _construct_nameR   s*   

r*   )clientr#   r   r   r+   "glm.PermissionServiceClient | Nonepermission_types.Permissionc                C  s    t | |||d} tjj| |dS )aw  Calls the API to retrieve detailed information about a specific permission based on resource type and permission identifiers

    Args:
        name: The name of the permission.
        resource_name: The name of the supported resource for which the permission details are needed.
        permission_id: The name of the permission.
        resource_type: The type of the resource (corpus or tunedModel as of now) for which the permission details are needed.
                        If not provided, it will be inferred from `resource_name`.

    Returns:
        The permission as an instance of `permission_types.Permission`.
    r   r#   r   r   r   r+   )r*   r   
Permissionr   r   r+   r#   r   r   r   r   r   get_permissiony   s   r2   'glm.PermissionServiceAsyncClient | Nonec                  s(   t | |||d} tjj| |dI dH S )zC
    This is the async version of `permission.get_permission`.
    r.   r/   N)r*   r   r0   Z	get_asyncr1   r   r   r   get_permission_async   s   r4   )r
   r   r   r   )r
   r   r   r   r   r   )r
   r   r   r   )r   r   r   r   )NNNN)
r   r%   r#   r%   r   r&   r   r%   r   r   )N)r   r%   r+   r,   r#   r%   r   r&   r   r%   r   r-   )r   r%   r+   r3   r#   r%   r   r&   r   r%   r   r-   )
__future__r   typingr   Zgoogle.ai.generativelanguageZaiZgenerativelanguageZglmZgoogle.generativeai.typesr   r   r   r	   __annotations__r   r   r   r$   r*   r2   r4   r   r   r   r   <module>   sD   




(