o
    j6h                     @  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)corpusr   
tunedmodel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   m/var/www/html/chefvision.cloud.itp360.com/venv/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   
valid_namer   NAME_ERROR_MSGformatlenr   valid_tuned_model_name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   valid_idr   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   name_path_componentsr   resource_name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   resource_path_componentsr   r   r   _construct_nameR   s*   

r6   )clientr-   r$   r   r7   "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   r7   )r6   r   
Permissionr   r   r7   r-   r$   r   r   r   r   get_permissiony   s   r>   '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)r6   r   r<   	get_asyncr=   r   r   r   get_permission_async   s   rA   )r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )NNNN)
r   r0   r-   r0   r$   r1   r   r0   r   r   )N)r   r0   r7   r8   r-   r0   r$   r1   r   r0   r   r9   )r   r0   r7   r?   r-   r0   r$   r1   r   r0   r   r9   )
__future__r   typingr   google.ai.generativelanguageaigenerativelanguageglmgoogle.generativeai.typesr   r   r   r   __annotations__r   r#   r'   r/   r6   r>   rA   r   r   r   r   <module>   sD   



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