
                             S r SSKJr  SSKJr  SSKJr  SSKJr   " S S\5      r " S S	\5      r	 " S
 S\	5      r
 " S S\	5      rg)z2Generic implementations of Apigee Management APIs.    )absolute_import)division)unicode_literals)requestc                   Z    \ rS rSrSrSr \SS j5       r\S	S j5       r\S	S j5       r	Sr
g)

BaseClient   z-Base class for Apigee Management API clients.Nc                     U R                   c  [        SU -  5      e[        R                  " U=(       d    0 U R                   S S U R                   S   US9$ )N%%s class must provide an entity path.)query_params_entity_pathNotImplementedErrorr   ResponseToApiRequest)clsidentifiersextra_paramss      )lib/googlecloudsdk/api_lib/apigee/base.pyListBaseClient.List!   s[    
 G# MNN''r"!	# #    c                     U R                   c  [        SU -  5      e[        R                  " U=(       d    0 U R                   5      $ )Nr   r   r   r   s     r   DescribeBaseClient.Describe+   s=    
 G# MNN''(9r3;K;KLLr   c                     U R                   c  [        SU -  5      e[        R                  " U=(       d    0 U R                   SS9$ )Nr   DELETE)methodr   r   s     r   DeleteBaseClient.Delete1   sD    
 G# MNN''r3++H> >r    NN)N)__name__
__module____qualname____firstlineno____doc__r   classmethodr   r   r    __static_attributes__r"   r   r   r   r      sM    5,
 # # M M
 > >r   r   c                   ,    \ rS rSrSrSr\S 5       rSrg)PagedListClient9   zClient for `List` APIs that can only return a limited number of objects.

Attributes:
  _list_container: the field name in the List API's response that contains the
    list of objects. None if the API returns a list directly.
Nc                     U R                   c  U$  XR                      $ ! [         a    X R                   U4n[        SU-  5      e[        [        4 a    U < SU< 3n[        U5      ef = f)z0Returns a list of the results in `result_chunk`.zS%s specifies a _list_container %r that's not present in API responses.
Response: %rz{ specifies a _list_container, implying that the API response should be a JSON object, but received something else instead: )_list_containerKeyErrorAssertionError
IndexError	TypeError)r   result_chunkfailure_infoerrors       r   _NormalizedResultChunk&PagedListClient._NormalizedResultChunkB   s     ""--.. 5..=l%'345 5 	" " '*<9e 5!!	"s
    A
A)r"   )	r$   r%   r&   r'   r(   r/   r)   r7   r*   r"   r   r   r,   r,   9   s      /" "r   r,   c                   J   ^  \ rS rSrSrSrSrSrSr\	S	U 4S jj5       r
SrU =r$ )
TokenPagedListClientU   ar  Client for paged `List` APIs that identify pages using a page token.

This is the AIP-approved way to paginate results and is preferred for new
APIs.

Attributes:
  _page_token_field: the field name in the List API's response that contains
    an explicit page token.
  _list_container: the field name in the List API's response that contains the
    list of objects.
  _page_token_param: the query parameter for the previous page's token.
  _max_per_page: the maximum number of items that can be returned in each List
    response.
  _limit_param: the query parameter for the number of items to be returned on
    each page.
nextPageToken	pageTokend   pageSizec              #     >#    U R                   c  SU -  n[        U5      eU R                  U R                  0nU(       a  UR	                  U5         [
        [        U ]  X5      nU R                  U5       H  nUv   M	     U R                  U;   a/  XPR                     (       a  XPR                     X@R                  '   Mo  g 7f)NzG%s does not specify a _list_container, but token pagination requires it)r/   r1   _limit_param_max_per_pageupdatesuperr:   r   r7   _page_token_field_page_token_param)r   r   r   r6   paramsresponseitem	__class__s          r   r   TokenPagedListClient.Listk   s     
"!$&e5!! 1 12FmmL!
+S6{Kh,,X6$
 7 
		(	*x8M8M/N(01F1F(G$$% s   B>Cr"   r#   )r$   r%   r&   r'   r(   rE   rF   rB   rA   r)   r   r*   __classcell__rJ   s   @r   r:   r:   U   s2      &!-, r   r:   c                   J   ^  \ rS rSrSrSrSrSrSr\	S	U 4S jj5       r
SrU =r$ )
FieldPagedListClient   a  Client for paged `List` APIs that identify pages using a page field.

This is the pagination method used by legacy Apigee CG APIs, and has been
preserved for backwards compatibility in Apigee's GCP offering.

Attributes:
  _list_container: the field name in the List API's response that contains the
    list of objects. None if the API returns a list directly.
  _page_field: the field name in each list element that can be used as a page
    identifier. PageListClient will take the value of this field in the last
    list item for a page, and use it as the  _start_at_param for the next
    page. None if each list element is a primitive which can be used for this
    purpose directly.
  _max_per_page: the maximum number of items that can be returned in each List
    response.
  _limit_param: the query parameter for the number of items to be returned on
    each page.
  _start_at_param: the query parameter for where in the available data the
    response should begin.
Ni  countstartKeyc              #     >#    Uc  U R                   nU R                  U R                  0nU(       a  UR                  U5         [        [
        U ]  X5      nU(       d  X$;  a  g U R                  b  U R                  U5      nUS U R                  S-
    H  nUv   M	     [        U5      U R                  :  a  g US   nU R                  b  XpR                     nXtU'   M  7f)N   r   )_start_at_paramrA   rB   rC   rD   rO   r   r/   r7   len_page_field)	r   r   start_at_paramr   rG   r4   rI   last_item_on_pagerJ   s	           r   r   FieldPagedListClient.List   s     **n 1 12FmmL!
/:;Oln:				( 11,?
 5 1 1A 56$
 7 
\	S..	. 	&r*		$-oo>0^5 s   CCr"   )NNN)r$   r%   r&   r'   r(   rW   rB   rA   rU   r)   r   r*   rL   rM   s   @r   rO   rO      s0    * +-,/ 1  1r   rO   N)r(   
__future__r   r   r   !googlecloudsdk.command_lib.apigeer   objectr   r,   r:   rO   r"   r   r   <module>r^      sH    9 &  ' 5> >B"j "8*? *Z<1? <1r   