o 3a2@sddlZddlZddlZddlZddlZddlZddlZddlZddl Z ddl Z ddl Z ddl Z ddl mZddlmZddlmZddlmZmZddlmZmZddlmZddlmZGd d d ZGd d d eZGd ddeZGdddeZ GdddeZ!GdddeZ"GdddeZ#GdddeZ$GdddeZ%GdddeZ&GdddeZ'Gdd d eZ(Gd!d"d"eZ)Gd#d$d$eZ*Gd%d&d&eZ+Gd'd(d(e$Z,Gd)d*d*e$Z-Gd+d,d,eZ.Gd-d.d.eZ/Gd/d0d0eZ0Gd1d2d2eZ1Gd3d4d4eZ2Gd5d6d6eZ3Gd7d8d8eZ4Gd9d:d:eZ5Gd;d<dd>eZ7Gd?d@d@Z8dAdBZ9dS)CN)SettingsReference)models) Operation)COMPILED_REGEX_TYPE RegexObject) LazyObjectPromise)utc)get_docs_versionc@eZdZddZddZdS)BaseSerializercCs ||_dSNvalue)selfrrA/usr/lib/python3/dist-packages/django/db/migrations/serializer.py__init__s zBaseSerializer.__init__cCtd)NzCSubclasses of BaseSerializer must implement the serialize() method.NotImplementedErrorrrrr serializezBaseSerializer.serializeN)__name__ __module__ __qualname__rrrrrrr  r c@r )BaseSequenceSerializercCr)NzISubclasses of BaseSequenceSerializer must implement the _format() method.rrrrr_format rzBaseSequenceSerializer._formatcCsTt}g}|jD]}t|\}}||||q|}|d||fS)N, )setrserializer_factoryrupdateappendrjoinrimportsstringsitem item_string item_importsrrrrr#s   z BaseSequenceSerializer.serializeN)rrrrrrrrrrrrc@eZdZddZdS)BaseSimpleSerializercCst|jtfSr )reprrr!rrrrr/zBaseSimpleSerializer.serializeNrrrrrrrrr-. r-c@r,)ChoicesSerializercCst|jjSr )r"rrrrrrr4r/zChoicesSerializer.serializeNr0rrrrr23r1r2c@eZdZdZddZdS)DateTimeSerializerz)For datetime.*, except datetime.datetime.cCt|jdhfS)Nimport datetimer.rrrrrr:r/zDateTimeSerializer.serializeNrrr__doc__rrrrrr48 r4c@r3)DatetimeDatetimeSerializerzFor datetime.datetime.cCs\|jjdur|jjtkr|jt|_dg}|jjdur!|dt|jddt|fS)Nr6z%from django.utils.timezone import utczr )rtzinfor astimezoner$r.replacer!)rr'rrrr@s   z$DatetimeDatetimeSerializer.serializeNr8rrrrr;>r:r;c@r,)DecimalSerializercCr5)Nzfrom decimal import Decimalr7rrrrrJr/zDecimalSerializer.serializeNr0rrrrr?Ir1r?c@s,eZdZeddZeddZddZdS)DeconstructableSerializerc Cst|\}}g}|D]}t|\}}||||q t|D]\} }t|\}}|||d| |fq&d|d|f|fS)Nz%s=%sz%s(%s)r ) r@_serialize_pathr"rr$r#sorteditemsr%) pathargskwargsnamer'r(arg arg_string arg_importskwrrrserialize_deconstructedOs   z1DeconstructableSerializer.serialize_deconstructedcCsD|dd\}}|dkrdh}d|}||fSd|h}|}||fS)N.zdjango.db.modelszfrom django.db import modelsz models.%s import %s)rsplit)rDmodulerGr'rrrrA]s z)DeconstructableSerializer._serialize_pathcCs|j|jSr )rLr deconstructrrrrrhr/z#DeconstructableSerializer.serializeN)rrr staticmethodrLrArrrrrr@Ns    r@c@r,)DictionarySerializerc Cst}g}t|jD]%\}}t|\}}t|\}}|||||||fq dddd|D|fS)N{%s}r css |] \}}d||fVqdS)z%s: %sNr).0kvrrr vsz1DictionarySerializer.serialize..) r!rBrrCr"rr#r$r%) rr'r(rWrXk_string k_importsv_string v_importsrrrrms  zDictionarySerializer.serializeNr0rrrrrTlr1rTc@r,)EnumSerializercCs,|jj}|j}d||j|jjfd|hfS)Nz %s.%s[%r]rO)r __class__rrrG)r enum_classrQrrrrzs zEnumSerializer.serializeNr0rrrrr^yr1r^cseZdZfddZZS)FloatSerializercs4t|js t|jrd|jtfStS)Nz float("{}"))mathisnanrisinfformatr!superrrr_rrrs zFloatSerializer.serialize)rrrr __classcell__rrrgrrasrac@r,)FrozensetSerializercCdS)Nzfrozenset([%s])rrrrrrzFrozensetSerializer._formatNrrrrrrrrrir1ric@r,)FunctionTypeSerializercCst|jddr$t|jjtr$|jj}|j}d||j|jjfd|hfS|jjdkr.td|jjdur;td|j|jj}d|jjvrTd||jjfd|jjhfStd |jj|f) N__self__z%s.%s.%srOzz!Cannot serialize function: lambdaz'Cannot serialize function %r: No module<%s.%sz"Could not find function %s in %s. ) getattrr isinstancerntyperr ValueErrorr)rklassrQ module_namerrrrs   z FunctionTypeSerializer.serializeNr0rrrrrmr1rmc@r,)FunctoolsPartialSerializercCsht|jj\}}t|jj\}}t|jj\}}dh|||}d|jjj|||f|fS)Nzimport functoolszfunctools.%s(%s, *%s, **%s))r"rfuncrrEkeywordsr_r)r func_string func_imports args_string args_importskeywords_stringkeywords_importsr'rrrrsz$FunctoolsPartialSerializer.serializeNr0rrrrrwr1rwc@r,)IterableSerializercCs`t}g}|jD]}t|\}}||||qt|dkr%dnd}|d||fS)NrN(%s)(%s,)r )r!rr"rr#r$lenr%r&rrrrs   zIterableSerializer.serializeNr0rrrrrr1rc@r,)ModelFieldSerializercCs |j\}}}}||||Sr )rrRrL)r attr_namerDrErFrrrrszModelFieldSerializer.serializeNr0rrrrrr1rc@r,)ModelManagerSerializercCs@|j\}}}}}|r||\}}d||fS||||S)Nz%s.as_manager())rrRrArL)r as_manager manager_pathqs_pathrErFrGr'rrrrs  z ModelManagerSerializer.serializeNr0rrrrrr1rc@r,)OperationSerializercCs0ddlm}||jdd\}}|d|fS)Nr)OperationWriter) indentation,)django.db.migrations.writerrrrrstrip)rrstringr'rrrrs zOperationSerializer.serializeNr0rrrrrr1rc@r,)PathLikeSerializercCstt|jifSr )r.osfspathrrrrrrzPathLikeSerializer.serializeNr0rrrrrr1rc@r,)PathSerializercCs*t|jtjr dnd}d||jfdhfS)NPurez pathlib.%s%rzimport pathlib)rrrpathlibPath)rprefixrrrrszPathSerializer.serializeNr0rrrrrr1rc@r,)RegexSerializercCslt|jj\}}|jjtdjA}t|\}}dh||}|g}|r-||dd||fS)Nrz import rezre.compile(%s)r ) r"rpatternrflagsrecompiler$r%)r regex_patternpattern_importsr regex_flags flag_importsr'rErrrrs zRegexSerializer.serializeNr0rrrrrr1rc@r,)SequenceSerializercCrj)Nz[%s]rrrrrrrkzSequenceSerializer._formatNrlrrrrrr1rc@r,) SetSerializercCs|jrdSdS)NrUzset(%s)rrrrrrszSetSerializer._formatNrlrrrrrr1rc@r,)SettingsReferenceSerializercCsd|jjdhfS)Nz settings.%sz from django.conf import settings)r setting_namerrrrrsz%SettingsReferenceSerializer.serializeNr0rrrrrr1rc@r,)TupleSerializercCst|jdkr dSdS)NrNrr)rrrrrrr szTupleSerializer._formatNrlrrrrr r1rc@r,)TypeSerializercCstjdgftddgfg}|D]\}}}||jur!|t|fSqt|jdrE|jj}|tjkr8|jjtfSd||jj fd|hfSdS)Nz models.Modelz type(None)rrprO) rModelrsrr!hasattrrbuiltinsrr)r special_casescaserr'rQrrrrs     zTypeSerializer.serializeNr0rrrrrr1rc@r,)UUIDSerializercCsdt|jdhfS)Nzuuid.%sz import uuidr7rrrrr#rzUUIDSerializer.serializeNr0rrrrr"r1rc@seZdZieeeeeee e e e e jeejeejeejejejfeeeeeeeede e!e"fe#e$j%e&e'j(e'j)fe*e+j,e+j-e+j.fe/e0j1j2e3e4e5fe6e7j8e9e:j;ee?iZ@eAddZBeAddZCdS) SerializerNcCs&t|ts td|j||j|<dS)Nz('%s' must inherit from 'BaseSerializer'.) issubclassr rtr _registry)clstype_ serializerrrrregister@s zSerializer.registercCs|j|dSr )rpop)rrrrr unregisterFszSerializer.unregister)Drrr frozensetrilistrr!rtuplerdictrTrChoicesr2enumEnumr^datetimer;date timedeltatimer4rrfloatraboolintrsbytesstrranger-decimalDecimalr? functoolspartial partialmethodrwtypes FunctionTypeBuiltinFunctionType MethodTyperm collectionsabcIterablerrrruuidUUIDrrPurePathrrPathLikerr classmethodrrrrrrr'sX       rcCst|tr t|}n t|tr|dd}t|tjr!t|St|tjj r,t |St|t r5t |St|t r>t|St|drGt|StjD]\}}t||r[||SqLtd|tf)NrNrrRzCannot 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)rrrrr __reduce__rFieldrmanager BaseManagerrrrrsrrr@rrrCrtr )rrserializer_clsrrrr"Ks.         r"):rcollections.abcrrrrrrbrrrrr django.confr django.dbr$django.db.migrations.operations.baserdjango.db.migrations.utilsrrdjango.utils.functionalrrdjango.utils.timezoner django.utils.versionr r rr-r2r4r;r?r@rTr^rarirmrwrrrrrrrrrrrrrrr"rrrrs`          $