o
    ȷe                     @   s   d dl Z G dd deZdS )    Nc                   @   sT   e Zd ZdZdddZdd Zdd	 Zd
d Zdd ZdddZ	dd Z
dd ZdS )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 <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`.
     Fc                 C   s>   t |  || _|| _|| _d| _d| _d| _| jjj	| _	dS )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__domainnameactive
request_idencodingin_attribute
connection	converter)selfr   r   r    r   D/var/www/ideatree/venv/lib/python3.10/site-packages/boto/sdb/item.pyr   &   s   
	zItem.__init__c                 C   s    |dkrd| _ |dd | _d S )N	AttributeTr
   )r   getr
   )r   r   attrsr   r   r   r   startElement8   s   zItem.startElementc                 C   s   | j dkrd | _ t|S |S )Nbase64)r
   r   decodestring)r   valuer   r   r   decode_value>   s   

zItem.decode_valuec                 C   s6  |dkr|  || _d S |dkr#| jr|  || _d S |  || _d S |dkrj| j| v rUt| | j ts=| | j g| | j< |  |}| jrK| j|}| | j | d S |  |}| jrc| j|}|| | j< d S |dkrz| j	t
|7  _	W d S    Y d S |dkr|| _d S |dkrd| _d S t| || d S )NItemNameNameValueBoxUsage	RequestIdr   F)r   r   r   last_key
isinstancelistr   decodeappend	box_usagefloatr	   setattr)r   r   r   r   r   r   r   
endElementE   s8   




zItem.endElementc                 C   s   | j j| j| d dS )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)r   get_attributesr   r   r   r   r   loadf   s   
z	Item.loadTc                 C   sb   | j | j| | |r-g }| D ]}| | du r|| qt|dkr/| j | j| dS dS dS )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   )r   put_attributesr   r"   lendelete_attributes)r   replace	del_attrsr   r   r   r   saver   s   
z	Item.savec                 C   sB   || v rt | | ts| | g| |< | | | dS || |< dS )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)r   r    r"   )r   keyr   r   r   r   	add_value   s
   zItem.add_valuec                 C   s   | j |  dS )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)   r   r   r   delete   s   zItem.deleteN)r   F)T)__name__
__module____qualname____doc__r   r   r   r&   r*   r0   r2   r4   r   r   r   r   r      s    
!
'r   )r   r   r   r   r   r   r   <module>   s   