U
    3ìdX   ã                   @   s    d dl mZ G dd„ deƒZdS )é    )ÚDynamoDBItemErrorc                   @   s¢   e Zd ZdZd!dd„Zedd„ ƒZedd„ ƒZed	d
„ ƒZedd„ ƒZ	dd„ Z
d"dd„Zdd„ Zd#dd„Zd$dd„Zd%dd„Zdd„ Zdd„ Zdd„ Zdd „ ZdS )&ÚItemay  
    An item in Amazon DynamoDB.

    :ivar hash_key: The HashKey of this item.
    :ivar range_key: The RangeKey of this item or None if no RangeKey
        is defined.
    :ivar hash_key_name: The name of the HashKey associated with this item.
    :ivar range_key_name: The name of the RangeKey associated with this item.
    :ivar table: The Table this item belongs to.
    Nc                 C   s´   || _ d | _| j jj| _| j jj| _|d kr0i }|d krF| | jd ¡}|| | j< | jrv|d krl| | jd ¡}|| | j< i | _| ¡ D ]$\}}|| jkr„|| jkr„|| |< q„d| _	d S )Nr   )
ÚtableÚ_updatesZschemaÚhash_key_nameÚ_hash_key_nameÚrange_key_nameÚ_range_key_nameÚgetÚitemsZconsumed_units)Úselfr   Úhash_keyÚ	range_keyÚattrsÚkeyÚvalue© r   ú6/tmp/pip-unpacked-wheel-d7dsrkjd/boto/dynamodb/item.pyÚ__init__'   s$    


zItem.__init__c                 C   s
   | | j  S ©N©r   ©r   r   r   r   r   ;   s    zItem.hash_keyc                 C   s   |   | j¡S r   )r
   r	   r   r   r   r   r   ?   s    zItem.range_keyc                 C   s   | j S r   r   r   r   r   r   r   C   s    zItem.hash_key_namec                 C   s   | j S r   )r	   r   r   r   r   r   G   s    zItem.range_key_namec                 C   s   d|f| j |< dS )a²  
        Queue the addition of an attribute to an item in DynamoDB.
        This will eventually result in an UpdateItem request being issued
        with an update action of ADD when the save method is called.

        :type attr_name: str
        :param attr_name: Name of the attribute you want to alter.

        :type attr_value: int|long|float|set
        :param attr_value: Value which is to be added to the attribute.
        ZADDN©r   ©r   Ú	attr_nameÚ
attr_valuer   r   r   Úadd_attributeK   s    zItem.add_attributec                 C   s   d|f| j |< dS )a  
        Queue the deletion of an attribute from an item in DynamoDB.
        This call will result in a UpdateItem request being issued
        with update action of DELETE when the save method is called.

        :type attr_name: str
        :param attr_name: Name of the attribute you want to alter.

        :type attr_value: set
        :param attr_value: A set of values to be removed from the attribute.
            This parameter is optional. If None, the whole attribute is
            removed from the item.
        ÚDELETENr   r   r   r   r   Údelete_attributeY   s    zItem.delete_attributec                 C   s   d|f| j |< dS )aŸ  
        Queue the putting of an attribute to an item in DynamoDB.
        This call will result in an UpdateItem request being issued
        with the update action of PUT when the save method is called.

        :type attr_name: str
        :param attr_name: Name of the attribute you want to alter.

        :type attr_value: int|long|float|str|set
        :param attr_value: New value of the attribute.
        ÚPUTNr   r   r   r   r   Úput_attributei   s    zItem.put_attributec                 C   s   | j j | ||¡S )añ  
        Commits pending updates to Amazon DynamoDB.

        :type expected_value: dict
        :param expected_value: A dictionary of name/value pairs that
            you expect.  This dictionary should have name/value pairs
            where the name is the name of the attribute and the value is
            either the value you are expecting or False if you expect
            the attribute not to exist.

        :type return_values: str
        :param return_values: Controls the return of attribute name/value pairs
            before they were updated. Possible values are: None, 'ALL_OLD',
            'UPDATED_OLD', 'ALL_NEW' or 'UPDATED_NEW'. If 'ALL_OLD' is
            specified and the item is overwritten, the content of the old item
            is returned. If 'ALL_NEW' is specified, then all the attributes of
            the new version of the item are returned. If 'UPDATED_NEW' is
            specified, the new versions of only the updated attributes are
            returned.
        )r   Úlayer2Zupdate_item©r   Zexpected_valueZreturn_valuesr   r   r   Úsavew   s    ÿz	Item.savec                 C   s   | j j | ||¡S )aÛ  
        Delete the item from DynamoDB.

        :type expected_value: dict
        :param expected_value: A dictionary of name/value pairs that
            you expect.  This dictionary should have name/value pairs
            where the name is the name of the attribute and the value
            is either the value you are expecting or False if you expect
            the attribute not to exist.

        :type return_values: str
        :param return_values: Controls the return of attribute
            name-value pairs before then were changed.  Possible
            values are: None or 'ALL_OLD'. If 'ALL_OLD' is
            specified and the item is overwritten, the content
            of the old item is returned.
        )r   r!   Zdelete_itemr"   r   r   r   Údelete   s    ÿzItem.deletec                 C   s   | j j | ||¡S )a  
        Store a new item or completely replace an existing item
        in Amazon DynamoDB.

        :type expected_value: dict
        :param expected_value: A dictionary of name/value pairs that
            you expect.  This dictionary should have name/value pairs
            where the name is the name of the attribute and the value
            is either the value you are expecting or False if you expect
            the attribute not to exist.

        :type return_values: str
        :param return_values: Controls the return of attribute
            name-value pairs before then were changed.  Possible
            values are: None or 'ALL_OLD'. If 'ALL_OLD' is
            specified and the item is overwritten, the content
            of the old item is returned.
        )r   r!   Zput_itemr"   r   r   r   Úput¤   s    zItem.putc                 C   s(   | j dk	r|  ||¡ t | ||¡ dS )zfOverrwrite the setter to instead update the _updates
        method so this can act like a normal dictN)r   r    ÚdictÚ__setitem__)r   r   r   r   r   r   r'   ¹   s    
zItem.__setitem__c                 C   s$   | j dk	r|  |¡ t | |¡ dS )zRemove this key from the itemsN)r   r   r&   Ú__delitem__)r   r   r   r   r   r(   À   s    

zItem.__delitem__c                 C   s   | j S r   )Ú__dict__r   r   r   r   Ú__getstate__Ç   s    zItem.__getstate__c                 C   s   | j  |¡ d S r   )r)   Úupdate)r   Údr   r   r   Ú__setstate__É   s    zItem.__setstate__)NNN)N)NN)NN)NN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   Úpropertyr   r   r   r   r   r   r    r#   r$   r%   r'   r(   r*   r-   r   r   r   r   r      s(   








r   N)Zboto.dynamodb.exceptionsr   r&   r   r   r   r   r   Ú<module>   s   