B
    ©0H[  ã               @   sD   d dl Z d dlZd dlZd dlmZ d dlmZ G dd„ deƒZdS )é    N)ÚImproperlyConfigured)ÚBaseDatabaseCreationc               @   sL   e Zd Zedd„ ƒZdd„ Zddd„Zdd	„ Zdd
d„Zdd„ Z	dd„ Z
dS )ÚDatabaseCreationc             C   s   | dkpd| kS )Nz:memory:zmode=memory© )Zdatabase_namer   r   úgC:\Users\HIRONO~1\AppData\Local\Temp\pip-install-6bm3nxem\django\django\db\backends\sqlite3\creation.pyÚis_in_memory_db   s    z DatabaseCreation.is_in_memory_dbc             C   sP   | j jd d }| j jj}|s"d}|r<|dkrLd| j j S nd|krLtdƒ‚|S )NZTESTÚNAMEz:memory:z)file:memorydb_%s?mode=memory&cache=sharedzmode=memoryz„Using a shared memory database with `mode=memory` in the database name is not supported in your environment, use `:memory:` instead.)Ú
connectionÚsettings_dictÚfeaturesÚcan_share_in_memory_dbÚaliasr   )ÚselfÚtest_database_namer   r   r   r   Ú_get_test_db_name   s    
z"DatabaseCreation._get_test_db_nameFc          
   C   sÆ   |   ¡ }|r|S |  |¡sÂ|dkr8td|  ||¡f ƒ t |tj¡rÂ|sVtd| ƒ}|sb|dkr°yt |¡ W qÂ t	k
r¬ } zt
j d| ¡ t
 d¡ W d d }~X Y qÂX ntdƒ t
 d¡ |S )Né   z,Destroying old test database for alias %s...zXType 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: Úyesz0Got an error deleting the old test database: %s
é   zTests cancelled.)r   r   ÚprintÚ_get_database_display_strÚosÚaccessÚF_OKÚinputÚremoveÚ	ExceptionÚsysÚstderrÚwriteÚexit)r   Ú	verbosityZautoclobberÚkeepdbr   ZconfirmÚer   r   r   Ú_create_test_db   s*    

z DatabaseCreation._create_test_dbc             C   sT   | j j}|d }|  |¡r|S | ¡ }tj |d ¡\}}d |||¡|d< |S d S )Nr   z{}_{}.{})r	   r
   r   Úcopyr   ÚpathÚsplitextÚformat)r   ÚsuffixZorig_settings_dictÚsource_database_nameZnew_settings_dictÚrootÚextr   r   r   Úget_test_db_clone_settings;   s    
z+DatabaseCreation.get_test_db_clone_settingsc          
   C   sö   | j jd }|  |¡d }|  |¡sòt |tj¡r¤|r:d S |dkrXtd|  ||¡f ƒ yt 	|¡ W n< t
k
r¢ } ztj d| ¡ t d¡ W d d }~X Y nX yt ||¡ W n< t
k
rð } ztj d| ¡ t d¡ W d d }~X Y nX d S )Nr   r   z,Destroying old test database for alias %s...z0Got an error deleting the old test database: %s
r   z+Got an error cloning the test database: %s
)r	   r
   r,   r   r   r   r   r   r   r   r   r   r   r   r   Úshutilr$   )r   r(   r    r!   r)   Ztarget_database_namer"   r   r   r   Ú_clone_test_dbF   s&    
zDatabaseCreation._clone_test_dbc             C   s   |r|   |¡st |¡ d S )N)r   r   r   )r   r   r    r   r   r   Ú_destroy_test_db^   s    z!DatabaseCreation._destroy_test_dbc             C   s6   |   ¡ }| jjd g}|  |¡r.| | jj¡ t|ƒS )a  
        Return a tuple that uniquely identifies a test database.

        This takes into account the special cases of ":memory:" and "" for
        SQLite since the databases will be distinct despite having the same
        TEST NAME. See http://www.sqlite.org/inmemorydb.html
        r   )r   r	   r
   r   Úappendr   Útuple)r   r   Úsigr   r   r   Útest_db_signaturec   s
    
z"DatabaseCreation.test_db_signatureN)F)F)Ú__name__Ú
__module__Ú__qualname__Ústaticmethodr   r   r#   r,   r.   r/   r3   r   r   r   r   r   	   s   

r   )r   r-   r   Zdjango.core.exceptionsr   Z django.db.backends.base.creationr   r   r   r   r   r   Ú<module>   s
   