o ckF[@sddlZGdddeZdS)Nc@sTeZdZdZdddZddZdd Zd d Zd d ZdddZ ddZ ddZ dS)Itemat A ``dict`` sub-class that serves as an object representation of a SimpleDB item. An item in SDB is similar to a row in a relational database. Items belong to a :py:class:`Domain `, which is similar to a table in a relational database. The keys on instances of this object correspond to attributes that are stored on the SDB item. .. tip:: While it is possible to instantiate this class directly, you may want to use the convenience methods on :py:class:`boto.sdb.domain.Domain` for that purpose. For example, :py:meth:`boto.sdb.domain.Domain.get_item`. FcCs>t|||_||_||_d|_d|_d|_|jjj |_ dS)a5 :type domain: :py:class:`boto.sdb.domain.Domain` :param domain: The domain that this item belongs to. :param str name: The name of this item. This name will be used when querying for items using methods like :py:meth:`boto.sdb.domain.Domain.get_item` NF) dict__init__domainnameactive request_idencoding in_attribute connection converter)selfrrrr//usr/lib/python3/dist-packages/boto/sdb/item.pyr&s z Item.__init__cCs |dkrd|_|dd|_dS)N AttributeTr )r getr )rrattrsr rrr startElement8szItem.startElementcCs|jdkr d|_t|S|S)Nbase64)r r decodestring)rvaluerrr decode_value>s  zItem.decode_valuecCs6|dkr |||_dS|dkr#|jr|||_dS|||_dS|dkrj|j|vrUt||jts=||jg||j<||}|jrK|j|}||j|dS||}|jrc|j|}|||j<dS|dkrz |j t |7_ WdSYdS|dkr||_ dS|dkrd|_dSt |||dS)NItemNameNameValueBoxUsage RequestIdrF) rrr last_key isinstancelistr decodeappend box_usagefloatr setattr)rrrr rrr endElementEs8       zItem.endElementcCs|jj|j|ddS)aR Loads or re-loads this item's attributes from SDB. .. warning:: If you have changed attribute values on an Item instance, this method will over-write the values if they are different in SDB. For any local attributes that don't yet exist in SDB, they will be safe. )itemN)rget_attributesrrrrrloadfs z Item.loadTcCsb|j|j|||r-g}|D] }||dur||qt|dkr/|j|j|dSdSdS)z Saves this item to SDB. :param bool replace: If ``True``, delete any attributes on the remote SDB item that have a ``None`` value on this object. Nr)rput_attributesrr"lendelete_attributes)rreplace del_attrsrrrrsavers   z Item.savecCsB||vrt||ts||g||<|||dS|||<dS)a Helps set or add to attributes on this item. If you are adding a new attribute that has yet to be set, it will simply create an attribute named ``key`` with your given ``value`` as its value. If you are adding a value to an existing attribute, this method will convert the attribute to a list (if it isn't already) and append your new value to said list. For clarification, consider the following interactive session: .. code-block:: python >>> item = some_domain.get_item('some_item') >>> item.has_key('some_attr') False >>> item.add_value('some_attr', 1) >>> item['some_attr'] 1 >>> item.add_value('some_attr', 2) >>> item['some_attr'] [1, 2] :param str key: The attribute to add a value to. :param object value: The value to set or append to the attribute. N)rr r")rkeyrrrr add_values  zItem.add_valuecCs|j|dS)z Deletes this item in SDB. .. note:: This local Python object remains in its current state after deletion, this only deletes the remote item in SDB. N)r delete_itemr)rrrdeletesz Item.deleteN)rF)T) __name__ __module__ __qualname____doc__rrrr&r*r0r2r4rrrrrs !  'r)rrrrrrrs