
    ; i                        U d dl mZ d dlmZ d dlmc 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Zd#dZd$dZd%dZ	 	 	 	 d&d'dZ	 d(dddddd)dZ	 d(dddddd*d!ZdS )+    )annotations)CallableN)permission_types)retriever_types)model_typescorporatunedModels)corpusr   
tunedmodeltunedmodelszdict[str, str]_RESOURCE_TYPExstrreturnc                    t          | t                    r|                                 } t                              | d           }|st          d|  d          |S )Nz!Unsupported resource type. Got: `
` instead.)
isinstancer   lowerr   get
ValueErrorr   resource_types     v/var/www/development/aibuddy-work/election-extract/venv/lib/python3.11/site-packages/google/generativeai/permission.py_to_resource_typer   "   s_    !S GGII"&&q$//M LJQJJJKKK    r   Nonec                   |dk    rQt          j        |           s;t          t           j                            t          |           |                     d S |dk    rQt          j        |           s;t          t          j                            t          |           |                     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   s     r   _validate_resource_namer&   ,   s    	!!)!,, 	[_;BB#a&&WXBYYZZZ	[ 	[ 
-	'	'1!44 	c[CJJRUVWRXRX_`Jaabbb	c 	c F}FFGGGr   c                    t          j        |           s-t          t           j                            |                     d S )N)permission_id)r   valid_idr   INVALID_PERMISSION_ID_MSGr"   )r   s    r   _validate_permission_idr+   9   sF    $Q'' ])CJJYZJ[[\\\] ]r   r   c                @   |                      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(   s         r   _get_valid_name_componentsr4   >   s    ::c??
  A%%eTXe e e
 
 	

 K_GM="8-%m44MHH4mDEEMM=999M***88]M=ABBBr   
str | Noner2   r(   str | int | Nonec           	        | s|r|st          d|  d| d| d          |rt          |          }n`|                    d          }t          |          dk    r#t          d| dt          |           d	          t          |d
                   }| d|v r| d} n| d| d} t	          |t
                    sd|vr	| d| z  } n| |z  } 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   intr4   )r   r2   r(   r   resource_path_componentss        r   _construct_namer<   R   s     " 	- 	 I  BF  I  I  Yf  I  I  yF  I  I  I    		K-m<<MM (5':':3'?'?$+,,11  E  DQ  E  E  Z]  ^v  Zw  Zw  E  E  E   ..Fq.IJJM-//#&&&DD#66m666DmS)) 	"^=-P-P2=222DDM!D &d++DKr   )clientr2   r(   r   r=   "glm.PermissionServiceClient | Nonepermission_types.Permissionc               j    t          | |||          } t          j                            | |          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   r2   r(   r   r   r=   )r<   r   
Permissionr   r   r=   r2   r(   r   s        r   get_permissionrE   y   sB    ( ###	  D &**V*DDDr   'glm.PermissionServiceAsyncClient | Nonec               z   K   t          | |||          } t          j                            | |           d{V S )zC
    This is the async version of `permission.get_permission`.
    rA   rB   N)r<   r   rC   	get_asyncrD   s        r   get_permission_asyncrI      sX       ###	  D ",66D6PPPPPPPPPr   )r   r   r   r   )r   r   r   r   r   r   )r   r   r   r   )r   r   r   r   )NNNN)
r   r5   r2   r5   r(   r6   r   r5   r   r   )N)r   r5   r=   r>   r2   r5   r(   r6   r   r5   r   r?   )r   r5   r=   rF   r2   r5   r(   r6   r   r5   r   r?   )
__future__r   typingr   google.ai.generativelanguageaigenerativelanguageglmgoogle.generativeai.typesr   r   r   r   __annotations__r   r&   r+   r4   r<   rE   rI    r   r   <module>rS      s   # " " " " " "       * * * * * * * * * 6 6 6 6 6 6 5 5 5 5 5 5 1 1 1 1 1 1  	" "       
H 
H 
H 
H] ] ] ]
C C C C*  $&* $	$ $ $ $ $P E 26 $&* $E E E E E E< Q 7; $&* $Q Q Q Q Q Q Q Qr   