U å€C^•ã@s>ddlZe e¡Zdd„ZGdd„deƒZGdd„deƒZdS)éNcKs| dt¡dS)Nr)ÚinsertÚ TableResource)Z base_classesÚkwargs©rú7/tmp/pip-install-6_kvzl1k/boto3/boto3/dynamodb/table.pyÚregister_table_methodssrcs&eZdZ‡fdd„Zddd„Z‡ZS)rcstt|ƒj||ŽdS©N)ÚsuperrÚ__init__)ÚselfÚargsr©Ú __class__rrr szTableResource.__init__NcCst|j|jj|d�S)aZCreate 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 xrange(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)r rrrrÚ batch_writer s ÿzTableResource.batch_writer)N)Ú__name__Ú __module__Ú __qualname__r rÚ __classcell__rrr rrs rc@sbeZdZdZddd„Zdd„Zdd „Zd d „Zd d „Zdd„Z dd„Z dd„Z dd„Z dd„Z dS)rzAAutomatically handle batch writes to DynamoDB for a single table.éNcCs"||_||_g|_||_||_dS)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 Z table_namerZ flush_amountrrrrr As zBatchWriter.__init__cCs| dd|ii¡dS)NÚ PutRequestÚItem©Ú_add_request_and_process)r r rrrÚput_itemdszBatchWriter.put_itemcCs| dd|ii¡dS)NÚ DeleteRequestÚKeyr!)r r%rrrÚ delete_itemgszBatchWriter.delete_itemcCs(|jr| |¡|j |¡| ¡dSr)rÚ _remove_dup_pkeys_request_if_anyrÚappendÚ_flush_if_needed©r Úrequestrrrr"js  z$BatchWriter._add_request_and_processcCs@| |¡}|jD]*}| |¡|kr|j |¡t d|¡qdS)Nz4With overwrite_by_pkeys enabled, skipping request:%s)Ú_extract_pkey_valuesrÚremoveÚloggerÚdebug)r r+Zpkey_values_newÚitemrrrr'ps   ÿz,BatchWriter._remove_dup_pkeys_request_if_anycs@ˆ d¡r‡fdd„|jDƒSˆ d¡r<‡fdd„|jDƒSdS)Nrcsg|]}ˆdd|‘qS)rr r©Ú.0Úkey©r+rrÚ zsÿz4BatchWriter._extract_pkey_values..r$csg|]}ˆdd|‘qS)r$r%rr1r4rrr5}sÿ)Úgetrr*rr4rr,xs  ÿ  ÿz BatchWriter._extract_pkey_valuescCst|jƒ|jkr| ¡dSr)ÚlenrrÚ_flush©r rrrr)�szBatchWriter._flush_if_neededcCs‚|jd|j…}|j|jd…|_|jj|j|id�}|d}|r`||jr`|j ||j¡ng|_t dt|ƒt|jƒ¡dS)N)Z RequestItemsZUnprocessedItemsz$Batch write sent %s, unprocessed: %s) rrrZbatch_write_itemrÚextendr.r/r7)r Z items_to_sendÚresponseZunprocessed_itemsrrrr8…sÿÿzBatchWriter._flushcCs|Srrr9rrrÚ __enter__•szBatchWriter.__enter__cCs|jr| ¡qdSr)rr8)r Úexc_typeÚ exc_valueÚtbrrrÚ__exit__˜szBatchWriter.__exit__)rN)rrrÚ__doc__r r#r&r"r'r,r)r8r<r@rrrrr?sÿ # r)ÚloggingÚ getLoggerrr.rÚobjectrrrrrrÚ s  #