U
    W¨+dR&  ã                   @   sP   d dl mZ G dd„ deƒZG dd„ deƒZG dd„ deƒZG dd	„ d	eƒZd
S )é    )Úsixc                   @   s"   e Zd ZdZddd„Zdd„ ZdS )	ÚBatcha	  
    Used to construct a BatchGet request.

    :ivar table: The Table object from which the item is retrieved.

    :ivar keys: A list of scalar or tuple values.  Each element in the
        list represents one Item to retrieve.  If the schema for the
        table has both a HashKey and a RangeKey, each element in the
        list should be a tuple consisting of (hash_key, range_key).  If
        the schema for the table contains only a HashKey, each element
        in the list should be a scalar value of the appropriate type
        for the table schema. NOTE: The maximum number of items that
        can be retrieved for a single operation is 100. Also, the
        number of items retrieved is constrained by a 1 MB size limit.

    :ivar attributes_to_get: A list of attribute names.
        If supplied, only the specified attribute names will
        be returned.  Otherwise, all attributes will be returned.

    :ivar consistent_read: Specify whether or not to use a
        consistent read. Defaults to False.

    NFc                 C   s   || _ || _|| _|| _d S ©N)ÚtableÚkeysÚattributes_to_getÚconsistent_read©Úselfr   r   r   r   © r   ú7/tmp/pip-unpacked-wheel-dlxw5sjy/boto/dynamodb/batch.pyÚ__init__3   s    zBatch.__init__c                 C   s„   i }g }| j D ]@}t|tƒr&|\}}n|}d}| jj | jj||¡}| |¡ q||d< | jrh| j|d< | j	rxd|d< nd|d< |S )úO
        Convert the Batch object into the format required for Layer1.
        NÚKeysÚAttributesToGetTZConsistentReadF)
r   Ú
isinstanceÚtupler   Úlayer2Úbuild_key_from_valuesÚschemaÚappendr   r   )r
   Ú
batch_dictZkey_listÚkeyÚhash_keyÚ	range_keyÚkr   r   r   Úto_dict:   s&    


 ÿ

zBatch.to_dict)NF©Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r   r      s
     ÿ
r   c                   @   s"   e Zd ZdZddd„Zdd„ ZdS )Ú
BatchWritea  
    Used to construct a BatchWrite request.  Each BatchWrite object
    represents a collection of PutItem and DeleteItem requests for
    a single Table.

    :ivar table: The Table object from which the item is retrieved.

    :ivar puts: A list of :class:`boto.dynamodb.item.Item` objects
        that you want to write to DynamoDB.

    :ivar deletes: A list of scalar or tuple values.  Each element in the
        list represents one Item to delete.  If the schema for the
        table has both a HashKey and a RangeKey, each element in the
        list should be a tuple consisting of (hash_key, range_key).  If
        the schema for the table contains only a HashKey, each element
        in the list should be a scalar value of the appropriate type
        for the table schema.
    Nc                 C   s   || _ |pg | _|pg | _d S r   )r   ÚputsÚdeletes©r
   r   r#   r$   r   r   r   r   g   s    
zBatchWrite.__init__c                 C   s”   g }| j D ](}d| jj |¡i}d|i}| |¡ q
| jD ]L}t|tƒrR|\}}n|}d}| jj | jj	||¡}d|i}| d|i¡ q:| jj
|fS )r   ZItemZ
PutRequestNZKeyZDeleteRequest)r#   r   r   Zdynamize_itemr   r$   r   r   r   r   Úname)r
   Zop_listÚitemÚdr   r   r   r   r   r   r   r   l   s"    



 ÿzBatchWrite.to_dict)NNr   r   r   r   r   r"   S   s   
r"   c                   @   s:   e Zd ZdZdd„ Zddd„Zdd	„ Zd
d„ Zdd„ ZdS )Ú	BatchListzs
    A subclass of a list object that contains a collection of
    :class:`boto.dynamodb.batch.Batch` objects.
    c                 C   s   t  | ¡ d | _|| _d S r   )Úlistr   Úunprocessedr   ©r
   r   r   r   r   r   ˆ   s    
zBatchList.__init__NFc                 C   s   |   t||||ƒ¡ dS )aO  
        Add a Batch to this BatchList.

        :type table: :class:`boto.dynamodb.table.Table`
        :param table: The Table object in which the items are contained.

        :type keys: list
        :param keys: A list of scalar or tuple values.  Each element in the
            list represents one Item to retrieve.  If the schema for the
            table has both a HashKey and a RangeKey, each element in the
            list should be a tuple consisting of (hash_key, range_key).  If
            the schema for the table contains only a HashKey, each element
            in the list should be a scalar value of the appropriate type
            for the table schema. NOTE: The maximum number of items that
            can be retrieved for a single operation is 100. Also, the
            number of items retrieved is constrained by a 1 MB size limit.

        :type attributes_to_get: list
        :param attributes_to_get: A list of attribute names.
            If supplied, only the specified attribute names will
            be returned.  Otherwise, all attributes will be returned.
        N)r   r   r	   r   r   r   Ú	add_batch   s    zBatchList.add_batchc           
      C   s¢   | dd…= | j sdS t | j ¡D ]x\}}|d }| j |¡}g }|D ].}|d }d}d|krd|d }| ||f¡ qDd}	d|krˆ|d }	| j|||	d q |  ¡ S )a  
        Resubmit the batch to get the next result set. The request object is
        rebuild from scratch meaning that all batch added between ``submit``
        and ``resubmit`` will be lost.

        Note: This method is experimental and subject to changes in future releases
        Nr   ZHashKeyElementZRangeKeyElementr   )r   )r+   r   Ú	iteritemsr   Z	get_tabler   r-   Úsubmit)
r
   Ú
table_nameZ	table_reqZ
table_keysr   r   r   ÚhÚrr   r   r   r   Úresubmit§   s$    
zBatchList.resubmitc                 C   s"   | j  | ¡}d|kr|d | _|S )NZUnprocessedKeys)r   Zbatch_get_itemr+   )r
   Úresr   r   r   r/   È   s    
zBatchList.submitc                 C   s.   i }| D ] }|  ¡ }|d r|||jj< q|S )zM
        Convert a BatchList object into format required for Layer1.
        r   )r   r   r&   )r
   r(   ÚbatchÚbr   r   r   r   Î   s    zBatchList.to_dict)NF)	r   r   r    r!   r   r-   r3   r/   r   r   r   r   r   r)   ‚   s     ÿ
!r)   c                   @   s2   e Zd ZdZdd„ Zddd„Zdd„ Zd	d
„ ZdS )ÚBatchWriteListzx
    A subclass of a list object that contains a collection of
    :class:`boto.dynamodb.batch.BatchWrite` objects.
    c                 C   s   t  | ¡ || _d S r   )r*   r   r   r,   r   r   r   r   à   s    
zBatchWriteList.__init__Nc                 C   s   |   t|||ƒ¡ dS )aW  
        Add a BatchWrite to this BatchWriteList.

        :type table: :class:`boto.dynamodb.table.Table`
        :param table: The Table object in which the items are contained.

        :type puts: list of :class:`boto.dynamodb.item.Item` objects
        :param puts: A list of items that you want to write to DynamoDB.

        :type deletes: A list
        :param deletes: A list of scalar or tuple values.  Each element
            in the list represents one Item to delete.  If the schema
            for the table has both a HashKey and a RangeKey, each
            element in the list should be a tuple consisting of
            (hash_key, range_key).  If the schema for the table
            contains only a HashKey, each element in the list should
            be a scalar value of the appropriate type for the table
            schema.
        N)r   r"   r%   r   r   r   r-   ä   s    zBatchWriteList.add_batchc                 C   s   | j  | ¡S r   )r   Zbatch_write_item)r
   r   r   r   r/   ú   s    zBatchWriteList.submitc                 C   s&   i }| D ]}|  ¡ \}}|||< q|S )zR
        Convert a BatchWriteList object into format required for Layer1.
        )r   )r
   r(   r5   r0   r   r   r   r   r   ý   s
    
zBatchWriteList.to_dict)NN)r   r   r    r!   r   r-   r/   r   r   r   r   r   r7   Ú   s
   
r7   N)Zboto.compatr   Úobjectr   r"   r*   r)   r7   r   r   r   r   Ú<module>   s   9/X