ó FRTc@s”dZddlZddlmZmZmZmZmZmZm Z m Z ddl m Z ddl mZmZmZmZedddd d dd d d eeee e gƒZd„Zd„Zejräd„Zd„Znd„Zd„Zd„Zd„Zd„Zd„Zd„ZejrEdefd„ƒYZnde fd„ƒYZd„Z!defd„ƒYZ"de"fd „ƒYZ#dS(!sc Some utility functions to deal with mapping Amazon DynamoDB types to Python types and vice-versa. iÿÿÿÿN(tDecimaltDecimalExceptiontContexttClampedtOverflowtInexactt UnderflowtRounded(tDynamoDBNumberError(tfiltertmaptsixt long_typetEmini€ÿÿÿtEmaxi~troundingtpreci&ttrapscCs‰|jƒ\}}t|ƒt|ƒ}}t}|j||ƒ}x?|jtr„t|jt<|jd9_|j||ƒ}qFW|S(Ni(tas_integer_ratioRtDYNAMODB_CONTEXTtdividetflagsRtFalseR(tftntdt numeratort denominatortctxtresult((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pytfloat_to_decimal*s cCs.tttttf}t||ƒp-||kS(N(tintR tfloattboolRt isinstance(Rttypes((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pytis_num6scCs+t|tƒp*t|tƒo*t|tƒS(N(R"t basestringttypet issubclass(R((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pytis_str<scCs t|tƒS(N(R"tBinary(R((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt is_binary@scCs+t|tƒp*t|tƒo*t|tƒS(N(R"tstrR&R'(R((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyR(DscCs t|tƒS(N(R"tbytes(R((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyR*HscCs)t|tƒrtt|ƒƒSt|ƒS(s\Cast a number to a string and perform validation to ensure no loss of precision. (R"R!R+R(tval((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt serialize_numLscCs+d|krt|ƒ}n t|ƒ}|S(Nt.(R R(tsR((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt convert_numUs  cCsttj|ƒƒS(N(R)tbase64t b64decode(R((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pytconvert_binary]scCsìd}t|ƒrd}nœt|ƒr0d}n‡t|ttfƒr¢ttt|ƒkrcd}q·ttt|ƒkrd}q·ttt|ƒkr·d}q·nt|ƒr·d}n|dkrèdt |ƒ|f}t |ƒ‚n|S( s¹ Take a scalar Python value and return a string representing the corresponding Amazon DynamoDB type. If the value passed in is not a supported type, raise a TypeError. tNtStNStSStBStBs$Unsupported type "%s" for value "%s"N( tNoneR$R(R"tsett frozensetRR R*R&t TypeError(R-t dynamodb_typetmsg((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pytget_dynamodb_typeas$          cCst|ƒ}|dkr.it|ƒ|6}në|dkrJi||6}nÏ|dkruittt|ƒƒ|6}n¤|dkr¤ig|D] }|^q‹|6}nu|dkrät|tƒrÎt|ƒ}ni|jƒ|6}n5|dkrig|D]}|jƒ^qú|6}n|S(sí Take a scalar Python value and return a dict consisting of the Amazon DynamoDB type specification and the value that needs to be sent to Amazon DynamoDB. If the type of the value is not supported, raise a TypeError R5R6R7R8R:R9(RAR.tlistR R"R,R)tencode(R-R?R((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pytdynamize_value{s      #  )R)cBsGeZd„Zd„Zd„Zd„Zd„Zd„Zd„ZRS(cCsUt|ttjfƒs'tdƒ‚nt|tƒsH|jdƒ}n||_dS(Ns&Value must be a string of binary data!sutf-8(R"R,R t text_typeR>RCtvalue(tselfRF((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt__init__–s cCstj|jƒjdƒS(Nsutf-8(R2t b64encodeRFtdecode(RG((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyRCžscCs0t|tƒr|j|jkS|j|kSdS(N(R"R)RF(RGtother((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt__eq__¡scCs|j|ƒ S(N(RL(RGRK((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt__ne__§scCs d|jS(Ns Binary(%r)(RF(RG((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt__repr__ªscCs|jS(N(RF(RG((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt__str__­scCs t|jƒS(N(thashRF(RG((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt__hash__°s( t__name__t __module__RHRCRLRMRNRORQ(((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyR)•s      cBs)eZd„Zed„ƒZd„ZRS(cCstj|ƒjdƒS(Nsutf-8(R2RIRJ(RG((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyRC´scCs t|ƒS(N(R,(RG((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyRF·scCs d|jS(Ns Binary(%r)(RF(RG((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyRN¾s(RRRSRCtpropertyRFRN(((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyR)³s cCsÈt|jƒƒdkr|Sd|kr0|dSd|krJt|dƒSd|krdt|dƒSd|kr‡ttt|dƒƒSd|kr¡t|dƒSd|krÄttt|dƒƒS|S(s½ A custom object hook for use when decoding JSON item bodys. This hook will transform Amazon DynamoDB JSON responses to something that maps directly to native Python types. iR6R5R8R7R:R9(tlentkeysR1R<R R4(tdct((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pytitem_object_hookÂs      t DynamizercBs•eZdZd„Zd„Zd„Zd„Zd„Zd„Zd„Z d„Z d „Z d „Z d „Z d „Zd „Zd„Zd„ZRS(s&Control serialization/deserialization of types. This class controls the encoding of python types to the format that is expected by the DynamoDB API, as well as taking DynamoDB types and constructing the appropriate python types. If you want to customize this process, you can subclass this class and override the encoding/decoding of specific types. For example:: 'foo' (Python type) | v encode('foo') | v _encode_s('foo') | v {'S': 'foo'} (Encoding sent to/received from DynamoDB) | V decode({'S': 'foo'}) | v _decode_s({'S': 'foo'}) | v 'foo' (Python type) cCs t|ƒS(N(RA(RGtattr((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt_get_dynamodb_typeúscCsa|j|ƒ}yt|d|jƒƒ}Wn!tk rOtd|ƒ‚nXi||ƒ|6S(sT Encodes a python type to the format expected by DynamoDB. s _encode_%ss"Unable to encode dynamodb type: %s(R[tgetattrtlowertAttributeErrort ValueError(RGRZR?tencoder((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyRCýs csÑy~t|tƒr7ttdƒ r7tt|ƒƒ‰nttj|ƒƒ‰tt ‡fd†dƒƒryt dƒ‚nˆSWn@t t fk rÀ}dj |j j|t|ƒp·dƒ}nXt|ƒ‚dS( Nt from_floatcs |ˆkS(N((tx(R(s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pytstInfinitytNaNsInfinity and NaN not supporteds{0} numeric for `{1}` {2}t(sInfinitysNaN(R"R thasattrRR+RRtcreate_decimalRBR R>Rtformatt __class__RRR(RGRZteR@((Rs@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt _encode_n s%cCsFt|tƒr!|jdƒ}n!t|tjƒsBt|ƒ}n|S(Nsutf-8(R"R,RJR RER+(RGRZ((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt _encode_ss cCstt|j|ƒƒS(N(RBR Rl(RGRZ((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt _encode_ns"scCs g|D]}|j|ƒ^qS(N(Rm(RGRZR((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt _encode_ss%scCs(t|tƒrt|ƒ}n|jƒS(N(R"R,R)RC(RGRZ((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt _encode_b(scCs g|D]}|j|ƒ^qS(N(Rp(RGRZR((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt _encode_bs-scCs‰t|ƒdks| r|St|jƒƒd}|jƒ|krI|Syt|d|jƒƒ}Wntk rz|SX|||ƒS(sl Takes the format returned by DynamoDB and constructs the appropriate python type. iis _decode_%s(RURBRVR]R\R^(RGRZR?tdecoder((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyRJ0s cCs tj|ƒS(N(RRh(RGRZ((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt _decode_nCscCs|S(N((RGRZ((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt _decode_sFscCstt|j|ƒƒS(N(R<R Rs(RGRZ((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt _decode_nsIscCstt|j|ƒƒS(N(R<R Rt(RGRZ((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt _decode_ssLscCs t|ƒS(N(R4(RGRZ((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt _decode_bOscCstt|j|ƒƒS(N(R<R Rw(RGRZ((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyt _decode_bsRs(RRRSt__doc__R[RCRlRmRnRoRpRqRJRsRtRuRvRwRx(((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyRYÙs                tLossyFloatDynamizercBs2eZdZd„Zd„Zd„Zd„ZRS(sVUse float/int instead of Decimal for numeric types. This class is provided for backwards compatibility. Instead of using Decimals for the 'N', 'NS' types it uses ints/floats. This class is deprecated and its usage is not encouraged, as doing so may result in loss of precision. Use the `Dynamizer` class instead. cCs t|ƒS(N(R.(RGRZ((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyRlascCsg|D]}t|ƒ^qS(N(R+(RGRZti((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyRndscCs t|ƒS(N(R1(RGRZ((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyRsgscCstt|j|ƒƒS(N(R<R Rs(RGRZ((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyRujs(RRRSRyRlRnRsRu(((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyRzVs     ($RyR2tdecimalRRRRRRRRtboto.dynamodb.exceptionsRt boto.compatR R R R R;RRR$tPY2R(R*R.R1R4RARDtobjectR)R,RXRYRz(((s@/opt/freeware/lib/python2.7/site-packages/boto/dynamodb/types.pyts2 :"            }