o
                      
   @   sP   d Z ddlmZ ddlZdgZdd Zdd Zddd	d
dddddef
ddZdS )zGA helper function that executes a series of List queries for many APIs.    )encodingNYieldFromListc                 C   sB   t |tjrt| |S t|dkr| S tt| |d |dd S )a-  Gets a possibly nested attribute.

    Same as getattr() if attribute is a string;
    if attribute is a tuple, returns the nested attribute referred to by
    the fields in the tuple as if they were a dotted accessor path.

    (ex _GetattrNested(msg, ('foo', 'bar', 'baz')) gets msg.foo.bar.baz
    r      N)
isinstancesixstring_typesgetattrlen_GetattrNested)message	attribute r   D/tmp/google-cloud-sdk/lib/third_party/apitools/base/py/list_pager.pyr
      s
   	
r
   c                 C   sf   t |tjrt| ||S t|dk rtdt|dkr$t| |d |S tt| |dd |d |S )a:  Sets a possibly nested attribute.

    Same as setattr() if attribute is a string;
    if attribute is a tuple, sets the nested attribute referred to by
    the fields in the tuple as if they were a dotted accessor path.

    (ex _SetattrNested(msg, ('foo', 'bar', 'baz'), 'v') sets msg.foo.bar.baz
    to 'v'
    r   zNeed an attribute to setr   N)r   r   r   setattrr	   
ValueErrorr
   )r   r   valuer   r   r   _SetattrNested,   s   
r   d   Listitems	pageTokennextPageToken
maxResultsc                 c   s    t |}t||d |du s|rl|
r(|du rd}nt||p |}t||
| t| |||d}|||}|r?tt||}|D ]}|V  |du rKqA|d8 }|sT dS qAt||	}|s^dS t||| |du s|sdS dS )a  Make a series of List requests, keeping track of page tokens.

    Args:
      service: apitools_base.BaseApiService, A service with a .List() method.
      request: protorpc.messages.Message, The request message
          corresponding to the service's .List() method, with all the
          attributes populated except the .maxResults and .pageToken
          attributes.
      global_params: protorpc.messages.Message, The global query parameters to
           provide when calling the given method.
      limit: int, The maximum number of records to yield. None if all available
          records should be yielded.
      batch_size: int, The number of items to retrieve per request.
      method: str, The name of the method used to fetch resources.
      field: str, The field in the response that will be a list of items.
      predicate: lambda, A function that returns true for items to be yielded.
      current_token_attribute: str or tuple, The name of the attribute in a
          request message holding the page token for the page being
          requested. If a tuple, path to attribute.
      next_token_attribute: str or tuple, The name of the attribute in a
          response message holding the page token for the next page. If a
          tuple, path to the attribute.
      batch_size_attribute: str or tuple, The name of the attribute in a
          response message holding the maximum number of results to be
          returned. None if caller-specified batch size is unsupported.
          If a tuple, path to the attribute.
      get_field_func: Function that returns the items to be yielded. Argument
          is response message, and field.

    Yields:
      protorpc.message.Message, The resources listed by the service.

    N)global_paramsr   )r   CopyProtoMessager   minr   listfilterr
   )servicerequestr   limit
batch_sizemethodfield	predicatecurrent_token_attributenext_token_attributebatch_size_attributeget_field_funcrequest_batch_sizeresponser   itemtokenr   r   r   r   A   s8   
(


)__doc__apitools.base.pyr   r   __all__r
   r   r   r   r   r   r   <module>   s   