
                  
          S r SSKJr  SSKJr  SSKJr  SSKJr  SSKJr  SSK	J
r
  SSK	Jr  S	\R                  S
SS\S\S\4
S jrS	\R                  S
S4S jr SS	\R                  S
SS\\   SS4S jjrS\R                  S
\R&                  R(                  S\SS4S jrS\R                  S
\R&                  R(                  SS4S jrg)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                     U R                  5       R                  UR                  UR                  UUUS9R	                  5       $ )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                 *   [         R                  " U[         R                  R                  SS9   U R	                  5       R                  UR                  UR                  UR                  S9R                  5       $ ! [        R                   a     gf = f)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
A; ;BBignore_not_foundreturnNc                    [         R                  " U[         R                  R                  SS9   U R	                  5       R
                  " S0 [        U5      D6R                  5         g! [        R                   a    U(       d  e  gf = f)ay  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   ss    " !!22
  "))<DO<DDF		'	'  s   7A( (BB	apiclientpolicy.c                     [         R                  " U[         R                  R                  SS9  SU0nU R	                  5       R                  X1R                  5       S9R                  5       $ )aj  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'|>>+;|<wyr   c                     [         R                  " U[         R                  R                  SS9  U R	                  5       R                  UR                  5       S9R                  5       $ )a6  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   