ó
i4Vdc           @   s˜   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  d l
 m Z d  d l m Z d Z d	 e f d
 „  ƒ  YZ d S(   iÿÿÿÿN(   t   apps(   t   settings(   t   serializers(   t   router(   t   StringIO(   t   inputt   test_t   BaseDatabaseCreationc           B   sË   e  Z d  Z d „  Z e d „  ƒ Z d e e e d „ Z d „  Z	 d „  Z
 d „  Z d „  Z d	 „  Z e d
 „ Z d e e d „ Z d „  Z e d „ Z d d e d d „ Z d „  Z d „  Z d „  Z RS(   s…   
    This class encapsulates all backend-specific differences that pertain to
    creation and destruction of the test database.
    c         C   s   | |  _  d  S(   N(   t
   connection(   t   selfR   (    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyt   __init__   s    c         C   s
   |  j  j S(   sH   
        Used to be defined here, now moved to DatabaseWrapper.
        (   R   t   _nodb_connection(   R	   (    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyR      s    i   c      
   C   s  d d l  m } |  j ƒ  } | d k r[ d } | r= d } n  d | |  j | | ƒ f GHn  |  j | | | ƒ |  j j ƒ  | t j |  j j	 d <| |  j j
 d <| d d	 t | d d
 ƒ d t d |  j j	 d t ƒ| rò |  j ƒ  |  j _ n  | d d |  j j	 ƒ|  j j ƒ  | S(   s¥   
        Creates a test database, prompting the user for confirmation if the
        database already exists. Returns the name of the test database created.
        iÿÿÿÿ(   t   call_commandi   t   Creatings   Using existings    %s test database for alias %s...t   NAMEt   migratet	   verbosityi    t   interactivet   databaset
   run_syncdbt   createcachetable(   t   django.core.managementR   t   _get_test_db_namet   _get_database_display_strt   _create_test_dbR   t   closeR   t	   DATABASESt   aliast   settings_dictt   maxt   Falset   Truet   serialize_db_to_stringt   _test_serialized_contentst   ensure_connection(   R	   R   t   autoclobbert	   serializet   keepdbR   t   test_database_namet   action(    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyt   create_test_db   s0    	c         C   s   | d |  j  j d <d S(   s   
        Set this database up to be used in testing as a mirror of a primary database
        whose settings are given
        R   N(   R   R   (   R	   t   primary_settings_dict(    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyt   set_as_test_mirrorW   s    c            sÉ   d d l  m } | ˆ j ƒ } g  ‰  x] t j ƒ  D]O } | j d k	 r2 | j | j k r2 | j	 t
 j k r2 ˆ  j | d f ƒ q2 q2 W‡  ‡ f d †  } t ƒ  } t j d | ƒ  d d d | ƒ| j ƒ  S(   s¥   
        Serializes all data in the database into a JSON string.
        Designed only for test runner usage; will not handle large
        amounts of data.
        iÿÿÿÿ(   t   MigrationLoaderc          3   s”   x t  j ˆ  ƒ D]| }  |  j j ˆ j ƒ r t j ˆ j j |  ƒ r |  j j	 ˆ j j ƒ j
 |  j j j ƒ } x | j ƒ  D] } | Vqz Wq q Wd  S(   N(   R   t   sort_dependenciest   _metat   can_migrateR   R   t   allow_migrate_modelR   t   _default_managert   usingt   order_byt   pkt   namet   iterator(   t   modelt   querysett   obj(   t   app_listR	   (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyt   get_objectsq   s    *t   jsont   indentt   streamN(   t   django.db.migrations.loaderR+   R   R    t   get_app_configst   models_modulet   Nonet   labelt   migrated_appsR4   R   t   TEST_NON_SERIALIZED_APPSt   appendR   R   R$   t   getvalue(   R	   R+   t   loadert
   app_configR:   t   out(    (   R9   R	   sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyR    ^   s    	c         C   sC   t  | ƒ } x0 t j d | d |  j j ƒD] } | j ƒ  q+ Wd S(   sv   
        Reloads the database with data from a string generated by
        the serialize_db_to_string method.
        R;   R1   N(   R   R   t   deserializeR   R   t   save(   R	   t   dataR8   (    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyt   deserialize_db_from_string}   s    %c         C   s*   d |  j  j | d k r" d | n d f S(   sR   
        Return display string for a database for use in various actions.
        s   '%s'%si   s    ('%s')t    (   R   R   (   R	   R   t   database_name(    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyR   †   s    	c         C   s8   |  j  j d d r& |  j  j d d St |  j  j d S(   sü   
        Internal implementation - returns the name of the test DB that will be
        created. Only useful when called from create_test_db() and
        _create_test_db() and when no external munging is done with the 'NAME'
        settings.
        t   TESTR   (   R   R   t   TEST_DATABASE_PREFIX(   R	   (    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyR      s    c   
   	   C   sn  |  j  ƒ  } |  j ƒ  } |  j j j } |  j j ƒ  2} y! | j d | | ƒ | f ƒ Wnt k
 rc} | rv | St	 j
 j d | ƒ | s£ t d | ƒ }	 n  | sµ |	 d k rNy_ | d k rß d |  j | | ƒ f GHn  | j d | | ƒ ƒ | j d | | ƒ | f ƒ Wq`t k
 rJ} t	 j
 j d | ƒ t	 j d	 ƒ q`Xqdd
 GHt	 j d ƒ n XWd QX| S(   sG   
        Internal implementation - creates the test db tables.
        s   CREATE DATABASE %s %ss,   Got an error creating the test database: %s
sX   Type 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: t   yesi   s,   Destroying old test database for alias %s...s   DROP DATABASE %ss.   Got an error recreating the test database: %s
i   s   Tests cancelled.N(   t   sql_table_creation_suffixR   R   t   opst
   quote_nameR   t   cursort   executet	   Exceptiont   syst   stderrt   writeR   R   t   exit(
   R	   R   R#   R%   t   suffixR&   t   qnRV   t   et   confirm(    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyR   š   sB    		c         C   sf   |  j  j d } | d k rO d } | r1 d } n  d | |  j | | ƒ f GHn  |  j | | | ƒ d S(   s(   
        Clone a test database.
        R   i   s   Cloning test databases   Using existing clones   %s for alias %s...N(   R   R   R   t   _clone_test_db(   R	   t   numberR   R#   R%   t   source_database_nameR'   (    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyt   clone_test_dbÊ   s    	c         C   s6   |  j  j } | j ƒ  } d j | d | ƒ | d <| S(   sX   
        Return a modified connection settings dict for the n-th clone of a DB.
        s   {}_{}R   (   R   R   t   copyt   format(   R	   Rb   t   orig_settings_dictt   new_settings_dict(    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyt   get_test_db_clone_settingsÝ   s    c         C   s   t  d ƒ ‚ d S(   sI   
        Internal implementation - duplicate the test db tables.
        sn   The database backend doesn't support cloning databases. Disable the option to run tests in parallel processes.N(   t   NotImplementedError(   R	   Rb   R   R%   (    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyRa   é   s    c         C   sÑ   |  j  j ƒ  | d k r, |  j  j d } n |  j | ƒ d } | d k r~ d } | r` d } n  d | |  j | | ƒ f GHn  | s— |  j | | ƒ n  | d k	 rÍ | t j |  j  j	 d <| |  j  j d <n  d S(   sv   
        Destroy a test database, prompting the user for confirmation if the
        database already exists.
        R   i   t
   Destroyingt
   Preservings    %s test database for alias %s...N(
   R   R   RA   R   Ri   R   t   _destroy_test_dbR   R   R   (   R	   t   old_database_nameR   R%   Rb   R&   R'   (    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyt   destroy_test_dbñ   s     	c         C   sL   |  j  j j ƒ  4 } t j d ƒ | j d |  j  j j | ƒ ƒ Wd QXd S(   sF   
        Internal implementation - remove the test db tables.
        i   s   DROP DATABASE %sN(   R   R   RV   t   timet   sleepRW   RT   RU   (   R	   R&   R   RV   (    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyRm     s    	c         C   s   d S(   sQ   
        SQL to append to the end of the test table creation statements.
        RN   (    (   R	   (    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyRS     s    c         C   s,   |  j  j } | d | d | d | d f S(   sÈ   
        Returns a tuple with elements of self.connection.settings_dict (a
        DATABASES setting value) that uniquely identify a database
        accordingly to the RDBMS particularities.
        t   HOSTt   PORTt   ENGINER   (   R   R   (   R	   R   (    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyt   test_db_signature#  s
    N(   t   __name__t
   __module__t   __doc__R
   t   propertyR   R   R   R(   R*   R    RM   R   R   R   Rd   Ri   Ra   RA   Ro   Rm   RS   Ru   (    (    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyR      s"   	8							0			(   RY   Rp   t   django.appsR    t   django.confR   t   django.coreR   t	   django.dbR   t   django.utils.sixR   t   django.utils.six.movesR   RQ   t   objectR   (    (    (    sn   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/django/db/backends/base/creation.pyt   <module>   s   