o
    È·eÊ  ã                   @   s$   G d d„ de ƒZG dd„ deƒZdS )c                       sZ   e Zd ZdZd‡ fdd„	Zedd„ ƒZdd„ Zd	d
„ Zdd„ Z	e	Z
dd„ Zdd„ Z‡  ZS )Ú	ResultSeta¼  
    A class used to lazily handle page-to-page navigation through a set of
    results.

    It presents a transparent iterator interface, so that all the user has
    to do is use it in a typical ``for`` loop (or list comprehension, etc.)
    to fetch results, even if they weren't present in the current page of
    results.

    This is used by the ``Table.query`` & ``Table.scan`` methods.

    Example::

        >>> users = Table('users')
        >>> results = ResultSet()
        >>> results.to_call(users.query, username__gte='johndoe')
        # Now iterate. When it runs out of results, it'll fetch the next page.
        >>> for res in results:
        ...     print res['username']

    Nc                    sN   t t| ƒ ¡  d | _g | _i | _g | _d| _d| _d | _	d| _
|| _d | _d S )NéÿÿÿÿTé    )Úsuperr   Ú__init__Úthe_callableÚ	call_argsÚcall_kwargsÚ_resultsÚ_offsetÚ_results_leftÚ_last_key_seenÚ_fetchesÚ_max_page_sizeÚ_limit)ÚselfÚmax_page_size©Ú	__class__© úM/var/www/ideatree/venv/lib/python3.10/site-packages/boto/dynamodb2/results.pyr      s   
zResultSet.__init__c                 C   s   dS )NÚexclusive_start_keyr   ©r   r   r   r   Ú	first_key$   s   zResultSet.first_keyc                 C   s   g | _ d| _dS )zº
        Resets the internal state of the ``ResultSet``.

        This prevents results from being cached long-term & consuming
        excess memory.

        Largely internal.
        r   N)r	   r
   r   r   r   r   Ú_reset(   s   	
zResultSet._resetc                 C   s   | S ©Nr   r   r   r   r   Ú__iter__4   s   zResultSet.__iter__c                 C   s¨   |  j d7  _ | j t| jƒkr/| jdu rtƒ ‚|  ¡  t| jƒs/| jr/|  ¡  t| jƒs/| js#| j t| jƒk rQ| jd urK|  jd8  _| jdk rKtƒ ‚| j| j  S tƒ ‚)Né   Fr   )r
   Úlenr	   r   ÚStopIterationÚ
fetch_morer   r   r   r   r   Ú__next__7   s   
ÿ

zResultSet.__next__c                 O   sN   t |ƒstdƒ‚| dd¡| _| jdur| jdk rd| _|| _|| _|| _dS )aê  
        Sets up the callable & any arguments to run it with.

        This is stored for subsequent calls so that those queries can be
        run without requiring user intervention.

        Example::

            # Just an example callable.
            >>> def squares_to(y):
            ...     for x in range(1, y):
            ...         yield x**2
            >>> rs = ResultSet()
            # Set up what to call & arguments.
            >>> rs.to_call(squares_to, y=3)

        z3You must supply an object or function to be called.ÚlimitNr   )ÚcallableÚ
ValueErrorÚpopr   r   r   r   )r   r   ÚargsÚkwargsr   r   r   Úto_callS   s   ÿ
zResultSet.to_callc                 C   s   |   ¡  | jdd… }| j ¡ }| jdur| j|| j< | jr+| jr+| j| jkr+| j| _| jdur6| j|d< n
| jdur@| j|d< | j|i |¤Ž}|  j	d7  _	| 
dg ¡}| 
dd¡| _t|ƒrh| j |d ¡ | jdur„| jdkr„| j}|t|d ƒ8 }|dkr„d| _| jdu rŽd| _dS dS )z¯
        When the iterator runs out of results, this method is run to re-execute
        the callable (& arguments) to fetch the next page.

        Largely internal.
        Nr!   r   ÚresultsÚlast_keyr   F)r   r   r   Úcopyr   r   r   r   r   r   Úgetr   r	   Úextendr   )r   r%   r&   r(   Únew_resultsr!   r   r   r   r   v   s2   






ÿzResultSet.fetch_morer   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r    Únextr'   r   Ú__classcell__r   r   r   r   r      s    
#r   c                       s$   e Zd Z‡ fdd„Zdd„ Z‡  ZS )ÚBatchGetResultSetc                    s6   |  dg ¡| _|  dd¡| _tt| ƒj|i |¤Ž d S )NÚkeysÚmax_batch_getéd   )r$   Ú
_keys_leftÚ_max_batch_getr   r5   r   )r   r%   r&   r   r   r   r   ¨   s   zBatchGetResultSet.__init__c                 C   sø   |   ¡  | jd d … }| j ¡ }| jd | j… |d< | j| jd … | _t| jƒdkr-d| _| j|i |¤Ž}t| 	dg ¡ƒs?d S | j
 |d ¡ t| 	dg ¡ƒD ]\}}| j ||¡ qOt| jƒdkred| _| j 	d¡rz| jd  t|d ƒ8  < d S d S )Nr6   r   Fr(   Úunprocessed_keysTr!   )r   r   r   r*   r9   r:   r   r   r   r+   r	   r,   Ú	enumerateÚinsert)r   r%   r&   r(   ÚoffsetÚkey_datar   r   r   r   ­   s$   
ÿzBatchGetResultSet.fetch_more)r.   r/   r0   r   r   r4   r   r   r   r   r5   §   s    r5   N)Úobjectr   r5   r   r   r   r   Ú<module>   s     '