o dO@sdZddlZddlmZeeZGdddZGdddZGdd d Z Gd d d Z Gd d d e Z Gddde Z GdddZ GdddeZGdddZdS)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)selfrrrp/private/var/folders/v1/_jykv66s6qd26_69j1njbrl80000gr/T/pip-target-p1gutpg6/lib/python/boto3/resources/model.py__init__)s zIdentifier.__init__r__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|vrt|di|_d|_d|vr't|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 Xs zDefinitionWithParams.__init__cC0g}|jdgD] }|tdi|q |S)zt Get a list of auto-filled parameters for this request. :type: list(:py:class:`Parameter`) paramsNrrrappend Parameter)rritemrrr r[zDefinitionWithParams.paramsN)r r rrr propertyrrrrr rNs  rc@seZdZdZ dddZdS)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`` NcKs6||_||_||_||_||_|rtd|dSdS)Nz#Unknown parameter options found: %s)targetsourcerrvalueloggerwarning)rr%r&rrr'kwargsrrr r xszParameter.__init__)NNNr rrrr r!jsr!cs eZdZdZfddZZS)rzt A service operation action request. :type definition: dict :param definition: The JSON definition cst||d|_dS)N operation)superr rr+r __class__rr r s zRequest.__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"t|||_|d|_dS)NZ waiterName)r,r rrZ waiter_name)rrrr-rr r s zWaiter.__init__)r r rrPREFIXr r/rrr-r r0s r0c@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_defsrr2r)rrrrrr r s zResponseResource.__init__cCr)z^ A list of resource identifiers. :type: list(:py:class:`Identifier`) identifiersNrr)rr4r"rrr r4r#zResponseResource.identifierscCst|j|j|j|jS)zm Get the resource model for the response resource. :type: :py:class:`ResourceModel` ) ResourceModelr2r3rrrr modelszResponseResource.modelN)r r rrr r$r4r7rrrr 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`) )rr7 batch_actionsr6rrr r9s zCollection.batch_actionsN)r r rrr$r9rrrr r8s r8c@seZdZdZddZd"ddZd#dd Zd#d d Zd d Ze ddZ e ddZ e ddZ e ddZ ddZddZe ddZe ddZe ddZe d d!ZdS)$r5a 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)rr3_renamedrrr:rrrr r s zResourceModel.__init__NcCsHdh}i|_|jdr|d|jdgD] }|||ddq|jdiD] }|||dq+|D],\}}d}|d dD] }|d d krSd }nqG|s`|j||d ddq;|||dq;|jdiD] }|||dqo|jdiD] }||tj|dq|dur|j D] }|||dqdSdS)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. metaloadr4r identifieractionsactionFrr&dataT subresource snake_case referencehasMany collectionwaiterswaiterN attribute) r;rradd_load_name_with_category_get_has_definitionitemsr0r1memberskeys)rr:namesr"rref data_requiredr>rrr load_rename_maps>&    zResourceModel.load_rename_mapTcCs~|rt|}||vr8td|jd|d||d||j||f<|d|7}||vr8td|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. z Renaming  _zProblem renaming {} {} to {}!N)rr(debugrr; ValueErrorformatrK)rrQrcategoryrDrrr rL]s z&ResourceModel._load_name_with_categorycCs|rt|}|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. )rr;r)rrZrrDrrr _get_nameszResourceModel._get_namecCsZi}dd|jD}|jD]\}}t|}||vrq|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..rJFrC)r4rOrNrr[)rr: attributesZidentifier_namesrmemberZ snake_casedrrr get_attributesszResourceModel.get_attributescCsXg}|jdgD] }|d|d}|dd}|r!|d|}|t||q |S)zb Get a list of resource identifiers. :type: list(:py:class:`Identifier`) r4r>rZ memberNameNrJ)rrr[r r)rr4r"rrrrr r4s  zResourceModel.identifierscCs&|jd}|durtd||j}|S)zy Get the load action for this resource, if it is defined. :type: :py:class:`Action` or ``None`` r=N)rrrr3)rr@rrr r=s zResourceModel.loadcCDg}|jdiD]\}}|d|}|t|||jq |S)zc Get a list of actions for this resource. :type: list(:py:class:`Action`) r?r@rrrNr[r rr3rr?rr"rrr r?  zResourceModel.actionscCrb)zi Get a list of batch actions for this resource. :type: list(:py:class:`Action`) Z batchActionsZ batch_actionrcrdrrr r9rezResourceModel.batch_actionsc Cs|j|jvr[i}|jD]K\}}d}|jdi}|D]\}}|did|kr3|||<d}q|sXd|gdi}|dgD]} |dd| dd d qC|||<q |S|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. Fhasrr2T)r2r4r4rinput)r%r&)rr3rNrrr ) rrrZ resource_deffoundZ has_itemsZhas_nameZhas_defZfake_hasr>rrr rMs*    z!ResourceModel._get_has_definitioncCsg}|D]A\}}|r|jd|dd}n|d|}t|||j}d}|jjD] }|jdkr5d}nq*|r@|s@||q|sI|rI||q|S)z 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:`Action`) rBFrCrErAT) rMrNr[rr3rr4r&r )r subresources resourcesrrr@rSr>rrr _get_related_resources+s$      z$ResourceModel._get_related_resourcescC |dS)zW Get a list of sub-resources. :type: list(:py:class:`Action`) Trkr6rrr riJ zResourceModel.subresourcescCrl)z] Get a list of reference resources. :type: list(:py:class:`Action`) Frmr6rrr referencesSrnzResourceModel.referencescCrb)zk Get a list of collections for this resource. :type: list(:py:class:`Collection`) rFrG)rrrNr[r r8r3)r collectionsrr"rrr rp\rezResourceModel.collectionscCsFg}|jdiD]\}}|dtj|}|t||q |S)zc Get a list of waiters for this resource. :type: list(:py:class:`Waiter`) rHrI)rrrNr[r0r1r )rrHrr"rrr rHks zResourceModel.waitersr)T)r r rrr rTrLr[rar$r4r=r?r9rMrkrirorprHrrrr r5s2 N #    :   r5)rloggingZbotocorer getLoggerr r(rrrr!rr0rr8r5rrrr s   !.