
    g]-                         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 dlmZmZ d d	lmZ d d
lmZ d dlmZ  G d d      Z G d d      ZdZdZy)    N)import_module)get_version)apps)SettingsReference)
migrations)MigrationLoader)
Serializerserializer_factory)get_func_args)
module_dir)nowc                   2    e Zd ZddZd Zd Zd Zd Zd Zy)	OperationWriterc                 .    || _         g | _        || _        y N)	operationbuffindentation)selfr   r   s      s/var/www/python.vincentserveurtest.ovh/public_html/venv/lib/python3.12/site-packages/django/db/migrations/writer.py__init__zOperationWriter.__init__   s    "	&    c                    
 
 fd}t               
 j                  j                         \  }}}t         j                  j                        }t        t        |d        j                  j                  k(  r j                  d|z         ng
j                  d j                  j                  j                  z          j                   j                  j                  j                  d|d        j                          t        |      D ]  \  }}|}||   }	 ||	|        t        |      }||d  D ]  }	|	|v s||	   } ||	|         j                           j                  d        j                         
fS )Nc                    | j                   j                  v r9t        |t        t        t
        f      rt        |t
              r1j                  d| z         j                          |j                         D ]  \  }}t        j                  |      \  }}t        j                  |      \  }}|j                         }t        |      dkD  rLj                  |d|d          |dd D ]  }	j                  |	        j                  d|d   z         nj                  |d|d       j                  |       j                  |        j                          j                  d       y j                  d	| z         j                          |D ]  }
t        j                  |
      \  }}|j                         }t        |      dkD  r3|d d D ]  }	j                  |	        j                  d|d   z         nj                  d|z         j                  |        j                          j                  d
       y t        j                  |      \  }}|j                         }t        |      dkD  rLj                  | d|d          |dd D ]  }	j                  |	        j                  d|d   z         nj                  | d|d       j                  |       y )Nz%s={   z: r   z%s,,z},z%s=[z],=)r   serialization_expand_args
isinstancelisttupledictfeedindentitemsMigrationWriter	serialize
splitlineslenupdateunindent)	_arg_name
_arg_valuekeyvalue
key_stringkey_imports
arg_stringarg_importsargsargitemimportsr   s              r   _writez)OperationWriter.serialize.<locals>._write   sr   DNNDDDT5$/J j$/IIfy01KKM&0&6&6&8
U2A2K2KC2P/
K2A2K2KE2R/
K)446t9q= II*d1g&FG'+Abz $		# (2 IIed2h&67 II:z&JK{3{3 '9 MMOIIdOIIfy01KKM *2A2K2KD2Q/
K)446t9q='+CRy $		# (1 IIed2h&67 IIej&89{3 !+ MMOIIdO*9*C*CJ*O'
K!,,.t9q=IIDG<=#Abz		#  *IIed2h./II)Z@A{+r   zmigrations.%s(z	import %s.(z),)setr   deconstructr   r   getattrr   	__class__r$   add
__module__r%   	enumerater*   r,   render)r   r9   namer5   kwargsoperation_argsir6   	arg_valuearg_namer8   s   `         @r   r(   zOperationWriter.serialize   sC   /	,b %!^^779dF&t~~'>'>?
 :tT*dnn.F.FFII&-.KKt~~'?'?'J'JKLII$..":":"E"EtLMoFAsI%a(H8Y' &
 I&qr*H6!"8,	x+ +
 			${{}g%%r   c                 .    | xj                   dz  c_         y Nr   r   r   s    r   r%   zOperationWriter.indenti       Ar   c                 .    | xj                   dz  c_         y rK   rL   rM   s    r   r,   zOperationWriter.unindentl   rN   r   c                 `    | j                   j                  d| j                  dz  z  |z          y )N    )r   appendr   )r   lines     r   r$   zOperationWriter.feedo   s)    		 0 01 45<=r   c                 8    dj                  | j                        S )N
)joinr   rM   s    r   rC   zOperationWriter.renderr   s    yy##r   N)   )	__name__rA   __qualname__r   r(   r%   r,   r$   rC    r   r   r   r      s"    '
O&b>$r   r   c                   ~    e Zd ZdZddZd Zed        Zed        Zed        Z	e
d        Ze
d        Ze
d	        Zy
)r'   zj
    Take a Migration instance and is able to produce the contents
    of the migration file from it.
    c                 .    || _         || _        d| _        y )NF)	migrationinclude_headerneeds_manual_porting)r   r^   r_   s      r   r   zMigrationWriter.__init__|   s    ",$)!r   c           	         ddd}t               }g }| j                  j                  D ]@  }t        |      j	                         \  }}|j                  |       |j                  |       B |rdj                  |      dz   nd|d<   g }| j                  j                  D ]Y  }|d   dk(  r)|j                  d|d   z         |j                  d	       4|j                  d
| j	                  |      d   z         [ |rdj                  t        |            dz   nd|d<   t               }	t        |      D ]b  }
t        j                  d|
      s|	j                  |
j                  d      d   j                                |j!                  |
       d| _        d d|v r#|j%                  d       |j                  d       n|j                  d       t        |d       }|rdj                  |      dz   nd|d<   |	r(|dxx   ddj                  t        |	            z  z  cc<   | j                  j&                  r.d| j	                  | j                  j&                        d   z  |d<   | j(                  r/t*        t-               t/               j1                  d      dz  |d<   nd|d<   | j                  j2                  rd|d<   t4        |z  S )z%Return a string of the file contents. )replaces_strinitial_strrV   
operationsr   __setting__z5        migrations.swappable_dependency(settings.%s),r   z from django.conf import settingsz        %s,dependenciesz^import (.*)\.\d+[^\s]*$importTzfrom django.db import modelsz(from django.db import migrations, modelsz from django.db import migrationsc                 T    | j                         d   dk(  | j                         d   fS )Nr   fromr   )split)rG   s    r   <lambda>z+MigrationWriter.as_string.<locals>.<lambda>   s"    AGGIaLF$:AGGIaL#Ir   )r/   r8   z

# Functions from the following migrations need manual copying.
# Move them and any dependencies into this file, then update the
# RunPython operations to refer to the local versions:
# %sz
# z
    replaces = %s
rc   z%Y-%m-%d %H:%M)version	timestampmigration_headerz
    initial = True
rd   )r<   r^   re   r   r(   r+   rS   rW   rg   r@   sortedr!   rematchrk   stripremover`   discardreplacesr_   MIGRATION_HEADER_TEMPLATEr   r   strftimeinitialMIGRATION_TEMPLATE)r   r&   r8   re   r   operation_stringoperation_importsrg   
dependencymigration_importsrT   sorted_importss               r   	as_stringzMigrationWriter.as_string   s    

 % 
22I2A)2L2V2V2X//NN,-./ 3 ?Idii
3d:bl ..55J!}-##K m$ >?##MDNN:4Nq4Q$QR 6 7CDIIf\*+d2 	n  EMDxx3T:!%%djj&:1&=&C&C&EFt$,0)	 " *W4OO:;KKBCKK:;
  I
 @G499^4t;Bi)" F#456!7 7 >>""'$..9P9P*QRS*TT .! (A&= U^^,<=E )E$%
 )+E$%>>!!#;E- !E))r   c                 \   t        j                  | j                  j                        \  }}|"t	        d| j                  j                  z        	 t        |      }	 t        |      S # t        $ r Y nw xY w# t        $ r Y nw xY wt        j                  | j                  j                        }|j                  d      \  }}}|j                  |k(  r*t        j                  j                  |j                  |      S |j                  d      g }}|rm|j!                  d|j#                  d             	 t        dj                  |            }		 t        |	      }
n2# t        $ r Y Vw xY w# t        t        f$ r Y kw xY wt	        d|z        t        j                  j                  |
g| }t        j$                  |d       |D ]b  }t        j                  j                  |
|      }
t'        t        j                  j                  |
d      d	      5  	 d d d        X# 1 sw Y   axY w |S )
NztDjango can't create migrations for app '%s' because migrations have been disabled via the MIGRATION_MODULES setting.r:   r   r   zCould not locate an appropriate location to create migrations package %s. Make sure the toplevel package exists and can be imported.T)exist_okz__init__.pyw)r   migrations_moduler^   	app_label
ValueErrorr   r   ImportErrorr   get_app_config
rpartitionrD   ospathrW   rk   insertpopmakedirsopen)r   migrations_package_name_r   
app_configmaybe_app_namemigrations_package_basenameexisting_dirsmissing_dirsbase_modulebase_dir	final_dirmissing_dirs                r   basedirzMigrationWriter.basedir   s   %4%F%FNN$$&
" #*!^^556 	 -.E F!"344   		 (()A)AB

 $..s3		
'??n,77<<
1LMM '>&C&CC&H"|=#4#4R#89
+CHH],CD)+6H  "   ,  68OP  GGLL9L9	
I-'Kww||Hk:Hbggll8];SA BAA (
 sT   A8 
A) )	A54A58	BB5E+ E 	E('E(+E=<E=HH(	c                 4    d| j                   j                  z  S )Nz%s.py)r^   rD   rM   s    r   filenamezMigrationWriter.filename  s    ,,,,r   c                 j    t         j                  j                  | j                  | j                        S r   )r   r   rW   r   r   rM   s    r   r   zMigrationWriter.path  s    ww||DLL$--88r   c                 4    t        |      j                         S r   )r
   r(   )clsr0   s     r   r(   zMigrationWriter.serialize  s    !%(2244r   c                 0    t        j                  ||       y r   )r	   register)r   type_
serializers      r   register_serializerz#MigrationWriter.register_serializer!  s    E:.r   c                 .    t        j                  |       y r   )r	   
unregister)r   r   s     r   unregister_serializerz%MigrationWriter.unregister_serializer%  s    e$r   N)T)rY   rA   rZ   __doc__r   r   propertyr   r   r   classmethodr(   r   r   r[   r   r   r'   r'   v   s    
*
P*d ? ?B - - 9 9 5 5 / / % %r   r'   z4# Generated by Django %(version)s on %(timestamp)s

z%(migration_header)s%(imports)s

class Migration(migrations.Migration):
%(replaces_str)s%(initial_str)s
    dependencies = [
%(dependencies)s    ]

    operations = [
%(operations)s    ]
)r   rq   	importlibr   djangor   django.appsr   django.confr   	django.dbr   django.db.migrations.loaderr   django.db.migrations.serializerr	   r
   django.utils.inspectr   django.utils.module_loadingr   django.utils.timezoner   r   r'   rw   rz   r[   r   r   <module>r      sU    	 	 #   *   7 J . 2 %a$ a$Hq% q%h  r   