o ÚøaÅ/ã@sòddlmZmZddlmZmZmZmZmZGdd„deƒZ d*dd„Z d*dd „Z d*d d „Z d*d d „Z d*dd„Zd*dd„Zd*dd„Zd*dd„Zd*dd„Zd*dd„Zd*dd„Zed*dd„ƒZd*dd„ZGd d!„d!eƒZd+d$d%„Zd&d'„Zd*d(d)„ZdS),é)ÚContextDecoratorÚcontextmanager)ÚDEFAULT_DB_ALIASÚ DatabaseErrorÚErrorÚProgrammingErrorÚ connectionsc@seZdZdZdS)ÚTransactionManagementErrorz*Transaction management is used improperly.N)Ú__name__Ú __module__Ú __qualname__Ú__doc__©rrú7/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)rr©ÚusingrrrÚget_connection srcCó t|ƒ ¡S)z,Get the autocommit status of the connection.)rÚget_autocommitrrrrró rcCót|ƒ |¡S)z,Set the autocommit status of the connection.)rÚset_autocommit)Ú autocommitrrrrrsrcCót|ƒ ¡dS)zCommit a transaction.N)rÚcommitrrrrr!órcCr)zRoll back a transaction.N)rÚrollbackrrrrr&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 rcCót|ƒ |¡dS)zn Roll back the most recent savepoint (if one exists). Do nothing if savepoints are not supported. N)rÚsavepoint_rollback©Úsidrrrrr4órcCr)zk Commit the most recent savepoint (if one exists). Do nothing if savepoints are not supported. N)rÚsavepoint_commitr rrrr#<r"r#cCr)zQ Reset the counter used to generate unique savepoint ids in this thread. N)rÚclean_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)Ú ExceptionrÚin_atomic_blockÚneeds_rollback)rÚ connectionrrrÚmark_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,eZdZdZdZdd„Zdd„Zdd„Zd 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||_||_||_dS©N©rrÚdurable)Úselfrrr1rrrÚ__init__¬s zAtomic.__init__cCsœt|jƒ}|jr|jr|jrtdƒ‚|js%d|_d|_| ¡s%d|_d|_|jrB|j r:|js:|  ¡}|j   |¡dS|j   d¡dS|j dddd|_dS)NzDA durable atomic block cannot be nested within another atomic block.TF)Ú.force_begin_transaction_with_broken_autocommit) rrr1Ú_ensure_durabilityr(Ú RuntimeErrorÚcommit_on_exitr)rrÚ savepoint_idsÚappendr)r2r*r!rrrÚ __enter__±s$ ÿ  zAtomic.__enter__c Csêt|jƒ}|jr|j ¡}nd|_zÂ|jrn”|duro|jso|jrM|durLz| |¡Wn~tyKz |  |¡| |¡W‚t yJd|_Y‚wwn]z|  ¡WnVtynz|  ¡W‚t ym|  ¡Y‚wwd|_|jr–|dur}d|_n-z |  |¡| |¡Wn t y•d|_Ynwz|  ¡Wn t y©|  ¡YnwW|js½|jr¶d|_dS| d¡dS|jsÐ|jsÒ|jrËd|_dSd|_dSdSdS|jsä|jrÞd|_w| d¡w|jsô|jsô|jrñd|_wd|_w)NFT)rrr8Úpopr(Úclosed_in_transactionr)r#rrrrrÚcloser*rr7)r2Úexc_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.rr0rrrÚatomic+s rCcCs0z |j |¡W|Sty|h|_Y|Swr/)Ú_non_atomic_requestsÚaddÚAttributeError)ÚviewrrrrrD5s þ þrDcs*tˆƒr tˆtƒSˆdurt‰‡fdd„S)Ncs t|ˆƒSr/)rD)rGrrrÚCs z%non_atomic_requests..)rBrDrrrrrÚnon_atomic_requests=s   rIr/)NTF)Ú contextlibrrÚ django.dbrrrrrr rrrrrrrr#r$r%r&r+r,r.rCrDrIrrrrÚs,             %