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

��e�X���ddlZddlmZddlmZddlmZddlmZm	Z	ddl
mZmZdd	l
mZdd
lmZddlmZmZej(e�ZGd�d
�Zy)�N)�partial�)�	docstring)�ResourceLoadException�)�
ServiceAction�WaiterAction)�ResourceMeta�ServiceResource)�CollectionFactory)�
ResourceModel)�ResourceHandler�build_identifiersc�z�eZdZdZd�Zd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�Z	dd�Zy)�ResourceFactoryaW
    A factory to create new :py:class:`~boto3.resources.base.ServiceResource`
    classes from a :py:class:`~boto3.resources.model.ResourceModel`. There are
    two types of lookups that can be done: one on the service itself (e.g. an
    SQS resource) and another on models contained within the service (e.g. an
    SQS Queue resource).
    c�0�t�|_||_y�N)r�_collection_factory�_emitter)�self�emitters  �9/usr/lib/python3/dist-packages/boto3/resources/factory.py�__init__zResourceFactory.__init__%s��#4�#6�� ���
�c��tjd|j|�t|||j�}d}|j
r%|jj|j
�}|j|�t|j|��}d|i}|j||||��|j||||��|j|||||��|j|||��|j||||��|j||||��|}|j|k(rd	}|jd
z|z}t g}	|j"�"|j"j%d|��||	|��t't)|�t+|	�|�S)
a{
        Loads a resource from a model, creating a new
        :py:class:`~boto3.resources.base.ServiceResource` subclass
        with the correct properties and methods, named based on the service
        and resource name, e.g. EC2.Instance.

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

        :type single_resource_json_definition: dict
        :param single_resource_json_definition:
            The loaded json of a single service resource or resource
            definition.

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

        :rtype: Subclass of :py:class:`~boto3.resources.base.ServiceResource`
        :return: The service or resource class.
        z
Loading %s:%sN)�resource_model�meta)�attrsr�
resource_namer)rrr�service_context)rrrrr )rrr r�.zcreating-resource-class.)�class_attributes�base_classesr )�logger�debug�service_namer
�resource_json_definitions�shape�
service_model�	shape_for�load_rename_mapr
�_load_identifiers�
_load_actions�_load_attributes�_load_collections�_load_has_relations�
_load_waitersrr�emit�type�str�tuple)
rr�single_resource_json_definitionr rr(rr�cls_namer#s
          r�load_from_definitionz$ResourceFactory.load_from_definition)s���0	����_�9�9�=�	
�
'��+��5�5�
�������#�1�1�;�;��$�$��E�	�&�&�u�-���(�(��
��
�D�
��	
�����'�)�		�	
�	
����'�)�+�		�	
�	
�����'�)�+�	�	
�	
����)�+�	�	
�	
� � ��'�)�+�		!�	
�	
����'�)�+�		�	
�!���'�'�=�8�(�H�"�/�/�#�5��@��'�(���=�=�$��M�M���*�8�*�5�!&�)� /�	
�
��C��M�5��#6��>�>rc��|jD]F}|jj|j�|j||�||j<�Hy)z�
        Populate required identifiers. These are arguments without which
        the resource cannot be used. Identifiers become arguments for
        operations on the resource.
        N)�identifiers�append�name�_create_identifier)rrrrr�
identifiers      rr,z!ResourceFactory._load_identifiers�sO��)�4�4�	�J����#�#�J�O�O�4�%)�%<�%<��M�&�E�*�/�/�"�	rc���|jr*|j|j||d��|d<|d|d<|jD]#}|j|||��||j<�%y)z�
        Actions on the resource become methods, with the ``load`` method
        being a special case which sets internal data for attributes, and
        ``reload`` is an alias for ``load``.
        T)�action_modelrr �is_load�load�reload)r@rr N)rB�_create_action�actionsr<)rrrrr �actions      rr-zResourceFactory._load_actions�s������ �/�/�+�0�0�+� /��	0��E�&�M�$�F�m�E�(�O�$�,�,�	�F�!%�!4�!4�#�+� /�"5�"�E�&�+�+��	rc��|jsy|jj|j�}|jD�cic]}|jr
|j|��}}|j|�}	|	j
�D]@\}
\}}|
|vr|j|||
||��}
n|j|||
||��}
|
||
<�Bycc}w)a
        Load resource attributes based on the resource shape. The shape
        name is referenced in the resource JSON, but the shape itself
        is defined in the Botocore service JSON, hence the need for
        access to the ``service_model``.
        N)rr>�member_modelr )rr<�snake_casedrHr )	r(r)r*r:�member_name�get_attributes�items�_create_identifier_alias�_create_autoload_property)rrrrrr r(�ir:�
attributesr<�	orig_name�member�props              rr.z ResourceFactory._load_attributes�s����#�#���-�-�7�7��8L�8L�M��$�/�/�
���}�}�
�M�M�1��
��
�
$�2�2�5�9�
�)3�)9�)9�);�	�%�D�%�9�f��{�"��4�4�"/�*�4�0�!'�$3�	5����5�5�"/�"� $�!'�$3�6����E�$�K�!	��

s� Cc�|�|jD]-}|j|j||��||j<�/y)a
        Load resource collections from the model. Each collection becomes
        a :py:class:`~boto3.resources.collection.CollectionManager` instance
        on the resource instance, which allows you to iterate and filter
        through the collection's items.
        )r�collection_modelr N)�collections�_create_collectionr<)rrrr rUs     rr/z!ResourceFactory._load_collections�sK��!/� :� :�	��+/�+B�+B�,�1�1�!1� /�,C�,�E�"�'�'�(�	rc��|jD]#}|j|||��||j<�%|jD]#}|j	|||��||j<�%|j||j�y)a�
        Load related resources, which are defined via a ``has``
        relationship but conceptually come in two forms:

        1. A reference, which is a related resource instance and can be
           ``None``, such as an EC2 instance's ``vpc``.
        2. A subresource, which is a resource constructor that will always
           return a resource instance which shares identifiers/data with
           this resource, such as ``s3.Bucket('name').Object('key')``.
        )�reference_modelrr )�subresource_modelrr N)�
references�_create_referencer<�subresources�_create_class_partial�&_create_available_subresources_command)rrrrr �	reference�subresources       rr0z#ResourceFactory._load_has_relations�s���(�2�2�	�I�%)�$:�$:� )�+� /�%;�%�E�)�.�.�!�		�*�6�6�	�K�'+�&@�&@�"-�+� /�'A�'�E�+�"�"�#�	�	
�3�3��>�.�.�	
rc�n��|D�cgc]}|j��c}�t����fd�}||d<ycc}w)Nc����S)z�
            Returns a list of all the available sub-resources for this
            Resource.

            :returns: A list containing the name of each sub-resource for this
                resource
            :rtype: list of str
            �)�factory_self�
_subresourcess �r�get_available_subresourceszZResourceFactory._create_available_subresources_command.<locals>.get_available_subresources s���!� rrg)r<�sorted)rrr]rargrfs     @rr_z6ResourceFactory._create_available_subresources_commands<���=I�J�k��)�)�J�
��}�-�
�		!�/I��*�+��Ks�2c�h�|jD]#}|j|||��||j<�%y)z�
        Load resource waiters from the model. Each waiter allows you to
        wait until a resource reaches a specific state by polling the state
        of the resource.
        )�resource_waiter_modelrr N)�waiters�_create_waiterr<)rrrrr �waiters      rr1zResourceFactory._load_waiters-s@��%�,�,�	�F�!%�!4�!4�&,�+� /�"5�"�E�&�+�+��	rc����fd�}t�j�|_tj|�d��|_t
|�S)zI
        Creates a read-only property for identifier attributes.
        c�8��t|d�jzd�S�N�_��getattrr<�rr>s �r�get_identifierz:ResourceFactory._create_identifier.<locals>.get_identifierAs����4��z���!6��=�=rF)r�identifier_model�include_signature)r4r<�__name__r�IdentifierDocstring�__doc__�property)rer>rrus `  rr=z"ResourceFactory._create_identifier<sD���
	>�#&�j�o�o�"6���!*�!>�!>�'�'�#�"
�����'�'rc�����fd�}t�j�|_tj|j
|�j|j|d��|_t|�S)zJ
        Creates a read-only property that aliases an identifier.
        c�8��t|d�jzd�Srprrrts �rruz@ResourceFactory._create_identifier_alias.<locals>.get_identifierZs����4��z���!6��=�=rF�r&r�	attr_name�
event_emitter�
attr_modelrw)	r4rJrxr�AttributeDocstringr&rrzr{)rerr>rHr rus  `   rrMz(ResourceFactory._create_identifier_aliasSsa���	>�#&�j�&<�&<�"=���!*�!=�!=�(�5�5�'� �,�,�&�/�/�#�#�
"
�����'�'rc����fd�}t|�|_tj|j|||j
|d��|_t|�S)z�
        Creates a new property on the resource to lazy-load its value
        via the resource's ``load`` method (if it exists).
        c���|jj�?t|d�r|j�n"t	|j
j�d���|jjj��S)NrBz has no load method)r�data�hasattrrBr�	__class__rx�get)rr<s �r�property_loaderzBResourceFactory._create_autoload_property.<locals>.property_loaderzsb����y�y�~�~�%��4��(��I�I�K�/��>�>�2�2�3�3F�G����9�9�>�>�%�%�d�+�+rFr~)r4rxrr�r&rrzr{)rerr<rIrHr r�s  `    rrNz)ResourceFactory._create_autoload_propertyisU���"		,�$'�{�#3�� �"+�">�">�(�5�5�'�!�&�/�/�#�#�
#
�����(�(rc����t||j����fd�}t|j�|_t	j
||j|j||jd��|_	|S)zx
        Creates a new wait method for each resource where both a waiter and
        resource model is defined.
        )�waiter_resource_namec����|g|��i|��yrrd)r�args�kwargsrms   �r�	do_waiterz1ResourceFactory._create_waiter.<locals>.do_waiter�s����4�)�$�)�&�)rF)rr�r)rj�service_waiter_modelrw)
r	r<r4rxr�ResourceWaiterDocstringrr)r�rz)rerjrr r�rms     @rrlzResourceFactory._create_waiter�su����!�!6�!;�!;�
��
	*�!�!6�!;�!;�<�	��%�=�=�'�&�/�/�)�7�7�"7�!0�!E�!E�#�

�	���rc��������jj|���j�������fd�}t�j�|_t
j�d��|_t|�S)zS
        Creates a new property on the resource to lazy-load a collection.
        )rrUr r�c�����|����S)N)rU�parent�factoryr rd)r�clsrUrer s ����r�get_collectionz:ResourceFactory._create_collection.<locals>.get_collection�s����!1��$� /�	�
rF)rUrw)
rr8rr4r<rxr�CollectionDocstringrzr{)rerrUr r�r�s` `` @rrWz"ResourceFactory._create_collection�ss����.�.�C�C�'�-�+�&�/�/�	D�
��	�#&�&6�&;�&;�"<���!*�!>�!>�-��"
�����'�'rc�:���t|jj||j|���td�|jjD�����fd�}t|j�|_tj|d��|_
t|�S)zR
        Creates a new property on the resource to lazy-load a reference.
        )�search_pathr�rr c3�:K�|]}|jdk(���y�w)r�N)�source)�.0rOs  r�	<genexpr>z4ResourceFactory._create_reference.<locals>.<genexpr>�s����
�#$�A�H�H���
�s�c����r2|jj�t|d�r|j��|i|jj�S�NrB)rr�r�rB)r�handler�
needs_datas ��r�
get_referencez8ResourceFactory._create_reference.<locals>.get_reference�s>����d�i�i�n�n�4���v�9N��	�	���4��T�Y�Y�^�^�4�4rF)rYrw)r�resource�path�anyr:r4r<rxr�ReferenceDocstringrzr{)rerYrr r�r�r�s     @@rr\z!ResourceFactory._create_reference�s����"�'�0�0�5�5� �*�3�3�+�	
���
�(7�(@�(@�(L�(L�
�
�
�
	5�"%�_�%9�%9�!:�
�� )� <� <�+�u�!
�
���
�&�&rc�������jj�����fd�}t��|_t	j
|��jd��|_|S)z�
        Creates a new method which acts as a functools.partial, passing
        along the instance's low-level `client` to the new resource
        class' constructor.
        c�4��g}�jj�
i�}�	j�
|���}�jj}|�%t||�D]\}}|j
|��t|g|��d|jji�|i|��S)N)rr6r �client)
r'r�r8r�r:rr;rrr�)
rr�r��positional_args�json_def�resource_clsr:r>�valuerer<r rZs
         ����r�create_resourcez>ResourceFactory._create_class_partial.<locals>.create_resource�s����!�O�'�@�@�D�D�T�2�N�H�'�<�<�"�08� /�=��L�,�4�4�@�@�K��&�):�;��)M�2�%�J��#�*�*�5�1�2��7���.��7;�y�y�7G�7G������
rF)r�sub_resource_modelr)rw)r�r3r4rxr�SubResourceDocstringr)rz)rerZrr r�r<s`` ` @rr^z%ResourceFactory._create_class_partial�sV���!�)�)�.�.��	�6$'�t�9�� �"+�"@�"@�'�0�)�7�7�#�	#
����rc�N��t|||���|r?�fd�}tj|j||j||j
d��}n3�fd�}tj||j||j
d��}t|j�|_||_	|S)zc
        Creates a new method which makes a request to the underlying
        AWS service.
        )r�r c�@���|g|��i|��}||j_yr)rr��rr�r��responserFs    �r�	do_actionz1ResourceFactory._create_action.<locals>.do_action4s"���!�$�8��8��8��!)��	�	�rF)�action_namerr��
load_modelr)rwc�Z���|g|��i|��}t|d�rd|j_|Sr�)r�rr�r�s    �rr�z1ResourceFactory._create_action.<locals>.do_actionDs3���!�$�8��8��8���4��(�&*�D�I�I�N��r)rr�r@r)rw)
rr�LoadReloadDocstringr<rr)�ActionDocstringr4rxrz)rer@rr rAr��lazy_docstringrFs       @rrDzResourceFactory._create_actions������,��
���
*�
'�:�:�(�-�-�+�*�3�3�'�-�;�;�"'�
�N�	
 �'�6�6�+�*�3�3�)�-�;�;�"'��N�!��!2�!2�3�	��*�	���rN)F)rx�
__module__�__qualname__rzrr8r,r-r.r/r0r_r1r=rMrNrlrWr\r^rDrdrrrrsi��� �u?�n
��0$�L�"
�HI�"
�(�.(�,&)�P�4(�6''�R,�f�<rr)�logging�	functoolsr�docsr�
exceptionsrrFrr	�baser
r�
collectionr�modelr
r�rr�	getLoggerrxr$rrdrr�<module>r�s@�����.�/�/�)� �8�	��	�	�8�	$��}�}r