
                  
          d 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	ej                  d
ddededef
dZd	ej                  d
dfdZ	 dd	ej                  d
ddee   ddfdZdej                  d
ej&                  j(                  deddfdZdej                  d
ej&                  j(                  ddfdZy)z(The BigQuery CLI routine client library.    )absolute_import)division)print_function)Optional)	discovery)bq_error)bq_id_utilsroutines_api_client	referencez,bq_id_utils.ApiClientHelper.DatasetReferencemax_results
page_tokenfilter_expressionc                     | j                         j                  |j                  |j                  |||      j	                         S )a  Lists routines for the given dataset reference.

  Arguments:
    routines_api_client: the api client used to make the request.
    reference: Reference to the dataset.
    max_results: Number of results to return.
    page_token: Token to retrieve the next page of results.
    filter_expression: An expression for filtering routines.

  Returns:
    A dict that contains entries:
      'routines': a list of routines.
      'token': nextPageToken for the last page, if present.
  )	projectId	datasetId
maxResults	pageTokenfilter)routineslistr   r   execute)r
   r   r   r   r   s        %platform/bq/clients/client_routine.pyListRoutinesr      sH    , ""$t'''' "   wy
    z,bq_id_utils.ApiClientHelper.RoutineReferencec                 2   t        j                  |t         j                  j                  d       	 | j	                         j                  |j                  |j                  |j                        j                         S # t        j                  $ r Y yw xY w)z#Returns true if the routine exists.RoutineExistsmethod)r   r   	routineIdF)r	   	typecheckApiClientHelperRoutineReferencer   getr   r   r   r   r   BigqueryNotFoundError)r
   r   s     r   r   r   2   s    
 !!22
$$&	)))))) 
 


 
 
	'	' s   AB   BBignore_not_foundreturnNc                    t        j                  |t         j                  j                  d       	  | j	                         j
                  di t        |      j                          y# t        j                  $ r |s Y yw xY w)a  Deletes RoutineReference reference.

  Args:
    routines_api_client: the api client used to make the request.
    reference: the RoutineReference to delete.
    ignore_not_found: Whether to ignore "not found" errors.

  Raises:
    BigqueryTypeError: if reference is not a RoutineReference.
    bq_error.BigqueryNotFoundError: if reference does not exist and
      ignore_not_found is False.
  DeleteRoutiner   N )
r	   r    r!   r"   r   deletedictr   r   r$   )r
   r   r%   s      r   r(   r(   J   sv    " !!22
)  "))<DO<DDF		'	'  s   7A* *BB	apiclientpolicy.c                     t        j                  |t         j                  j                  d       d|i}| j	                         j                  ||j                               j                         S )a|  Sets IAM policy for the given routine resource.

  Arguments:
    apiclient: the apiclient used to make the request.
    reference: the RoutineReference for the routine resource.
    policy: The policy string in JSON format.

  Returns:
    The updated IAM policy attached to the given routine resource.

  Raises:
    BigqueryTypeError: if reference is not a RoutineReference.
  SetRoutineIAMPolicyr   r-   )bodyresource)r	   r    r!   r"   r   setIamPolicypathr   )r,   r   r-   requests       r   r/   r/   g   s`    $ !!22"
 v'|9>>+;|<wyr   c                     t        j                  |t         j                  j                  d       | j	                         j                  |j                               j                         S )aF  Gets IAM policy for the given routine resource.

  Arguments:
    apiclient: the apiclient used to make the request.
    reference: the RoutineReference for the routine resource.

  Returns:
    The IAM policy attached to the given routine resource.

  Raises:
    BigqueryTypeError: if reference is not a RoutineReference.
  GetRoutineIAMPolicyr   )r1   )r	   r    r!   r"   r   getIamPolicyr3   r   )r,   r   s     r   r6   r6      sV      !!22"
 
				*	*INN4D	*	E	M	M	OOr   )F)__doc__
__future__r   r   r   typingr   googleapiclientr   utilsr   r	   Resourceintstrr   r   boolr(   r!   r"   r/   r6   r)   r   r   <module>rA      s   . &  %  %  "++=  	
 D"++=6 (-"++= tn 
	:!!**;;  		>P!!P**;;P 	Pr   