o
    ß­jß  ã                   @  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   ú[/var/www/html/CropPilot/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   ü




ü(ÿúÿú