ó
è?F[c           @   s&   d  d l  Z  d e f d „  ƒ  YZ d S(   iÿÿÿÿNt   Itemc           B   s_   e  Z d  Z d e d „ Z d „  Z d „  Z d „  Z d „  Z e	 d „ Z
 d „  Z d	 „  Z RS(
   st  
    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 <boto.sdb.domain.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`.
    t    c         C   sY   t  j |  ƒ | |  _ | |  _ | |  _ d |  _ d |  _ t |  _	 |  j j
 j |  _ d S(   s5  
        :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`
        N(   t   dictt   __init__t   domaint   namet   activet   Nonet
   request_idt   encodingt   Falset   in_attributet
   connectiont	   converter(   t   selfR   R   R   (    (    s,   lib/python2.7/site-packages/boto/sdb/item.pyR   &   s    							c         C   s1   | d k r t  |  _ n  | j d d  ƒ |  _ d  S(   Nt	   AttributeR	   (   t   TrueR   t   getR   R	   (   R   R   t   attrsR   (    (    s,   lib/python2.7/site-packages/boto/sdb/item.pyt   startElement8   s    c         C   s-   |  j  d k r% d  |  _  t j | ƒ S| Sd  S(   Nt   base64(   R	   R   R   t   decodestring(   R   t   value(    (    s,   lib/python2.7/site-packages/boto/sdb/item.pyt   decode_value>   s    	c         C   s¢  | d k r! |  j  | ƒ |  _ n}| d k r` |  j rK |  j  | ƒ |  _ qž|  j  | ƒ |  _ n>| d k r,|  j |  k rï t |  |  j t ƒ s« |  |  j g |  |  j <n  |  j  | ƒ } |  j rØ |  j j | ƒ } n  |  |  j j | ƒ qž|  j  | ƒ } |  j r|  j j | ƒ } n  | |  |  j <nr | d k r^y | j	 t
 | ƒ 7_	 WqžqžXn@ | d k rv| |  _ n( | d k rŽt |  _ n t |  | | ƒ d  S(   Nt   ItemNamet   Namet   Valuet   BoxUsaget	   RequestIdR   (   R   R   R   t   last_keyt
   isinstancet   listR   t   decodet   appendt	   box_usaget   floatR   R
   t   setattr(   R   R   R   R   (    (    s,   lib/python2.7/site-packages/boto/sdb/item.pyt
   endElementE   s8    			c         C   s   |  j  j |  j d |  ƒd S(   sR  
        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.
        t   itemN(   R   t   get_attributesR   (   R   (    (    s,   lib/python2.7/site-packages/boto/sdb/item.pyt   loadf   s    
c         C   sˆ   |  j  j |  j |  | ƒ | r„ g  } x. |  D]& } |  | d k r, | j | ƒ q, q, Wt | ƒ d k r„ |  j  j |  j | ƒ q„ n  d S(   s¸   
        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.
        i    N(   R   t   put_attributesR   R   R!   t   lent   delete_attributes(   R   t   replacet	   del_attrsR   (    (    s,   lib/python2.7/site-packages/boto/sdb/item.pyt   saver   s    c         C   sU   | |  k rG t  |  | t ƒ s3 |  | g |  | <n  |  | j | ƒ n
 | |  | <d S(   sÁ  
        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(   R   R   R!   (   R   t   keyR   (    (    s,   lib/python2.7/site-packages/boto/sdb/item.pyt	   add_valueƒ   s
    c         C   s   |  j  j |  ƒ d S(   sº   
        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   t   delete_item(   R   (    (    s,   lib/python2.7/site-packages/boto/sdb/item.pyt   deleteª   s    (   t   __name__t
   __module__t   __doc__R
   R   R   R   R%   R(   R   R.   R0   R2   (    (    (    s,   lib/python2.7/site-packages/boto/sdb/item.pyR       s   			!		'(   R   R   R    (    (    (    s,   lib/python2.7/site-packages/boto/sdb/item.pyt   <module>   s   