o
    di                     @   s   d dl Z d dlmZmZmZ d dlmZ d dlmZm	Z	m
Z
mZ d dlmZ d dlmZmZ e eZG dd de	ZG d	d
 d
e
ZG dd deZdS )    N)AsyncIteratorAnycast)	docstring)CollectionFactoryResourceCollectionCollectionManagermerge_dicts)create_request_parameters)AioBatchActionAIOResourceHandlerc                   @   s0   e Zd ZdZdd Zdd Zdd Zdd	 Zd
S )AIOResourceCollectionz
    Converted the ResourceCollection.pages() function to an async generator so that we can do
    async for on a paginator inside that function

    Converted the __iter__
    c                 C  sj   | j dd }d}ttt |  2 z3 d H W }|D ]}|V  |d7 }|d ur0||kr0  d S qq6 d S )Nlimitr      )_paramsgetr   r   r   pages)selfr   countpageitem r   Q/home/ubuntu/.local/lib/python3.10/site-packages/aioboto3/resources/collection.py	__anext__   s   zAIOResourceCollection.__anext__c                 C   s   |   S N)r   r   r   r   r   	__aiter__       zAIOResourceCollection.__aiter__c                 C   s   t d)NzUse async-for instead)NotImplementedErrorr   r   r   r   __iter__#   r   zAIOResourceCollection.__iter__c                   sD  j jj j }|dd }|dd }tj jjt	|dd  
jrLtdj jjj  j}|jdd||di}n fdd	}td
j jjj | }d}|2 z73 d H W }g }	j |I d H D ]}
|	|
 |d7 }|d ur||kr nqz|	V  |d ur||kr d S qg6 d S )Nr   	page_sizeT)append_listszCalling paginated %s:%s with %rPaginationConfig)MaxItemsPageSizec                     s$   t  jdi I d H V  d S )Nr   )getattr_py_operation_namer   clientparamsr   r   r   _aiopaginatordummy@   s   "z7AIOResourceCollection.pages.<locals>._aiopaginatordummyzCalling %s:%s with %rr   r   r   )_parentmetar(   r   copypopr
   _modelrequestr	   can_paginater&   loggerdebugservice_nameget_paginatorpaginate_handlerappend)r   cleaned_paramsr   r    	paginatorr   r*   r   r   
page_itemsr   r   r'   r   r   &   sT   


zAIOResourceCollection.pagesN)__name__
__module____qualname____doc__r   r   r   r   r   r   r   r   r      s    r   c                   @   s   e Zd ZeZdd ZdS )AIOCollectionManagerc                 C   s8   || _ | j jj}|| _|jj}t|||j||d| _d S )N)search_pathfactoryresource_modelservice_contextoperation_name)r/   r0   	operationr+   resourcepathr   r7   )r   collection_modelparentrB   rD   rE   rA   r   r   r   __init__c   s   
zAIOCollectionManager.__init__N)r<   r=   r>   r   _collection_clsrK   r   r   r   r   r@   `   s    r@   c                   @   s   e Zd Zdd Zdd ZdS )AIOCollectionFactoryc           	      C   s   i }|j }| ||||j| | j||||j|td |j|kr*|j d| d}n|j d| d| d}tt|tf|}| j||||j|td ||d< |d7 }tt|tf|S )N)attrsresource_namerI   service_modelevent_emitter
base_class.
CollectionrL   Manager)	name_load_batch_actionsrP   #_load_documented_collection_methodsr   r4   typestrr@   )	r   rO   rI   rD   rQ   rN   collection_namecls_namecollection_clsr   r   r   load_from_definitions   sB   
	z)AIOCollectionFactory.load_from_definitionc                    s:   t |  fdd}t||_tj|||||dd|_|S )zs
        Creates a new method which makes a batch operation request
        to the underlying service API.
        c                    s    | g|R i |S r   r   )r   argskwargsactionr   r   batch_action   s   z?AIOCollectionFactory._create_batch_action.<locals>.batch_actionF)rO   rQ   batch_action_modelrP   rI   include_signature)r   rZ   r<   r   BatchActionDocstringr?   )factory_selfrO   snake_casedaction_modelrI   rP   rQ   rc   r   ra   r   _create_batch_action   s   
z)AIOCollectionFactory._create_batch_actionN)r<   r=   r>   r^   rj   r   r   r   r   rM   r   s    /rM   )loggingtypingr   r   r   
boto3.docsr   boto3.resources.collectionr   r   r   r	   boto3.resources.paramsr
   aioboto3.resources.actionr   r   	getLoggerr<   r2   r   r@   rM   r   r   r   r   <module>   s    
S