o
    lf4                     @   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 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 d.d/ d/eZ/G d0d1 d1eZ0G d2d3 d3eZ1G d4d5 d5eZ2G d6d7 d7eZ3G d8d9 d9eZ4G d:d; d;eZ5G d<d= d=eZ6G d>d? d?Z7d@dA Z8dS )B    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   c/var/www/ticemtrilhas/avaliacao_env/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dd ZdS )BaseSimpleSerializerc                 C   s   t | jt fS r   )reprr   r    r   r   r   r   r   2      zBaseSimpleSerializer.serializeNr   r   r   r   r   r   r   r   r,   1       r,   c                   @   r+   )ChoicesSerializerc                 C   s   t | jj S r   )r!   r   r   r   r   r   r   r   7   r.   zChoicesSerializer.serializeNr/   r   r   r   r   r1   6   r0   r1   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r-   r   r   r   r   r   r   >   r.   zDateTimeSerializer.serializeNr   r   r   __doc__r   r   r   r   r   r3   ;       r3   c                   @   r2   )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 r5   )r   tzinfodatetimetimezoneutc
astimezoner-   r    )r   r&   r   r   r   r   E   s   z$DatetimeDatetimeSerializer.serializeNr7   r   r   r   r   r:   B   r9   r:   c                   @   r+   )DecimalSerializerc                 C   r4   )Nzfrom decimal import Decimalr6   r   r   r   r   r   M   r.   zDecimalSerializer.serializeNr/   r   r   r   r   r@   L   r0   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   )	rA   _serialize_pathr!   r   r#   r"   sorteditemsr$   )
pathargskwargsnamer&   r'   arg
arg_stringarg_importskwr   r   r   serialize_deconstructedR   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)rE   modulerH   r&   r   r   r   rB   `   s   
z)DeconstructableSerializer._serialize_pathc                 C   s   | j | j  S r   )rM   r   deconstructr   r   r   r   r   k   r.   z#DeconstructableSerializer.serializeN)r   r   r   staticmethodrM   rB   r   r   r   r   r   rA   Q   s    


rA   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>y   s    z1DictionarySerializer.serialize.<locals>.<genexpr>)	r    rC   r   rD   r!   r   r"   r#   r$   )	r   r&   r'   rY   rZ   k_string	k_importsv_string	v_importsr   r   r   r   p   s   

zDictionarySerializer.serializeNr/   r   r   r   r   rV   o   r0   rV   c                   @   r+   )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 )rN   [])r   rH   )rX   r(   
enum_classrS   r   r   
<listcomp>   s    z,EnumSerializer.serialize.<locals>.<listcomp>rQ   )r   	__class__r   
issubclassenumFlagr	   list
_decomposereversedr$   )r   members_r   rc   r   r   }   s   
zEnumSerializer.serializeNr/   r   r   r   r   r`   |   r0   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   rf   r   r   r      s   
zFloatSerializer.serialize)r   r   r   r   __classcell__r   r   ru   r   ro      s    ro   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   rw      r0   rw   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.%srQ   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   
ValueErrorr   )r   klassrS   module_namer   r   r   r      s(   
z FunctionTypeSerializer.serializeNr/   r   r   r   r   r{      r0   r{   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   rF   keywordsrf   r   )r   func_stringfunc_importsargs_stringargs_importskeywords_stringkeywords_importsr&   r   r   r   r      s"   z$FunctoolsPartialSerializer.serializeNr/   r   r   r   r   r      r0   r   c                   @   r+   )IterableSerializerc                 C   s`   t  }g }| jD ]}t| \}}|| || qt|dkr%dnd}|d| |fS )NrO   (%s)(%s,)r   )r    r   r!   r   r"   r#   lenr$   r%   r   r   r   r      s   

zIterableSerializer.serializeNr/   r   r   r   r   r      r0   r   c                   @   r+   )ModelFieldSerializerc                 C   s    | j  \}}}}| |||S r   )r   rT   rM   )r   	attr_namerE   rF   rG   r   r   r   r      s   zModelFieldSerializer.serializeNr/   r   r   r   r   r      r0   r   c                   @   r+   )ModelManagerSerializerc                 C   s@   | j  \}}}}}|r| |\}}d| |fS | |||S )Nz%s.as_manager())r   rT   rB   rM   )r   
as_managermanager_pathqs_pathrF   rG   rH   r&   r   r   r   r      s
   z ModelManagerSerializer.serializeNr/   r   r   r   r   r      r0   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.serializeNr/   r   r   r   r   r      r0   r   c                   @   r+   )PathLikeSerializerc                 C   s   t t| ji fS r   )r-   osfspathr   r   r   r   r   r         zPathLikeSerializer.serializeNr/   r   r   r   r   r      r0   r   c                   @   r+   )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.serializeNr/   r   r   r   r   r      r0   r   c                   @   r+   )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&   rF   r   r   r   r     s   
zRegexSerializer.serializeNr/   r   r   r   r   r     r0   r   c                   @   r+   )SequenceSerializerc                 C   rx   )Nz[%s]r   r   r   r   r   r     ry   zSequenceSerializer._formatNrz   r   r   r   r   r     r0   r   c                   @   r+   )SetSerializerc                 C   s   | j rdS dS )NrW   zset(%s)r   r   r   r   r   r     s   zSetSerializer._formatNrz   r   r   r   r   r     r0   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.serializeNr/   r   r   r   r   r   !  r0   r   c                   @   r+   )TupleSerializerc                 C   s   t | jdkr	dS dS )NrO   r   r   )r   r   r   r   r   r   r   )  s   zTupleSerializer._formatNrz   r   r   r   r   r   (  r0   r   c                   @   r+   )TypeSerializerc                 C   s   t jddgft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.ModelrP   z
type(None)r   r~   rQ   )
r   Modelr   r   r    hasattrr   builtinsr   r   )r   special_casescaser   r&   rS   r   r   r   r   0  s   

zTypeSerializer.serializeNr/   r   r   r   r   r   /  r0   r   c                   @   r+   )UUIDSerializerc                 C   s   dt | j dhfS )Nzuuid.%szimport uuidr6   r   r   r   r   r   C  r   zUUIDSerializer.serializeNr/   r   r   r   r   r   B  r0   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de e!e"fe#e$j%e&e'j(e'j)fe*e+j,e+j-e+j.fe/e0j1j2e3e4e5fe6e7j8e9e:j;e<e=j>e?iZ@eAdd ZBeAdd ZCdS )
SerializerNc                 C   s&   t |tstd|j || j|< d S )Nz('%s' must inherit from 'BaseSerializer'.)rg   r   r   r   	_registry)clstype_
serializerr   r   r   registerd  s
   
zSerializer.registerc                 C   s   | j | d S r   )r   pop)r   r   r   r   r   
unregisterl  s   zSerializer.unregister)Dr   r   r   	frozensetrw   rj   r   r    r   tupler   dictrV   r   Choicesr1   rh   Enumr`   r<   r:   date	timedeltatimer3   r   r   floatro   boolintr   bytesstrranger,   decimalDecimalr@   	functoolspartialpartialmethodr   typesFunctionTypeBuiltinFunctionType
MethodTyper{   collectionsabcIterabler   r   r   r   uuidUUIDr   r   PurePathr   r   PathLiker   r   classmethodr   r   r   r   r   r   r   G  s`    	

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 )NrO   r   rT   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   rA   r   r   rD   r   r
   )r   r   serializer_clsr   r   r   r!   q  s.   






r!   )9r   collections.abcr   r<   r   rh   r   rp   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
   r   r   r,   r1   r3   r:   r@   rA   rV   r`   ro   rw   r{   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r!   r   r   r   r   <module>   s^    


	*