B -<`T0@sddlZddlmZddlmZmZddlmZddlmZddl m Z ddZ d d Z Gd d d e ZGd dde ZGddde ZGddde ZdS)N)collections_abc)TypeSerializerTypeDeserializer) ConditionBase)ConditionExpressionBuilder)DocumentModifiedShapecKs|dtdS)Nr)insertDynamoDBHighLevelResource)Z base_classeskwargsr ?/tmp/pip-target-7cdyy134/lib/python/boto3/dynamodb/transform.pyregister_high_level_interfacesr cKs t|S)N)copydeepcopy)paramsr r r r copy_dynamodb_paramssrcseZdZfddZZS)r cstt|j|||jjjjjdtddt|_ |jjjjjd|j j dd|jjjjjd|j j dd|jjjjjd|j j ddt d d d d d }t ddddd }t ddddd }|jjjjjd|jdd|jjjjjd|jdd|jjjjjd|jdddS)Nzprovide-client-params.dynamodbzdynamodb-create-params-copy)Z 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)superr __init__metaclienteventsregisterrTransformationInjectorZ _injectorinject_condition_expressionsinject_attribute_value_inputinject_attribute_value_outputrZ(replace_documentation_for_matching_shape)selfargsr Zattr_value_shape_docsZkey_expression_shape_docsZcon_expression_shape_docs) __class__r r rsZ       z"DynamoDBHighLevelResource.__init__)__name__ __module__ __qualname__r __classcell__r r )r"r r sr c@s2eZdZdZd ddZddZddZd d ZdS) rz>Injects the transformations into the user provided parameters.NcCs\||_|dkrt|_||_|dkr,t|_||_|dkrBt|_||_|dkrXt|_dS)N) _transformerParameterTransformer_condition_builderr _serializerr _deserializerr)r Z 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_conditionrTrZExpressionAttributeNamesZExpressionAttributeValuesN)r)reset!ConditionExpressionTransformationr' transform input_shapeupdate) r rmodelr Zgenerated_namesZgenerated_valuestransformationZexpr_attr_names_inputZexpr_attr_values_inputr r r rs: z3TransformationInjector.inject_condition_expressionscKs|j||j|jjddS)z3Injects DynamoDB serialization into parameter inputrN)r'r3r4r* serialize)r rr6r r r r rs z3TransformationInjector.inject_attribute_value_inputcKs&|jdk r"|j||j|jjddS)z/Injects DynamoDB deserialization into responsesNr)Z output_shaper'r3r+Z deserialize)r parsedr6r r r r rs  z4TransformationInjector.inject_attribute_value_output)NNNN)r#r$r%__doc__rrrrr r r r r{s  2rc@s"eZdZdZdddZddZdS) r2zProvides 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)r)_placeholder_names_placeholder_values_is_key_condition)r r,r.r/r0r r r rsz*ConditionExpressionTransformation.__init__cCsBt|tr>|jj||jd}|j|j|j|j |j S|S)N)r0) isinstancerr)Zbuild_expressionr=r;r5Zattribute_name_placeholdersr<Zattribute_value_placeholdersZcondition_expression)r valueZbuilt_expressionr r r __call__s  z*ConditionExpressionTransformation.__call__N)F)r#r$r%r:rr@r r r r r2s r2c@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)r rr6r7 target_shaper r r r3s zParameterTransformer.transformcCs*|j}|dkr&t|d|||||dS)N)Z structuremaplistz _transform_%s) type_namegetattr)r r6rr7rBrEr r r rAs z*ParameterTransformer._transform_parameterscCsjt|tjsdSxT|D]L}||jkr|j|}|j}||krN|||||<q||||||qWdS)N)r>rMappingmembersnamerA)r r6rr7rBparam member_model member_shaper r r _transform_structures     z)ParameterTransformer._transform_structurec Cs`t|tjsdS|j}|j}x>|D]2\}}||krD||||<q&||||||q&WdS)N)r>rrGr?rIitemsrA) r r6rr7rBZ value_modelZ value_shapekeyr?r r r _transform_maps z#ParameterTransformer._transform_mapc Cs`t|tjsdS|j}|j}x>t|D]2\}}||krD||||<q&||||||q&WdS)N)r>rMutableSequencememberrI enumeraterA) r r6rr7rBrKrLiitemr r r _transform_list"s z$ParameterTransformer._transform_listN) r#r$r%r:r3rArMrPrVr r r r r(s  r()rZ boto3.compatrZboto3.dynamodb.typesrrZboto3.dynamodb.conditionsrrZboto3.docs.utilsrr robjectr rr2r(r r r r  s    ]U