U C^P@sdZddlZddlmZeeZGdddeZGdddeZ Gdd d eZ Gd d d eZ Gd d d e Z Gddde Z GdddeZGddde ZGdddeZdS)a The models defined in this file represent the resource JSON description format and provide a layer of abstraction from the raw JSON. The advantages of this are: * Pythonic interface (e.g. ``action.request.operation``) * Consumers need not change for minor JSON changes (e.g. renamed field) These models are used both by the resource factory to generate resource classes as well as by the documentation generator. N) xform_namec@seZdZdZdddZdS) Identifierzw A resource identifier, given by its name. :type name: string :param name: The name of the identifier NcCs||_||_dSN)name member_name)selfrrr8/tmp/pip-install-6_kvzl1k/boto3/boto3/resources/model.py__init__)szIdentifier.__init__)N__name__ __module__ __qualname____doc__r rrrr r"src@seZdZdZddZdS)Actiona A service operation action. :type name: string :param name: The name of the action :type definition: dict :param definition: The JSON definition :type resource_defs: dict :param resource_defs: All resources defined in the service cCs^||_||_d|_d|kr,t|di|_d|_d|krNt|di||_|d|_dS)Nrequestresourcepath) _definitionrrRequestgetrResponseResourcerrr definition resource_defsrrr r :s zAction.__init__Nr rrrr r/s rc@s$eZdZdZddZeddZdS)DefinitionWithParamsa An item which has parameters exposed via the ``params`` property. A request has an operation and parameters, while a waiter has a name, a low-level waiter name and parameters. :type definition: dict :param definition: The JSON definition cCs ||_dSr)rrrrrr r UszDefinitionWithParams.__init__cCs,g}|jdgD]}|tf|q|S)zt Get a list of auto-filled parameters for this request. :type: list(:py:class:`Parameter`) paramsrrappend Parameter)rritemrrr rXszDefinitionWithParams.paramsN)r r rrr propertyrrrrr rLsrc@seZdZdZdddZdS)r a An auto-filled parameter which has a source and target. For example, the ``QueueUrl`` may be auto-filled from a resource's ``url`` identifier when making calls to ``queue.receive_messages``. :type target: string :param target: The destination parameter name, e.g. ``QueueUrl`` :type source_type: string :param source_type: Where the source is defined. :type source: string :param source: The source name, e.g. ``Url`` NcKs2||_||_||_||_||_|r.td|dS)Nz#Unknown parameter options found: %s)targetsourcerrvalueloggerwarning)rr#r$rrr%kwargsrrr r tszParameter.__init__)NNNr rrrr r gs r cs eZdZdZfddZZS)rzt A service operation action request. :type definition: dict :param definition: The JSON definition cs tt|||d|_dS)N operation)superrr rr)r __class__rr r szRequest.__init__)r r rrr __classcell__rrr+r rsrcs$eZdZdZdZfddZZS)Waiterz An event waiter specification. :type name: string :param name: Name of the waiter :type definition: dict :param definition: The JSON definition Z WaitUntilcs&tt||||_|d|_dS)NZ waiterName)r*r.r rrZ waiter_name)rrrr+rr r szWaiter.__init__)r r rrPREFIXr r-rrr+r r.sr.c@s0eZdZdZddZeddZeddZdS) rz A resource response to create after performing an action. :type definition: dict :param definition: The JSON definition :type resource_defs: dict :param resource_defs: All resources defined in the service cCs(||_||_|d|_|d|_dS)Ntyper)r_resource_defsrr0r)rrrrrr r s zResponseResource.__init__cCs,g}|jdgD]}|tf|q|S)z^ A list of resource identifiers. :type: list(:py:class:`Identifier`) identifiersr)rr2r!rrr r2s zResponseResource.identifierscCst|j|j|j|jS)zm Get the resource model for the response resource. :type: :py:class:`ResourceModel` ) ResourceModelr0r1rrrr modelszResponseResource.modelN)r r rrr r"r2r5rrrr rs   rc@seZdZdZeddZdS) Collectiona A group of resources. See :py:class:`Action`. :type name: string :param name: The name of the collection :type definition: dict :param definition: The JSON definition :type resource_defs: dict :param resource_defs: All resources defined in the service cCs |jjjS)z Get a list of batch actions supported by the resource type contained in this action. This is a shortcut for accessing the same information through the resource model. :rtype: list(:py:class:`Action`) )rr5 batch_actionsr4rrr r7s zCollection.batch_actionsN)r r rrr"r7rrrr r6s r6c@seZdZdZddZd"ddZd#dd Zd$d d Zd d Ze ddZ e ddZ e ddZ e ddZ ddZddZe ddZe ddZe ddZe d d!ZdS)%r3a A model representing a resource, defined via a JSON description format. A resource has identifiers, attributes, actions, sub-resources, references and collections. For more information on resources, see :ref:`guide_resources`. :type name: string :param name: The name of this resource, e.g. ``sqs`` or ``Queue`` :type definition: dict :param definition: The JSON definition :type resource_defs: dict :param resource_defs: All resources defined in the service cCs(||_||_i|_||_|d|_dS)Nshape)rr1_renamedrrr8rrrr r s zResourceModel.__init__NcCsNtdg}i|_|jdr&|d|jdgD]}|||ddq4|jdiD]}|||dqZ|D]X\}}d}|d dD]}|d d krd }qq|s|j||d ddqz|||dqz|jdiD]}|||dq|jdiD]}||tj |dq|dk rJ|j D]}|||dq4dS)a Load a name translation map given a shape. This will set up renamed values for any collisions, e.g. if the shape, an action, and a subresource all are all named ``foo`` then the resource will have an action ``foo``, a subresource named ``Foo`` and a property named ``foo_attribute``. This is the order of precedence, from most important to least important: * Load action (resource.load) * Identifiers * Actions * Subresources * References * Collections * Waiters * Attributes (shape members) Batch actions are only exposed on collections, so do not get modified here. Subresources use upper camel casing, so are unlikely to collide with anything but other subresources. Creates a structure like this:: renames = { ('action', 'id'): 'id_action', ('collection', 'id'): 'id_collection', ('attribute', 'id'): 'id_attribute' } # Get the final name for an action named 'id' name = renames.get(('action', 'id'), 'id') :type shape: botocore.model.Shape :param shape: The underlying shape for this resource. metaloadr2r identifieractionsactionFrr$dataT subresource snake_case referencehasMany collectionwaiterswaiterN attribute) setr9rradd_load_name_with_category_get_has_definitionitemsr.r/memberskeys)rr8namesr!rref data_requiredr<rrr load_rename_maps8&      zResourceModel.load_rename_mapTcCsv|r t|}||krhtd|j||f|d||j||f<|d|7}||krhtd|j||||dS)a Load a name with a given category, possibly renaming it if that name is already in use. The name will be stored in ``names`` and possibly be set up in ``self._renamed``. :type names: set :param names: Existing names (Python attributes, properties, or methods) on the resource. :type name: string :param name: The original name of the value. :type category: string :param category: The value type, such as 'identifier' or 'action' :type snake_case: bool :param snake_case: True (default) if the name should be snake cased. zRenaming %s %s %s_z Problem renaming {0} {1} to {2}!N)rr&debugrr9 ValueErrorformatrJ)rrPrcategoryrBrrr rKQs z&ResourceModel._load_name_with_categorycCs|r t|}|j||f|S)a] Get a possibly renamed value given a category and name. This uses the rename map set up in ``load_rename_map``, so that method must be called once first. :type category: string :param category: The value type, such as 'identifier' or 'action' :type name: string :param name: The original name of the value :type snake_case: bool :param snake_case: True (default) if the name should be snake cased. :rtype: string :return: Either the renamed value if it is set, otherwise the original name. )rr9r)rrXrrBrrr _get_namerszResourceModel._get_namecCsZi}dd|jD}|jD]6\}}t|}||kr8q|jd|dd}||f||<q|S)a Get a dictionary of attribute names to original name and shape models that represent the attributes of this resource. Looks like the following: { 'some_name': ('SomeName', ) } :type shape: botocore.model.Shape :param shape: The underlying shape for this resource. :rtype: dict :return: Mapping of resource attributes. cSsg|] }|jqSr)r).0irrr sz0ResourceModel.get_attributes..rHFrA)r2rNrMrrY)rr8 attributesZidentifier_namesrmemberZ snake_casedrrr get_attributesszResourceModel.get_attributescCsXg}|jdgD]@}|d|d}|dd}|rB|d|}|t||q|S)zb Get a list of resource identifiers. :type: list(:py:class:`Identifier`) r2r<rZ memberNameNrH)rrrYrr)rr2r!rrrrr r2s  zResourceModel.identifierscCs&|jd}|dk r"td||j}|S)zy Get the load action for this resource, if it is defined. :type: :py:class:`Action` or ``None`` r;N)rrrr1)rr>rrr r;s zResourceModel.loadcCsDg}|jdiD](\}}|d|}|t|||jq|S)zc Get a list of actions for this resource. :type: list(:py:class:`Action`) r=r>rrrMrYrrr1rr=rr!rrr r=s  zResourceModel.actionscCsDg}|jdiD](\}}|d|}|t|||jq|S)zi Get a list of batch actions for this resource. :type: list(:py:class:`Action`) Z batchActionsZ batch_actionr`rarrr r7s  zResourceModel.batch_actionsc Cs|j|jkri}|jD]\}}d}|jdi}|D]*\}}|did|kr<|||<d}q<|sd|gdi}|dgD] } |dd| dd d q|||<qn|jdi}|S) a Get a ``has`` relationship definition from a model, where the service resource model is treated special in that it contains a relationship to every resource defined for the service. This allows things like ``s3.Object('bucket-name', 'key')`` to work even though the JSON doesn't define it explicitly. :rtype: dict :return: Mapping of names to subresource and reference definitions. FZhasrr0T)r0r2r2rinput)r#r$)rr1rMrrr) rrrZ resource_deffoundZ has_itemsZhas_nameZhas_defZfake_hasr<rrr rLs.     z!ResourceModel._get_has_definitioncCsg}|D]\}}|r.|jd|dd}n |d|}t|||j}d}|jjD]}|jdkrTd}qlqT|r|s||q|s|r||q|S)a Get a list of sub-resources or references. :type subresources: bool :param subresources: ``True`` to get sub-resources, ``False`` to get references. :rtype: list(:py:class:`ResponseResource`) r@FrArCr?T) rLrMrYrr1rr2r$r)r subresources resourcesrrr>rRr<rrr _get_related_resources!s      z$ResourceModel._get_related_resourcescCs |dS)za Get a list of sub-resources. :type: list(:py:class:`ResponseResource`) Trfr4rrr rd@szResourceModel.subresourcescCs |dS)zg Get a list of reference resources. :type: list(:py:class:`ResponseResource`) Frgr4rrr referencesIszResourceModel.referencescCsDg}|jdiD](\}}|d|}|t|||jq|S)zk Get a list of collections for this resource. :type: list(:py:class:`Collection`) rDrE)rrrMrYrr6r1)r collectionsrr!rrr riRs  zResourceModel.collectionscCsFg}|jdiD]*\}}|dtj|}|t||q|S)zc Get a list of waiters for this resource. :type: list(:py:class:`Waiter`) rFrG)rrrMrYr.r/r)rrFrr!rrr rFas zResourceModel.waiters)N)T)T)r r rrr rSrKrYr_r"r2r;r=r7rLrfrdrhrirFrrrr r3s2  M !     ?   r3)rloggingZbotocorer getLoggerr r&objectrrrr rr.rr6r3rrrr s    -