ó
®â0_c           @   s~   d  d l  Z  d  d l Z d  d l Z d  d l m Z d  d l m Z d  d l m Z d  d l	 m
 Z
 d e f d „  ƒ  YZ d S(   iÿÿÿÿN(   t   ImproperlyConfigured(   t   BaseDatabaseCreation(   t
   force_text(   t   inputt   DatabaseCreationc           B   sS   e  Z e d  „  ƒ Z d „  Z e d „ Z d „  Z e d „ Z d „  Z	 d „  Z
 RS(   c         C   s   |  d k p d t  |  ƒ k S(   Ns   :memory:s   mode=memory(   R   (   t   database_name(    (    sE   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/sqlite3/creation.pyt   is_in_memory_db   s    c         C   st   |  j  j d d } |  j  j j } | s2 d } n  | rU | d k rp d |  j  j Sn d | k rp t d ƒ ‚ n  | S(   Nt   TESTt   NAMEs   :memory:s)   file:memorydb_%s?mode=memory&cache=shareds   mode=memorys„   Using a shared memory database with `mode=memory` in the database name is not supported in your environment, use `:memory:` instead.(   t
   connectiont   settings_dictt   featurest   can_share_in_memory_dbt   aliasR    (   t   selft   test_database_nameR   (    (    sE   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/sqlite3/creation.pyt   _get_test_db_name   s    	c         C   só   |  j  ƒ  } | r | S|  j | ƒ sï | d k rL d |  j | | ƒ f GHn  t j | t j ƒ rï | sz t d | ƒ } n  | sŒ | d k r× y t j | ƒ Wqé t k
 rÓ } t	 j
 j d | ƒ t	 j d ƒ qé Xqì d GHt	 j d ƒ qï n  | S(   Ni   s,   Destroying old test database for alias %s...sX   Type 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: t   yess0   Got an error deleting the old test database: %s
i   s   Tests cancelled.(   R   R   t   _get_database_display_strt   ost   accesst   F_OKR   t   removet	   Exceptiont   syst   stderrt   writet   exit(   R   t	   verbosityt   autoclobbert   keepdbR   t   confirmt   e(    (    sE   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/sqlite3/creation.pyt   _create_test_db!   s*    c         C   sr   |  j  j } | d } |  j | ƒ r) | S| j ƒ  } t j j | d ƒ \ } } d j | | | ƒ | d <| Sd  S(   NR   s   {}_{}.{}(   R	   R
   R   t   copyR   t   patht   splitextt   format(   R   t   numbert   orig_settings_dictt   source_database_namet   new_settings_dictt   roott   ext(    (    sE   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/sqlite3/creation.pyt   get_test_db_clone_settings=   s    
c         C   s  |  j  j d } |  j | ƒ d } |  j | ƒ st j | t j ƒ rÃ | rQ d  S| d k rx d |  j | | ƒ f GHn  y t j | ƒ WqÃ t	 k
 r¿ } t
 j j d | ƒ t
 j d ƒ qÃ Xn  y t j | | ƒ Wqt	 k
 r} t
 j j d | ƒ t
 j d ƒ qXn  d  S(   NR   i   s,   Destroying old test database for alias %s...s0   Got an error deleting the old test database: %s
i   s+   Got an error cloning the test database: %s
(   R	   R
   R,   R   R   R   R   R   R   R   R   R   R   R   t   shutilR"   (   R   R&   R   R   R(   t   target_database_nameR    (    (    sE   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/sqlite3/creation.pyt   _clone_test_dbH   s&    c         C   s*   | r& |  j  | ƒ r& t j | ƒ n  d  S(   N(   R   R   R   (   R   R   R   (    (    sE   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/sqlite3/creation.pyt   _destroy_test_db`   s    c         C   sN   |  j  ƒ  } |  j j d g } |  j | ƒ rD | j |  j j ƒ n  t | ƒ S(   s   
        Returns 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   t   appendR   t   tuple(   R   R   t   sig(    (    sE   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/sqlite3/creation.pyt   test_db_signaturee   s
    (   t   __name__t
   __module__t   staticmethodR   R   t   FalseR!   R,   R/   R0   R4   (    (    (    sE   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/sqlite3/creation.pyR      s   			(   R   R-   R   t   django.core.exceptionsR    t    django.db.backends.base.creationR   t   django.utils.encodingR   t   django.utils.six.movesR   R   (    (    (    sE   /tmp/pip-unpacked-wheel-BAJOf3/django/db/backends/sqlite3/creation.pyt   <module>   s   