o
    uvXjö/  ã                   @   sP  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 d dlmZmZ d dlmZmZ d dlmZ d d	lm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ƒ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 d0d1„ d1eƒZ/G d2d3„ d3eƒZ0G d4d5„ d5eƒZ1G d6d7„ d7eƒZ2G d8d9„ d9eƒZ3G d:d;„ d;ƒZ4d<d=„ Z5dS )>é    N)ÚOrderedDict)ÚSettingsReference)Úmodels)Ú	Operation)ÚCOMPILED_REGEX_TYPEÚRegexObject)Ú
LazyObjectÚPromise)Úutc)Úget_docs_versionc                   @   ó   e Zd Zdd„ Zdd„ ZdS )ÚBaseSerializerc                 C   s
   || _ d S ©N©Úvalue)Úselfr   © r   ú\/var/www/html/myproject/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      ó    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      r   r   c                   @   ó   e Zd Zdd„ ZdS )ÚBaseSimpleSerializerc                 C   s   t | jƒtƒ fS r   )Úreprr   r"   r   r   r   r   r   .   ó   zBaseSimpleSerializer.serializeN©r   r   r   r   r   r   r   r   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 )Núimport datetime©r/   r   r   r   r   r   r   4   r0   zDateTimeSerializer.serializeN©r   r   r   Ú__doc__r   r   r   r   r   r4   2   ó    r4   c                   @   r3   )ÚDatetimeDatetimeSerializerzFor datetime.datetime.c                 C   s\   | j jd ur| j jtkr| j  t¡| _ dg}| j jd ur!| d¡ t| j ƒ dd¡t|ƒfS )Nr6   z%from django.utils.timezone import utcz<UTC>r
   )r   Útzinfor
   Ú
astimezoner%   r/   Úreplacer"   )r   r(   r   r   r   r   :   s   
z$DatetimeDatetimeSerializer.serializeNr8   r   r   r   r   r;   8   r:   r;   c                   @   r-   )ÚDecimalSerializerc                 C   r5   )Nzfrom decimal import Decimalr7   r   r   r   r   r   D   r0   zDecimalSerializer.serializeNr1   r   r   r   r   r?   C   r2   r?   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!   )	r@   Ú_serialize_pathr#   r   r%   r$   ÚsortedÚitemsr&   )
ÚpathÚargsÚkwargsÚnamer(   r)   ÚargÚ
arg_stringÚarg_importsÚkwr   r   r   Úserialize_deconstructedI   s   

z1DeconstructableSerializer.serialize_deconstructedc                 C   sD   |   dd¡\}}|dkrdh}d| }||fS d| h}| }||fS )NÚ.é   zdjango.db.modelszfrom django.db import modelsz	models.%sú	import %s)Úrsplit)rD   ÚmodulerG   r(   r   r   r   rA   W   s   
þz)DeconstructableSerializer._serialize_pathc                 C   s   | j | j ¡ Ž S r   )rL   r   Údeconstructr   r   r   r   r   b   r0   z#DeconstructableSerializer.serializeN)r   r   r   ÚstaticmethodrL   rA   r   r   r   r   r   r@   H   s    


r@   c                   @   r-   )Ú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>p   s   € z1DictionarySerializer.serialize.<locals>.<genexpr>)	r"   rB   r   rC   r#   r   r$   r%   r&   )	r   r(   r)   rW   rX   Úk_stringÚ	k_importsÚv_stringÚ	v_importsr   r   r   r   g   s   

zDictionarySerializer.serializeNr1   r   r   r   r   rT   f   r2   rT   c                   @   r-   )ÚEnumSerializerc                 C   sD   | j j}|j}t| j j ƒ ¡ \}}d| h|£}d||j|f |fS )NrO   z	%s.%s(%s))r   Ú	__class__r   r#   r   r   )r   Ú
enum_classrQ   r\   r]   r(   r   r   r   r   t   s
   zEnumSerializer.serializeNr1   r   r   r   r   r^   s   r2   r^   c                       s   e Zd Z‡ fdd„Z‡  ZS )ÚFloatSerializerc                    s4   t  | j¡st  | j¡rd | j¡tƒ fS tƒ  ¡ S )Nzfloat("{}"))ÚmathÚisnanr   ÚisinfÚformatr"   Úsuperr   r   ©r_   r   r   r   }   s   
zFloatSerializer.serialize)r   r   r   r   Ú__classcell__r   r   rg   r   ra   |   s    ra   c                   @   r-   )ÚFrozensetSerializerc                 C   ó   dS )Nzfrozenset([%s])r   r   r   r   r   r    „   ó   zFrozensetSerializer._formatN©r   r   r   r    r   r   r   r   ri   ƒ   r2   ri   c                   @   r-   )Ú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.%srO   z<lambda>z!Cannot serialize function: lambdaz'Cannot serialize function %r: No moduleú<ú%s.%sz"Could not find function %s in %s.
)	Úgetattrr   Ú
isinstancern   Útyper   r   Ú
ValueErrorr   )r   ÚklassrQ   Úmodule_namer   r   r   r   ‰   s   ÿz FunctionTypeSerializer.serializeNr1   r   r   r   r   rm   ˆ   r2   rm   c                   @   r-   )Ú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   rE   Úkeywordsr_   r   )r   Úfunc_stringÚfunc_importsÚargs_stringÚargs_importsÚkeywords_stringÚkeywords_importsr(   r   r   r   r   Ÿ   s   üùz$FunctoolsPartialSerializer.serializeNr1   r   r   r   r   rw   ž   r2   rw   c                   @   r-   )ÚIterableSerializerc                 C   s`   t ƒ }g }| jD ]}t|ƒ ¡ \}}| |¡ | |¡ qt|ƒdkr%dnd}|d |¡ |fS )NrN   ú(%s)ú(%s,)r!   )r"   r   r#   r   r$   r%   Úlenr&   r'   r   r   r   r   ²   s   

zIterableSerializer.serializeNr1   r   r   r   r   r€   ±   r2   r€   c                   @   r-   )ÚModelFieldSerializerc                 C   s    | j  ¡ \}}}}|  |||¡S r   )r   rR   rL   )r   Ú	attr_namerD   rE   rF   r   r   r   r   À   s   zModelFieldSerializer.serializeNr1   r   r   r   r   r„   ¿   r2   r„   c                   @   r-   )ÚModelManagerSerializerc                 C   s@   | j  ¡ \}}}}}|r|  |¡\}}d| |fS |  |||¡S )Nz%s.as_manager())r   rR   rA   rL   )r   Ú
as_managerÚmanager_pathÚqs_pathrE   rF   rG   r(   r   r   r   r   Æ   s
   z ModelManagerSerializer.serializeNr1   r   r   r   r   r†   Å   r2   r†   c                   @   r-   )Ú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.serializeNr1   r   r   r   r   rŠ   Ï   r2   rŠ   c                   @   r-   )ÚRegexSerializerc                 C   sl   t | jjƒ ¡ \}}| jjt d¡jA }t |ƒ ¡ \}}dh|£|£}|g}|r-| |¡ dd |¡ |fS )NÚ z	import rezre.compile(%s)r!   )	r#   r   Úpatternr   ÚflagsÚreÚcompiler%   r&   )r   Úregex_patternÚpattern_importsr”   Úregex_flagsÚflag_importsr(   rE   r   r   r   r   Ø   s   
zRegexSerializer.serializeNr1   r   r   r   r   r‘   ×   r2   r‘   c                   @   r-   )ÚSequenceSerializerc                 C   rj   )Nz[%s]r   r   r   r   r   r    æ   rk   zSequenceSerializer._formatNrl   r   r   r   r   r›   å   r2   r›   c                   @   r-   )ÚSetSerializerc                 C   s   | j rdS dS )NrU   zset(%s)r   r   r   r   r   r    ë   s   zSetSerializer._formatNrl   r   r   r   r   rœ   ê   r2   rœ   c                   @   r-   )Ú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   ò   s   z%SettingsReferenceSerializer.serializeNr1   r   r   r   r   r�   ñ   r2   r�   c                   @   r-   )ÚTupleSerializerc                 C   s   t | jƒdkr	dS dS )NrN   r�   r‚   )rƒ   r   r   r   r   r   r    ÷   s   zTupleSerializer._formatNrl   r   r   r   r   rŸ   ö   r2   rŸ   c                   @   r-   )ÚTypeSerializerc                 C   sŽ   t jdg ftd ƒdg fg}|D ]\}}}|| ju r!|t|ƒf  S qt| jdƒrE| jj}|tjkr8| jjtƒ fS d|| jjf d| hfS d S )Nzmodels.Modelz
type(None)r   rp   rO   )	r   ÚModelrs   r   r"   Úhasattrr   Úbuiltinsr   )r   Úspecial_casesÚcaser�   r(   rQ   r   r   r   r   þ   s   
þ
ÿ
ûzTypeSerializer.serializeNr1   r   r   r   r   r    ý   r2   r    c                   @   r-   )ÚUUIDSerializerc                 C   s   dt | jƒ dhfS )Nzuuid.%szimport uuidr7   r   r   r   r   r     s   zUUIDSerializer.serializeNr1   r   r   r   r   r¦     r2   r¦   c                   @   sÒ   e Zd Zeeefeefee	fe
efeefejefejefejejejfefeefeefeeedƒeee fe!fe"j#e$fe%j&e%j'fe(fe)j*e)j+e)j,fe-fe.j/j0e1fe2e3fe4fe5j6e7fgƒZ8e9dd„ ƒZ:e9dd„ ƒZ;dS )Ú
SerializerNc                 C   s&   t |tƒstd|j ƒ‚|| j|< d S )Nz('%s' must inherit from 'BaseSerializer'.)Ú
issubclassr   rt   r   Ú	_registry)ÚclsÚtype_Ú
serializerr   r   r   Úregister(  s   
zSerializer.registerc                 C   s   | j  |¡ d S r   )r©   Úpop)rª   r«   r   r   r   Ú
unregister.  s   zSerializer.unregister)<r   r   r   r   Ú	frozensetri   Úlistr›   r"   rœ   ÚtuplerŸ   ÚdictrT   ÚenumÚEnumr^   Údatetimer;   ÚdateÚ	timedeltaÚtimer4   r   r�   Úfloatra   ÚboolÚintrs   ÚbytesÚstrÚranger.   ÚdecimalÚDecimalr?   Ú	functoolsÚpartialÚpartialmethodrw   ÚtypesÚFunctionTypeÚBuiltinFunctionTypeÚ
MethodTyperm   ÚcollectionsÚabcÚIterabler€   r   r   r‘   ÚuuidÚUUIDr¦   r©   Úclassmethodr­   r¯   r   r   r   r   r§     s0    

ï
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 ƒ‚)NrN   r   rR   z´Cannot 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)rr   r	   r¾   r   Ú
__reduce__r   ÚFieldr„   ÚmanagerÚBaseManagerr†   r   rŠ   rs   r    r¢   r@   r§   r©   rC   rt   r   )r   r«   Úserializer_clsr   r   r   r#   3  s.   






ÿþÿr#   )6r£   Úcollections.abcrÉ   r¶   rÀ   r´   rÂ   rb   r•   rÅ   rÌ   r   Údjango.confr   Ú	django.dbr   Ú$django.db.migrations.operations.baser   Údjango.db.migrations.utilsr   r   Údjango.utils.functionalr   r	   Údjango.utils.timezoner
   Údjango.utils.versionr   r   r   r.   r4   r;   r?   r@   rT   r^   ra   ri   rm   rw   r€   r„   r†   rŠ   r‘   r›   rœ   r�   rŸ   r    r¦   r§   r#   r   r   r   r   Ú<module>   sX    	
 