o d:@sddlZddlmZddlmZmZmZedZGdddZ GdddZ Gd d d e e Z Gd d d e Z Gd dde Z Gddde ZGddde ZGddde ZGddde ZGddde ZGddde ZGddde ZGddde ZGdd d e ZGd!d"d"e ZGd#d$d$e ZGd%d&d&e ZGd'd(d(e ZGd)d*d*e ZGd+d,d,e ZGd-d.d.e ZGd/d0d0e ZGd1d2d2e Zed3gd4Z Gd5d6d6Z!dS)7N) namedtuple)DynamoDBNeedsConditionErrorDynamoDBNeedsKeyConditionError"DynamoDBOperationNotSupportedErrorz[^.\[\]]+(?![^\[]*\])c@sPeZdZdZdZdZddZddZddZd d Z d d Z d dZ ddZ dS) ConditionBaseFcG ||_dSN)_valuesselfvaluesrt/private/var/folders/v1/_jykv66s6qd26_69j1njbrl80000gr/T/pip-target-p1gutpg6/lib/python/boto3/dynamodb/conditions.py__init__ zConditionBase.__init__cCt|ts td|t||SNAND) isinstancerrAndr otherrrr__and__"   zConditionBase.__and__cCrNOR)rrrOrrrrr__or__'rzConditionBase.__or__cCt|Sr )Notr rrr __invert__,szConditionBase.__invert__cCs|j|j|jdS)N)formatoperatorr )expression_formatexpression_operatorr r!rrrget_expression/szConditionBase.get_expressioncCs"t|t|r|j|jkrdSdS)NTF)rtyper rrrr__eq__6s zConditionBase.__eq__cC || Sr r)rrrr__ne__< zConditionBase.__ne__N) __name__ __module__ __qualname__r%r&has_grouped_valuesrrrr"r'r)r,rrrrrs rc@steZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZdS) AttributeBasecCrr )name)r r3rrrrArzAttributeBase.__init__cC td|rrr valuerrrrDrzAttributeBase.__and__cCr4rr5r6rrrrGrzAttributeBase.__or__cCr4)NNOTr5r!rrrr"JrzAttributeBase.__invert__cC t||S)zCreates a condition where the attribute is equal to the value. :param value: The value that the attribute is equal to. )Equalsr6rrreqM zAttributeBase.eqcCr9)zCreates a condition where the attribute is less than the value. :param value: The value that the attribute is less than. )LessThanr6rrrltTr<zAttributeBase.ltcCr9)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. )LessThanEqualsr6rrrlte[ zAttributeBase.ltecCr9)zCreates a condition where the attribute is greater than the value. :param value: The value that the attribute is greater than. ) GreaterThanr6rrrgtcr<zAttributeBase.gtcCr9)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. )GreaterThanEqualsr6rrrgtejrAzAttributeBase.gtecCr9)zCreates a condition where the attribute begins with the value. :param value: The value that the attribute begins with. ) BeginsWithr6rrr begins_withrr<zAttributeBase.begins_withcCs t|||S)a3Creates 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 Z low_valueZ high_valuerrrbetweenys zAttributeBase.betweencCst|t|o |j|jkSr )rr(r3rrrrr)szAttributeBase.__eq__cCr*r r+rrrrr,r-zAttributeBase.__ne__N)r.r/r0rrrr"r;r>r@rCrErGrIr)r,rrrrr2@s r2c@s(eZdZdZddZddZddZdS) 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(). cGs(tj|g|Rt||djdS)Nr)rrr2r3r rrrrszConditionAttributeBase.__init__cCst||o t||Sr )rr)r2rrrrr)szConditionAttributeBase.__eq__cCr*r r+rrrrr,r-zConditionAttributeBase.__ne__N)r.r/r0__doc__rr)r,rrrrrJs  rJc@eZdZdZdS)ComparisonConditionz{0} {operator} {1}N)r.r/r0r%rrrrrMrMc@rL)r:=Nr.r/r0r&rrrrr:rNr:c@rL) NotEqualsz<>NrPrrrrrQrNrQc@rL)r=NrPrrrrrBrNrBc@rL)rDz>=NrPrrrrrDrNrDc@eZdZdZdZdS)InINTN)r.r/r0r&r1rrrrrUrUc@rT)rHZBETWEENz{0} {operator} {1} AND {2}Nr.r/r0r&r%rrrrrHrWrHc@rT)rFrG{operator}({0}, {1})NrXrrrrrFrWrFc@rT)ContainscontainsrYNrXrrrrrZrWrZc@rT)Sizesize{operator}({0})NrXrrrrr\rWr\c@rT) AttributeTypeattribute_typerYNrXrrrrr_rWr_c@rT)AttributeExistsZattribute_existsr^NrXrrrrrarWrac@rT)AttributeNotExistsZattribute_not_existsr^NrXrrrrrbrWrbc@rT)rr({0} {operator} {1})NrXrrrrrrWrc@rT)rrrcNrXrrrrrrWrc@rT)r r8z({operator} {0})NrXrrrrr rWr c@s eZdZdS)KeyN)r.r/r0rrrrrdsrdc@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)Attrz(Represents an DynamoDB item's attribute.cCr9)zCreates a condition where the attribute is not equal to the value :param value: The value that the attribute is not equal to. )rQr6rrrner<zAttr.necCr9)zCreates a condition where the attribute is in the value, :type value: list :param value: The value that the attribute is in. )rUr6rrris_inrAz Attr.is_incCr)z/Creates a condition where the attribute exists.)rar!rrrexistsz Attr.existscCr)z7Creates a condition where the attribute does not exist.)rbr!rrr not_exists rizAttr.not_existscCr9)z}Creates a condition where the attribute contains the value. :param value: The value the attribute contains. )rZr6rrrr[r<z Attr.containscCr)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!rrrr]sz Attr.sizecCr9)zfCreates a condition for the attribute type. :param value: The type of the attribute. )r_r6rrrr`r<zAttr.attribute_typeN) r.r/r0rKrfrgrhrjr[r]r`rrrrres reBuiltConditionExpressioncondition_expressionattribute_name_placeholdersattribute_value_placeholdersc@s^eZdZdZddZddZddZdd Zdd d Zd dZ ddZ ddZ dddZ dS)ConditionExpressionBuilderzCThis class is used to build condition expressions with placeholderscCsd|_d|_d|_d|_dS)Nrnv) _name_count _value_count_name_placeholder_value_placeholderr!rrrr4s z#ConditionExpressionBuilder.__init__cCd|jt|jS)N#)rustrrsr!rrr_get_name_placeholder:z0ConditionExpressionBuilder._get_name_placeholdercCrw)N:)rvryrtr!rrr_get_value_placeholder=r{z1ConditionExpressionBuilder._get_value_placeholdercCsd|_d|_dS)z&Resets the placeholder name and valuesrN)rsrtr!rrrreset@s z ConditionExpressionBuilder.resetFcCs:t|ts t|i}i}|j||||d}t|||dS)aBuilds 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_conditionrl)rrr_build_expressionrk)r conditionrrnrormrrrbuild_expressionEs z+ConditionExpressionBuilder.build_expressionc CsP|}g}|dD]}|||||j|}||q |dj|d|diS)Nr r#r$)r'_build_expression_componentr1appendr#) r rrnrorZexpression_dictZreplaced_valuesr7Zreplaced_valuerrrrhs   z,ConditionExpressionBuilder._build_expressioncCsht|tr |||||St|tr-|r't|ts'td|jdt|d|||S| |||S)NzAttribute object z is of type zD. KeyConditionExpression only supports Attribute objects of type Key) rrrr2rdrr3r(_build_name_placeholder_build_value_placeholder)r r7rnror1rrrrrs$  z6ConditionExpressionBuilder._build_expression_componentc Cs^|j}t|}td|}g}|D]}|}|jd7_|||||<q|t|S)Nz%s)r3ATTR_NAME_REGEXfindallsubrzrsrtuple) r r7rnZattribute_nameZattribute_name_partsZplaceholder_formatZstr_format_argspartZname_placeholderrrrrs     z2ConditionExpressionBuilder._build_name_placeholdercCsn|r&g}|D]}|}|jd7_|||||<qdd|dS|}|jd7_|||<|S)Nr(z, ))r}rtrjoin)r r7ror1Zplaceholder_listrrZvalue_placeholderrrrrs  z3ConditionExpressionBuilder._build_value_placeholderN)F) r.r/r0rKrrzr}r~rrrrrrrrrrp1s #%rp)"re collectionsrZboto3.exceptionsrrrcompilerrr2rJrMr:rQr=r?rBrDrUrHrFrZr\r_rarbrrr rdrerkrprrrrs@  'I1