
    /Jf:                        d dl Z d dlmZ d dlmZmZmZ  e j        d          Z G d d          Z	 G d d          Z
 G d	 d
e	e
          Z G d de	          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de	          Z G d de	          Z G d d e	          Z G d! d"e          Z G d# d$e	          Z G d% d&e	          Z G d' d(e	          Z G d) d*e	          Z G d+ d,e	          Z G d- d.e	          Z G d/ d0e
          Z G d1 d2e
          Z ed3g d4          Z  G d5 d6          Z!dS )7    N)
namedtuple)DynamoDBNeedsConditionErrorDynamoDBNeedsKeyConditionError"DynamoDBOperationNotSupportedErrorz[^.\[\]]+(?![^\[]*\])c                   D    e Zd ZdZdZdZd Zd Zd Zd Z	d Z
d Zd	 Zd
S )ConditionBase Fc                     || _         d S N)_valuesselfvaluess     \/home/alex/cs2snipeproduction/venv/lib/python3.11/site-packages/boto3/dynamodb/conditions.py__init__zConditionBase.__init__   s        c                 l    t          |t                    st          d|          t          | |          S NAND)
isinstancer   r   Andr   others     r   __and__zConditionBase.__and__!   s5    %// 	C4UEBBB4r   c                 l    t          |t                    st          d|          t          | |          S NOR)r   r   r   Orr   s     r   __or__zConditionBase.__or__&   s3    %// 	B4T5AAA$r   c                      t          |           S r   )Notr   s    r   
__invert__zConditionBase.__invert__+   s    4yyr   c                 ,    | j         | j        | j        dS )N)formatoperatorr   )expression_formatexpression_operatorr   r"   s    r   get_expressionzConditionBase.get_expression.   s"    ,0l
 
 	
r   c                 d    t          |t          |                     r| j        |j        k    rdS dS )NTF)r   typer   r   s     r   __eq__zConditionBase.__eq__5   s3    eT$ZZ(( 	|u},,tur   c                 .    |                      |           S r   r,   r   s     r   __ne__zConditionBase.__ne__;       ;;u%%%%r   N)__name__
__module____qualname__r'   r(   has_grouped_valuesr   r   r   r#   r)   r,   r/    r   r   r   r      s               
  
  
 
 
  & & & & &r   r   c                   \    e Zd Zd Zd Zd Zd Zd Zd Zd Z	d Z
d	 Zd
 Zd Zd Zd ZdS )AttributeBasec                     || _         d S r   )name)r   r9   s     r   r   zAttributeBase.__init__@   s    			r   c                 "    t          d|           r   r   r   values     r   r   zAttributeBase.__and__C       0===r   c                 "    t          d|           r   r;   r<   s     r   r   zAttributeBase.__or__F   s    0t<<<r   c                 "    t          d|           )NNOTr;   r"   s    r   r#   zAttributeBase.__invert__I   r>   r   c                 "    t          | |          S )zCreates a condition where the attribute is equal to the value.

        :param value: The value that the attribute is equal to.
        )Equalsr<   s     r   eqzAttributeBase.eqL   s    
 dE"""r   c                 "    t          | |          S )zCreates a condition where the attribute is less than the value.

        :param value: The value that the attribute is less than.
        )LessThanr<   s     r   ltzAttributeBase.ltS       
 e$$$r   c                 "    t          | |          S )zCreates a condition where the attribute is less than or equal to the
           value.

        :param value: The value that the attribute is less than or equal to.
        )LessThanEqualsr<   s     r   ltezAttributeBase.lteZ   s     dE***r   c                 "    t          | |          S )zCreates a condition where the attribute is greater than the value.

        :param value: The value that the attribute is greater than.
        )GreaterThanr<   s     r   gtzAttributeBase.gtb   s    
 4'''r   c                 "    t          | |          S )zCreates a condition where the attribute is greater than or equal to
           the value.

        :param value: The value that the attribute is greater than or equal to.
        )GreaterThanEqualsr<   s     r   gtezAttributeBase.gtei   s     !u---r   c                 "    t          | |          S )zCreates a condition where the attribute begins with the value.

        :param value: The value that the attribute begins with.
        )
BeginsWithr<   s     r   begins_withzAttributeBase.begins_withq   s    
 $&&&r   c                 $    t          | ||          S )a3  Creates a condition where the attribute is greater than or equal
        to the low value and less than or equal to the high value.

        :param low_value: The value that the attribute is greater than or equal to.
        :param high_value: The value that the attribute is less than or equal to.
        )Between)r   	low_value
high_values      r   betweenzAttributeBase.betweenx   s     tY
333r   c                 \    t          |t          |                     o| j        |j        k    S r   )r   r+   r9   r   s     r   r,   zAttributeBase.__eq__   s&    %d,,Hej1HHr   c                 .    |                      |           S r   r.   r   s     r   r/   zAttributeBase.__ne__   r0   r   N)r1   r2   r3   r   r   r   r#   rD   rG   rK   rN   rQ   rT   rY   r,   r/   r5   r   r   r7   r7   ?   s          > > >= = => > ># # #% % %+ + +( ( (. . .' ' '4 4 4I I I& & & & &r   r7   c                   $    e Zd ZdZd Zd Zd ZdS )ConditionAttributeBasezThis base class is for conditions that can have attribute methods.

    One example is the Size condition. To complete a condition, you need
    to apply another AttributeBase method like eq().
    c                 v    t          j        | g|R   t                              | |d         j                   d S )Nr   )r   r   r7   r9   r   s     r   r   zConditionAttributeBase.__init__   s?    t-f---- 	tVAY^44444r   c                 n    t                               | |          ot                              | |          S r   )r   r,   r7   r   s     r   r,   zConditionAttributeBase.__eq__   s6    ##D%00 
]5I5I%6
 6
 	
r   c                 .    |                      |           S r   r.   r   s     r   r/   zConditionAttributeBase.__ne__   r0   r   N)r1   r2   r3   __doc__r   r,   r/   r5   r   r   r]   r]      sK         5 5 5
 
 

& & & & &r   r]   c                       e Zd ZdZdS )ComparisonConditionz{0} {operator} {1}N)r1   r2   r3   r'   r5   r   r   rc   rc      s        ,r   rc   c                       e Zd ZdZdS )rC   =Nr1   r2   r3   r(   r5   r   r   rC   rC              r   rC   c                       e Zd ZdZdS )	NotEqualsz<>Nrf   r5   r   r   ri   ri              r   ri   c                       e Zd ZdZdS )rF   <Nrf   r5   r   r   rF   rF      rg   r   rF   c                       e Zd ZdZdS )rJ   z<=Nrf   r5   r   r   rJ   rJ      rj   r   rJ   c                       e Zd ZdZdS )rM   >Nrf   r5   r   r   rM   rM      rg   r   rM   c                       e Zd ZdZdS )rP   z>=Nrf   r5   r   r   rP   rP      rj   r   rP   c                       e Zd ZdZdZdS )InINTN)r1   r2   r3   r(   r4   r5   r   r   rr   rr      s        r   rr   c                       e Zd ZdZdZdS )rV   BETWEENz{0} {operator} {1} AND {2}Nr1   r2   r3   r(   r'   r5   r   r   rV   rV      s        #4r   rV   c                       e Zd ZdZdZdS )rS   rT   {operator}({0}, {1})Nrv   r5   r   r   rS   rS      s        '.r   rS   c                       e Zd ZdZdZdS )Containscontainsrx   Nrv   r5   r   r   rz   rz      s        $.r   rz   c                       e Zd ZdZdZdS )Sizesize{operator}({0})Nrv   r5   r   r   r}   r}      s         )r   r}   c                       e Zd ZdZdZdS )AttributeTypeattribute_typerx   Nrv   r5   r   r   r   r      s        *.r   r   c                       e Zd ZdZdZdS )AttributeExistsattribute_existsr   Nrv   r5   r   r   r   r      s        ,)r   r   c                       e Zd ZdZdZdS )AttributeNotExistsattribute_not_existsr   Nrv   r5   r   r   r   r      s        0)r   r   c                       e Zd ZdZdZdS )r   r   ({0} {operator} {1})Nrv   r5   r   r   r   r      s        .r   r   c                       e Zd ZdZdZdS )r   r   r   Nrv   r5   r   r   r   r      s        .r   r   c                       e Zd ZdZdZdS )r!   rA   z({operator} {0})Nrv   r5   r   r   r!   r!      s        *r   r!   c                       e Zd ZdS )KeyN)r1   r2   r3   r5   r   r   r   r      s        Dr   r   c                   <    e Zd ZdZd Zd Zd Zd Zd Zd Z	d Z
d	S )
Attrz(Represents an DynamoDB item's attribute.c                 "    t          | |          S )zCreates a condition where the attribute is not equal to the value

        :param value: The value that the attribute is not equal to.
        )ri   r<   s     r   nezAttr.ne   s    
 u%%%r   c                 "    t          | |          S )zCreates a condition where the attribute is in the value,

        :type value: list
        :param value: The value that the attribute is in.
        )rr   r<   s     r   is_inz
Attr.is_in   s     $r   c                      t          |           S )z/Creates a condition where the attribute exists.)r   r"   s    r   existszAttr.exists  s    t$$$r   c                      t          |           S )z7Creates a condition where the attribute does not exist.)r   r"   s    r   
not_existszAttr.not_exists  s    !$'''r   c                 "    t          | |          S )z}Creates a condition where the attribute contains the value.

        :param value: The value the attribute contains.
        )rz   r<   s     r   r{   zAttr.contains  rH   r   c                      t          |           S )zCreates a condition for the attribute size.

        Note another AttributeBase method must be called on the returned
        size condition to be a valid DynamoDB condition.
        )r}   r"   s    r   r~   z	Attr.size  s     Dzzr   c                 "    t          | |          S )zfCreates a condition for the attribute type.

        :param value: The type of the attribute.
        )r   r<   s     r   r   zAttr.attribute_type  s    
 T5)))r   N)r1   r2   r3   ra   r   r   r   r   r{   r~   r   r5   r   r   r   r      s        22& & &  % % %( ( (% % %  * * * * *r   r   BuiltConditionExpressioncondition_expressionattribute_name_placeholdersattribute_value_placeholdersc                   N    e Zd ZdZd Zd Zd Zd ZddZd Z	d	 Z
d
 Z	 ddZdS )ConditionExpressionBuilderzCThis class is used to build condition expressions with placeholdersc                 >    d| _         d| _        d| _        d| _        d S )Nr   nv)_name_count_value_count_name_placeholder_value_placeholderr"   s    r   r   z#ConditionExpressionBuilder.__init__3  s(    !$"%r   c                 @    d| j         z   t          | j                  z   S )N#)r   strr   r"   s    r   _get_name_placeholderz0ConditionExpressionBuilder._get_name_placeholder9  s     T++c$2B.C.CCCr   c                 @    d| j         z   t          | j                  z   S )N:)r   r   r   r"   s    r   _get_value_placeholderz1ConditionExpressionBuilder._get_value_placeholder<  s     T,,s43D/E/EEEr   c                 "    d| _         d| _        dS )z&Resets the placeholder name and valuesr   N)r   r   r"   s    r   resetz ConditionExpressionBuilder.reset?  s    r   Fc                     t          |t                    st          |          i }i }|                     ||||          }t	          |||          S )a  Builds the condition expression and the dictionary of placeholders.

        :type condition: ConditionBase
        :param condition: A condition to be built into a condition expression
            string with any necessary placeholders.

        :type is_key_condition: Boolean
        :param is_key_condition: True if the expression is for a
            KeyConditionExpression. False otherwise.

        :rtype: (string, dict, dict)
        :returns: Will return a string representing the condition with
            placeholders inserted where necessary, a dictionary of
            placeholders for attribute names, and a dictionary of
            placeholders for attribute values. Here is a sample return value:

            ('#n0 = :v0', {'#n0': 'myattribute'}, {':v1': 'myvalue'})
        )is_key_conditionr   )r   r   r   _build_expressionr   )r   	conditionr   r   r   r   s         r   build_expressionz+ConditionExpressionBuilder.build_expressionD  sy    & )]33 	9-i888&(#')$#55'(-	  6  
  
 (!5(C)E
 
 
 	
r   c                     |                                 }g }|d         D ]5}|                     ||||j        |          }|                    |           6 |d         j        |d|d         iS )Nr   r%   r&   )r)   _build_expression_componentr4   appendr%   )	r   r   r   r   r   expression_dictreplaced_valuesr=   replaced_values	            r   r   z,ConditionExpressionBuilder._build_expressiong  s     $2244$X. 
	3 
	3E "==+,,  N "">2222 0x(/
'6z'B
 
 	
r   c                 ^   t          |t                    r|                     ||||          S t          |t                    rU|r=t          |t                    s(t          d|j         dt          |           d          |                     ||          S | 	                    |||          S )NzAttribute object z is of type zD. KeyConditionExpression only supports Attribute objects of type Key)
r   r   r   r7   r   r   r9   r+   _build_name_placeholder_build_value_placeholder)r   r=   r   r   r4   r   s         r   r   z6ConditionExpressionBuilder._build_expression_component  s     e]++ 	))+, 	   }-- 	 
5#(>(> 4#
 # #U # # #  
 //2   0035G  r   c                 (   |j         }t                              |          }t                              d|          }g }|D ]@}|                                 }| xj        dz  c_        |                    |           |||<   A|t          |          z  S )Nz%s   )r9   ATTR_NAME_REGEXfindallsubr   r   r   tuple)	r   r=   r   attribute_nameattribute_name_partsplaceholder_formatstr_format_argspartname_placeholders	            r   r   z2ConditionExpressionBuilder._build_name_placeholder  s    .66~FF -00~FF( 	A 	AD#99;;!""#3444<@'(899!E/$:$:::r   c                    |r`g }|D ]@}|                                  }| xj        dz  c_        |                    |           |||<   Add                    |          z   dz   S |                                  }| xj        dz  c_        |||<   |S )Nr   (z, ))r   r   r   join)r   r=   r   r4   placeholder_listr   value_placeholders          r   r   z3ConditionExpressionBuilder._build_value_placeholder  s    
  	%! D D$($?$?$A$A!!!Q&!! ''(9:::BC,->?? #3444s:: !% ; ; = =">C():;$$r   N)F)r1   r2   r3   ra   r   r   r   r   r   r   r   r   r   r5   r   r   r   r   0  s        MM& & &D D DF F F  
!
 !
 !
 !
F
 
 
4# # #J; ; ;$ GL% % % % % %r   r   )"recollectionsr   boto3.exceptionsr   r   r   compiler   r   r7   r]   rc   rC   ri   rF   rJ   rM   rP   rr   rV   rS   rz   r}   r   r   r   r   r   r!   r   r   r   r   r5   r   r   <module>r      s   
			 " " " " " "          "*566#& #& #& #& #& #& #& #&LF& F& F& F& F& F& F& F&R& & & & &]M & & &,- - - - -- - - -            #       "       (       %       +       	   
5 5 5 5 5m 5 5 5
/ / / / / / / /
/ / / / /} / / /
* * * * *! * * *
/ / / / /M / / /
* * * * *m * * *
* * * * * * * *
/ / / / /- / / /
/ / / / / / / /
+ + + + +- + + +
	 	 	 	 	- 	 	 	.* .* .* .* .*= .* .* .*b &:    ]% ]% ]% ]% ]% ]% ]% ]% ]% ]%r   