Ë
    ö%9j]7  ã                  ó  — d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
mZ ddl	mZ ddlmZmZ ddlmZ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rdd
lZddlm Z  ddl!m"Z" ddl#m$Z$  G d„ dejJ                  e«      Z& G d„ de«      Z'dd„Z(y
)zEHelpers for applying Google Cloud Firestore changes in a transaction.é    )Úannotations)ÚTYPE_CHECKINGÚAnyÚCallableÚ	GeneratorÚOptional)Ú
exceptionsÚgapic_v1)Úretry)Ú_helpersÚbatch)Ú_CANT_BEGINÚ_CANT_COMMITÚ_CANT_ROLLBACKÚ_EXCEED_ATTEMPTS_TEMPLATEÚ_WRITE_READ_ONLYÚMAX_ATTEMPTSÚBaseTransactionÚ_BaseTransactional)ÚDocumentReference)ÚQueryN)ÚDocumentSnapshot)ÚExplainOptions)ÚStreamGeneratorc                  óò   ‡ — e Zd ZdZedfdˆ fd„Zdˆ fd„Zddd„Zdd„Zdd„Z	e
j                  j                  dfdd	œ	 	 	 	 	 	 	 	 	 dd
„Ze
j                  j                  dfdddœ	 	 	 	 	 	 	 	 	 	 	 dd„Zˆ xZS )ÚTransactionaD  Accumulate read-and-write operations to be sent in a transaction.

    Args:
        client (:class:`~google.cloud.firestore_v1.client.Client`):
            The client that created this transaction.
        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`.
    Fc                óZ   •— t         t        | �  |«       t        j                  | ||«       y ©N)Úsuperr   Ú__init__r   )ÚselfÚclientÚmax_attemptsÚ	read_onlyÚ	__class__s       €úa/var/www/html/truck-me/venv/lib/python3.12/site-packages/google/cloud/firestore_v1/transaction.pyr    zTransaction.__init__=   s$   ø€ ÜŒk˜4Ñ)¨&Ô1Ü× Ñ   |°YÕ?ó    c                ób   •— | j                   rt        t        «      ‚t        t        | �  |«       y)a
  Add `Write`` protobufs to this transaction.

        Args:
            write_pbs (List[google.cloud.firestore_v1.                write.Write]): A list of write protobufs to be added.

        Raises:
            ValueError: If this transaction is read-only.
        N)Ú
_read_onlyÚ
ValueErrorr   r   r   Ú_add_write_pbs)r!   Ú	write_pbsr%   s     €r&   r+   zTransaction._add_write_pbsA   s'   ø€ ð �?Š?ÜÔ-Ó.Ð.äŒk˜4Ñ/°	Õ:r'   Nc                óT  — | j                   r*t        j                  | j                  «      }t	        |«      ‚| j
                  j                  j                  | j
                  j                  | j                  |«      dœ| j
                  j                  ¬«      }|j                  | _        y)zìBegin the transaction.

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

        Raises:
            ValueError: If the current transaction has already begun.
        )ÚdatabaseÚoptions©ÚrequestÚmetadataN)Úin_progressr   ÚformatÚ_idr*   Ú_clientÚ_firestore_apiÚbegin_transactionÚ_database_stringÚ_options_protobufÚ_rpc_metadataÚtransaction)r!   Úretry_idÚmsgÚtransaction_responses       r&   Ú_beginzTransaction._beginP   sŠ   € ð ×ÒÜ×$Ñ$ T§X¡XÓ.ˆCÜ˜S“/Ð!à#Ÿ|™|×:Ñ:×LÑLà ŸL™L×9Ñ9Ø×1Ñ1°(Ó;ñð —\‘\×/Ñ/ð  Mó  
Ðð (×3Ñ3ˆ�r'   c                ó>  — | j                   st        t        «      ‚	 | j                  j                  j                  | j                  j                  | j                  dœ| j                  j                  ¬«       | j                  «        y# | j                  «        w xY w)zÀRoll back the transaction.

        Raises:
            ValueError: If no transaction is in progress.
            google.api_core.exceptions.GoogleAPICallError: If the rollback fails.
        )r.   r<   r0   N)
r3   r*   r   r6   r7   Úrollbackr9   r5   r;   Ú	_clean_up)r!   s    r&   Ú	_rollbackzTransaction._rollbackg   sy   € ð ×ÒÜœ^Ó,Ð,ð	à�L‰L×'Ñ'×0Ñ0à $§¡× =Ñ =Ø#'§8¡8ñð Ÿ™×3Ñ3ð 1ô ð �N‰NÕøˆD�N‰NÕús   �AB
 Â
Bc                ó”  — | j                   st        t        «      ‚| j                  j                  j                  | j                  j                  | j                  | j                  dœ| j                  j                  ¬«      }| j                  «        t        |j                  «      | _        |j                  | _        | j                  S )a¾  Transactionally commit the changes accumulated.

        Returns:
            List[:class:`google.cloud.firestore_v1.write.WriteResult`, ...]:
            The write results corresponding to the changes committed, returned
            in the same order as the changes were applied to this transaction.
            A write result contains an ``update_time`` field.

        Raises:
            ValueError: If no transaction is in progress.
        )r.   Úwritesr<   r0   )r3   r*   r   r6   r7   Úcommitr9   Ú
_write_pbsr5   r;   rC   ÚlistÚwrite_resultsÚcommit_time)r!   Úcommit_responses     r&   Ú_commitzTransaction._commit~   sŸ   € ð ×ÒÜœ\Ó*Ð*àŸ,™,×5Ñ5×<Ñ<à ŸL™L×9Ñ9ØŸ/™/Ø#Ÿx™xñð
 —\‘\×/Ñ/ð =ó 
ˆð 	�‰ÔÜ! /×"?Ñ"?Ó@ˆÔØ*×6Ñ6ˆÔØ×!Ñ!Ð!r'   )Ú	read_timec               óz   — t        j                  ||«      }|�||d<    | j                  j                  |fd| i|¤ŽS )a  Retrieves multiple documents from Firestore.

        Args:
            references (List[.DocumentReference, ...]): Iterable of document
                references to be retrieved.
            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.
            read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
                time. This must be a timestamp within the past one hour, or if Point-in-Time Recovery
                is enabled, can additionally be a whole minute timestamp within the past 7 days. If no
                timezone is specified in the :class:`datetime.datetime` object, it is assumed to be UTC.

        Yields:
            .DocumentSnapshot: The next document snapshot that fulfills the
            query, or :data:`None` if the document does not exist.
        rN   r<   )r   Úmake_retry_timeout_kwargsr6   Úget_all)r!   Ú
referencesr   ÚtimeoutrN   Úkwargss         r&   rQ   zTransaction.get_all›   sG   € ô4 ×3Ñ3°E¸7ÓCˆØÐ Ø"+ˆF�;ÑØ#ˆt�|‰|×#Ñ# JÑK¸DÐKÀFÑKÐKr'   )Úexplain_optionsrN   c               ó"  — t        j                  ||«      }|�||d<   t        |t        «      r-|�t	        d«      ‚ | j
                  j                  |gfd| i|¤ŽS t        |t        «      r|�||d<    |j                  dd| i|¤ŽS t	        d«      ‚)a>  Retrieve a document or a query result from the database.

        Args:
            ref_or_query (DocumentReference | Query):
                The document references or query object to return.
            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.
            explain_options
                (Optional[:class:`~google.cloud.firestore_v1.query_profile.ExplainOptions`]):
                Options to enable query profiling for this query. When set,
                explain_metrics will be available on the returned generator.
                Can only be used when running a query, not a document reference.
            read_time (Optional[datetime.datetime]): If set, reads documents as they were at the given
                time. This must be a timestamp within the past one hour, or if Point-in-Time Recovery
                is enabled, can additionally be a whole minute timestamp within the past 7 days. If no
                timezone is specified in the :class:`datetime.datetime` object, it is assumed to be UTC.

        Yields:
            .DocumentSnapshot: The next document snapshot that fulfills the
            query, or :data:`None` if the document does not exist.

        Raises:
            ValueError: if `ref_or_query` is not one of the supported types, or
            explain_options is provided when `ref_or_query` is a document
            reference.
        rN   z^When type of `ref_or_query` is `AsyncDocumentReference`, `explain_options` cannot be provided.r<   rU   zIValue for argument "ref_or_query" must be a DocumentReference or a Query.© )	r   rP   Ú
isinstancer   r*   r6   rQ   r   Ústream)r!   Úref_or_queryr   rS   rU   rN   rT   s          r&   ÚgetzTransaction.getº   sµ   € ôJ ×3Ñ3°E¸7ÓCˆØÐ Ø"+ˆF�;ÑÜ�lÔ$5Ô6ØÐ*Ü ð<óð ð (�4—<‘<×'Ñ'¨¨ÑSÀDÐSÈFÑSÐSÜ˜¤eÔ,ØÐ*Ø,;�Ð(Ñ)Ø&�<×&Ñ&ÑB°4ÐB¸6ÑBÐBäØ[óð r'   ©ÚreturnÚNone)r,   rI   r]   r^   r   )r=   zbytes | Noner]   r^   )r]   rI   )
rR   rI   r   úretries.Retry | object | NonerS   zfloat | NonerN   zdatetime.datetime | Noner]   z&Generator[DocumentSnapshot, Any, None])rZ   zDocumentReference | Queryr   r_   rS   zOptional[float]rU   zOptional[ExplainOptions]rN   zOptional[datetime.datetime]r]   zJStreamGenerator[DocumentSnapshot] | Generator[DocumentSnapshot, Any, None])Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r    r+   r@   rD   rM   r
   ÚmethodÚDEFAULTrQ   r[   Ú__classcell__©r%   s   @r&   r   r   /   sâ   ø„ ñð -9ÀEö @õ;ô4ó.ó."ð@ 08¯©×/FÑ/FØ $ð	Lð /3ñLàðLð -ðLð ð	Lð ,ðLð 
0óLðD 08¯©×/FÑ/FØ#'ð	6ð 59Ø15ñ6à/ð6ð -ð6ð !ð	6ð 2ð6ð /ð6ð 
T÷6r'   r   c                  ó4   ‡ — e Zd ZdZdˆ fd„Zdd„Zdd„Zˆ xZS )Ú_TransactionalaY  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.
    c                ó,   •— t         t        | �  |«       y r   )r   ri   r    )r!   Úto_wrapr%   s     €r&   r    z_Transactional.__init__þ   s   ø€ ÜŒn˜dÑ,¨WÕ5r'   c                óâ   — |j                  «        |j                  | j                  ¬«       |j                  | _        | j                  €| j                  | _         | j
                  |g|¢­i |¤ŽS )am  Begin transaction and call the wrapped callable.

        Args:
            transaction
                (:class:`~google.cloud.firestore_v1.transaction.Transaction`):
                A transaction to execute the callable within.
            args (Tuple[Any, ...]): The extra positional arguments to pass
                along to the wrapped callable.
            kwargs (Dict[str, Any]): The extra keyword arguments to pass
                along to the wrapped callable.

        Returns:
            Any: result of the wrapped callable.

        Raises:
            Exception: Any failure caused by ``to_wrap``.
        )r=   )rC   r@   r=   r5   Ú
current_idrk   )r!   r<   ÚargsrT   s       r&   Ú_pre_commitz_Transactional._pre_commit  sb   € ð& 	×ÑÔØ×Ñ D§M¡MÐÔ2ð &Ÿ/™/ˆŒØ�=‰=Ð Ø ŸO™OˆDŒMØˆt�|‰|˜KÐ9¨$Ò9°&Ñ9Ð9r'   c                ó¦  — | j                  «        |j                  st        j                  nd}d}	 t	        |j
                  «      D ],  } | j                  |g|¢­i |¤Ž}	 |j                  «        |c S  t        j                  |j
                  «      }	t        |	«      |‚# |$ r}|}Y d}~Œfd}~ww xY w# t        $ r |j                  «        ‚ w xY w)aš  Execute the wrapped callable within a transaction.

        Args:
            transaction
                (:class:`~google.cloud.firestore_v1.transaction.Transaction`):
                A transaction to execute the callable within.
            args (Tuple[Any, ...]): The extra positional arguments to pass
                along to the wrapped callable.
            kwargs (Dict[str, Any]): The extra keyword arguments to pass
                along to the wrapped callable.

        Returns:
            Any: The result of the wrapped callable.

        Raises:
            ValueError: If the transaction does not succeed in
                ``max_attempts``.
        rW   N)Ú_resetr)   r	   ÚAbortedÚrangeÚ_max_attemptsro   rM   r   r4   r*   ÚBaseExceptionrD   )
r!   r<   rn   rT   Úretryable_exceptionsÚlast_excÚattemptÚresultÚexcr>   s
             r&   Ú__call__z_Transactional.__call__  sÙ   € ð& 	�‰Œà(3×(>Ò(>ŒZ×ÒÀBð 	ð ˆð	Ü  ×!:Ñ!:Ó;ò #�Ø)˜×)Ñ)¨+ÐG¸ÒGÀÑG�ð#Ø×'Ñ'Ô)Ø!’Mð	#ô ,×2Ñ2°;×3LÑ3LÓMˆCÜ˜S“/ xÐ/øð ,ò #Ø"•Hûð#ûô ò 	ð ×!Ñ!Ô#Øð		ús;   ².B5 Á!B!Á2B5 Á5,B5 Â!B2Â&B-Â(B5 Â-B2Â2B5 Â5Cr\   )r<   r   r]   r   )r<   r   )r`   ra   rb   rc   r    ro   r{   rf   rg   s   @r&   ri   ri   ó   s   ø„ ñõ6ó:÷8/r'   ri   c                ó   — t        | «      S )a‡  Decorate a callable so that it runs in a transaction.

    Args:
        to_wrap
            (Callable[[:class:`~google.cloud.firestore_v1.transaction.Transaction`, ...], Any]):
            A callable that should be run (and retried) in a transaction.

    Returns:
        Callable[[:class:`~google.cloud.firestore_v1.transaction.Transaction`, ...], Any]:
        the wrapped callable.
    )ri   )rk   s    r&   Útransactionalr}   O  s   € ô ˜'Ó"Ð"r'   )rk   r   r]   ri   ))rc   Ú
__future__r   Útypingr   r   r   r   r   Úgoogle.api_corer	   r
   r   ÚretriesÚgoogle.cloud.firestore_v1r   r   Ú*google.cloud.firestore_v1.base_transactionr   r   r   r   r   r   r   r   Ú"google.cloud.firestore_v1.documentr   Úgoogle.cloud.firestore_v1.queryr   ÚdatetimeÚ'google.cloud.firestore_v1.base_documentr   Ú'google.cloud.firestore_v1.query_profiler   Ú*google.cloud.firestore_v1.stream_generatorr   Ú
WriteBatchr   ri   r}   rW   r'   r&   ú<module>r‹      sr   ðñ Lå "ç DÕ Dç 0Ý ,ç 5÷	÷ 	ó 	õ AÝ 1ñ ÛåHÝFÝJôA�%×"Ñ" Oô AôHYÐ'ô Yôx#r'   