o
    tBh                     @   s0   d dl Z dd Z		ddeded	efd
dZdS )    Nc                 C   s   |r
| r
dt |  S |S )N   )float)
rate_limituse_rate_limit_headerthrottle_by_seconds r   q/var/www/html/riverr-enterprise-integrations-main/venv/lib/python3.10/site-packages/sp_api/util/load_all_pages.pymake_sleep_time   s   r	      	NextTokenFr   r   extrasc                    s    si   fdd}|S )a  
    Load all pages if a next token is returned

    Args:
        throttle_by_seconds: float
        next_token_param: str | The param amazon expects to hold the next token
        use_rate_limit_header: if the function should try to use amazon's rate limit header
        extras: additional data to be sent with NextToken, e.g `dict(QueryType='NEXT_TOKEN')` for `FulfillmentInbound`
    Returns:
        Transforms the function in a generator, returning all pages
    c                    s"    fdd j _ S )Nc                  ?   sz    | i |}|V  |j r9|  ||j i  t|j}| i |D ]}|V  |dkr8t| q*d S d S )Nr   )
next_tokenclearupdater	   r   timesleep)argskwargsres
sleep_timex)r   functionnext_token_paramr   r   wrapperr   r   r      s   
z2load_all_pages.<locals>.decorator.<locals>.wrapper)__doc__)r   r   r   r   r   )r   r   r   	decorator   s   z!load_all_pages.<locals>.decoratorr   )r   r   r   r   r   r   r   r   load_all_pages
   s   r   )r
   r   FN)r   r	   r   booldictr   r   r   r   r   <module>   s    