o
    ܀c)1                     @   s   d dl Z d dlmZ d dlmZ d dlmZmZ d dlm	Z	m
Z
 dd Zdd	 ZG d
d dZG dd dZG dd dZG dd dZdS )    N)collections_abc)DocumentModifiedShape)ConditionBaseConditionExpressionBuilder)TypeDeserializerTypeSerializerc                 K   s   |  dt d S )Nr   )insertDynamoDBHighLevelResource)base_classeskwargs r   C/usr/local/lib/python3.10/dist-packages/boto3/dynamodb/transform.pyregister_high_level_interface   s   r   c                 K   s
   t | S N)copydeepcopy)paramsr   r   r   r   copy_dynamodb_params   s   
r   c                       s   e Zd Z fddZ  ZS )r	   c                    s  t  j|i | | jjjjjdtdd t | _| jjjjjd| jj	dd | jjjjjd| jj
dd | jjjjjd| jjdd td	d
ddd}tddddd}tddddd}| jjjjjd|jdd | jjjjjd|jdd | jjjjjd|jdd d S )Nzprovide-client-params.dynamodbzdynamodb-create-params-copy)	unique_idzbefore-parameter-build.dynamodbzdynamodb-condition-expressionzdynamodb-attr-value-inputzafter-call.dynamodbzdynamodb-attr-value-outputAttributeValuezvalid DynamoDB typez- The value of the attribute. The valid value types are listed in the :ref:`DynamoDB Reference Guide<ref_valid_dynamodb_types>`.z`'string'|123|Binary(b'bytes')|True|None|set(['string'])|set([123])|set([Binary(b'bytes')])|[]|{})new_typenew_descriptionnew_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<ref_dynamodb_conditions>`.zKey('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<ref_dynamodb_conditions>`.z!Attr('myattribute').eq('myvalue')z"docs.*.dynamodb.*.complete-sectionzdynamodb-attr-value-docszdynamodb-key-expression-docszdynamodb-cond-expression-docs)super__init__metaclienteventsregisterr   TransformationInjector	_injectorinject_condition_expressionsinject_attribute_value_inputinject_attribute_value_outputr   (replace_documentation_for_matching_shape)selfargsr   attr_value_shape_docskey_expression_shape_docscon_expression_shape_docs	__class__r   r   r      sn   
z"DynamoDBHighLevelResource.__init__)__name__
__module____qualname__r   __classcell__r   r   r,   r   r	      s    r	   c                   @   s:   e Zd ZdZ				dddZdd Zdd Zd	d
 ZdS )r!   z>Injects the transformations into the user provided parameters.Nc                 C   s`   || _ |d u rt | _ || _|d u rt | _|| _|d u r!t | _|| _|d u r.t | _d S d S r   )_transformerParameterTransformer_condition_builderr   _serializerr   _deserializerr   )r'   transformercondition_builder
serializerdeserializerr   r   r   r      s   zTransformationInjector.__init__c           	      K   s   | j   i }i }t| j ||dd}| j||j|d t| j ||dd}| j||j|d d}d}||v r?|| | n|rE|||< ||v rR|| | dS |rZ|||< dS dS )	a7  Injects 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_namesplaceholder_valuesis_key_conditionr   Tr   ExpressionAttributeNamesExpressionAttributeValuesN)r4   reset!ConditionExpressionTransformationr2   	transforminput_shapeupdate)	r'   r   modelr   generated_namesgenerated_valuestransformationexpr_attr_names_inputexpr_attr_values_inputr   r   r   r#      s@   


z3TransformationInjector.inject_condition_expressionsc                 K   s   | j ||j| jjd dS )z3Injects DynamoDB serialization into parameter inputr   N)r2   rB   rC   r5   	serialize)r'   r   rE   r   r   r   r   r$      s   z3TransformationInjector.inject_attribute_value_inputc                 K   s*   |j dur| j||j | jjd dS dS )z/Injects DynamoDB deserialization into responsesNr   )output_shaper2   rB   r6   deserialize)r'   parsedrE   r   r   r   r   r%      s   
z4TransformationInjector.inject_attribute_value_output)NNNN)r.   r/   r0   __doc__r   r#   r$   r%   r   r   r   r   r!      s    
2	r!   c                   @   s$   e Zd ZdZ	dddZdd ZdS )	rA   zProvides a transformation for condition expressions

    The ``ParameterTransformer`` class can call this class directly
    to transform the condition expressions in the parameters provided.
    Fc                 C   s   || _ || _|| _|| _d S r   )r4   _placeholder_names_placeholder_values_is_key_condition)r'   r8   r;   r<   r=   r   r   r   r      s   
z*ConditionExpressionTransformation.__init__c                 C   sB   t |tr| jj|| jd}| j|j | j|j	 |j
S |S )N)r=   )
isinstancer   r4   build_expressionrR   rP   rD   attribute_name_placeholdersrQ   attribute_value_placeholderscondition_expression)r'   valuebuilt_expressionr   r   r   __call__   s   
z*ConditionExpressionTransformation.__call__N)F)r.   r/   r0   rO   r   rZ   r   r   r   r   rA      s
    
rA   c                   @   s8   e Zd ZdZdd Zdd Zdd Zdd	 Zd
d ZdS )r3   z?Transforms the input to and output from botocore based on shapec                 C   s   |  |||| dS )a  Transforms 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'   r   rE   rH   target_shaper   r   r   rB     s   zParameterTransformer.transformc                 C   s0   |j }|dv rt| d| |||| d S d S )N)	structuremaplist_transform_)	type_namegetattr)r'   rE   r   rH   r\   ra   r   r   r   r[     s   z*ParameterTransformer._transform_parametersc                 C   sf   t |tjsd S |D ]&}||jv r0|j| }|j}||kr&||| ||< q
| ||| || q
d S r   )rS   r   Mappingmembersnamer[   )r'   rE   r   rH   r\   parammember_modelmember_shaper   r   r   _transform_structure"  s    

z)ParameterTransformer._transform_structurec           	      C   s\   t |tjsd S |j}|j}| D ]\}}||kr!||||< q| ||| || qd S r   )rS   r   rc   rX   re   itemsr[   )	r'   rE   r   rH   r\   value_modelvalue_shapekeyrX   r   r   r   _transform_map5     z#ParameterTransformer._transform_mapc           	      C   s\   t |tjsd S |j}|j}t|D ]\}}||kr!||||< q| ||| || qd S r   )rS   r   MutableSequencememberre   	enumerater[   )	r'   rE   r   rH   r\   rg   rh   iitemr   r   r   _transform_listB  ro   z$ParameterTransformer._transform_listN)	r.   r/   r0   rO   rB   r[   ri   rn   ru   r   r   r   r   r3     s    	r3   )r   boto3.compatr   boto3.docs.utilsr   boto3.dynamodb.conditionsr   r   boto3.dynamodb.typesr   r   r   r   r	   r!   rA   r3   r   r   r   r   <module>   s   d`'