Current File : //usr/lib/python3/dist-packages/boto3/resources/__pycache__/collection.cpython-312.pyc
�

��e*K���ddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZdd	lm
Z
eje�ZGd
�d�ZGd�d
�ZGd�d�Zy)�N)�
xform_name)�merge_dicts�)�	docstring�)�BatchAction)�create_request_parameters)�ResourceHandlerc�F�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zy)�ResourceCollectiona�
    Represents a collection of resources, which can be iterated through,
    optionally with filtering. Collections automatically handle pagination
    for you.

    See :ref:`guide_collections` for a high-level overview of collections,
    including when remote service requests are performed.

    :type model: :py:class:`~boto3.resources.model.Collection`
    :param model: Collection model
    :type parent: :py:class:`~boto3.resources.base.ServiceResource`
    :param parent: The collection's parent resource
    :type handler: :py:class:`~boto3.resources.response.ResourceHandler`
    :param handler: The resource response handler used to create resource
                    instances
    c��||_||_t|jj�|_||_tj|�|_	y�N)
�_model�_parentr�request�	operation�_py_operation_name�_handler�copy�deepcopy�_params)�self�model�parent�handler�kwargss     �</usr/lib/python3/dist-packages/boto3/resources/collection.py�__init__zResourceCollection.__init__.s>��������",�U�]�]�-D�-D�"E�����
��}�}�V�,���c��dj|jj|jdj|jjj
|jjj��S�Nz
{}({}, {})z{}.{}�	�format�	__class__�__name__r�meta�service_namer�resource�type�rs r�__repr__zResourceCollection.__repr__5�Z���"�"��N�N�#�#��L�L��N�N����!�!�.�.����0D�0D�0I�0I�
�
�	
rc#�K�|jjdd�}d}|j�D]}|D]}|��|dz
}|��||k\s�y�y�w)a�
        A generator which yields resource instances after doing the
        appropriate service operation calls and handling any pagination
        on your behalf.

        Page size, item limit, and filter parameters are applied
        if they have previously been set.

            >>> bucket = s3.Bucket('boto3')
            >>> for obj in bucket.objects.all():
            ...     print(obj.key)
            'key1'
            'key2'

        �limitNrr)r�get�pages)rr.�count�page�items     r�__iter__zResourceCollection.__iter__>sf���� ��� � ��$�/�����J�J�L�	�D��
���
���
���$��%���
�	�s�AA�A�Ac���tj|j�}t||d��|j|j
|j|jfi|��}|S)aO
        Create a clone of this collection. This is used by the methods
        below to provide a chainable interface that returns copies
        rather than the original. This allows things like:

            >>> base = collection.filter(Param1=1)
            >>> query1 = base.filter(Param2=2)
            >>> query2 = base.filter(Param3=3)
            >>> query1.params
            {'Param1': 1, 'Param2': 2}
            >>> query2.params
            {'Param1': 1, 'Param3': 3}

        :rtype: :py:class:`ResourceCollection`
        :return: A clone of this resource collection
        T��append_lists)rrrrr$rrr)rr�params�clones    r�_clonezResourceCollection._clone[sT��"���t�|�|�,���F�F��6������K�K����t�}�}�
�8>�
���rc#��K�|jjj}|jj	�}|jdd�}|jdd�}t
|j|jj�}t||d��|j|j�rstjd|jjj|j|�|j|j�}|j dd||d�i|��}n]tjd	|jjj|j|�t#||j�di|��g}d
}|D]T}	g}
|j%|j||	�D]"}|
j'|�|dz
}|��||k\s�"n|
��|��N||k\s�Tyy�w)
a�
        A generator which yields pages of resource instances after
        doing the appropriate service operation calls and handling
        any pagination on your behalf. Non-paginated calls will
        return a single page of items.

        Page size, item limit, and filter parameters are applied
        if they have previously been set.

            >>> bucket = s3.Bucket('boto3')
            >>> for page in bucket.objects.pages():
            ...     for obj in page:
            ...         print(obj.key)
            'key1'
            'key2'

        :rtype: list(:py:class:`~boto3.resources.base.ServiceResource`)
        :return: List of resource instances
        r.N�	page_sizeTr6zCalling paginated %s:%s with %r�PaginationConfig)�MaxItems�PageSizezCalling %s:%s with %rrr�)rr&�clientrr�popr	rrr�can_paginater�logger�debugr'�
get_paginator�paginate�getattrr�append)rrA�cleaned_paramsr.r<r8�	paginatorr0r1r2�
page_itemsr3s            rr0zResourceCollection.pagesss�����(���"�"�)�)�����*�*�,���"�"�7�D�1��"�&�&�{�D�9�	�*�4�<�<����9L�9L�M���F�N��>����t�6�6�7��L�L�1����!�!�.�.��'�'��	
��,�,�T�-D�-D�E�I�&�I�&�&��.3��!K����E�

�L�L�'����!�!�.�.��'�'��	
�>�W�V�T�%<�%<�=�G��G�H�E����	�D��J��
�
�d�l�l�F�D�A�
���!�!�$�'���
���$��%���
���� �U�e�^��	�s�GG �G �	G �G �G c�"�|j�S)a
        Get all items from the collection, optionally with a custom
        page size and item count limit.

        This method returns an iterable generator which yields
        individual resource instances. Example use::

            # Iterate through items
            >>> for queue in sqs.queues.all():
            ...     print(queue.url)
            'https://url1'
            'https://url2'

            # Convert to list
            >>> queues = list(sqs.queues.all())
            >>> len(queues)
            2
        �r:r*s r�allzResourceCollection.all�s��&�{�{�}�rc�&�|jdi|��S)a�
        Get items from the collection, passing keyword arguments along
        as parameters to the underlying service operation, which are
        typically used to filter the results.

        This method returns an iterable generator which yields
        individual resource instances. Example use::

            # Iterate through items
            >>> for queue in sqs.queues.filter(Param='foo'):
            ...     print(queue.url)
            'https://url1'
            'https://url2'

            # Convert to list
            >>> queues = list(sqs.queues.filter(Param='foo'))
            >>> len(queues)
            2

        :rtype: :py:class:`ResourceCollection`
        r@rN�rrs  r�filterzResourceCollection.filter�s��,�t�{�{�$�V�$�$rc�&�|j|��S)a�
        Return at most this many resources.

            >>> for bucket in s3.buckets.limit(5):
            ...     print(bucket.name)
            'bucket1'
            'bucket2'
            'bucket3'
            'bucket4'
            'bucket5'

        :type count: int
        :param count: Return no more than this many items
        :rtype: :py:class:`ResourceCollection`
        �r.rN�rr1s  rr.zResourceCollection.limit�s�� �{�{��{�'�'rc�&�|j|��S)a3
        Fetch at most this many resources per service request.

            >>> for obj in s3.Bucket('boto3').objects.page_size(100):
            ...     print(obj.key)

        :type count: int
        :param count: Fetch this many items per request
        :rtype: :py:class:`ResourceCollection`
        �r<rNrUs  rr<zResourceCollection.page_size�s���{�{�U�{�+�+rN)
r%�
__module__�__qualname__�__doc__rr+r4r:r0rOrRr.r<r@rrrrs6���"-�
��:�0G�R�*%�0(�$,rrc�R�eZdZdZeZd�Zd�Zd�Zd�Z	ejje	_d�Z
ejje
_d�Zejje_d�Zejje_d	�Z
ejje
_y
)�CollectionManagera
    A collection manager provides access to resource collection instances,
    which can be iterated and filtered. The manager exposes some
    convenience functions that are also found on resource collections,
    such as :py:meth:`~ResourceCollection.all` and
    :py:meth:`~ResourceCollection.filter`.

    Get all items::

        >>> for bucket in s3.buckets.all():
        ...     print(bucket.name)

    Get only some items via filtering::

        >>> for queue in sqs.queues.filter(QueueNamePrefix='AWS'):
        ...     print(queue.url)

    Get whole pages of items:

        >>> for page in s3.Bucket('boto3').objects.pages():
        ...     for obj in page:
        ...         print(obj.key)

    A collection manager is not iterable. You **must** call one of the
    methods that return a :py:class:`ResourceCollection` before trying
    to iterate, slice, or convert to a list.

    See the :ref:`guide_collections` guide for a high-level overview
    of collections, including when remote service requests are performed.

    :type collection_model: :py:class:`~boto3.resources.model.Collection`
    :param model: Collection model

    :type parent: :py:class:`~boto3.resources.base.ServiceResource`
    :param parent: The collection's parent resource

    :type factory: :py:class:`~boto3.resources.factory.ResourceFactory`
    :param factory: The resource factory to create new resources

    :type service_context: :py:class:`~boto3.utils.ServiceContext`
    :param service_context: Context about the AWS service
    c���||_|jjj}||_|jj
}t
|||j||��|_y)N)�search_path�factory�resource_model�service_context�operation_name)rrrrr(�pathr
r)r�collection_modelrr_rarbr^s       rrzCollectionManager.__init__8sW��&������,�,�6�6�����&�/�/�4�4��'�#��+�4�4�+�)�
��
rc��dj|jj|jdj|jjj
|jjj��Sr!r"r*s rr+zCollectionManager.__repr__Fr,rc�h�|j|j|j|jfi|��S)z�
        Get a resource collection iterator from this manager.

        :rtype: :py:class:`ResourceCollection`
        :return: An iterable representing the collection of resources
        )�_collection_clsrrrrQs  r�iteratorzCollectionManager.iteratorOs4��$�t�#�#��K�K����t�}�}�
�8>�
�	
rc�"�|j�Sr�rhr*s rrOzCollectionManager.all[s���}�}��rc�&�|jdi|��S)Nr@rjrQs  rrRzCollectionManager.filter`s���t�}�}�&�v�&�&rc�&�|j|��S)NrTrjrUs  rr.zCollectionManager.limites���}�}�5�}�)�)rc�&�|j|��S)NrWrjrUs  rr<zCollectionManager.page_sizejs���}�}�u�}�-�-rc�>�|j�j�Sr)rhr0r*s rr0zCollectionManager.pagesos���}�}��$�$�&�&rN)r%rXrYrZrrgrr+rhrOrRr.r<r0r@rrr\r\	s���)�X)�O�
�
�	
��%�(�(�0�0�C�K�'�(�.�.�6�6�F�N�*�'�,�,�4�4�E�M�.�+�4�4�<�<�I��'�'�,�,�4�4�E�Mrr\c�(�eZdZdZd�Zd�Zd�Zd�Zy)�CollectionFactoryz�
    A factory to create new
    :py:class:`CollectionManager` and :py:class:`ResourceCollection`
    subclasses from a :py:class:`~boto3.resources.model.Collection`
    model. These subclasses include methods to perform batch operations.
    c��i}|j}|j||||j|�|j||||j|t��|j
|k(rdj
|j
|�}ndj
|j
||�}tt|�tf|�}|j||||j|t��||d<|dz
}tt|�tf|�S)a�
        Loads a collection from a model, creating a new
        :py:class:`CollectionManager` subclass
        with the correct properties and methods, named based on the service
        and resource name, e.g. ec2.InstanceCollectionManager. It also
        creates a new :py:class:`ResourceCollection` subclass which is used
        by the new manager class.

        :type resource_name: string
        :param resource_name: Name of the resource to look up. For services,
                              this should match the ``service_name``.

        :type service_context: :py:class:`~boto3.utils.ServiceContext`
        :param service_context: Context about the AWS service

        :type event_emitter: :py:class:`~botocore.hooks.HierarchialEmitter`
        :param event_emitter: An event emitter

        :rtype: Subclass of :py:class:`CollectionManager`
        :return: The collection class.
        )�attrs�
resource_namerd�
service_model�
event_emitter�
base_classz{}.{}Collectionz{}.{}.{}Collectionrg�Manager)
�name�_load_batch_actionsrt�#_load_documented_collection_methodsrr'r#r)�strr\)	rrsrdrarurr�collection_name�cls_name�collection_clss	         r�load_from_definitionz&CollectionFactory.load_from_definition}s#��0��*�/�/��	
� � �����)�)��	
�	
�0�0��'�-�)�7�7�'�)�
	1�	
��'�'�=�8�(�/�/��,�,�o��H�,�2�2��,�,�m�_��H��c�(�m�.@�-B�E�J��	
�0�0��'�-�)�7�7�'�(�
	1�	
�$2��� ��I����C��M�$5�#7��?�?rc	��|jD]0}t|j�}|j||||||�||<�2y)zv
        Batch actions on the collection become methods on both
        the collection manager and iterators.
        N)�
batch_actionsrrx�_create_batch_action)rrrrsrdrtru�action_model�snake_caseds        rryz%CollectionFactory._load_batch_actions�sP��-�:�:�		�L�$�\�%6�%6�7�K�!%�!:�!:���� ���
"�E�+��		rc�V���fd�}tj|d|||d��|_||d<�fd�}tj|d|||d��|_||d<�fd�}	tj|d|||d��|	_|	|d<�fd	�}
tj|d
|||d��|
_|
|d
<y)Nc�&���j|�Sr)rO)rrvs �rrOzBCollectionFactory._load_documented_collection_methods.<locals>.all�s����>�>�$�'�'rrOF)rs�action_namerurdrt�include_signaturec�*���j|fi|��Sr)rR)rrrvs  �rrRzECollectionFactory._load_documented_collection_methods.<locals>.filter�s���$�:�$�$�T�4�V�4�4rrRc�(���j||�SrrT�rr1rvs  �rr.zDCollectionFactory._load_documented_collection_methods.<locals>.limits����#�#�D�%�0�0rr.c�(���j||�SrrWr�s  �rr<zHCollectionFactory._load_documented_collection_methods.<locals>.page_sizes����'�'��e�4�4rr<)r�CollectionMethodDocstringrZ)�factory_selfrrrsrdrtrurvrOrRr.r<s      `    rrzz5CollectionFactory._load_documented_collection_methods�s���� 	(� �9�9�'��'�-�'�#�

�����e��	5�#�<�<�'� �'�-�'�#�

���!��h��	1�"�;�;�'��'�-�'�#�

��
���g��	5�&�?�?�'�#�'�-�'�#�

�	��'��k�rc���t|���fd�}t|�|_tj|||||d��|_|S)zs
        Creates a new method which makes a batch operation request
        to the underlying service API.
        c����|g|��i|��Srr@)r�argsr�actions   �r�batch_actionz<CollectionFactory._create_batch_action.<locals>.batch_action0s����$�0��0��0�0rF)rsru�batch_action_modelrtrdr�)rr{r%r�BatchActionDocstringrZ)	r�rsr�r�rdrtrur�r�s	        @rr�z&CollectionFactory._create_batch_action!sP����\�*��	1�!$�K� 0���(�=�=�'�'�+�'�-�#�
 
����rN)r%rXrYrZrryrzr�r@rrrprpus ���D@�L�.E'�Nrrp)r�logging�botocorer�botocore.utilsr�docsrr�rr8r	�responser
�	getLoggerr%rDrr\rpr@rr�<module>r�sW�����&���-�%�	��	�	�8�	$��j,�j,�Zi5�i5�XG�Gr