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/trac/db/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //lib/python3/dist-packages/trac/db/__pycache__/api.cpython-310.pyc
o

�k�`�f�@sLddlZddlZddlZddlZddlmZmZddlm	Z	ddl
mZmZddl
mZmZmZmZddlTddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lm Z m!Z!Gdd�de"�Z#Gdd�de#�Z$Gdd�de#�Z%Gdd�de"ed�Z&Gdd�de'�Z(Gdd�de)�Z*dd�Z+dd�Z,dd �Z-d!d"�Z.dS)#�N)�ABCMeta�abstractmethod)�
db_default)�IEnvironmentSetupParticipant�ISystemInfoProvider)�
BoolOption�ConfigurationError�	IntOption�Option)�*)�ConnectionPool)�Table)�ConnectionWrapper)�ThreadLocal)�tag)�unicode_passwd)�_�tag_c@s4eZdZdZdZdd�Zd	dd�ZeZd	dd�ZdS)
�DbContextManagerz^Database Context Manager

    The outermost `DbContextManager` will close the connection.
    NcCst|�|_dS�N)�DatabaseManager�dbmgr)�self�env�r�-/usr/lib/python3/dist-packages/trac/db/api.py�__init__,szDbContextManager.__init__cC�4|�}|�||�Wd�S1swYdS)z(Shortcut for directly executing a query.N)�execute�r�query�params�dbrrrr/�
$�zDbContextManager.executecCr)z7Shortcut for directly calling "executemany" on a query.N)�executemanyrrrrr$6r#zDbContextManager.executemanyr)	�__name__�
__module__�__qualname__�__doc__r"rr�__call__r$rrrrr$s
rc@� eZdZdZdd�Zdd�ZdS)�TransactionContextManagerz�Transactioned Database Context Manager for retrieving a
    `~trac.db.util.ConnectionWrapper`.

    The outermost such context manager will perform a commit upon
    normal exit or a rollback after an exception.
    cCsJ|jjj}|s#|jjj}|rt|j|j�}n|j��}||jj_|_|Sr)	r�_transaction_local�wdb�rdbr�cnx�log�get_connectionr"�rr"rrr�	__enter__Ds


z#TransactionContextManager.__enter__cCsN|jr#d|jj_|dur|j��n|j��|jjjs%|j��dSdSdSr)r"rr,r-�commit�rollbackr.�close�r�et�ev�tbrrr�__exit__Os


�z"TransactionContextManager.__exit__N�r%r&r'r(r3r;rrrrr+<sr+c@r*)�QueryContextManagerz_Database Context Manager for retrieving a read-only
    `~trac.db.util.ConnectionWrapper`.
    cCsR|jjj}|s'|jjj}|rt|j|jdd�}n|jjdd�}||jj_|_|S)NT��readonly)	rr,r.r-rr/r0r1r"r2rrrr3_s

zQueryContextManager.__enter__cCs0|jrd|jj_|jjjs|j��dSdSdSr)r"rr,r.r-r6r7rrrr;js

�zQueryContextManager.__exit__Nr<rrrrr=Zsr=c@s�eZdZdZedd��Zedd��Zedd��Zedd	��Zed
d��Z	ed$d
d��Z
edd��Zedd��Zedd��Z
edd��Zedd��Zedd��Zedd��Zedd��Zedd ��Zed$d!d"��Zd#S)%�ConnectionBasez4Abstract base class for database connection classes.cC�dS)z,Returns a clause casting `column` as `type`.Nr)r�column�typerrr�castt�zConnectionBase.castcGrA)z3Returns a clause concatenating the sequence `args`.Nr)r�argsrrr�concatyrEzConnectionBase.concatcCrA)z Drops the `column` from `table`.Nr)r�tablerBrrr�drop_column~rEzConnectionBase.drop_columncCrA)zDrops the `table`.Nr�rrHrrr�
drop_table�rEzConnectionBase.drop_tablecCrA)z0Returns the list of the column names in `table`.NrrJrrr�get_column_names�rEzConnectionBase.get_column_names�idcCrA)z�Returns the current value of the primary key sequence for `table`.
        The `column` of the primary key may be specified, which defaults
        to `id`.Nr�r�cursorrHrBrrr�get_last_id��zConnectionBase.get_last_idcCrA)z%Returns a list of the sequence names.Nr�rrrr�get_sequence_names�rEz!ConnectionBase.get_sequence_namescCrA)z"Returns a list of the table names.NrrRrrr�get_table_names�rEzConnectionBase.get_table_namescCrA�z!Returns whether the table exists.NrrJrrr�	has_table�rEzConnectionBase.has_tablecCrA)z)Returns a case-insensitive `LIKE` clause.NrrRrrr�like�rEzConnectionBase.likecCrA)z2Returns `text` escaped for use in a `LIKE` clause.Nr)r�textrrr�like_escape�rEzConnectionBase.like_escapecCrA)z1Return a case sensitive prefix-matching operator.NrrRrrr�prefix_match�rEzConnectionBase.prefix_matchcCrA)z;Return a value for case sensitive prefix-matching operator.Nr)r�prefixrrr�prefix_match_value�rEz!ConnectionBase.prefix_match_valuecCrA)z Returns the quoted `identifier`.Nr)r�
identifierrrr�quote�rEzConnectionBase.quotecCrA)z�Deletes all data from the tables and resets autoincrement indexes.

        :return: list of names of the tables that were reset.
        NrrRrrr�reset_tables�szConnectionBase.reset_tablescCrA)z�Updates the current value of the primary key sequence for `table`.
        The `column` of the primary key may be specified, which defaults
        to `id`.NrrNrrr�update_sequence�rQzConnectionBase.update_sequenceN)rM)r%r&r'r(rrDrGrIrKrLrPrSrTrVrWrYrZr\r^r_r`rrrrr@qsD













r@)�	metaclassc@s`eZdZdZdd�Zddd�Zdd�Zdd	d
�Zddd�Zdd
d�Z	dd�Z
dd�Zdd�ZdS)�IDatabaseConnectorzfExtension point interface for components that support the
    connection to relational databases.
    cCrA)alReturn the connection URL schemes supported by the
        connector, and their relative priorities as an iterable of
        `(scheme, priority)` tuples.

        If `priority` is a negative number, this is indicative of an
        error condition with the connector. An error message should be
        attached to the `error` attribute of the connector.
        Nrrrrr�get_supported_schemes��z(IDatabaseConnector.get_supported_schemesNcKrA)z(Create a new connection to the database.Nr)�pathr0�kwargsrrrr1�rdz!IDatabaseConnector.get_connectioncCrA)z�Return an object (typically a module) containing all the
        backend-specific exception types as attributes, named
        according to the Python Database API
        (http://www.python.org/dev/peps/pep-0249/).
        Nrrrrr�get_exceptions�rdz!IDatabaseConnector.get_exceptionscKrA)zInitialize the database.Nr)re�schemar0rfrrr�init_db�rdzIDatabaseConnector.init_dbcKrA)zDestroy the database.Nr�rrer0rfrrr�
destroy_db�rdzIDatabaseConnector.destroy_dbcKrA)z%Return `True` if the database exists.Nrrjrrr�	db_exists�rdzIDatabaseConnector.db_existscCrA)z]Return the DDL statements necessary to create the specified
        table, including indices.Nr)rHrrr�to_sql�rdzIDatabaseConnector.to_sqlcCrA)zDBackup the database to a location defined by
        trac.backup_dirNr)�destrrr�backup�rdzIDatabaseConnector.backupcCrA)z�Yield a sequence of `(name, version)` tuples describing the
        name and version information of external packages used by the
        connector.
        Nrrrrr�get_system_info�rdz"IDatabaseConnector.get_system_infor)NN)
r%r&r'r(rcr1rgrirkrlrmrorprrrrrb�s




rbc@sHeZdZdZeee�ee�Z	e
dddd�Ze
dddd�Ze
dd	d
d�Zeddd
d�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!d"�Zd#d$�ZdJd%d&�ZdKd(d)�Zd*d+�Zd,d-�Zd.d/�Z d0d1�Z!d2d3�Z"dKd4d5�Z#dKd6d7�Z$dLd9d:�Z%dMd<d=�Z&dMd>d?�Z'd@dA�Z(dBdC�Z)dDdE�Z*dFdG�Z+dHdI�Z,d;S)NrzBComponent used to manage the `IDatabaseConnector` implementations.�trac�databasezsqlite:db/trac.dbzlDatabase connection
        [wiki:TracEnvironment#DatabaseConnectionStrings string] for this
        project�
backup_dirr"zDatabase backup location�timeout�20z]Timeout value for database connection, in seconds.
        Use '0' to specify ''no timeout''.�	debug_sqlFz>Show the SQL queries in the Trac log, at DEBUG level.
        cCsd|_tddd�|_dS)N)r-r.)�	_cnx_poolrr,rRrrrrszDatabaseManager.__init__cCsF|��\}}tj|d<|jdi|��tj}|�|d�|�|�dS)Nrh�initial_database_versionr)�
get_connectorrrhri�
db_version�set_database_version)r�	connectorrF�versionrrrris
zDatabaseManager.init_dbcC�|�tj�dSr)�insert_into_tablesr�get_datarRrrr�insert_default_data �z#DatabaseManager.insert_default_datacCs(|��\}}|��|jdi|��dS�Nr)ry�shutdownrk�rr|rFrrrrk#szDatabaseManager.destroy_dbcCs|��\}}|jdi|��Sr�)ryrlr�rrrrl)szDatabaseManager.db_existscCs\|��d}|jj�}|D]}|�|�D]}||�qq
Wd�dS1s'wYdS)zzCreate the specified tables.

        :param schema: an iterable of table objects.

        :since: version 1.0.2
        rN)ryr�db_transactionrm)rrhr|r"rH�sqlrrr�
create_tables-s

��"�zDatabaseManager.create_tablescCszt|t�r|jn|}|jj�%}|�|�s |jj�d|�|���|D]}|�	||�q"Wd�dS1s6wYdS)zMDrops the specified columns from table.

        :since: version 1.2
        �Table %s not foundN)
�
isinstancer
�namerr�rV�db_exc�OperationalErrorr^rI)rrH�columns�
table_namer"�colrrr�drop_columns:s


��"�zDatabaseManager.drop_columnscCsV|jj�}|D]}t|t�r|jn|}|�|�qWd�dS1s$wYdS)z�Drop the specified tables.

        :param schema: an iterable of `Table` objects or table names.

        :since: version 1.0.2
        N)rr�r�r
r�rK)rrhr"rHr�rrr�drop_tablesGs
�"�zDatabaseManager.drop_tablescCs�|jj�4}t|�r
||�n|}|D]\}}}|�d|�|�d�|�d�dgt|��f|�qWd�dS1s;wYdS)a�Insert data into existing tables.

        :param data_or_callable: Nested tuples of table names, column names
                                 and row data::

                                   (table1,
                                    (column1, column2),
                                    ((row1col1, row1col2),
                                     (row2col1, row2col2)),
                                    table2, ...)

                                 or a callable that takes a single parameter
                                 `db` and returns the aforementioned nested
                                 tuple.
        :since: version 1.1.3
        zINSERT INTO %s (%s) VALUES (%s)�,z%sN)rr��callabler$r^�join�len)r�data_or_callabler"�datarH�cols�valsrrrrSs
�����"�z"DatabaseManager.insert_into_tablescC�4|jj�}|��Wd�S1swYdS)z�Deletes all data from the tables and resets autoincrement indexes.

        :return: list of names of the tables that were reset.

        :since: version 1.1.3
        N)rr�r_r2rrrr_ls
$�zDatabaseManager.reset_tablescs.|jj������}|D]y}|jd}|�|�}|rPt|�|��}dd�|jD�}||@}|rJd��fdd�|D��}	|�	d��
|���
|j�f�|�|f�|�|f�|r�|r�|�	d��
|j�|	|	��
|�f�|jD]}
|
j
r}��||j|
j�qo|�|f�qWd	�d	S1s�wYd	S)
z�Upgrade table schema to `new_schema`, preserving data in
        columns that exist in the current schema and `new_schema`.

        :param new_schema: tuple or list of `Table` objects

        :since: version 1.2
        �_oldcSsh|]}|j�qSr�r�)�.0r�rrr�	<setcomp>�sz1DatabaseManager.upgrade_tables.<locals>.<setcomp>r�c3s�|]}��|�VqdSr)r^)r�r��r"rr�	<genexpr>�s��z1DatabaseManager.upgrade_tables.<locals>.<genexpr>zg
                            CREATE TEMPORARY TABLE %s AS SELECT * FROM %s
                            zW
                        INSERT INTO %s (%s) SELECT %s FROM %s
                        N)rr�rOr�rV�setrLr�r�rr^r�r��auto_incrementr`)r�
new_schemarO�	new_table�temp_table_namerV�old_column_names�new_column_names�column_names�cols_to_copyr�rr�r�upgrade_tablesvsH


�
��
��

����"�zDatabaseManager.upgrade_tablescCsL|js|��\}}td|fi|��|_|j�|jpd�}|r$t|dd�}|S)z�Get a database connection from the pool.

        If `readonly` is `True`, the returned connection will purposely
        lack the `rollback` and `commit` methods.
        �NTr>)rwryr�get_cnxrtr)rr?r|rFr"rrrr1�szDatabaseManager.get_connection�database_versioncCsh|jj�&}|d�|�d��|f�D]\}t|�Wd�S	Wd�dS1s-wYdS)aPReturns the database version from the SYSTEM table as an int,
        or `False` if the entry is not found.

        :param name: The name of the entry that contains the database version
                     in the SYSTEM table. Defaults to `database_version`,
                     which contains the database version for Trac.
        zM
                    SELECT value FROM {0} WHERE name=%s
                    �systemNF)r�db_query�formatr^�int)rr�r"�valuerrr�get_database_version�s

�
�$�z$DatabaseManager.get_database_versioncCs|��d��S�Nr)ryrgrRrrrrg�r�zDatabaseManager.get_exceptionscCr�)zEReturns a list of the sequence names.

        :since: 1.3.2
        N)rr�rSr2rrrrS��
$�z"DatabaseManager.get_sequence_namescCr�)zBReturns a list of the table names.

        :since: 1.1.6
        N)rr�rTr2rrrrT�r�zDatabaseManager.get_table_namescCslt|t�r|jn|}|jj�}|�|�s |jj�d|�|���|�	|�Wd�S1s/wYdS)z�Returns a list of the column names for `table`.

        :param table: a `Table` object or table name.

        :since: 1.2
        r�N)
r�r
r�rr�rVr�r�r^rL�rrHr�r"rrrrL�s


�$�z DatabaseManager.get_column_namescCsJt|t�r|jn|}|jj�
}|�|�Wd�S1swYdSrU)r�r
r�rr�rVr�rrrrV�s
$�zDatabaseManager.has_tablecCs�|�|�}|dur-|jj�}|d�|�d��||f�Wd�dS1s&wYdS||�|�kr`|jj�}|d�|�d��||f�Wd�n1sPwY|j�d|||�dSdS)aHSets the database version in the SYSTEM table.

        :param version: an integer database version.
        :param name: The name of the entry that contains the database version
                     in the SYSTEM table. Defaults to `database_version`,
                     which contains the database version for Trac.
        FzW
                    INSERT INTO {0} (name, value) VALUES (%s, %s)
                    r�NzO
                    UPDATE {0} SET value=%s WHERE name=%s
                    zUpgraded %s from %d to %d)r�rr�r�r^r0�info)rr}r��current_database_versionr"rrrr{�s"

�"�
����z$DatabaseManager.set_database_versioncCsD|�|�}||krdS||krttd|d���|j�d|||�dS)akChecks the database version to determine if an upgrade is needed.

        :param version: the expected integer database version.
        :param name: the name of the entry in the SYSTEM table that contains
                     the database version. Defaults to `database_version`,
                     which contains the database version for Trac.

        :return: `True` if the stored version is less than the expected
                  version, `False` if it is equal to the expected version.
        :raises TracError: if the stored version is greater than the expected
                           version.
        FzNeed to downgrade %(name)s.r�z Need to upgrade %s from %d to %dT)r��	TracErrorrr0r�)rr}r��dbverrrr�
needs_upgrade�s

�zDatabaseManager.needs_upgrade�
trac.upgradesc
	Cs�|�|�}t|d|d�D]E}d||f}zt�|�}Wnty,ttd|d���w|jj�}|�	�}	|�
|j||	�|�||�Wd�n1sNwYqdS)a(Invokes `do_upgrade(env, version, cursor)` in module
        `"%s/db%i.py" % (pkg, version)`, for each required version upgrade.

        :param version: the expected integer database version.
        :param name: the name of the entry in the SYSTEM table that contains
                     the database version. Defaults to `database_version`,
                     which contains the database version for Trac.
        :param pkg: the package containing the upgrade modules.

        :raises TracError: if the package or module doesn't exist.
        �z%s.db%izNo upgrade module %(module)s.py)�moduleN)r��range�	importlib�
import_module�ImportErrorr�rrr�rO�
do_upgrader{)
rr}r��pkgr��ir��upgraderr"rOrrr�upgrades"
��
���zDatabaseManager.upgradeNcCs(|jr|j�|�|sd|_dSdSdSr)rwr�)r�tidrrrr�%s
�zDatabaseManager.shutdownc	Cs�|��\}}|s>|j}tj�|�stj�|jj|�}|j�dd�}|�	dd�\}}d||jj
tt���f}tj�||�}ntj�
|�}tj�|�sOt�|�|�|�S)z�Save a backup of the database.

        :param dest: base filename to write to.

        Returns the file actually written.
        rqrr�:r�z%s.%i.%d.bak)ryrs�osre�isabsr�r�config�get�splitr�r��time�dirname�exists�makedirsro)	rrnr|rFrs�db_str�db_name�db_path�	dest_namerrrro+s

�

zDatabaseManager.backupcs�t|j�\�}�fdd�|jD�}|sttd�d���t|�\}}|dkr*t|j���dkrM|ddkr5ntj�	|d�sMtj�
|jj|d�d	��|d<|j
rU|j|d
<||fS)Ncs.g|]}|��D]\}}|�kr||f�qqSr)rc)r�r|�scheme_�priority��schemerr�
<listcomp>Ds��z1DatabaseManager.get_connector.<locals>.<listcomp>z&Unsupported database type "%(scheme)s"r�r�sqliterez:memory:�/r0)�parse_connection_uri�connection_uri�
connectorsr�r�max�errorr�rer�r�r�lstriprvr0)rrF�
candidatesr�r|rr�rryBs*
��
�
zDatabaseManager.get_connectorcCsdSrrrRrrr�environment_createdbsz#DatabaseManager.environment_createdcCs|�tj�Sr)r�rrzrRrrr�environment_needs_upgradeesz)DatabaseManager.environment_needs_upgradecCr~r)r�rrzrRrrr�upgrade_environmenthr�z#DatabaseManager.upgrade_environmentccs&�|��d}|��D]}|VqdSr�)ryrp)rr|r�rrrrpms
��zDatabaseManager.get_system_info)F)r�)r�r�r)-r%r&r'r(�
implementsrr�ExtensionPointrbr�r
r�rsr	rtrrvrrir�rkrlr�r�r�rr_r�r1r�rgrSrTrLrVr{r�r�r�roryr�r�r�rprrrrr�sX
����



%





 rcCs|jrdd�|jD�SgS)z1Retrieve column names from a cursor, if possible.cSs0g|]}t|dt�rt|dd�n|d�qS)rzutf-8)r��bytes�str)r��drrrr�us(�z$get_column_names.<locals>.<listcomp>)�description)rOrrrrLss���rLc	Cs�|stjdtd�ddd�}ttdt�d�|t�d���z
|�d	d
�\}}Wnty0t	|��w|�
d�sE|dkrA|rAd
}|}n9t	|��|�
d�sSd
}|d
d
�}n%|�
d�rad
}|dd
�}n|dd
�}d|vrt|�dd
�\}}n|}d}d
}|r�d|vr�|�dd
�\}}d	|vr�|�d	d
�\}}nd
}|r�tj�
|�}|r�ttj�
|��}nd
}}|r�d	|vr�|�d	d
�\}}zt|�}Wn
ty�t	|��wd
}|s�d|}tjdkr�t|�d
kr�|d
dkr�d|d|dd
�f}i}	d|v�r.|�dd
�\}}
|
�d�}
|
D]$}z
|�dd
�\}}
Wnt�y!t	|��wtj�
|
�}
|
|	|<�q	td||||||	f�}|dd�|D�fS)aVParse the database connection string.

    The database connection string for an environment is specified through
    the `database` option in the `[trac]` section of trac.ini.

    :return: a tuple containing the scheme and a dictionary of attributes:
             `user`, `password`, `host`, `port`, `path`, `params`.
    :since: 1.1.3
    z[trac]zTracIni documentation�trac-target-newz3https://trac.edgewall.org/wiki/TracIni#trac-section��title�class_�hrefz�Database connection string is empty. Set the %(option)s configuration option in the %(section)s section of trac.ini. Please refer to the %(doc)s for help.rr)�option�section�docr�r�r�r�Nz//z///����@�nt�|z%s:%sr�?�&�=)�user�password�host�portrer!cSsi|]	\}}|r||�qSrr)r��keyr�rrr�
<dictcomp>�sz(parse_connection_uri.<locals>.<dictcomp>)r�arrr�code�_doc_db_strr��
ValueError�_invalid_db_str�
startswith�urllib�parse�unquoterr�r�r�r��zip)r�r�r��restrrerrrr!�qs�paramr�r�rFrrrr�ys�
�
���


��


��r�cCsttdt�|�t�d��S)NzcInvalid format %(db_str)s for the database connection string. Please refer to the %(doc)s for help.)r�r�)rrrrr)r�rrrr
�s
��r
cCstjtd�td�ddd�S)N�
documentationz)Database Connection Strings documentationr�z@https://trac.edgewall.org/wiki/TracIni#DatabaseConnectionStringsr�)rrrrrrrr�s

�r)/r�r�r��urllib.parser�abcrrrqr�trac.apirr�trac.configrrr	r
�	trac.core�trac.db.poolr�trac.db.schemar
�trac.db.utilr�trac.util.concurrencyr�trac.util.htmlr�trac.util.textr�trac.util.translationrr�objectrr+r=r@�	Interfacerb�	ComponentrrLr�r
rrrrr�<module>s8[1xa

https://t.me/RX1948 - 2025