Current File : //usr/lib/python3/dist-packages/boto3/dynamodb/__pycache__/table.cpython-312.pyc
�

��e���^�ddlZeje�Zd�ZGd�d�ZGd�d�Zy)�Nc�0�|jdt�y)Nr)�insert�
TableResource)�base_classes�kwargss  �6/usr/lib/python3/dist-packages/boto3/dynamodb/table.py�register_table_methodsr	s������=�)�c�&��eZdZ�fd�Zdd�Z�xZS)rc�$��t�|�|i|��y�N)�super�__init__)�self�argsr�	__class__s   �rrzTableResource.__init__s���
���$�)�&�)r
c�Z�t|j|jj|��S)aYCreate a batch writer object.

        This method creates a context manager for writing
        objects to Amazon DynamoDB in batch.

        The batch writer will automatically handle buffering and sending items
        in batches.  In addition, the batch writer will also automatically
        handle any unprocessed items and resend them as needed.  All you need
        to do is call ``put_item`` for any items you want to add, and
        ``delete_item`` for any items you want to delete.

        Example usage::

            with table.batch_writer() as batch:
                for _ in range(1000000):
                    batch.put_item(Item={'HashKey': '...',
                                         'Otherstuff': '...'})
                # You can also delete_items in a batch.
                batch.delete_item(Key={'HashKey': 'SomeHashKey'})

        :type overwrite_by_pkeys: list(string)
        :param overwrite_by_pkeys: De-duplicate request items in buffer
            if match new request item on specified primary keys. i.e
            ``["partition_key1", "sort_key2", "sort_key3"]``

        )�overwrite_by_pkeys)�BatchWriter�name�meta�client)rrs  r�batch_writerzTableResource.batch_writers'��6��I�I�t�y�y�'�'�<N�
�	
r
r
)�__name__�
__module__�__qualname__rr�
__classcell__)rs@rrrs
���*�
r
rc�P�eZdZdZ	d
d�Zd�Zd�Zd�Zd�Zd�Z	d	�Z
d
�Zd�Zd�Z
y)rzAAutomatically handle batch writes to DynamoDB for a single table.Nc�J�||_||_g|_||_||_y)aU

        :type table_name: str
        :param table_name: The name of the table.  The class handles
            batch writes to a single table.

        :type client: ``botocore.client.Client``
        :param client: A botocore client.  Note this client
            **must** have the dynamodb customizations applied
            to it for transforming AttributeValues into the
            wire protocol.  What this means in practice is that
            you need to use a client that comes from a DynamoDB
            resource if you're going to instantiate this class
            directly, i.e
            ``boto3.resource('dynamodb').Table('foo').meta.client``.

        :type flush_amount: int
        :param flush_amount: The number of items to keep in
            a local buffer before sending a batch_write_item
            request to DynamoDB.

        :type overwrite_by_pkeys: list(string)
        :param overwrite_by_pkeys: De-duplicate request items in buffer
            if match new request item on specified primary keys. i.e
            ``["partition_key1", "sort_key2", "sort_key3"]``

        N)�_table_name�_client�
_items_buffer�
_flush_amount�_overwrite_by_pkeys)r�
table_namer�flush_amountrs     rrzBatchWriter.__init__Bs+��<&���������)���#5�� r
c�.�|jdd|ii�y)N�
PutRequest�Item��_add_request_and_process)rr)s  r�put_itemzBatchWriter.put_itemfs���%�%�|�f�d�^�&D�Er
c�.�|jdd|ii�y)N�
DeleteRequest�Keyr*)rr/s  r�delete_itemzBatchWriter.delete_itemis���%�%�����&E�Fr
c��|jr|j|�|jj|�|j	�yr
)r$� _remove_dup_pkeys_request_if_anyr"�append�_flush_if_needed)r�requests  rr+z$BatchWriter._add_request_and_processls9���#�#��1�1�'�:����!�!�'�*����r
c���|j|�}|jD]H}|j|�|k(s�|jj|�tj	d|��Jy)Nz4With overwrite_by_pkeys enabled, skipping request:%s)�_extract_pkey_valuesr"�remove�logger�debug)rr5�pkey_values_new�items    rr2z,BatchWriter._remove_dup_pkeys_request_if_anyrs`���3�3�G�<���&�&�	�D��(�(��.�/�A��"�"�)�)�$�/����M���	r
c���|jd�r#|jD�cgc]
}|dd|��c}S|jd�r#|jD�cgc]
}|dd|��c}Sycc}wcc}w)Nr(r)r.r/)�getr$)rr5�keys   rr7z BatchWriter._extract_pkey_values|s����;�;�|�$� �3�3�����%�f�-�c�2��
��[�[��
)� �3�3�����(��/��4��
�����
s�A*�A/c�j�t|j�|jk\r|j�yyr
)�lenr"r#�_flush�rs rr4zBatchWriter._flush_if_needed�s)���t�!�!�"�d�&8�&8�8��K�K�M�9r
c��|jd|j}|j|jd|_|jj|j|i��}|d}|si}|j|jg�}|jj
|�tjdt|�t|j��y)N)�RequestItems�UnprocessedItemsz$Batch write sent %s, unprocessed: %s)
r"r#r!�batch_write_itemr r>�extendr9r:rA)r�
items_to_send�response�unprocessed_items�	item_lists     rrBzBatchWriter._flush�s����*�*�+?�T�-?�-?�@�
�!�/�/��0B�0B�0D�E����<�<�0�0��*�*�M�:�1�
��%�%7�8�� � "��%�)�)�$�*:�*:�B�?�	�	
���!�!�)�,����2��
����"�"�#�	
r
c��|Sr
�rCs r�	__enter__zBatchWriter.__enter__�s���r
c�X�|jr|j�|jr�yyr
)r"rB)r�exc_type�	exc_value�tbs    r�__exit__zBatchWriter.__exit__�s!��� � ��K�K�M�� � r
)�N)rrr�__doc__rr,r0r+r2r7r4rBrOrTrNr
rrr?sA��K�GK�"6�HF�G� ����
�&�r
r)�logging�	getLoggerrr9r	rrrNr
r�<module>rYs8���	��	�	�8�	$��*�!
�!
�Hh�hr