File: //lib/python3/dist-packages/django/db/backends/sqlite3/__pycache__/creation.cpython-310.pyc
o
3�a � @ sD d dl Z d dlZd dlZd dlmZ d dlmZ G dd� de�ZdS )� N)�Path)�BaseDatabaseCreationc @ sL e Zd Zedd� �Zdd� Zddd�Zdd � Zdd
d�Zdd
� Z dd� Z
dS )�DatabaseCreationc C s t | t� o
| dkp
d| v S )N�:memory:zmode=memory)�
isinstancer )�
database_name� r �E/usr/lib/python3/dist-packages/django/db/backends/sqlite3/creation.py�is_in_memory_db s �z DatabaseCreation.is_in_memory_dbc C s, | j jd d p d}|dkrd| j j S |S )N�TEST�NAMEr z)file:memorydb_%s?mode=memory&cache=shared)�
connection�
settings_dict�alias)�self�test_database_namer r r �_get_test_db_name s z"DatabaseCreation._get_test_db_nameFc
C s� | � � }|r|S | �|�sd|dkr| �d| �||�f � t�|tj�rd|s,td| �}|s2|dkrZzt�|� W |S t yY } z| �d| � t
�d� W Y d }~|S d }~ww | �d� t
�d� |S )N� �,Destroying old test database for alias %s...zXType 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: �yes�/Got an error deleting the old test database: %s� zTests cancelled.)r r
�log�_get_database_display_str�os�access�F_OK�input�remove� Exception�sys�exit)r � verbosity�autoclobber�keepdbr �confirm�er r r �_create_test_db s8
������
z DatabaseCreation._create_test_dbc C sL | j j}|d }| �|�r|S tj�|d �\}}i |�dd�|||�i�S )Nr z{}_{}.{})r
r r
r �path�splitext�format)r �suffix�orig_settings_dict�source_database_name�root�extr r r �get_test_db_clone_settings3 s
z+DatabaseCreation.get_test_db_clone_settingsc
C s� | j jd }| �|�d }| �|�s|t�|tj�rS|rd S |dkr-| �d| �||�f � zt� |� W n t
yR } z| �d| � t�d� W Y d }~nd }~ww z t
�||� W d S t
y{ } z| �d| � t�d� W Y d }~d S d }~ww d S )Nr r r r r z*Got an error cloning the test database: %s)r
r r0 r
r r r r r r r r r! �shutil�copy)r r+ r"