o
     iE                     @  s  U d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
 ddlmZ ddlmZ erGddlmZ ddlmZ ddlmZ dd	lmZ dd
lmZ dZ	 dZded< dZded< edZ ded< edZ!ded< dZ"ded< dZ#ded< dZ$ded< G dd de%Z&G dd de%Z'dS ) zEHelpers for applying Google Cloud Firestore changes in a transaction.    )annotations)TYPE_CHECKINGAnyAsyncGenerator	Coroutine	GeneratorOptionalUnion)retry)types)AsyncStreamGenerator)DocumentSnapshot)ExplainOptions)StreamGenerator)write   z@The transaction has already begun. Current transaction ID: {!r}.str_CANT_BEGINz:The transaction has no transaction ID, so it cannot be {}._MISSING_ID_TEMPLATEzrolled back_CANT_ROLLBACK	committed_CANT_COMMITz8Cannot perform write operation in read-only transaction._WRITE_READ_ONLYz.Failed to commit transaction in {:d} attempts._EXCEED_ATTEMPTS_TEMPLATEz,Only read-write transactions can be retried._CANT_RETRY_READ_ONLYc                   @  s   e Zd ZdZedfd-ddZd.d	d
Zd/ddZedd Z	edd Z
d-ddZd0ddZdd Zd1ddZ		d2d3d%d&Z		d2dd'd4d+d,ZdS )5BaseTransactiona  Accumulate read-and-write operations to be sent in a transaction.

    Args:
        max_attempts (Optional[int]): The maximum number of attempts for
            the transaction (i.e. allowing retries). Defaults to
            :attr:`~google.cloud.firestore_v1.transaction.MAX_ATTEMPTS`.
        read_only (Optional[bool]): Flag indicating if the transaction
            should be read-only or should allow writes. Defaults to
            :data:`False`.
    FreturnNonec                 C  s   || _ || _d | _d S N)_max_attempts
_read_only_id)selfmax_attempts	read_only r%   /var/www/snowflake_co_dev_github/snow_flake_back_end_deploy/env/lib/python3.10/site-packages/google/cloud/firestore_v1/base_transaction.py__init__@   s   
zBaseTransaction.__init__	write_pbslist[write_pb.Write]c                 C     t r   NotImplementedError)r"   r(   r%   r%   r&   _add_write_pbsE      zBaseTransaction._add_write_pbsretry_idUnion[bytes, None])Optional[types.common.TransactionOptions]c                 C  sH   |dur| j rtttjtjj|ddS | j r"tjtj dS dS )a  Convert the current object to protobuf.

        The ``retry_id`` value is used when retrying a transaction that
        failed (e.g. due to contention). It is intended to be the "first"
        transaction that failed (i.e. if multiple retries are needed).

        Args:
            retry_id (Union[bytes, NoneType]): Transaction ID of a transaction
                to be retried.

        Returns:
            Optional[google.cloud.firestore_v1.types.TransactionOptions]:
            The protobuf ``TransactionOptions`` if ``read_only==True`` or if
            there is a transaction ID to be retried, else :data:`None`.

        Raises:
            ValueError: If ``retry_id`` is not :data:`None` but the
                transaction is read-only.
        N)retry_transaction)
read_write)r$   )r    
ValueErrorr   r   TransactionOptions	ReadWriteReadOnlyr"   r/   r%   r%   r&   _options_protobufH   s   z!BaseTransaction._options_protobufc                 C  s
   | j duS )zDetermine if this transaction has already begun.

        Returns:
            bool: Indicates if the transaction has started.
        Nr!   r"   r%   r%   r&   in_progressn   s   
zBaseTransaction.in_progressc                 C  s   | j S )zGet the current transaction ID.

        Returns:
            Optional[bytes]: The transaction ID (or :data:`None` if the
            current transaction is not in progress).
        r:   r;   r%   r%   r&   idw   s   zBaseTransaction.idc                 C  s   g | _ d| _dS )zClean up the instance after :meth:`_rollback`` or :meth:`_commit``.

        This intended to occur on success or failure of the associated RPCs.
        N)
_write_pbsr!   r;   r%   r%   r&   	_clean_up   s   
zBaseTransaction._clean_upNc                 C  r*   r   r+   r8   r%   r%   r&   _begin   r.   zBaseTransaction._beginc                 C  r*   r   r+   r;   r%   r%   r&   	_rollback   r.   zBaseTransaction._rollback&Union[list, Coroutine[Any, Any, list]]c                 C  r*   r   r+   r;   r%   r%   r&   _commit   r.   zBaseTransaction._commit
referenceslistr
   2retries.Retry | retries.AsyncRetry | object | Nonetimeoutfloat | NonecGenerator[DocumentSnapshot, Any, None] | Coroutine[Any, Any, AsyncGenerator[DocumentSnapshot, Any]]c                 C  r*   r   r+   )r"   rD   r
   rG   r%   r%   r&   get_all   s   	zBaseTransaction.get_all)explain_optionsrK   Optional[ExplainOptions]StreamGenerator[DocumentSnapshot] | Generator[DocumentSnapshot, Any, None] | Coroutine[Any, Any, AsyncGenerator[DocumentSnapshot, Any]] | Coroutine[Any, Any, AsyncStreamGenerator[DocumentSnapshot]]c                C  r*   r   r+   )r"   ref_or_queryr
   rG   rK   r%   r%   r&   get   s   zBaseTransaction.getr   r   )r(   r)   )r/   r0   r   r1   r   )r   rB   )NN)rD   rE   r
   rF   rG   rH   r   rI   )r
   rF   rG   rH   rK   rL   r   rM   )__name__
__module____qualname____doc__MAX_ATTEMPTSr'   r-   r9   propertyr<   r=   r?   r@   rA   rC   rJ   rO   r%   r%   r%   r&   r   4   s*    

&


	

r   c                   @  s4   e Zd ZdZdddZdddZdd	 Zd
d ZdS )_BaseTransactionalaY  Provide a callable object to use as a transactional decorater.

    This is surfaced via
    :func:`~google.cloud.firestore_v1.transaction.transactional`.

    Args:
        to_wrap (Callable[[:class:`~google.cloud.firestore_v1.transaction.Transaction`, ...], Any]):
            A callable that should be run (and retried) in a transaction.
    r   r   c                 C  s   || _ d | _	 d | _d S r   )to_wrap
current_idr/   )r"   rX   r%   r%   r&   r'      s
   z_BaseTransactional.__init__c                 C  s   d| _ d| _dS )zUnset the transaction IDs.N)rY   r/   r;   r%   r%   r&   _reset   s   
z_BaseTransactional._resetc                 O  r*   r   r+   r"   transactionargskwargsr%   r%   r&   _pre_commit   r.   z_BaseTransactional._pre_commitc                 O  r*   r   r+   r[   r%   r%   r&   __call__   r.   z_BaseTransactional.__call__NrP   )rQ   rR   rS   rT   r'   rZ   r_   r`   r%   r%   r%   r&   rW      s    


rW   N)(rT   
__future__r   typingr   r   r   r   r   r   r	   google.api_corer
   retriesgoogle.cloud.firestore_v1r   0google.cloud.firestore_v1.async_stream_generatorr   "google.cloud.firestore_v1.documentr   'google.cloud.firestore_v1.query_profiler   *google.cloud.firestore_v1.stream_generatorr   google.cloud.firestore_v1.typesr   write_pbrU   r   __annotations__r   formatr   r   r   r   r   objectr   rW   r%   r%   r%   r&   <module>   s,   $
y