o a/@sddlmZmZddlmZmZmZmZmZGdddeZ d*ddZ d*dd Z d*d d Z d*d d Z d*ddZd*ddZd*ddZd*ddZd*ddZd*ddZd*ddZed*ddZd*ddZGd d!d!eZd+d$d%Zd&d'Zd*d(d)ZdS),)ContextDecoratorcontextmanager)DEFAULT_DB_ALIAS DatabaseErrorErrorProgrammingError connectionsc@seZdZdZdS)TransactionManagementErrorz*Transaction management is used improperly.N)__name__ __module__ __qualname____doc__rr7/usr/lib/python3/dist-packages/django/db/transaction.pyr sr NcCs|durt}t|S)z Get a database connection by name, or the default database connection if no name is provided. This is a private API. N)rrusingrrrget_connection srcC t|S)z,Get the autocommit status of the connection.)rget_autocommitrrrrr rcCt||S)z,Set the autocommit status of the connection.)rset_autocommit) autocommitrrrrrsrcCt|dS)zCommit a transaction.N)rcommitrrrrr!rcCr)zRoll back a transaction.N)rrollbackrrrrr&rrcCr)z Create a savepoint (if supported and required by the backend) inside the current transaction. Return an identifier for the savepoint that will be used for the subsequent rollback or commit. )r savepointrrrrr+s rcCt||dS)zn Roll back the most recent savepoint (if one exists). Do nothing if savepoints are not supported. N)rsavepoint_rollbacksidrrrrr4rcCr)zk Commit the most recent savepoint (if one exists). Do nothing if savepoints are not supported. N)rsavepoint_commitr rrrr#<r"r#cCr)zQ Reset the counter used to generate unique savepoint ids in this thread. N)rclean_savepointsrrrrr$Dsr$cCr)z9Get the "needs rollback" flag -- for *advanced use* only.)r get_rollbackrrrrr%Krr%cCr)a Set or unset the "needs rollback" flag -- for *advanced use* only. When `rollback` is `True`, trigger a rollback when exiting the innermost enclosing atomic block that has `savepoint=True` (that's the default). Use this to force a rollback without raising an exception. When `rollback` is `False`, prevent such a rollback. Use this only after rolling back to a known-good state! Otherwise, you break the atomic block and data corruption may occur. )r set_rollback)rrrrrr&Ps r&ccs4zdVWdStyt|}|jrd|_w)ab Internal low-level utility to mark a transaction as "needs rollback" when an exception is raised while not enforcing the enclosed block to be in a transaction. This is needed by Model.save() and friends to avoid starting a transaction when in autocommit mode and a single query is executed. It's equivalent to: connection = get_connection(using) if connection.get_autocommit(): yield else: with transaction.atomic(using=using, savepoint=False): yield but it uses low-level utilities to avoid performance overhead. NT) Exceptionrin_atomic_blockneeds_rollback)r connectionrrrmark_for_rollback_on_error_s  r+cCr)z Register `func` to be called when the current transaction is committed. If the current transaction is rolled back, `func` will not be called. N)r on_commit)funcrrrrr,{r"r,c@s,eZdZdZdZddZddZddZd S) Atomica Guarantee the atomic execution of a given block. An instance can be used either as a decorator or as a context manager. When it's used as a decorator, __call__ wraps the execution of the decorated function in the instance itself, used as a context manager. When it's used as a context manager, __enter__ creates a transaction or a savepoint, depending on whether a transaction is already in progress, and __exit__ commits the transaction or releases the savepoint on normal exit, and rolls back the transaction or to the savepoint on exceptions. It's possible to disable the creation of savepoints if the goal is to ensure that some code runs within a transaction without creating overhead. A stack of savepoints identifiers is maintained as an attribute of the connection. None denotes the absence of a savepoint. This allows reentrancy even if the same AtomicWrapper is reused. For example, it's possible to define `oa = atomic('other')` and use `@oa` or `with oa:` multiple times. Since database connections are thread-local, this is thread-safe. An atomic block can be tagged as durable. In this case, raise a RuntimeError if it's nested within another atomic block. This guarantees that database changes in a durable block are committed to the database when the block exists without error. This is a private API. TcCs||_||_||_dSNrrdurable)selfrrr1rrr__init__s zAtomic.__init__cCst|j}|jr|jr|jrtd|js%d|_d|_|s%d|_d|_|jrB|j r:|js:| }|j |dS|j ddS|j dddd|_dS)NzDA durable atomic block cannot be nested within another atomic block.TF).force_begin_transaction_with_broken_autocommit) rrr1_ensure_durabilityr( RuntimeErrorcommit_on_exitr)rr savepoint_idsappendr)r2r*r!rrr __enter__s$   zAtomic.__enter__c Cst|j}|jr|j}nd|_z|jrn|duro|jso|jrM|durLz||Wn~tyKz | |||Wt yJd|_Ywwn]z| WnVtynz| Wt ym| Ywwd|_|jr|dur}d|_n-z | |||Wn t yd|_Ynwz| Wn t y| YnwW|js|jrd|_dS|ddS|js|js|jrd|_dSd|_dSdSdS|js|jrd|_w|dw|js|js|jrd|_wd|_w)NFT)rrr8popr(closed_in_transactionr)r#rrrrrcloser*rr7)r2exc_type exc_value tracebackr*r!rrr__exit__s                        zAtomic.__exit__N)r r r r r5r3r:rArrrrr.s " !r.TFcCs$t|r tt|||St|||Sr/)callabler.rr0rrratomic+s rCcCs0z |j|W|Sty|h|_Y|Swr/)_non_atomic_requestsaddAttributeError)viewrrrrrD5s rDcs*tr ttSdurtfddS)Ncs t|Sr/)rD)rGrrrCs z%non_atomic_requests..)rBrDrrrrrnon_atomic_requests=s   rIr/)NTF) contextlibrr django.dbrrrrrr rrrrrrrr#r$r%r&r+r,r.rCrDrIrrrrs,             %