o
    
=h57                     @   s  d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	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mZ d dlmZmZ d dlmZmZ ejejejfZe ej!e"rneej!f7 ZG dd	 d	Z#G d
d de#Z$G dd de$Z%G dd de#Z&G dd de#Z'G dd de#Z(G dd de#Z)G dd de#Z*G dd de#Z+G dd de#Z,G dd de#Z-G dd de&Z.G d d! d!e%Z/G d"d# d#e#Z0G d$d% d%e#Z1G d&d' d'e#Z2G d(d) d)e+Z3G d*d+ d+e+Z4G d,d- d-e#Z5G d.d/ d/e#Z6G d0d1 d1e#Z7G d2d3 d3e#Z8G d4d5 d5e$Z9G d6d7 d7e%Z:G d8d9 d9e#Z;G d:d; d;e$Z<G d<d= d=e#Z=G d>d? d?e#Z>G d@dA dAZ?dBdC Z@dS )D    N)SettingsReference)models)	Operation)COMPILED_REGEX_TYPERegexObject)
LazyObjectPromise)PY311get_docs_versionc                   @      e Zd Zdd Zdd ZdS )BaseSerializerc                 C   s
   || _ d S Nvalueselfr    r   W/var/www/ecommerce/venv/lib/python3.10/site-packages/django/db/migrations/serializer.py__init__    s   
zBaseSerializer.__init__c                 C      t d)NzCSubclasses of BaseSerializer must implement the serialize() method.NotImplementedErrorr   r   r   r   	serialize#      zBaseSerializer.serializeN)__name__
__module____qualname__r   r   r   r   r   r   r      s    r   c                   @   r   )BaseSequenceSerializerc                 C   r   )NzISubclasses of BaseSequenceSerializer must implement the _format() method.r   r   r   r   r   _format*   r   zBaseSequenceSerializer._formatc                 C   sT   t  }g }| jD ]}t| \}}|| || q|  }|d| |fS )N, )setr   serializer_factoryr   updateappendr   joinr   importsstringsitemitem_stringitem_importsr   r   r   r   r   /   s   

z BaseSequenceSerializer.serializeN)r   r   r   r   r   r   r   r   r   r   )   s    r   c                          e Zd Z fddZ  ZS )BaseUnorderedSequenceSerializerc                    s   t  t|td d S )N)key)superr   sortedreprr   	__class__r   r   r   ;   s   z(BaseUnorderedSequenceSerializer.__init__)r   r   r   r   __classcell__r   r   r2   r   r-   :       r-   c                   @      e Zd Zdd ZdS )BaseSimpleSerializerc                 C   s   t | jt fS r   )r1   r   r!   r   r   r   r   r   @      zBaseSimpleSerializer.serializeNr   r   r   r   r   r   r   r   r7   ?       r7   c                   @   r6   )ChoicesSerializerc                 C   s   t | jj S r   )r"   r   r   r   r   r   r   r   E   r8   zChoicesSerializer.serializeNr9   r   r   r   r   r;   D   r:   r;   c                   @      e Zd ZdZdd ZdS )DateTimeSerializerz)For datetime.*, except datetime.datetime.c                 C      t | jdhfS Nzimport datetimer1   r   r   r   r   r   r   L   r8   zDateTimeSerializer.serializeNr   r   r   __doc__r   r   r   r   r   r=   I       r=   c                   @   r<   )DatetimeDatetimeSerializerzFor datetime.datetime.c                 C   sF   | j jd ur| j jtjjkr| j tjj| _ dg}t| j t|fS r?   )r   tzinfodatetimetimezoneutc
astimezoner1   r!   )r   r'   r   r   r   r   S   s   z$DatetimeDatetimeSerializer.serializeNrA   r   r   r   r   rD   P   rC   rD   c                   @   r6   )DecimalSerializerc                 C   r>   )Nzfrom decimal import Decimalr@   r   r   r   r   r   [   r8   zDecimalSerializer.serializeNr9   r   r   r   r   rJ   Z   r:   rJ   c                   @   s,   e Zd Zedd Zedd Zdd ZdS )DeconstructableSerializerc           
      C   s   t | \}}g }|D ]}t| \}}|| || qt| D ]\}	}t| \}}|| |d|	|f  q&d|d|f |fS )Nz%s=%sz%s(%s)r    )	rK   _serialize_pathr"   r   r$   r#   r0   itemsr%   )
pathargskwargsnamer'   r(   arg
arg_stringarg_importskwr   r   r   serialize_deconstructed`   s   

z1DeconstructableSerializer.serialize_deconstructedc                 C   sD   |  dd\}}|dkrdh}d| }||fS d| h}| }||fS )N.   zdjango.db.modelsfrom django.db import modelsz	models.%s	import %s)rsplit)rN   modulerQ   r'   r   r   r   rL   n   s   
z)DeconstructableSerializer._serialize_pathc                 C   s   | j | j  S r   )rV   r   deconstructr   r   r   r   r   y   r8   z#DeconstructableSerializer.serializeN)r   r   r   staticmethodrV   rL   r   r   r   r   r   rK   _   s    


rK   c                   @   r6   )DictionarySerializerc           	      C   s   t  }g }t| j D ]%\}}t| \}}t| \}}|| || |||f qdddd |D  |fS )N{%s}r    c                 s   s     | ]\}}d ||f V  qdS )z%s: %sNr   ).0kvr   r   r   	<genexpr>   s    z1DictionarySerializer.serialize.<locals>.<genexpr>)	r!   r0   r   rM   r"   r   r#   r$   r%   )	r   r'   r(   rb   rc   k_string	k_importsv_string	v_importsr   r   r   r   ~   s   

zDictionarySerializer.serializeNr9   r   r   r   r   r_   }   r:   r_   c                   @   r6   )EnumSerializerc                    sr   | j j  jt tjr#trt| j }nt | j \}}t	|}n| j f}d
 fdd|D d hfS )Nz | c                    s&   g | ]} d  j  d|jdqS )rW   [])r   rQ   )ra   r)   
enum_classr\   r   r   
<listcomp>   s    z,EnumSerializer.serialize.<locals>.<listcomp>rZ   )r   r3   r   
issubclassenumFlagr	   list
_decomposereversedr%   )r   members_r   rl   r   r      s   
zEnumSerializer.serializeNr9   r   r   r   r   ri      r:   ri   c                       r,   )FloatSerializerc                    s4   t | jst | jrd| jt fS t  S )Nzfloat("{}"))mathisnanr   isinfformatr!   r/   r   r   r2   r   r   r      s   
zFloatSerializer.serialize)r   r   r   r   r4   r   r   r2   r   rw      r5   rw   c                   @   r6   )FrozensetSerializerc                 C      dS )Nzfrozenset([%s])r   r   r   r   r   r         zFrozensetSerializer._formatNr   r   r   r   r   r   r   r   r|      r:   r|   c                   @   r6   )FunctionTypeSerializerc                 C   s   t | jdd r$t| jjtr$| jj}|j}d||j| jjf d| hfS | jjdkr.td| jjd u r;td| j | jj}d| jjvrTd|| jjf d| jj hfS td	| jj|f )
N__self__z%s.%s.%srZ   z<lambda>z!Cannot serialize function: lambdaz'Cannot serialize function %r: No module<%s.%sz"Could not find function %s in %s.
)	getattrr   
isinstancer   typer   r   r   
ValueError)r   klassr\   module_namer   r   r   r      s(   
z FunctionTypeSerializer.serializeNr9   r   r   r   r   r      r:   r   c                   @   r6   )FunctoolsPartialSerializerc                 C   sh   t | jj \}}t | jj \}}t | jj \}}dh|||}d| jjj|||f |fS )Nzimport functoolszfunctools.%s(%s, *%s, **%s))r"   r   funcr   rO   keywordsr3   r   )r   func_stringfunc_importsargs_stringargs_importskeywords_stringkeywords_importsr'   r   r   r   r      s"   z$FunctoolsPartialSerializer.serializeNr9   r   r   r   r   r      r:   r   c                   @   r6   )IterableSerializerc                 C   s`   t  }g }| jD ]}t| \}}|| || qt|dkr%dnd}|d| |fS )NrX   (%s)(%s,)r    )r!   r   r"   r   r#   r$   lenr%   r&   r   r   r   r      s   

zIterableSerializer.serializeNr9   r   r   r   r   r      r:   r   c                   @   r6   )ModelFieldSerializerc                 C   s    | j  \}}}}| |||S r   )r   r]   rV   )r   	attr_namerN   rO   rP   r   r   r   r      s   zModelFieldSerializer.serializeNr9   r   r   r   r   r      r:   r   c                   @   r6   )ModelManagerSerializerc                 C   s@   | j  \}}}}}|r| |\}}d| |fS | |||S )Nz%s.as_manager())r   r]   rL   rV   )r   
as_managermanager_pathqs_pathrO   rP   rQ   r'   r   r   r   r      s
   z ModelManagerSerializer.serializeNr9   r   r   r   r   r      r:   r   c                   @   r6   )OperationSerializerc                 C   s0   ddl m} || jdd \}}|d|fS )Nr   )OperationWriter)indentation,)django.db.migrations.writerr   r   r   rstrip)r   r   stringr'   r   r   r   r      s   zOperationSerializer.serializeNr9   r   r   r   r   r      r:   r   c                   @   r6   )PathLikeSerializerc                 C   s   t t| ji fS r   )r1   osfspathr   r   r   r   r   r        zPathLikeSerializer.serializeNr9   r   r   r   r   r     r:   r   c                   @   r6   )PathSerializerc                 C   s*   t | jtjr	dnd}d|| jf dhfS )NPure zpathlib.%s%rzimport pathlib)r   r   pathlibPath)r   prefixr   r   r   r     s   zPathSerializer.serializeNr9   r   r   r   r   r     r:   r   c                   @   r6   )RegexSerializerc                 C   sl   t | jj \}}| jjtdjA }t | \}}dh||}|g}|r-|| dd| |fS )Nr   z	import rezre.compile(%s)r    )	r"   r   patternr   flagsrecompiler$   r%   )r   regex_patternpattern_importsr   regex_flagsflag_importsr'   rO   r   r   r   r     s   
zRegexSerializer.serializeNr9   r   r   r   r   r     r:   r   c                   @   r6   )SequenceSerializerc                 C   r}   )Nz[%s]r   r   r   r   r   r   $  r~   zSequenceSerializer._formatNr   r   r   r   r   r   #  r:   r   c                   @   r6   )SetSerializerc                 C   s   | j rdS dS )Nr`   zset(%s)r   r   r   r   r   r   )  s   zSetSerializer._formatNr   r   r   r   r   r   (  r:   r   c                   @   r6   )SettingsReferenceSerializerc                 C   s   d| j j dhfS )Nzsettings.%sz from django.conf import settings)r   setting_namer   r   r   r   r   0  s   
z%SettingsReferenceSerializer.serializeNr9   r   r   r   r   r   /  r:   r   c                   @   r6   )TupleSerializerc                 C   s   t | jdkr	dS dS )NrX   r   r   )r   r   r   r   r   r   r   7  s   zTupleSerializer._formatNr   r   r   r   r   r   6  r:   r   c                   @   r6   )TypeSerializerc                 C   s   t jddgftjddgfg}|D ]\}}}|| ju r"|t|f  S qt| jdrF| jj}|tj	kr9| jj	t fS d|| jj
f d| hfS d S )Nzmodels.ModelrY   ztypes.NoneTypezimport typesr   r   rZ   )r   ModeltypesNoneTyper   r!   hasattrr   builtinsr   r   )r   special_casescaser   r'   r\   r   r   r   r   >  s   

zTypeSerializer.serializeNr9   r   r   r   r   r   =  r:   r   c                   @   r6   )UUIDSerializerc                 C   s   dt | j dhfS )Nzuuid.%szimport uuidr@   r   r   r   r   r   Q  r   zUUIDSerializer.serializeNr9   r   r   r   r   r   P  r:   r   c                   @   s   e Zd Zi eeeeeee	e
eeejeejeejeejejejfeeeeeeeej e!e"e#fe$e%j&e'e(j)e(j*fe+e,e-e.j/j0e1e2e3fe4e5j6e7e8j9e:e;j<e=iZ>e?dd Z@e?dd ZAdS )
Serializerc                 C   s&   t |tstd|j || j|< d S )Nz('%s' must inherit from 'BaseSerializer'.)ro   r   r   r   	_registry)clstype_
serializerr   r   r   registern  s
   
zSerializer.registerc                 C   s   | j | d S r   )r   pop)r   r   r   r   r   
unregisterv  s   zSerializer.unregisterN)Br   r   r   	frozensetr|   rr   r   r!   r   tupler   dictr_   r   Choicesr;   rp   Enumri   rF   rD   date	timedeltatimer=   r   r   floatrw   boolintr   r   bytesstrranger7   decimalDecimalrJ   	functoolspartialpartialmethodr   FUNCTION_TYPESr   collectionsabcIterabler   r   r   r   uuidUUIDr   r   PurePathr   r   PathLiker   r   classmethodr   r   r   r   r   r   r   U  sX    	

r   c                 C   s   t | tr
t| } nt | tr|  d d } t | tjr!t| S t | tjj	r,t
| S t | tr5t| S t | tr>t| S t| drGt| S tj D ]\}}t | |r[||   S qLtd| t f )NrX   r   r]   zCannot serialize: %r
There are some values Django cannot serialize into migration files.
For more, see https://docs.djangoproject.com/en/%s/topics/migrations/#migration-serializing)r   r   r   r   
__reduce__r   Fieldr   managerBaseManagerr   r   r   r   r   r   rK   r   r   rM   r   r
   )r   r   serializer_clsr   r   r   r"   {  s.   






r"   )Ar   collections.abcr   rF   r   rp   r   rx   r   r   r   r   r   django.confr   	django.dbr   $django.db.migrations.operations.baser   django.db.migrations.utilsr   r   django.utils.functionalr   r   django.utils.versionr	   r
   FunctionTypeBuiltinFunctionType
MethodTyper   r   _lru_cache_wrapperr   r   r   r-   r7   r;   r=   rD   rJ   rK   r_   ri   rw   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r"   r   r   r   r   <module>   sf    


	&