B 劇cm2@sddlZddlmZddlmZddlmZmZddlm Z m Z ddZ Gdd d e Z d d ZGd d d ZGdddZGdddZGdddZdS)N)collections_abc)DocumentModifiedShape) ConditionBaseConditionExpressionBuilder)TypeDeserializerTypeSerializercKs|dtdS)Nr)insertDynamoDBHighLevelResource)Z base_classeskwargsr s/private/var/folders/8c/hx9_v10d5x38qmnzt13b7b8j1k3n5b/T/pip-target-x6xd5gna/lib/python/boto3/dynamodb/transform.pyregister_high_level_interfacesr c@seZdZdZddZdS)_ForgetfulDictzA dictionary that discards any items set on it. For use as `memo` in `copy.deepcopy()` when every instance of a repeated object in the deepcopied data structure should result in a separate copy. cCsdS)Nr )selfkeyvaluer r r __setitem__sz_ForgetfulDict.__setitem__N)__name__ __module__ __qualname____doc__rr r r r rsrcKstj|tdS)N)memo)copydeepcopyr)paramsr r r r copy_dynamodb_params#srcseZdZfddZZS)r cstj|||jjjjjdtddt|_|jjjjjd|jj dd|jjjjjd|jj dd|jjjjjd|jj ddt d d d d d }t ddddd }t ddddd }|jjjjjd|j dd|jjjjjd|j dd|jjjjjd|j dddS)Nzprovide-client-params.dynamodbzdynamodb-create-params-copy) unique_idzbefore-parameter-build.dynamodbzdynamodb-condition-expressionzdynamodb-attr-value-inputzafter-call.dynamodbzdynamodb-attr-value-outputAttributeValuezvalid DynamoDB typez- The value of the attribute. The valid value types are listed in the :ref:`DynamoDB Reference Guide`.z`'string'|123|Binary(b'bytes')|True|None|set(['string'])|set([123])|set([Binary(b'bytes')])|[]|{})new_typeZnew_descriptionZnew_example_value KeyExpressionz?condition from :py:class:`boto3.dynamodb.conditions.Key` methodzThe condition(s) a key(s) must meet. Valid conditions are listed in the :ref:`DynamoDB Reference Guide`.zKey('mykey').eq('myvalue')ConditionExpressionz@condition from :py:class:`boto3.dynamodb.conditions.Attr` methodzThe condition(s) an attribute(s) must meet. Valid conditions are listed in the :ref:`DynamoDB Reference Guide`.z!Attr('myattribute').eq('myvalue')z"docs.*.dynamodb.*.complete-sectionzdynamodb-attr-value-docszdynamodb-key-expression-docszdynamodb-cond-expression-docs)super__init__metaclienteventsregisterrTransformationInjectorZ _injectorinject_condition_expressionsinject_attribute_value_inputinject_attribute_value_outputrZ(replace_documentation_for_matching_shape)rargsr Zattr_value_shape_docsZkey_expression_shape_docsZcon_expression_shape_docs) __class__r r r"(sZ       z"DynamoDBHighLevelResource.__init__)rrrr" __classcell__r r )r,r r 'sr c@s2eZdZdZd ddZddZddZd d ZdS) r'z>Injects the transformations into the user provided parameters.NcCs\||_|dkrt|_||_|dkr,t|_||_|dkrBt|_||_|dkrXt|_dS)N) _transformerParameterTransformer_condition_builderr _serializerr _deserializerr)rZ transformercondition_builder serializerZ deserializerr r r r"szTransformationInjector.__init__c Ks|ji}i}t|j||dd}|j||j|dt|j||dd}|j||j|dd}d}||kr~|||n |r|||<||kr|||n |r|||<dS) a7Injects the condition expression transformation into the parameters This injection includes transformations for ConditionExpression shapes and KeyExpression shapes. It also handles any placeholder names and values that are generated when transforming the condition expressions. F)placeholder_namesplaceholder_valuesis_key_conditionr TrZExpressionAttributeNamesZExpressionAttributeValuesN)r0reset!ConditionExpressionTransformationr. transform input_shapeupdate) rrmodelr Zgenerated_namesZgenerated_valuestransformationZexpr_attr_names_inputZexpr_attr_values_inputr r r r(s6 z3TransformationInjector.inject_condition_expressionscKs|j||j|jjddS)z3Injects DynamoDB serialization into parameter inputrN)r.r:r;r1 serialize)rrr=r r r r r)s z3TransformationInjector.inject_attribute_value_inputcKs&|jdk r"|j||j|jjddS)z/Injects DynamoDB deserialization into responsesNr)Z output_shaper.r:r2Z deserialize)rparsedr=r r r r r*s  z4TransformationInjector.inject_attribute_value_output)NNNN)rrrrr"r(r)r*r r r r r's 2 r'c@s"eZdZdZdddZddZdS) r9zProvides a transformation for condition expressions The ``ParameterTransformer`` class can call this class directly to transform the condition expressions in the parameters provided. FcCs||_||_||_||_dS)N)r0_placeholder_names_placeholder_values_is_key_condition)rr3r5r6r7r r r r"sz*ConditionExpressionTransformation.__init__cCsBt|tr>|jj||jd}|j|j|j|j |j S|S)N)r7) isinstancerr0Zbuild_expressionrCrAr<Zattribute_name_placeholdersrBZattribute_value_placeholdersZcondition_expression)rrZbuilt_expressionr r r __call__s  z*ConditionExpressionTransformation.__call__N)F)rrrrr"rEr r r r r9s r9c@s8eZdZdZddZddZddZdd Zd d Zd S) r/z?Transforms the input to and output from botocore based on shapecCs|||||dS)aTransforms the dynamodb input to or output from botocore It applies a specified transformation whenever a specific shape name is encountered while traversing the parameters in the dictionary. :param params: The parameters structure to transform. :param model: The operation model. :param transformation: The function to apply the parameter :param target_shape: The name of the shape to apply the transformation to N)_transform_parameters)rrr=r> target_shaper r r r:s zParameterTransformer.transformcCs,|j}|dkr(t|d|||||dS)N)Z structuremaplistZ _transform_) type_namegetattr)rr=rr>rGrJr r r rF#sz*ParameterTransformer._transform_parameterscCsjt|tjsdSxT|D]L}||jkr|j|}|j}||krN|||||<q||||||qWdS)N)rDrMappingmembersnamerF)rr=rr>rGparam member_model member_shaper r r _transform_structure,s    z)ParameterTransformer._transform_structurec Cs`t|tjsdS|j}|j}x>|D]2\}}||krD||||<q&||||||q&WdS)N)rDrrLrrNitemsrF) rr=rr>rGZ value_modelZ value_shaperrr r r _transform_map?s z#ParameterTransformer._transform_mapc Cs`t|tjsdS|j}|j}x>t|D]2\}}||krD||||<q&||||||q&WdS)N)rDrMutableSequencememberrN enumeraterF) rr=rr>rGrPrQiitemr r r _transform_listLs z$ParameterTransformer._transform_listN) rrrrr:rFrRrTrZr r r r r/s   r/)rZ boto3.compatrZboto3.docs.utilsrZboto3.dynamodb.conditionsrrZboto3.dynamodb.typesrrr dictrrr r'r9r/r r r r  s   d`'