B 劇cO@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||_||_dS)N)name member_name)selfrrrp/private/var/folders/8c/hx9_v10d5x38qmnzt13b7b8j1k3n5b/T/pip-target-x6xd5gna/lib/python/boto3/resources/model.py__init__)szIdentifier.__init__)N)__name__ __module__ __qualname____doc__r rrrrr!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) _definitionrrRequestgetrResponseResourcer)rr definition resource_defsrrrr ;szAction.__init__N)r r r r r rrrrr/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 ||_dS)N)r)rrrrrr XszDefinitionWithParams.__init__cCs0g}x&|jdgD]}|tf|qW|S)zt Get a list of auto-filled parameters for this request. :type: list(:py:class:`Parameter`) params)rrappend Parameter)rritemrrrr[szDefinitionWithParams.paramsN)r r r r r propertyrrrrrrNsrc@seZdZdZdddZdS)ra 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)rrrrrr kwargsrrrr xszParameter.__init__)NNN)r r r r r rrrrrjs rcs eZdZdZfddZZS)rzt A service operation action request. :type definition: dict :param definition: The JSON definition cst||d|_dS)N operation)superr rr$)rr) __class__rrr s zRequest.__init__)r r r r r __classcell__rr)r&rrsrcs$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)rrr)r&rrr s zWaiter.__init__)r r r r PREFIXr r'rr)r&rr(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_defsrr*r)rrrrrrr s zResponseResource.__init__cCs0g}x&|jdgD]}|tf|qW|S)z^ A list of resource identifiers. :type: list(:py:class:`Identifier`) identifiers)rrrr)rr,rrrrr,szResponseResource.identifierscCst|j|j|j|jS)zm Get the resource model for the response resource. :type: :py:class:`ResourceModel` ) ResourceModelr*r+)rrrrmodelszResponseResource.modelN)r r r r r rr,r.rrrrrs 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`) )rr. batch_actions)rrrrr0s zCollection.batch_actionsN)r r r r rr0rrrrr/s r/c@seZdZdZddZd"ddZd#dd Zd$d d Zd d Ze ddZ e ddZ e ddZ e ddZ ddZddZe ddZe ddZe ddZe d d!ZdS)%r-a 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)rr+_renamedrrr1)rrrrrrrr s zResourceModel.__init__NcCsddh}i|_|jdr"|dx(|jdgD]}|||ddq2Wx$|jdiD]}|||dq\Wxj|D]Z\}}d}x&|d dD]}|d d krd }PqW|s|j||d ddq|||dqWx$|jdiD]}|||dqWx,|jdiD]}||tj|dqW|dk r`x"|j D]}|||dqHWdS)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. metaloadr,r identifieractionsactionFrrdataT subresource) snake_case referencehasMany collectionwaiterswaiterN attribute) r2rradd_load_name_with_category_get_has_definitionitemsr(r)memberskeys)rr1namesrrref data_requiredr5rrrload_rename_maps4&    zResourceModel.load_rename_mapTcCs~|r t|}||krptd|jd|d||d||j||f<|d|7}||krptd|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!debugrr2 ValueErrorformatrA)rrGrcategoryr:rrrrB]s 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. )rr2r)rrPrr:rrr _get_nameszResourceModel._get_namecCs^i}dd|jD}xD|jD]6\}}t|}||kr:q |jd|dd}||f||<q W|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..r@F)r:)r,rErDrrQ)rr1 attributesZidentifier_namesrmemberZ snake_casedrrrget_attributess zResourceModel.get_attributescCs\g}xR|jdgD]@}|d|d}|dd}|rD|d|}|t||qW|S)zb Get a list of resource identifiers. :type: list(:py:class:`Identifier`) r,r5rZ memberNameNr@)rrrQrr)rr,rrrrrrr,s  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`` r4N)rrrr+)rr7rrrr4s zResourceModel.loadcCsHg}x>|jdiD](\}}|d|}|t|||jqW|S)zc Get a list of actions for this resource. :type: list(:py:class:`Action`) r6r7)rrrDrQrrr+)rr6rrrrrr6s  zResourceModel.actionscCsHg}x>|jdiD](\}}|d|}|t|||jqW|S)zi Get a list of batch actions for this resource. :type: list(:py:class:`Action`) Z batchActionsZ batch_action)rrrDrQrrr+)rr6rrrrrr0s  zResourceModel.batch_actionsc Cs|j|jkri}x|jD]\}}d}|jdi}x2|D]*\}}|did|kr@|||<d}q@W|sd|gdi}x0|dgD] } |dd| dd d qW|||<qWn|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. Fhasrr*T)r*r,r,rinput)rr)rr+rDrrr) rrrZ resource_deffoundZ has_itemsZhas_nameZhas_defZfake_hasr5rrrrCs"  z!ResourceModel._get_has_definitioncCsg}x|D]\}}|r0|jd|dd}n |d|}t|||j}d}x |jjD]}|jdkrXd}PqXW|r|s||q|s|r||qW|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`) r9F)r:r;r8T) rCrDrQrr+rr,rr)r subresources resourcesrrr7rIr5rrr_get_related_resources+s    z$ResourceModel._get_related_resourcescCs |dS)zW Get a list of sub-resources. :type: list(:py:class:`Action`) T)r])rrrrr[JszResourceModel.subresourcescCs |dS)z] Get a list of reference resources. :type: list(:py:class:`Action`) F)r])rrrr referencesSszResourceModel.referencescCsHg}x>|jdiD](\}}|d|}|t|||jqW|S)zk Get a list of collections for this resource. :type: list(:py:class:`Collection`) r<r=)rrrDrQrr/r+)r collectionsrrrrrr_\s  zResourceModel.collectionscCsJg}x@|jdiD]*\}}|dtj|}|t||qW|S)zc Get a list of waiters for this resource. :type: list(:py:class:`Waiter`) r>r?)rrrDrQr(r)r)rr>rrrrrr>ks zResourceModel.waiters)N)T)T)r r r r r rJrBrQrWrr,r4r6r0rCr]r[r^r_r>rrrrr-s   N #     : r-)r loggingZbotocorer getLoggerr r!rrrrrr(rr/r-rrrrs  !.