o
    ȷeR&                     @   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   J/var/www/ideatree/venv/lib/python3.10/site-packages/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r4| j|d< | j	r=d|d< |S d|d< |S )O
        Convert the Batch object into the format required for Layer1.
        NKeysAttributesToGetTConsistentReadF)
r   
isinstancetupler   layer2build_key_from_valuesschemaappendr   r   )r
   
batch_dict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 ]&}t|tr)|\}}n|}d}| jj| jj	||}d|i}|d|i q| jj
|fS )r   Item
PutRequestNKeyDeleteRequest)r&   r   r   dynamize_itemr   r'   r   r   r   r   name)r
   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 ]<\}}|d }| j|}g }|D ]}|d }d}d|v r2|d }|||f q"d}	d|v rD|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   HashKeyElementRangeKeyElementr   )r   )r5   r   	iteritemsr   	get_tabler   r7   submit)
r
   
table_name	table_req
table_keysr   r   r   hrr   r   r   r   resubmit   s$   
zBatchList.resubmitc                 C   s"   | j | }d|v r|d | _|S )NUnprocessedKeys)r   batch_get_itemr5   )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
   r1   batchbr   r   r   r      s   zBatchList.to_dictr   )	r!   r"   r#   r$   r   r7   rB   r<   r   r   r   r   r   r3      s    
!r3   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   )r4   r   r   r6   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   r7      s   zBatchWriteList.add_batchc                 C   s   | j | S r   )r   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
   r1   rF   r=   r   r   r   r   r      s
   
zBatchWriteList.to_dictr2   )r!   r"   r#   r$   r   r7   r<   r   r   r   r   r   rH      s    
rH   N)boto.compatr   objectr   r%   r4   r3   rH   r   r   r   r   <module>   s
   9/X