
                  
       J    d Z ddlmZ ddlZdgZd Zd Zddddd	dd
ddef
dZy)zGA helper function that executes a series of List queries for many APIs.    )encodingNYieldFromListc                     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	attributes     .lib/third_party/apitools/base/py/list_pager.pyr   r      sP     )S--.w	**	Y1	ggy|<imLL    c                     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   values      r   _SetattrNestedr   ,   s     )S--.w	511	Y!	344	Y1	w	!e44~gy"~> }e- 	-r   d   Listitems	pageTokennextPageToken
maxResultsc              #   |  K   t        j                  |      }t        ||d       ||r|
r"|d}nt        ||xs |      }t        ||
|        t	        | |      ||      } |||      }|rt        t        ||            }|D ]  }| |
|dz  }|r y t        ||	      }|syt        |||       ||ryyw)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tokens                    r   r   r   A   s     P ''0G73T:
-5 !%)"%(U5Hj%I"7$8:LM+77F+G:GIx/	512EDJ}QJE  x)=>w 7?9 -5s   BB<!B<7B<:B<)__doc__apitools.base.pyr   r   __all__r   r   r    r   r   <module>r6      sK   " N % 
 
M"-, )-DSW +,)%F@r   