B
    è?F[R&  ã               @   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	   ú2lib/python3.7/site-packages/boto/dynamodb/batch.pyÚ__init__3   s    zBatch.__init__c             C   sˆ   i }g }xJ| j D ]@}t|tƒr(|\}}n|}d}| jj | jj||¡}| |¡ qW ||d< | jrl| j|d< | j	r|d|d< nd|d< |S )zO
        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 )N)r   ÚputsÚdeletes)r   r   r   r    r	   r	   r
   r   g   s    
zBatchWrite.__init__c             C   sœ   g }x2| j D ](}d| jj |¡i}d|i}| |¡ qW xV| jD ]L}t|tƒrX|\}}n|}d}| jj | jj	||¡}d|i}| d|i¡ q@W | jj
|fS )zO
        Convert the Batch object into the format required for Layer1.
        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)NN)r   r   r   r   r   r   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 )N)Ú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   r   r	   r	   r
   Ú	add_batch   s    zBatchList.add_batchc       
      C   sª   | dd…= | j sdS xŒt | j ¡D ]|\}}|d }| j |¡}g }x6|D ].}|d }d}d|krh|d }| ||f¡ qHW d}	d|krŽ|d }	| j|||	d q"W |  ¡ 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   Z	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   Zresr	   r	   r
   r(   È   s    
zBatchList.submitc             C   s2   i }x(| D ] }|  ¡ }|d r
|||jj< q
W |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'   r,   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 )N)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	   r	   r
   r'   ä   s    zBatchWriteList.add_batchc             C   s   | j  | ¡S )N)r   Zbatch_write_item)r   r	   r	   r
   r(   ú   s    zBatchWriteList.submitc             C   s*   i }x | D ]}|  ¡ \}}|||< q
W |S )zR
        Convert a BatchWriteList object into format required for Layer1.
        )r   )r   r#   r-   r)   r   r	   r	   r
   r   ý   s
    
zBatchWriteList.to_dict)NN)r   r   r   r   r   r'   r(   r   r	   r	   r	   r
   r/   Ú   s
   
r/   N)Zboto.compatr   Úobjectr   r   r%   r$   r/   r	   r	   r	   r
   Ú<module>   s   9/X