ó
    ¼Rj4=  ã                   ó€   • S SK r S SKrS SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  S	r " S
 S5      rg)é    N)ÚStringIO)Úapps)Úsettings)Úserializers)Úrouter)Úatomic)Úimport_stringÚtest_c                   ó¬   • \ rS rSrSrS rS rS r SS jrS r	S r
S	 rS
 rS rSS jrSS jrSS jrS rSS jr SS jrS rS rS rS rS rSrg)ÚBaseDatabaseCreationé   zg
Encapsulate backend-specific differences pertaining to creation and
destruction of the test database.
c                 ó   • Xl         g ©N©Ú
connection)Úselfr   s     ÚLD:\diplom_project\venv\Lib\site-packages\django/db/backends/base/creation.pyÚ__init__ÚBaseDatabaseCreation.__init__   s   € Ø$�ó    c                 ó6   • U R                   R                  5       $ r   )r   Ú_nodb_cursor©r   s    r   r   Ú!BaseDatabaseCreation._nodb_cursor   s   € Ø�‰×+Ñ+Ó-Ð-r   c                 ód   • [         R                  R                  U[        R                  -   5        g r   )ÚsysÚstderrÚwriteÚosÚlinesep)r   Úmsgs     r   ÚlogÚBaseDatabaseCreation.log   s   € Ü�
‰
×Ñ˜œrŸz™zÑ)Õ*r   c                 ó‚  • SSK Jn  U R                  5       nUS:¼  a3  SnU(       a  SnU R                  U< SU R	                  X5      < S35        U R                  XU5        U R                  R                  5         U[        R                  U R                  R                     S'   X`R                  R                  S'    U R                  R                  S	   S
   SL aI  [        R                  n[        R                  " 5        V	s0 s H  o™R                  S_M     sn	[        l        U" S[!        US-
  S5      SU R                  R                  SS9  U R                  R                  S	   S
   SL a  W[        l        U(       a  U R#                  5       U R                  l        U" SU R                  R                  S9  U R                  R'                  5         [(        R*                  R-                  S5      S:X  a  U R/                  5         U$ s  sn	f ! U R                  R                  S	   S
   SL a  W[        l        f f = f)z‹
Create a test database, prompting the user for confirmation if the
database already exists. Return the name of the test database created.
r   )Úcall_commandé   ÚCreatingzUsing existingú test database for alias ú...ÚNAMEÚTESTÚMIGRATEFNÚmigrateT)Ú	verbosityÚinteractiveÚdatabaseÚ
run_syncdbÚcreatecachetable)r0   ÚRUNNING_DJANGOS_TEST_SUITEÚtrue)Údjango.core.managementr%   Ú_get_test_db_namer"   Ú_get_database_display_strÚ_create_test_dbr   Úcloser   Ú	DATABASESÚaliasÚsettings_dictÚMIGRATION_MODULESr   Úget_app_configsÚlabelÚmaxÚserialize_db_to_stringÚ_test_serialized_contentsÚensure_connectionr   ÚenvironÚgetÚ mark_expected_failures_and_skips)
r   r.   ÚautoclobberÚ	serializeÚkeepdbr%   Útest_database_nameÚactionÚold_migration_modulesÚapps
             r   Úcreate_test_dbÚ#BaseDatabaseCreation.create_test_db    sì  € õ 	8à!×3Ñ3Ó5Ðà˜‹>ØˆFÞØ)�à�H‰Hó Ø×2Ñ2°9ÖQðôð 	×Ñ˜Y°VÔ<à�‰×ÑÔØ<NŒ×Ñ˜4Ÿ?™?×0Ñ0Ñ1°&Ñ9Ø0B�‰×%Ñ% fÑ-ð	CØ�‰×,Ñ,¨VÑ4°YÑ?À5ÒHä(0×(BÑ(BÐ%ä/3×/CÒ/CÔ/Eó.Ú/E¨—I‘I˜t’OÑ/Eñ.”Ô*ñ ØÜ˜i¨!™m¨QÓ/Ø!ØŸ™×.Ñ.Øòð �‰×,Ñ,¨VÑ4°YÑ?À5ÒHØ-B”Ô*ö Ø8<×8SÑ8SÓ8UˆD�O‰OÔ5áÐ'°$·/±/×2GÑ2GÒHð 	�‰×)Ñ)Ô+ä�:‰:�>‰>Ð6Ó7¸6ÓAØ×1Ñ1Ô3à!Ð!ùòA.øð �‰×,Ñ,¨VÑ4°YÑ?À5ÒHØ-B”Õ*ð Iús   Â?AH ÄHÄ7H ÈH È-H>c                 ó<   • US   U R                   R                  S'   g)zh
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   Úprimary_settings_dicts     r   Úset_as_test_mirrorÚ'BaseDatabaseCreation.set_as_test_mirrorj   s   € ð
 1FÀfÑ0Mˆ�‰×%Ñ% fÒ-r   c                 ó|   ^ • U 4S jn[        5       n[        R                  " SU" 5       SUS9  UR                  5       $ )z„
Serialize all data in the database into a JSON string.
Designed only for test runner usage; will not handle large
amounts of data.
c               3   óæ  >#   • SSK Jn   U " TR                  5      n[        R                  " 5        GH8  nUR
                  c  M  UR                  UR                  ;   d  M/  UR                  [        R                  ;  d  MO  UR                  5        HÕ  nUR                  R                  TR                  5      (       d  M/  [        R                  " TR                  R                   U5      (       d  Ma  UR"                  R%                  TR                  R                   5      R'                  UR                  R(                  R                  5      nUR+                  5        S h  v•N   M×     GM;     g  N7f)Nr   )ÚMigrationLoader)Údjango.db.migrations.loaderrV   r   r   r>   Úmodels_moduler?   Úmigrated_appsÚnamer   ÚTEST_NON_SERIALIZED_APPSÚ
get_modelsÚ_metaÚcan_migrater   Úallow_migrate_modelr;   Ú_base_managerÚusingÚorder_byÚpkÚiterator)rV   ÚloaderÚ
app_configÚmodelÚquerysetr   s        €r   Úget_objectsÚ@BaseDatabaseCreation.serialize_db_to_string.<locals>.get_objectsy   s  øé € ÝCá$ T§_¡_Ó5ˆFÜ"×2Ò2×4�
à×,Ñ,Ó8Ø"×(Ñ(¨F×,@Ñ,@Õ@Ø"Ÿ™¬x×/PÑ/PÕPà!+×!6Ñ!6Ö!8˜Ø Ÿ;™;×2Ñ2Ø ŸO™O÷ó ä$×8Ò8¸¿¹×9NÑ9NÐPU×VÓVØ',×':Ñ':×'@Ñ'@Ø $§¡× 5Ñ 5ó(ç&™h u§{¡{§~¡~×':Ñ':Ó;ð %ð (0×'8Ñ'8Ó':×:Ò:ô "9ò 5ñ ;ùs0   ƒ=E1ÁE1Á E1Â ;E1Â?.E1Ã1A/E1Å E/Å!E1ÚjsonN)ÚindentÚstream)r   r   rH   Úgetvalue)r   ri   Úouts   `  r   rA   Ú+BaseDatabaseCreation.serialize_db_to_stringq   s3   ø€ õ	;ô( ‹jˆÜ×Ò˜f¡k£m¸DÈÒMØ�|‰|‹~Ðr   c                 ó(  • [        U5      n[        5       n[        U R                  R                  S9   U R                  R                  5          [        R                  " SXR                  R                  S9 HL  nUR                  5         UR                  UR                  R                  R                  R                  5        MN     SSS5        U R                  R                  US9  SSS5        g! , (       d  f       N0= f! , (       d  f       g= f)z_
Reload the database with data from a string generated by
the serialize_db_to_string() method.
)ra   rk   N)Útable_names)r   Úsetr   r   r;   Úconstraint_checks_disabledr   ÚdeserializeÚsaveÚaddÚobjectÚ	__class__r]   Údb_tableÚcheck_constraints)r   Údatarr   Úobjs       r   Údeserialize_db_from_stringÚ/BaseDatabaseCreation.deserialize_db_from_string‘   s¿   € ô
 ˜‹~ˆÜ“eˆä˜$Ÿ/™/×/Ñ/Ó0ð —‘×;Ñ;Õ=Ü&×2Ò2Ø˜D¯©×(=Ñ(=ô�Cð —H‘H”JØ—O‘O C§J¡J×$8Ñ$8×$>Ñ$>×$GÑ$GÖHñ	÷ >ð �O‰O×-Ñ-¸+Ð-ÑF÷ 1Ð0÷ >Õ=ú÷ 1Õ0ús$   ³DÁA:C2Ã!DÃ2
D 	Ã<DÄ
Dc                 óZ   • SU R                   R                  < SUS:¼  a  SU-  < 3$ S< 3$ )zB
Return display string for a database for use in various actions.
Ú'é   z ('%s')Ú )r   r;   )r   r.   Údatabase_names      r   r7   Ú.BaseDatabaseCreation._get_database_display_str¦   s<   � ð
 �O‰O×!Ô!Ø+4¸«>ˆY˜Ñ&ÑAð
ð 	
à?AÑAð
ð 	
r   c                 ó¼   • U R                   R                  S   S   (       a  U R                   R                  S   S   $ [        U R                   R                  S   -   $ )zÓ
Internal implementation - return 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.
r+   r*   )r   r<   ÚTEST_DATABASE_PREFIXr   s    r   r6   Ú&BaseDatabaseCreation._get_test_db_name¯   sO   € ð �?‰?×(Ñ(¨Ñ0°×8Ø—?‘?×0Ñ0°Ñ8¸Ñ@Ð@Ü# d§o¡o×&CÑ&CÀFÑ&KÑKÐKr   c                 ó,   • UR                  SU-  5        g )Nz%CREATE DATABASE %(dbname)s %(suffix)s)Úexecute)r   ÚcursorÚ
parametersrI   s       r   Ú_execute_create_test_dbÚ,BaseDatabaseCreation._execute_create_test_dbº   s   € Ø�‰Ð>ÀÑKÕLr   c           	      ó`  • U R                  5       nU R                  R                  R                  U5      U R	                  5       S.nU R                  5        n U R                  XeU5        SSS5        U$ ! [         Ga  nU(       a  Us SnAsSSS5        $ U R                  SU-  5        U(       d  [        SU-  5      nU(       d  WS:X  aœ   US:¼  a%  U R                  SU R                  X5      < S35        UR                  S	U-  5        U R                  XeU5         SnAN¹! [         a8  nU R                  S
U-  5        [        R                  " S5         SnA SnANöSnAff = fU R                  S5        [        R                  " S5         SnAGN+SnAff = f! , (       d  f       U$ = f)z6
Internal implementation - create the test db tables.
)ÚdbnameÚsuffixNz+Got an error creating the test database: %szXType 'yes' if you would like to try deleting the test database '%s', or 'no' to cancel: Úyesr&   z'Destroying old test database for alias r)   zDROP DATABASE %(dbname)sz-Got an error recreating the test database: %sr‚   zTests cancelled.)r6   r   ÚopsÚ
quote_nameÚsql_table_creation_suffixr   r�   Ú	Exceptionr"   Úinputr7   rŠ   r   Úexit)	r   r.   rG   rI   rJ   Útest_db_paramsr‹   ÚeÚconfirms	            r   r8   Ú$BaseDatabaseCreation._create_test_db½   sˆ  € ð "×3Ñ3Ó5Ðà—o‘o×)Ñ)×4Ñ4Ð5GÓHØ×4Ñ4Ó6ñ
ˆð
 ×ÑÔ  Fð  Ø×,Ñ,¨VÀVÔL÷ !ðF "Ð!øôA ô  ö Ø-Ô-÷ !Ñ ð —‘ÐFÈÑJÔKÞ"Ü#ð=Ø?QñRó�Gö  '¨UÓ"2ð$Ø$¨›>Ø ŸHšHð %)×$BÑ$BØ(1ö%&ð!"ôð Ÿ™Ð'AÀNÑ'RÔSØ×4Ñ4°VÈV×TÑTøÜ$ó $ØŸ™Ð!PÐSTÑ!TÔUÜŸš Ÿ�ûð$úð —H‘HÐ/Ô0Ü—H’H˜Q—K’Kûð= ú÷ !Ô ðF "Ð!úss   ÁFÁA5Á5FÂ FÂFÂ	FÂ6FÃAD$ÄFÄ$
E&Ä.*E!ÅFÅFÅ!E&Å&*FÆFÆFÆFÆ
F-c                 óÌ   • U R                   R                  S   nUS:¼  a3  SnU(       a  SnU R                  U< SU R                  X%5      < S35        U R	                  XU5        g)z
Clone a test database.
r*   r&   zCloning test databasezUsing existing clonez for alias r)   N)r   r<   r"   r7   Ú_clone_test_db)r   r‘   r.   rG   rI   Úsource_database_namerK   s          r   Úclone_test_dbÚ"BaseDatabaseCreation.clone_test_dbì   sc   € ð  $Ÿ™×<Ñ<¸VÑDÐà˜‹>Ø,ˆFÞØ/�Ø�H‰Hó Ø×2Ñ2°9ÖSðôð 	×Ñ˜F¨vÕ6r   c                 ód   • U R                   R                  n0 UESSR                  US   U5      0E$ )zH
Return a modified connection settings dict for the n-th clone of a DB.
r*   z{}_{})r   r<   Úformat)r   r‘   Úorig_settings_dicts      r   Úget_test_db_clone_settingsÚ/BaseDatabaseCreation.get_test_db_clone_settings  sA   € ð "Ÿ_™_×:Ñ:Ðð
Ø ð
à�G—N‘NÐ#5°fÑ#=¸vÓFñ
ð 	
r   c                 ó   • [        S5      e)z9
Internal implementation - duplicate the test db tables.
znThe database backend doesn't support cloning databases. Disable the option to run tests in parallel processes.)ÚNotImplementedError)r   r‘   r.   rI   s       r   rž   Ú#BaseDatabaseCreation._clone_test_db  s   € ô "ðEó
ð 	
r   Nc                 óÈ  • U R                   R                  5         Uc  U R                   R                  S   nOU R                  U5      S   nUS:¼  a3  SnU(       a  SnU R	                  U< SU R                  X%5      < S35        U(       d  U R                  XR5        UbC  U[        R                  U R                   R                     S'   XR                   R                  S'   gg)z^
Destroy a test database, prompting the user for confirmation if the
database already exists.
Nr*   r&   Ú
DestroyingÚ
Preservingr(   r)   )
r   r9   r<   r¥   r"   r7   Ú_destroy_test_dbr   r:   r;   )r   Úold_database_namer.   rI   r‘   rJ   rK   s          r   Údestroy_test_dbÚ$BaseDatabaseCreation.destroy_test_db  sÎ   € ð 	�‰×ÑÔØ‰>Ø!%§¡×!>Ñ!>¸vÑ!FÑà!%×!@Ñ!@ÀÓ!HÈÑ!PÐà˜‹>Ø!ˆFÞØ%�Ø�H‰Hó Ø×2Ñ2°9ÖQðôö Ø×!Ñ!Ð"4Ô@ð Ñ(Ø@QŒH×Ñ˜tŸ™×4Ñ4Ñ5°fÑ=Ø4E�O‰O×)Ñ)¨&Ò1ð )r   c                 óÆ   • U R                  5        nUR                  SU R                  R                  R	                  U5      -  5        SSS5        g! , (       d  f       g= f)z6
Internal implementation - remove the test db tables.
zDROP DATABASE %sN)r   rŠ   r   r“   r”   )r   rJ   r.   r‹   s       r   r­   Ú%BaseDatabaseCreation._destroy_test_db;  sH   € ð ×ÑÔ  FØ�N‰NØ" T§_¡_×%8Ñ%8×%CÑ%CÐDVÓ%WÑWô÷ !× Ö ús   ‘8AÁ
A c           	      ó†  • SSK JnJn  U R                  R                  R
                   Hi  nUR                  S5      u  pEnUR                  S5      S   nU[        R                  ;   d  MA  [        U5      n[        X†5      n	[        X†U" U	5      5        Mk     U R                  R                  R                  R                  5        Hz  u  p«U Ho  nUR                  S5      u  pEnUR                  S5      S   nU[        R                  ;   d  MA  [        U5      n[        X†5      n	[        X†U" U
5      " U	5      5        Mq     M|     g)zƒ
Mark tests in Django's test suite which are expected failures on this
database and test which should be skipped on this database.
r   )ÚexpectedFailureÚskipÚ.N)Úunittestr´   rµ   r   ÚfeaturesÚdjango_test_expected_failuresÚ
rpartitionÚsplitr   ÚINSTALLED_APPSr	   ÚgetattrÚsetattrÚdjango_test_skipsÚitems)r   r´   rµ   Ú	test_nameÚtest_case_nameÚ_Útest_method_nameÚtest_appÚ	test_caseÚtest_methodÚreasonÚtestss               r   rF   Ú5BaseDatabaseCreation.mark_expected_failures_and_skipsH  s  € ÷ 	3àŸ™×1Ñ1×OÔOˆIØ2;×2FÑ2FÀsÓ2KÑ/ˆNÐ/Ø —‘ sÓ+¨AÑ.ˆHàœ8×2Ñ2Õ2Ü)¨.Ó9�	Ü% iÓB�Ü˜	±_À[Ó5QÖRñ Pð "Ÿ_™_×5Ñ5×GÑG×MÑMÖO‰MˆFÛ"�	Ø6?×6JÑ6JÈ3Ó6OÑ3�Ð#3Ø$Ÿ?™?¨3Ó/°Ñ2�àœx×6Ñ6Õ6Ü -¨nÓ =�IÜ")¨)Ó"F�KÜ˜I¹¸f¼ÀkÓ9RÖSó #ò Pr   c                 ó   • g)zA
SQL to append to the end of the test table creation statements.
rƒ   © r   s    r   r•   Ú.BaseDatabaseCreation.sql_table_creation_suffixb  s   € ð r   c                 óh   • U R                   R                  nUS   US   US   U R                  5       4$ )z§
Return a tuple with elements of self.connection.settings_dict (a
DATABASES setting value) that uniquely identify a database
accordingly to the RDBMS particularities.
ÚHOSTÚPORTÚENGINE)r   r<   r6   )r   r<   s     r   Útest_db_signatureÚ&BaseDatabaseCreation.test_db_signatureh  sA   € ð Ÿ™×5Ñ5ˆà˜&Ñ!Ø˜&Ñ!Ø˜(Ñ#Ø×"Ñ"Ó$ð	
ð 	
r   c                 ó¶   • U R                  [        U5      5      nU R                  R                  R	                  U5        U R                  R                  5         g r   )r¥   Ústrr   r<   Úupdater9   )r   Ú
_worker_idr<   s      r   Úsetup_worker_connectionÚ,BaseDatabaseCreation.setup_worker_connectionv  s@   € Ø×7Ñ7¼¸J»ÓHˆð
 	�‰×%Ñ%×,Ñ,¨]Ô;Ø�‰×ÑÕr   r   )r&   FTF)F)r&   FF)Nr&   FN)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r   r   r"   rN   rR   rA   r~   r7   r6   r�   r8   r    r¥   rž   r¯   r­   rF   r•   rÒ   rØ   Ú__static_attributes__rÌ   r   r   r   r      s„   † ñò
%ò.ò+ð FKôH"òTNòò@Gò*
ò	LôMô-"ô^7ò,
ô
ð IMô!FòFòTò4ò
õ r   r   )r   r   Úior   Údjango.appsr   Údjango.confr   Údjango.corer   Ú	django.dbr   Údjango.db.transactionr   Údjango.utils.module_loadingr	   r‡   r   rÌ   r   r   Ú<module>rç      s4   ðÛ 	Û 
Ý å Ý  Ý #Ý Ý (Ý 5ð Ð ÷l ò l r   