https://t.me/RX1948
Server : Apache
System : Linux iad1-shared-b8-43 6.6.49-grsec-jammy+ #10 SMP Thu Sep 12 23:23:08 UTC 2024 x86_64
User : dh_edsupp ( 6597262)
PHP Version : 8.2.26
Disable Function : NONE
Directory :  /lib/python3/dist-packages/django/db/backends/base/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/django/db/backends/base/__pycache__/base.cpython-310.pyc
o

3�a�`�@s�ddlZddlZddlZddlZddlZddlmZddlmZddl	Z	ddl
mZddlm
Z
ddlmZmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlm Z dZ!Gdd�d�Z"dS)�N)�deque)�contextmanager)�settings)�ImproperlyConfigured)�DEFAULT_DB_ALIAS�
DatabaseError)�utils)�BaseDatabaseValidation)�connection_created)�TransactionManagementError��DatabaseErrorWrapper)�timezone)�async_unsafe)�cached_property�	__no_db__c@s~eZdZdZiZiZiZdZdZdZ	dZ
dZdZdZ
dZdZeZdZefdd�Zdd�Zed	d
��Zedd��Zed
d��Zedd��Zdd�Zdd�Zdd�Zd|dd�Ze dd��Z!dd�Z"e dd��Z#dd �Z$d|d!d"�Z%d#d$�Z&d%d&�Z'd'd(�Z(e d)d*��Z)e d+d,��Z*e d-d.��Z+e d/d0��Z,d1d2�Z-d3d4�Z.d5d6�Z/d7d8�Z0e d9d:��Z1e d;d<��Z2e d=d>��Z3e d?d@��Z4dAdB�Z5dCdD�Z6d}dFdG�Z7dHdI�Z8dJdK�Z9dLdM�Z:dNdO�Z;e<dPdQ��Z=dRdS�Z>dTdU�Z?d|dVdW�Z@dXdY�ZAdZd[�ZBed\d]��ZCd^d_�ZDd`da�ZEdbdc�ZFddde�ZGedfdg��ZHdhdi�ZIdjdk�ZJdldm�ZKe<dndo��ZLe<dpdq��ZMdrds�ZNdtdu�ZOdvdw�ZPe<dxdy��ZQd|dzd{�ZRdS)~�BaseDatabaseWrapperz Represent a database connection.N�unknowni(#cCs�d|_||_||_t|jd�|_d|_d|_d|_d|_	g|_
d|_d|_d|_
d|_d|_t��|_d|_t��|_g|_d|_g|_|�|�|_|�|�|_|�|�|_|� |�|_!|�"|�|_#|�$|�|_%dS)N)�maxlenFrT)&�
connection�
settings_dict�aliasr�
queries_limit�queries_log�force_debug_cursor�
autocommit�in_atomic_block�savepoint_state�
savepoint_ids�commit_on_exit�needs_rollback�close_at�closed_in_transaction�errors_occurred�	threading�Lock�_thread_sharing_lock�_thread_sharing_count�_thread�	get_ident�
_thread_ident�
run_on_commit�%run_commit_hooks_on_set_autocommit_on�execute_wrappers�client_class�client�creation_class�creation�features_class�features�introspection_class�
introspection�	ops_class�ops�validation_class�
validation)�selfrr�r;�>/usr/lib/python3/dist-packages/django/db/backends/base/base.py�__init__0s4

zBaseDatabaseWrapper.__init__cC�dS)z
        Ensure the connection's timezone is set to `self.timezone_name` and
        return whether it changed or not.
        Fr;�r:r;r;r<�ensure_timezonen�z#BaseDatabaseWrapper.ensure_timezonecCs.tjsdS|jddurtjSt�|jd�S)a
        Return a tzinfo of the database connection time zone.

        This is only used when time zone support is enabled. When a datetime is
        read from the database, it is always returned in this time zone.

        When the database backend supports time zones, it doesn't matter which
        time zone Django uses, as long as aware datetimes are used everywhere.
        Other users connecting to the database can choose their own time zone.

        When the database backend doesn't support time zones, the time zone
        Django uses may be constrained by the requirements of other users of
        the database.
        N�	TIME_ZONE)r�USE_TZrr�utc�pytzr?r;r;r<rus
zBaseDatabaseWrapper.timezonecCs(tjstjS|jddurdS|jdS)zC
        Name of the time zone of the database connection.
        rBN�UTC)rrCrBrr?r;r;r<�
timezone_name�s

z!BaseDatabaseWrapper.timezone_namecCs|jptjS�N)rr�DEBUGr?r;r;r<�queries_logged��z"BaseDatabaseWrapper.queries_loggedcCs0t|j�|jjkrt�d�|jj��t|j�S)NzLLimit for query logging exceeded, only the last {} queries will be returned.)�lenrr�warnings�warn�format�listr?r;r;r<�queries�s
�
zBaseDatabaseWrapper.queriescC�td��)z<Return a dict of parameters suitable for get_new_connection.zNsubclasses of BaseDatabaseWrapper may require a get_connection_params() method��NotImplementedErrorr?r;r;r<�get_connection_params��z)BaseDatabaseWrapper.get_connection_paramscCrR)z"Open a connection to the database.zKsubclasses of BaseDatabaseWrapper may require a get_new_connection() methodrS)r:�conn_paramsr;r;r<�get_new_connection�rVz&BaseDatabaseWrapper.get_new_connectioncCrR)z,Initialize the database connection settings.zOsubclasses of BaseDatabaseWrapper may require an init_connection_state() methodrSr?r;r;r<�init_connection_state�rVz)BaseDatabaseWrapper.init_connection_statecCrR)z9Create a cursor. Assume that a connection is established.zFsubclasses of BaseDatabaseWrapper may require a create_cursor() methodrS�r:�namer;r;r<�
create_cursor�rVz!BaseDatabaseWrapper.create_cursorcCs�|��d|_g|_d|_|jd}|durdnt��||_d|_d|_	|�
�}|�|�|_|�
|jd�|��tj|j|d�g|_dS)z>Connect to the database. Assume that the connection is closed.F�CONN_MAX_AGEN�
AUTOCOMMIT)�senderr)�check_settingsrrr r�time�	monotonicr!r"r#rUrXr�set_autocommitrYr
�send�	__class__r+)r:�max_agerWr;r;r<�connect�s

zBaseDatabaseWrapper.connectcCs*|jddurtjstd|j��dSdS)NrBz=Connection '%s' cannot set TIME_ZONE because USE_TZ is False.)rrrCrrr?r;r;r<r`�s���z"BaseDatabaseWrapper.check_settingscCsB|jdur|j�
|��Wd�dS1swYdSdS)z;Guarantee that a connection to the database is established.N)r�wrap_database_errorsrgr?r;r;r<�ensure_connection�s


"��z%BaseDatabaseWrapper.ensure_connectioncCs*|��|jr|�|�}|S|�|�}|S)zY
        Validate the connection is usable and perform database cursor wrapping.
        )�validate_thread_sharingrJ�make_debug_cursor�make_cursor)r:�cursor�wrapped_cursorr;r;r<�_prepare_cursor�s

�z#BaseDatabaseWrapper._prepare_cursorcCsB|��|j�|�|�|��Wd�S1swYdSrH)rirhror\rZr;r;r<�_cursor�s$�zBaseDatabaseWrapper._cursorcC�B|jdur|j�
|j��Wd�S1swYdSdSrH)rrh�commitr?r;r;r<�_commit��

$��zBaseDatabaseWrapper._commitcCrqrH)rrh�rollbackr?r;r;r<�	_rollback�rtzBaseDatabaseWrapper._rollbackcCrqrH)rrh�closer?r;r;r<�_close�rtzBaseDatabaseWrapper._closecC�|��S)z3Create a cursor, opening a connection if necessary.)rpr?r;r;r<rmszBaseDatabaseWrapper.cursorcCs(|��|��|��d|_d|_dS)z.Commit a transaction and reset the dirty flag.FTN)rj�validate_no_atomic_blockrsr#r,r?r;r;r<rrs

zBaseDatabaseWrapper.commitcCs.|��|��|��d|_d|_g|_dS)z1Roll back a transaction and reset the dirty flag.FN)rjrzrvr#r r+r?r;r;r<rus
zBaseDatabaseWrapper.rollbackcCsj|��g|_|js|jdurdSz|��W|jr"d|_d|_dSd|_dS|jr1d|_d|_wd|_w)z%Close the connection to the database.NT)rjr+r"rrxrr r?r;r;r<rws


�
zBaseDatabaseWrapper.closecC�@|���}|�|j�|��Wd�dS1swYdSrH)rm�executer7�savepoint_create_sql�r:�sidrmr;r;r<�
_savepoint0�
"�zBaseDatabaseWrapper._savepointcCr{rH)rmr|r7�savepoint_rollback_sqlr~r;r;r<�_savepoint_rollback4r�z'BaseDatabaseWrapper._savepoint_rollbackcCr{rH)rmr|r7�savepoint_commit_sqlr~r;r;r<�_savepoint_commit8r�z%BaseDatabaseWrapper._savepoint_commitcCs|jjo|��SrH)r3�uses_savepoints�get_autocommitr?r;r;r<�_savepoint_allowed<sz&BaseDatabaseWrapper._savepoint_allowedcCsV|��sdSt��}t|��dd�}|jd7_d||jf}|��|�|�|S)z�
        Create a savepoint inside the current transaction. Return an
        identifier for the savepoint that will be used for the subsequent
        rollback or commit. Do nothing if savepoints are not supported.
        N�-��zs%s_x%d)r�r(r)�str�replacerrjr�)r:�thread_ident�tidrr;r;r<�	savepointBs
zBaseDatabaseWrapper.savepointcs8|��sdS|��|����fdd�|jD�|_dS)zW
        Roll back to a savepoint. Do nothing if savepoints are not supported.
        Ncs g|]\}}�|vr||f�qSr;r;)�.0�sids�func�rr;r<�
<listcomp>csz:BaseDatabaseWrapper.savepoint_rollback.<locals>.<listcomp>)r�rjr�r+�r:rr;r�r<�savepoint_rollbackWs

�z&BaseDatabaseWrapper.savepoint_rollbackcCs"|��sdS|��|�|�dS)zR
        Release a savepoint. Do nothing if savepoints are not supported.
        N)r�rjr�r�r;r;r<�savepoint_commitgsz$BaseDatabaseWrapper.savepoint_commitcCs
d|_dS)zY
        Reset the counter used to generate unique savepoint ids in this thread.
        rN)rr?r;r;r<�clean_savepointsrs
z$BaseDatabaseWrapper.clean_savepointscCrR)zR
        Backend-specific implementation to enable or disable autocommit.
        zHsubclasses of BaseDatabaseWrapper may require a _set_autocommit() methodrS)r:rr;r;r<�_set_autocommit{sz#BaseDatabaseWrapper._set_autocommitcCs|��|jS)zGet the autocommit state.)rirr?r;r;r<r��sz"BaseDatabaseWrapper.get_autocommitFcCsf|��|��|o|ot|d�}|r|��n|�|�||_|r/|jr1|��d|_dSdSdS)a�
        Enable or disable autocommit.

        The usual way to start a transaction is to turn autocommit off.
        SQLite does not properly start a transaction when disabling
        autocommit. To avoid this buggy behavior and to actually enter a new
        transaction, an explicit BEGIN is required. Using
        force_begin_transaction_with_broken_autocommit=True will issue an
        explicit BEGIN with SQLite. This option will be ignored for other
        backends.
        �#_start_transaction_under_autocommitFN)rzri�hasattrr�r�rr,�run_and_clear_commit_hooks)r:r�.force_begin_transaction_with_broken_autocommit�"start_transaction_under_autocommitr;r;r<rc�s
�



�z"BaseDatabaseWrapper.set_autocommitcCs|jstd��|jS)z9Get the "needs rollback" flag -- for *advanced use* only.�<The rollback flag doesn't work outside of an 'atomic' block.�rrr r?r;r;r<�get_rollback�s
�z BaseDatabaseWrapper.get_rollbackcCs|jstd��||_dS)zT
        Set or unset the "needs rollback" flag -- for *advanced use* only.
        r�Nr�)r:rur;r;r<�set_rollback�s
�
z BaseDatabaseWrapper.set_rollbackcCs|jrtd��dS)z,Raise an error if an atomic block is active.z3This is forbidden when an 'atomic' block is active.N)rrr?r;r;r<rz�s
��z,BaseDatabaseWrapper.validate_no_atomic_blockcCs|jrtd��dS)NzlAn error occurred in the current transaction. You can't execute queries until the end of the 'atomic' block.)r rr?r;r;r<�validate_no_broken_transaction�s
��z2BaseDatabaseWrapper.validate_no_broken_transactionccs8�|��}zdVW|r|��dSdS|r|��ww)z:
        Disable foreign key constraint checking.
        N)�disable_constraint_checking�enable_constraint_checking)r:�disabledr;r;r<�constraint_checks_disabled�s��
�z.BaseDatabaseWrapper.constraint_checks_disabledcCr>)z�
        Backends can implement as needed to temporarily disable foreign key
        constraint checking. Should return True if the constraints were
        disabled and will need to be reenabled.
        Fr;r?r;r;r<r���z/BaseDatabaseWrapper.disable_constraint_checkingcCr>)zh
        Backends can implement as needed to re-enable foreign key constraint
        checking.
        Nr;r?r;r;r<r��rAz.BaseDatabaseWrapper.enable_constraint_checkingcCr>)z�
        Backends can override this method if they can apply constraint
        checking (e.g. via "SET CONSTRAINTS ALL IMMEDIATE"). Should raise an
        IntegrityError if any invalid foreign key references are encountered.
        Nr;)r:�table_namesr;r;r<�check_constraints�r�z%BaseDatabaseWrapper.check_constraintscCrR)a
        Test if the database connection is usable.

        This method may assume that self.connection is not None.

        Actual implementations should take care not to raise exceptions
        as that may prevent Django from recycling unusable connections.
        zCsubclasses of BaseDatabaseWrapper may require an is_usable() methodrSr?r;r;r<�	is_usable�s	�zBaseDatabaseWrapper.is_usablecCsz|jdur7|��|jdkr|��dS|jr%|��rd|_n|��dS|jdur9t��|jkr;|��dSdSdSdS)z
        Close the current connection if unrecoverable errors have occurred
        or if it outlived its maximum age.
        Nr^F)	rr�rrwr#r�r!rarbr?r;r;r<�close_if_unusable_or_obsolete�s
�z1BaseDatabaseWrapper.close_if_unusable_or_obsoletecCs4|j�
|jdkWd�S1swYdS�Nr�r&r'r?r;r;r<�allow_thread_sharings$�z(BaseDatabaseWrapper.allow_thread_sharingcCs:|j�|jd7_Wd�dS1swYdS)Nr�r�r?r;r;r<�inc_thread_sharings"�z&BaseDatabaseWrapper.inc_thread_sharingcCsL|j�|jdkr
td��|jd8_Wd�dS1swYdS)Nrz5Cannot decrement the thread sharing count below zero.r�)r&r'�RuntimeErrorr?r;r;r<�dec_thread_sharings

"�z&BaseDatabaseWrapper.dec_thread_sharingcCs6|js|jt��kstd|j|jt��f��dSdS)a3
        Validate that the connection isn't accessed by another thread than the
        one which originally created it, unless the connection was explicitly
        authorized to be shared between threads (via the `inc_thread_sharing()`
        method). Raise an exception if the validation fails.
        z�DatabaseWrapper objects created in a thread can only be used in that same thread. The object with alias '%s' was created in thread id %s and this is thread id %s.N)r�r*r(r)rrr?r;r;r<rj s���z+BaseDatabaseWrapper.validate_thread_sharingcCr>)z~
        Hook to do any database check or preparation, generally called before
        migrating a project or an app.
        Nr;r?r;r;r<�prepare_database2rAz$BaseDatabaseWrapper.prepare_databasecCst|�S)z�
        Context manager and decorator that re-throws backend-specific database
        exceptions using Django's common wrappers.
        rr?r;r;r<rh9sz(BaseDatabaseWrapper.wrap_database_errorscCry)z�
        Return a cursor that tries to avoid caching in the database (if
        supported by the database), otherwise return a regular cursor.
        )rmr?r;r;r<�chunked_cursorAsz"BaseDatabaseWrapper.chunked_cursorcC�t�||�S)z:Create a cursor that logs all queries in self.queries_log.)r�CursorDebugWrapper�r:rmr;r;r<rkHrKz%BaseDatabaseWrapper.make_debug_cursorcCr�)z&Create a cursor without debug logging.)r�
CursorWrapperr�r;r;r<rlLrKzBaseDatabaseWrapper.make_cursorccsb�|jdu}z"|���}|VWd�n1swYW|r'|��dSdS|r0|��ww)a8
        Context manager that ensures that a connection is established, and
        if it opened one, closes it to avoid leaving a dangling connection.
        This is useful for operations outside of the request-response cycle.

        Provide a cursor: with self.temporary_connection() as cursor: ...
        N)rrmrw)r:�
must_closermr;r;r<�temporary_connectionPs�
	
���
�z(BaseDatabaseWrapper.temporary_connectionccst�|ji|j�ddi�td�}z%|���}|VWd�n1s"wYW|��dSW|��dS|��w)aq
        Return a cursor from an alternative connection to be used when there is
        no need to access the main database, specifically for test db
        creation/deletion. This also prevents the production database from
        being exposed to potential child threads while (or after) the test
        database is destroyed. Refs #10868, #17786, #16969.
        �NAMEN)r)rer�NO_DB_ALIASrmrw)r:�connrmr;r;r<�_nodb_cursoras�	
��z BaseDatabaseWrapper._nodb_cursorcOs*|jdur	td��|j|g|�Ri|��S)zG
        Return a new instance of this backend's SchemaEditor.
        NzFThe SchemaEditorClass attribute of this database wrapper is still None)�SchemaEditorClassrT)r:�args�kwargsr;r;r<�
schema_editorqs

�z!BaseDatabaseWrapper.schema_editorcCsJt|�std��|jr|j�t|j�|f�dS|��s td��|�dS)Nz*on_commit()'s callback must be a callable.z;on_commit() cannot be used in manual transaction management)	�callable�	TypeErrorrr+�append�setrr�r)r:r�r;r;r<�	on_commitzs
zBaseDatabaseWrapper.on_commitcCs8|��|j}g|_|r|�d�\}}|�|sdSdSr�)rzr+�pop)r:�current_run_on_commitr�r�r;r;r<r��s�z.BaseDatabaseWrapper.run_and_clear_commit_hooksccs2�|j�|�zdVW|j��dS|j��w)z|
        Return a context manager under which the wrapper is applied to suitable
        database query executions.
        N)r-r�r�)r:�wrapperr;r;r<�execute_wrapper�s
�z#BaseDatabaseWrapper.execute_wrappercCs(t�|j�}|dur
|j}t|�||�S)zy
        Return a copy of this connection.

        For tests that require two connections to the same database.
        N)�copy�deepcopyrr�type)r:rrr;r;r<r��szBaseDatabaseWrapper.copyrH)F)S�__name__�
__module__�__qualname__�__doc__�
data_types�data_types_suffix�data_type_check_constraintsr7�vendor�display_namer�r.r0r2r4r6r	r8rrr=r@rrrG�propertyrJrQrUrXrYr\rrgr`rirorprsrvrxrmrrrurwr�r�r�r�r�r�r�r�r�r�rcr�r�rzr�rr�r�r�r�r�r�r�r�r�rjr�rhr�rkrlr�r�r�r�r�r�r�r;r;r;r<rs�>



	





	








	






	

r)#r(r�r$rarM�collectionsr�
contextlibrrE�django.confr�django.core.exceptionsr�	django.dbrr�django.db.backendsr�"django.db.backends.base.validationr	�django.db.backends.signalsr
�django.db.transactionr�django.db.utilsr
�django.utilsr�django.utils.asyncior�django.utils.functionalrr�rr;r;r;r<�<module>s*

https://t.me/RX1948 - 2025