o
    ×èFh  ã                   @   s<   d Z ddlmZ ddlmZ ddlmZ G dd„ deƒZdS )z=Helpers for batch requests to the Google Cloud Firestore API.é    )Úgapic_v1)Úretry)ÚBaseWriteBatchc                       sT   e Zd ZdZd‡ fdd„Zejjdfdej	de
defdd	„Zd
d„ Zdd„ Z‡  ZS )Ú
WriteBatcha
  Accumulate write operations to be sent in a batch. Use this over
    `BulkWriteBatch` for lower volumes or when the order of operations
    within a given batch is important.

    This has the same set of methods for write operations that
    :class:`~google.cloud.firestore_v1.document.DocumentReference` does,
    e.g. :meth:`~google.cloud.firestore_v1.document.DocumentReference.create`.

    Args:
        client (:class:`~google.cloud.firestore_v1.client.Client`):
            The client that created this batch.
    ÚreturnNc                    s   t t| ƒj|d� d S )N)Úclient)Úsuperr   Ú__init__)Úselfr   ©Ú	__class__© úX/var/www/html/loop/nvenv/lib/python3.10/site-packages/google/cloud/firestore_v1/batch.pyr	   %   s   zWriteBatch.__init__r   Útimeoutc                 C   sP   |   ||¡\}}| jjjd|| jjdœ|¤Ž}g | _t|jƒ | _}|j| _|S )a’  Commit the changes accumulated in this batch.

        Args:
            retry (google.api_core.retry.Retry): Designation of what errors, if any,
                should be retried.  Defaults to a system-specified policy.
            timeout (float): The timeout for this request.  Defaults to a
                system-specified value.

        Returns:
            List[:class:`google.cloud.proto.firestore.v1.write.WriteResult`, ...]:
            The write results corresponding to the changes committed, returned
            in the same order as the changes were applied to this batch. A
            write result contains an ``update_time`` field.
        )ÚrequestÚmetadataNr   )	Ú_prep_commitÚ_clientÚ_firestore_apiÚcommitÚ_rpc_metadataÚ
_write_pbsÚlistÚwrite_resultsÚcommit_time)r
   r   r   r   ÚkwargsÚcommit_responseÚresultsr   r   r   r   (   s   
þýzWriteBatch.commitc                 C   s   | S ©Nr   )r
   r   r   r   Ú	__enter__G   s   zWriteBatch.__enter__c                 C   s   |d u r
|   ¡  d S d S r   )r   )r
   Úexc_typeÚ	exc_valueÚ	tracebackr   r   r   Ú__exit__J   s   ÿzWriteBatch.__exit__)r   N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r	   r   ÚmethodÚDEFAULTÚretriesÚRetryÚfloatr   r   r   r#   Ú__classcell__r   r   r   r   r      s    ÿÿÿ
þr   N)r'   Úgoogle.api_corer   r   r*   Ú$google.cloud.firestore_v1.base_batchr   r   r   r   r   r   Ú<module>   s
   