B -<`3:@sddlmZddlZddlmZddlmZddlmZedZGddde Z Gd d d e Z Gd d d e 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 ZGd3d4d4e Z ed5d6d7d8gZ!Gd9d:d:e Z"dS);) namedtupleN)"DynamoDBOperationNotSupportedError)DynamoDBNeedsConditionError)DynamoDBNeedsKeyConditionErrorz[^.\[\]]+(?![^\[]*\])c@sPeZdZdZdZdZddZddZddZd d Z d d Z d dZ ddZ dS) ConditionBaseFcGs ||_dS)N)_values)selfvaluesr @/tmp/pip-target-7cdyy134/lib/python/boto3/dynamodb/conditions.py__init__szConditionBase.__init__cCst|tstd|t||S)NAND) isinstancerrAnd)r otherr r r __and__!s  zConditionBase.__and__cCst|tstd|t||S)NOR)rrrOr)r rr r r __or__&s  zConditionBase.__or__cCst|S)N)Not)r r r r __invert__+szConditionBase.__invert__cCs|j|j|jdS)N)formatoperatorr )expression_formatexpression_operatorr)r r r r get_expression.szConditionBase.get_expressioncCs"t|t|r|j|jkrdSdS)NTF)rtyper)r rr r r __eq__3s zConditionBase.__eq__cCs || S)N)r)r rr r r __ne__9szConditionBase.__ne__N) __name__ __module__ __qualname__rrhas_grouped_valuesr rrrrrrr r r r rsrc@steZdZddZddZddZddZd d Zd d Zd dZ ddZ ddZ ddZ ddZ ddZddZdS) AttributeBasecCs ||_dS)N)name)r r%r r r r >szAttributeBase.__init__cCstd|dS)Nr)r)r valuer r r rAszAttributeBase.__and__cCstd|dS)Nr)r)r r&r r r rDszAttributeBase.__or__cCstd|dS)NNOT)r)r r r r rGszAttributeBase.__invert__cCs t||S)zCreates a condition where the attribute is equal to the value. :param value: The value that the attribute is equal to. )Equals)r r&r r r eqJszAttributeBase.eqcCs t||S)zCreates a condition where the attribute is less than the value. :param value: The value that the attribute is less than. )LessThan)r r&r r r ltQszAttributeBase.ltcCs 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. )LessThanEquals)r r&r r r lteXszAttributeBase.ltecCs t||S)zCreates a condition where the attribute is greater than the value. :param value: The value that the attribute is greater than. ) GreaterThan)r r&r r r gt`szAttributeBase.gtcCs 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. )GreaterThanEquals)r r&r r r gtegszAttributeBase.gtecCs t||S)zCreates a condition where the attribute begins with the value. :param value: The value that the attribute begins with. ) BeginsWith)r r&r r r begins_withoszAttributeBase.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_valuer r r betweenvszAttributeBase.betweencCst|t|o|j|jkS)N)rrr%)r rr r r rszAttributeBase.__eq__cCs || S)N)r)r rr r r rszAttributeBase.__ne__N)r r!r"r rrrr)r+r-r/r1r3r5rrr r r r r$=s r$c@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|f|t||djdS)Nr)rr r$r%)r r r r r r szConditionAttributeBase.__init__cCst||ot||S)N)rrr$)r rr r r rs zConditionAttributeBase.__eq__cCs || S)N)r)r rr r r rszConditionAttributeBase.__ne__N)r r!r"__doc__r rrr r r r r6sr6c@seZdZdZdS)ComparisonConditionz{0} {operator} {1}N)r r!r"rr r r r r8sr8c@seZdZdZdS)r(=N)r r!r"rr r r r r(sr(c@seZdZdZdS) NotEqualsz<>N)r r!r"rr r r r r:sr:c@seZdZdZdS)r*N)r r!r"rr r r r r.sr.c@seZdZdZdS)r0z>=N)r r!r"rr r r r r0sr0c@seZdZdZdZdS)InINTN)r r!r"rr#r r r r r=sr=c@seZdZdZdZdS)r4ZBETWEENz{0} {operator} {1} AND {2}N)r r!r"rrr r r r r4sr4c@seZdZdZdZdS)r2r3z{operator}({0}, {1})N)r r!r"rrr r r r r2sr2c@seZdZdZdZdS)Containscontainsz{operator}({0}, {1})N)r r!r"rrr r r r r?sr?c@seZdZdZdZdS)Sizesizez{operator}({0})N)r r!r"rrr r r r rAsrAc@seZdZdZdZdS) AttributeTypeattribute_typez{operator}({0}, {1})N)r r!r"rrr r r r rCsrCc@seZdZdZdZdS)AttributeExistsZattribute_existsz{operator}({0})N)r r!r"rrr r r r rEsrEc@seZdZdZdZdS)AttributeNotExistsZattribute_not_existsz{operator}({0})N)r r!r"rrr r r r rFsrFc@seZdZdZdZdS)rrz({0} {operator} {1})N)r r!r"rrr r r r rsrc@seZdZdZdZdS)rrz({0} {operator} {1})N)r r!r"rrr r r r rsrc@seZdZdZdZdS)rr'z({operator} {0})N)r r!r"rrr r r r rsrc@s eZdZdS)KeyN)r r!r"r r r r rGsrGc@sHeZdZdZddZddZddZdd Zd d Zd d Z ddZ dS)Attrz(Represents an DynamoDB item's attribute.cCs 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. )r:)r r&r r r neszAttr.necCs t||S)zCreates a condition where the attribute is in the value, :type value: list :param value: The value that the attribute is in. )r=)r r&r r r is_insz Attr.is_incCst|S)z/Creates a condition where the attribute exists.)rE)r r r r existssz Attr.existscCst|S)z7Creates a condition where the attribute does not exist.)rF)r r r r not_existsszAttr.not_existscCs t||S)z}Creates a condition where the attribute contains the value. :param value: The value the attribute contains. )r?)r r&r r r r@ sz Attr.containscCst|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. )rA)r r r r rBsz Attr.sizecCs t||S)zfCreates a condition for the attribute type. :param value: The type of the attribute. )rC)r r&r r r rDszAttr.attribute_typeN) r r!r"r7rIrJrKrLr@rBrDr r r r rHsrHBuiltConditionExpressioncondition_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_placeholder)r r r r r *sz#ConditionExpressionBuilder.__init__cCsd|jt|jS)N#)rVstrrT)r r r r _get_name_placeholder0sz0ConditionExpressionBuilder._get_name_placeholdercCsd|jt|jS)N:)rWrYrU)r r r r _get_value_placeholder3sz1ConditionExpressionBuilder._get_value_placeholdercCsd|_d|_dS)z&Resets the placeholder name and valuesrN)rTrU)r r r r reset6sz ConditionExpressionBuilder.resetFcCs:t|tst|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_condition)rNrOrP)rrr_build_expressionrM)r conditionr^rOrPrNr r r build_expression;s  z+ConditionExpressionBuilder.build_expressionc CsT|}g}x.|dD]"}|||||j|}||qW|dj|d|diS)Nr rr)r_build_expression_componentr#appendr) r r`rOrPr^Zexpression_dictZreplaced_valuesr&Zreplaced_valuer r r r_[sz,ConditionExpressionBuilder._build_expressioncCsft|tr|||||St|trT|rHt|tsHtd|jt|f|||S| |||SdS)NzeAttribute object %s is of type %s. KeyConditionExpression only supports Attribute objects of type Key) rrr_r$rGrr%r_build_name_placeholder_build_value_placeholder)r r&rOrPr#r^r r r rbls  z6ConditionExpressionBuilder._build_expression_componentc Csb|j}t|}td|}g}x4|D],}|}|jd7_|||||<q&W|t|S)Nz%s)r%ATTR_NAME_REGEXfindallsubrZrTrctuple) r r&rOZattribute_nameZattribute_name_partsZplaceholder_formatZstr_format_argspartZname_placeholderr r r rds     z2ConditionExpressionBuilder._build_name_placeholdercCsv|rPg}x4|D],}|}|jd7_|||||<qWdd|dS|}|jd7_|||<|SdS)Nrf(z, ))r\rUrcjoin)r r&rPr#Zplaceholder_listrSZvalue_placeholderr r r res   z3ConditionExpressionBuilder._build_value_placeholderN)F)F) r r!r"r7r rZr\r]rar_rbrdrer r r r rQ(s rQ)# collectionsrreZboto3.exceptionsrrrcompilergobjectrr$r6r8r(r:r*r,r.r0r=r4r2r?rArCrErFrrrrGrHrMrQr r r r  sB     %I0