Server : LiteSpeed
System : Linux server51.dnsbootclub.com 4.18.0-553.62.1.lve.el8.x86_64 #1 SMP Mon Jul 21 17:50:35 UTC 2025 x86_64
User : nandedex ( 1060)
PHP Version : 8.1.33
Disable Function : NONE
Directory :  /opt/cppython/lib/python3.8/site-packages/boto3/resources/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]


Current File : //opt/cppython/lib/python3.8/site-packages/boto3/resources/__pycache__/factory.cpython-38.pyc
U

Q��g�X�@s�ddlZddlmZddlmZddlmZddlmZm	Z	ddl
mZmZdd	l
mZdd
lmZddlmZmZe�e�ZGdd
�d
�ZdS)�N)�partial�)�	docstring)�ResourceLoadException�)�
ServiceAction�WaiterAction)�ResourceMeta�ServiceResource)�CollectionFactory)�
ResourceModel)�ResourceHandler�build_identifiersc@s�eZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zd d!�Zd&d#d$�Zd%S)'�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).
    cCst�|_||_dS�N)r�_collection_factory�_emitter)�selfZemitter�r�D/opt/cppython/lib/python3.8/site-packages/boto3/resources/factory.py�__init__%szResourceFactory.__init__c
Cs"t�d|j|�t|||j�}d}|jr6|j�|j�}|�|�t	|j|d�}d|i}|j
||||d�|j||||d�|j|||||d�|j
|||d�|j||||d�|j||||d�|}|j|kr�d	}|jd
|}tg}	|jdk	�r|jjd|��||	|d�tt|�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)rrrr
�.zcreating-resource-class.)Zclass_attributes�base_classesr)�logger�debug�service_namer�resource_json_definitions�shape�
service_model�	shape_forZload_rename_mapr	�_load_identifiers�
_load_actions�_load_attributes�_load_collections�_load_has_relations�
_load_waitersr
r�emit�type�str�tuple)
rr�single_resource_json_definitionrrr"rr�cls_namerrrr�load_from_definition)s����
�����	���
�z$ResourceFactory.load_from_definitioncCs0|jD]$}|j�|j�|�||�||j<qdS)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�
identifierrrrr%�s
�z!ResourceFactory._load_identifierscCsP|jr*|j|j||dd�|d<|d|d<|jD]}|j|||d�||j<q0dS)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)r7rrN)r9�_create_action�actionsr4)rrrrr�actionrrrr&�s�

�zResourceFactory._load_actionsc
Cs�|js
dS|j�|j�}dd�|jD�}|�|�}|��D]H\}	\}
}|	|krf|j|||	||d�}n|j||
|	||d�}|||	<q:dS)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``.
        NcSsi|]}|jr|j|�qSr)�member_name��.0�irrr�
<dictcomp>�s�z4ResourceFactory._load_attributes.<locals>.<dictcomp>)rr6�member_modelr)rr4�snake_casedrCr)r"r#r$r2Zget_attributes�items�_create_identifier_alias�_create_autoload_property)
rrrrrrr"r2�
attributesr4�	orig_name�member�proprrrr'�s.	�
��z ResourceFactory._load_attributescCs(|jD]}|j|j||d�||j<qdS)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_modelrN)�collections�_create_collectionr4)rrrrrLrrrr(�s
�z!ResourceFactory._load_collectionscCsV|jD]}|j|||d�||j<q|jD]}|j|||d�||j<q(|�||j�dS)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_modelrrN)Z
references�_create_referencer4�subresources�_create_class_partial�&_create_available_subresources_command)rrrrr�	reference�subresourcerrrr)�s 
�
��z#ResourceFactory._load_has_relationscs.dd�|D��t����fdd�}||d<dS)NcSsg|]
}|j�qSr�r4)r@rVrrr�
<listcomp>szJResourceFactory._create_available_subresources_command.<locals>.<listcomp>cs�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
            r)�factory_self�Z
_subresourcesrr�get_available_subresources s	zZResourceFactory._create_available_subresources_command.<locals>.get_available_subresourcesr[)�sorted)rrrRr[rrZrrTsz6ResourceFactory._create_available_subresources_commandcCs&|jD]}|j|||d�||j<qdS)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_modelrrN)�waiters�_create_waiterr4)rrrrr�waiterrrrr*-s
�zResourceFactory._load_waiterscs2�fdd�}t�j�|_tj|�dd�|_t|�S)zI
        Creates a read-only property for identifier attributes.
        cst|d�jd�S�N�_��getattrr4�r�r6rr�get_identifierAsz:ResourceFactory._create_identifier.<locals>.get_identifierF)rZidentifier_model�include_signature)r-r4�__name__rZIdentifierDocstring�__doc__�property)rYr6rrgrrfrr5<s	�z"ResourceFactory._create_identifiercs>�fdd�}t�j�|_tj|j|�j|j|dd�|_t|�S)zJ
        Creates a read-only property that aliases an identifier.
        cst|d�jd�SrarcrerfrrrgZsz@ResourceFactory._create_identifier_alias.<locals>.get_identifierF�r r�	attr_name�
event_emitterZ
attr_modelrh)	r-r>rir�AttributeDocstringr rrjrk)rYrr6rCrrgrrfrrFSs�	z(ResourceFactory._create_identifier_aliascs:�fdd�}t|�|_tj|j|||j|dd�|_t|�S)z�
        Creates a new property on the resource to lazy-load its value
        via the resource's ``load`` method (if it exists).
        cs@|jjdkr2t|d�r |��nt|jj�d���|jj���S)Nr9z has no load method)r�data�hasattrr9r�	__class__ri�getrerWrr�property_loaderzs

�zBResourceFactory._create_autoload_property.<locals>.property_loaderFrl)r-rirror rrjrk)rYrr4rDrCrrtrrWrrGis
�	z)ResourceFactory._create_autoload_propertycsHt||jd���fdd�}t|j�|_tj||j|j||jdd�|_	|S)zx
        Creates a new wait method for each resource where both a waiter and
        resource model is defined.
        )Zwaiter_resource_namecs�|f|�|�dSrr)r�args�kwargs�r`rr�	do_waiter�sz1ResourceFactory._create_waiter.<locals>.do_waiterF)rrnr#r]�service_waiter_modelrh)
rr4r-rirZResourceWaiterDocstringrr#ryrj)rYr]rrrxrrwrr_�s��zResourceFactory._create_waitercsL�jj|���jd������fdd�}t�j�|_tj�dd�|_t	|�S)zS
        Creates a new property on the resource to lazy-load a collection.
        )rrLrrncs��|��d�S)N)rL�parent�factoryrrre��clsrLrYrrr�get_collection�s�z:ResourceFactory._create_collection.<locals>.get_collectionF)rLrh)
rr1rr-r4rirZCollectionDocstringrjrk)rYrrLrr~rr|rrN�s��z"ResourceFactory._create_collectioncs^t|jj||j|d��tdd�|jjD�����fdd�}t|j�|_tj	|dd�|_
t|�S)zR
        Creates a new property on the resource to lazy-load a reference.
        )�search_pathr{rrcss|]}|jdkVqdS)rpN)�sourcer?rrr�	<genexpr>�sz4ResourceFactory._create_reference.<locals>.<genexpr>cs2�r"|jjdkr"t|d�r"|���|i|jj�S�Nr9)rrprqr9re��handlerZ
needs_datarr�
get_reference�sz8ResourceFactory._create_reference.<locals>.get_referenceF)rOrh)r
�resource�path�anyr2r-r4rirZReferenceDocstringrjrk)rYrOrrr�rr�rrQ�s 	�
��z!ResourceFactory._create_referencecs>�jj�����fdd�}t��|_tj|��jdd�|_|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	sng}�j��i�}�j�|�d�}�jj}|dk	rPt||�D]\}}|�|�q<t|f|�d|jj	i�||�S)N)rr/r�client)
r!rsr1r�r2rr3rrr�)	rrurvZpositional_argsZjson_defZresource_clsr2r6�value�rYr4rrPrr�create_resource�s*�����z>ResourceFactory._create_class_partial.<locals>.create_resourceF)rZsub_resource_modelr#rh)r�r,r-rirZSubResourceDocstringr#rj)rYrPrrr�rr�rrS�s
�z%ResourceFactory._create_class_partialFcsvt|||d��|r<�fdd�}tj|j||j||jdd�}n$�fdd�}tj||j||jdd�}t|j�|_||_	|S)zc
        Creates a new method which makes a request to the underlying
        AWS service.
        )r{rcs�|f|�|�}||j_dSr)rrp�rrurv�response�r=rr�	do_action4sz1ResourceFactory._create_action.<locals>.do_actionF)�action_namerrnZ
load_modelr#rhcs&�|f|�|�}t|d�r"d|j_|Sr�)rqrrpr�r�rrr�Ds
)rrnr7r#rh)
rrZLoadReloadDocstringr4rr#ZActionDocstringr-rirj)rYr7rrr8r�Zlazy_docstringrr�rr;s4���zResourceFactory._create_actionN)F)ri�
__module__�__qualname__rjrr1r%r&r'r(r)rTr*r5rFrGr_rNrQrSr;rrrrrs&w&$()3�r)�logging�	functoolsr�docsr�
exceptionsrr=rr�baser	r
Z
collectionr�modelrr�r
r�	getLoggerrirrrrrr�<module>s


F1le Man4ger