mfx ddlmZn #e$reZYnwxYwddlmZddlmZddlZddlZddl Tddl m Z ddl m Z ddl m Z dd l m Z dd l mZdd l mZ dd lmZn #e$r dd lmZn #e$rdZYnwxYwYnwxYw dd lmZn #e$rdZYnwxYw ddlmZn #e$rdZYnwxYwegdZGddeZGddeZGddeZGddeZGddeZGddeZGddeZ eddZ!Gd d!e!Z"Gd"d#eZ#d+d$Z$d+d%Z%d,d(Z&d)Z'd*Z(dS)-) OrderedDict) namedtuple)isclassN)*) _StringField)_query_val_transform) CommaNodeList) SCOPE_VALUES)make_snake_case) text_type) FIELD_TYPE) postgres_ext)CockroachDatabase)andasassertbreakclasscontinuedefdelelifelseexceptexecfinallyforfromglobalifimportinislambdanotorpassprintraisereturntrywhilewithyieldceZdZdS) UnknownFieldN)__name__ __module__ __qualname__K/opt/imunify360/venv/lib64/python3.11/site-packages/playhouse/reflection.pyr0r0)sDr5r0cVeZdZdZeefZ d dZdZdZ dZ dZ d Z d d Z d ZdS)Columnz1 Store metadata about a database column. FNc ||_||_||_||_||_||_||_||_| |_| |_ d|_ d|_ d|_ dSN) name field_classraw_column_typenullable primary_key column_nameindexuniquedefaultextra_parameters rel_model related_nameto_field) selfr;r<r=r>r?r@rArBrCrDs r6__init__zColumn.__init__3sk &.  &&   0  r5cjgd}dfd|D}djd|dS)N)r<r=r>r?r@, c3BK|]}|dt|VdS=N)getattr).0attrrHs r6 z"Column.__repr__..MsM!!ttWT4000 1!!!!!!r5zColumn())joinr;)rHattrs keyword_argss` r6__repr__zColumn.__repr__Fsh yy!!!!!!! $(999lll;;r5c<i}|j||j|jrd|d<|jtus|j|jkr d|jz|d<|jrt|jtsd|d<|j d|j z|d<| r2|j |d<|j r d|j z|d <|jr d|jz|d <|s-|jrd |d <n |jr| sd |d <|S)NTnull'%s'r@r?z[SQL("DEFAULT %s")] constraintsmodelfieldbackrefTruerBrA)rDupdater>r<ForeignKeyFieldr;r@r? issubclass AutoFieldrCis_foreign_keyrErGrFis_primary_keyrBrA)rHparamss r6get_field_parameterszColumn.get_field_parametersRs[  , MM$/ 0 0 0 = "!F6N   . .$)t?O2O2O$*T-=$=F= !   )Jt/?$K$K )$(F= ! < #$9DL$HF= !     ?"nF7O} 9"(4="8w  ?$*T->$>y!""$$ ){ )#)x   )D$7$7$9$9 )"(w r5c,|jtup|jSr:)r<rcr?rHs r6rezColumn.is_primary_keyrs9,@0@@r5c|jtuSr:)r<raris r6rdzColumn.is_foreign_keyus?22r5c4|jtuo |jdkSNz'self')r<rarEris r6is_self_referential_fkzColumn.is_self_referential_fkxs! O3+(* ,r5c||_t|_|j|jkrd|_n||j|_|r|jpd|_|pd|_dSrl) foreign_keyrar< dest_tabletablerEr;rGrF)rHro model_namesdestrFs r6set_foreign_keyzColumn.set_foreign_key|sa&*  ![%6 6 6%DNN()?@DN*2d (0Dr5ci}|D]5\}}t|rt|tr|j}|||<6ddt|D}|jd|j jd|d}|j tur |d|j }|S)NrKc3*K|]\}}|d|VdSrMr4)rPkvs r6rRz#Column.get_field..sMHH"&!Q*+AA.HHHHHHr5z = (rSz # ) rgitemsrrbFieldr1rTsortedr;r<r0r=)rH field_paramskeyvalue param_strr]s r6 get_fieldzColumn.get_fields 3355;;== & &JCu~~ '*UE":": ' %L  IIHH*01C1C1E1E*F*FHHHHH  III   % % % II  | + +"'%%)=)=>E r5)FNFFNN)NN)r1r2r3__doc__ IntegerFieldrcprimary_key_typesrIrWrgrerdrmrtrr4r5r6r8r8-s&y1=B>B& < < <@AAA333,,,>B%) 1 1 1 1r5r8cPeZdZiZdZdZdZd dZd dZdZ d dZ d d Z d d Z dS) Metadatac"||_d|_dS)NF)databaserequires_extension)rHrs r6rIzMetadata.__init__s  "'r5c8|j||Sr:)r execute_sql)rHsqlrfs r6executezMetadata.executes}((f555r5Nc rtd|j||D}|||\}}|||}t |dkr;|d}||t ur t||<n||tur t||<t}| D]d\} } || } | | | j } t| | | j| j| j| | || || <e|S)Nc3(K|] }|j|fVdSr:r;)rPmetadatas r6rRz'Metadata.get_columns..sEFF]H %FFFFFFr5r)r<r=r>r?r@rCrD)rr get_columnsget_column_typesget_primary_keyslenrrcBigIntegerField BigAutoFieldrz_clean_defaultrCr8 data_typerYr?get) rHrqschemar column_types extra_paramspk_namespkcolumnsr; column_datar<rCs r6rzMetadata.get_columnsscFF M55eVDDFFFFF &*%:%:5&%I%I" l((77 x==A  !BB<//#, R  b!_44#/ R --!)!1!1 9 9 D+&t,K))+{7JKKG"' + 5$)'3 !-!1!1$!7!7999GDMMr5ctr:)NotImplementedErrorrHrqrs r6rzMetadata.get_column_typess!!r5c|(|ttfvs|dkrdSt|tr/t |t r|dsd|z}|pdS)NrY'rZz'')rcrlowerrbr isinstancer startswith)rHr<rCs r6rzMetadata._clean_defaults| ?ki-FFF ==??f $ $ F k< 0 0 ' gy ) ) '292D2DS2I2I 'w&G$r5c8|j||Sr:)rget_foreign_keysrs r6rzMetadata.get_foreign_keys}--eV<<$$# $ #  ? ?r5ci}i}tFttjtjtjtjtjfn t}|d|d}|d|d}|D]T\}} |j | t||<|||vrd|_ | |j vrd|j | i||<U||fS)Nz.""zcSELECT attname, atttypid FROM pg_catalog.pg_attribute WHERE attrelid = %s::regclass AND attnum > %srTr<)rsetrrrrrrrrrr0rr) rHrqrrrextension_types identifierrr;rs r6rz#PostgresqlMetadata.get_column_typess  +7*B   #  (  "  &  $ &''' IL #)&&%%%0  <=GLL  ** L LID#!%!4!4S,!G!GL D!_44*.'d&&&&3T5Ec5J%K T"\))r5Nc^|pd}tt|||SNpublic)rrrrHrqrrs r6rzPostgresqlMetadata.get_columns3.#8'..::5&IIIr5c^|pd}tt|||Sr)rrrrs r6rz#PostgresqlMetadata.get_foreign_keys7.#8'..??vNNNr5c^|pd}tt|||Sr)rrrrs r6rz#PostgresqlMetadata.get_primary_keys;rr5c^|pd}tt|||Sr)rrrrs r6rzPostgresqlMetadata.get_indexes?rr5r:)r1r2r3 BooleanField BlobFieldrSmallIntegerFieldr TextField FloatField DoubleField CharField DateField DateTimeField TimeField DecimalField UUIDFieldrrrrIrrrrr __classcell__rs@r6rrs L I O   L  I  Z [ i i i m m i i l!" i#J(  K>?????,***4JJJJJJOOOOOOOOOOOOJJJJJJJJJJr5rceZdZejZeed<ejZeed<dZdZ dS)CockroachDBMetadatarrz#from playhouse.cockroachdb import *c0t||d|_tj|d}|}|D] \}}}|dkrtj|j|<!|jD]}tj |j|<dSdS)NTrr) rrIrrrrrrrr)rHrrrrrrs r6rIzCockroachDBMetadata.__init__Ms$)))"&  #\\#344Foo''G07 H H,Wng%%+7+GDOC(' ? ?'3'>$$ $ # ? ?r5N) r1r2r3rrcopyrrrrIr4r5r6rrDsf$.3355J!JrN$05577K$K<?????r5rcreZdZeiZniejeejeej e ej e ej eejeejeejeejeejeejeejeejeejeejeeje ejeejeej eej!eiZfdZ"ddZ#xZ$S) MySQLMetadataNc d|vr|d|d<tt|j|fi|dS)Npasswordpasswd)poprrrI)rHrkwargsrs r6rIzMySQLMetadata.__init__zsO   %zz*55F8 +mT""+H???????r5ci}|d|z}|jD]2}|dd\}}|j|t||<3|ifS)NzSELECT * FROM `%s` LIMIT 1)r descriptionrrr0)rHrqrrrcolumn_descriptionr; type_codes r6rzMySQLMetadata.get_column_typesss :UBCC#)"4 N N 0!4OD)!%!4!4Y !M!ML  Rr5r:)%r1r2r3r rBLOBrCHARrDATErDATETIMErDECIMALrDOUBLErFLOATINT24r LONG_BLOBLONGLONGLONGr MEDIUM_BLOB NEWDECIMALSHORTSTRING TIMESTAMPTIMEr TINY_BLOBTINY VAR_STRINGrIrrrs@r6rr_s~  OY OY  OY         z    j   l   )  O\      "I   !<   l   y  -! " OY# $  ) O\  !9)  .@@@@@         r5rceZdZidededededededede d e d e d e d e d ede de de de e e e edZdZdZdeeZdZdZddZdS)SqliteMetadatabigintblobboolbooleanchardatedatetimedecimalfloatintegerzinteger unsignedintlongnumericreal smallintegersmallint)zsmallint unsignedtexttimevarcharz (?:["\[\(]+)?z (?:["\]\)]+)?zi(?:FOREIGN KEY\s*)?{begin}(.+?){end}\s+(?:.+\s+)?references\s+{begin}(.+?){end}\s*\(["|\[]?(.+?)["|\]]?\))beginendz&^\s*(?:var)?char\s*\(\s*(\d+)\s*\)\s*$c(|}||jvr|j|}nftj|j|rt }nDtjdd|}|dkrt}n |j|t}|S)Nz\(.+\)r) rrresearch re_varcharrsub BareFieldrr0)rH column_typer=r<s r6_map_colzSqliteMetadata._map_cols%++-- do - -//:KK Yt 8 8 M#KK&2??Kb  ' "o11+|LL r5Nci}|j|}|D]$}||j||j<%|ifSr:)rrr/rr;)rHrqrrrcolumns r6rzSqliteMetadata.get_column_typessV -++E22 H HF(, f6F(G(GL % %Rr5r:)r1r2r3rrrrrrrrrrrrr&r'formatre_foreign_keyr+r/rr4r5r6rrsS/    <      M <  < L |  <    !" L#$*+J0 E C %'-f5cf&B&B  ;J         r5r_DatabaseMetadata)r primary_keys foreign_keysrrindexesceZdZdZdZdS)DatabaseMetadatacg}jD]J}t|jdkr0fd|jD}|||jfK|S)Nrc^g|])}|jvj|j*Sr4)rr;)rPr1rHrqs r6 z9DatabaseMetadata.multi_column_indexes..sGAAA#)"(DL,?"?"? $|E26:?"?"?"?r5)r7rrappendrB)rHrqaccumrA field_namess`` r6multi_column_indexesz%DatabaseMetadata.multi_column_indexess\%( : :E5=!!A%%AAAAA-2]AAA  k5<8999 r5ci}|j|D]/}t|jdkr|j||jd<0|S)Nrr)r7rrrB)rHrqr>rAs r6column_indexeszDatabaseMetadata.column_indexessK\%( 7 7E5=!!Q&&*/,emA&' r5N)r1r2r3r@rBr4r5r6r9r9s2r5r9c~eZdZeegZddZdZeddZ dZ dZ dZ dZ dd Zdd Z dd Z ddZdS) IntrospectorNc"||_||_dSr:)rr)rHrrs r6rIzIntrospector.__init__s   r5c d|jjzS)Nzrrris r6rWzIntrospector.__repr__s#dm&<<K|]}|VdSr:)title)rPr,s r6rRz/Introspector.make_model_name..s*EESSYY[[EEEEEEr5_rT)r r)r,rTsplitisalpha)rHrq snake_caser\ model_names r6make_model_namezIntrospector.make_model_name s~  +#E**Ey"e,,WWEEEKK4D4DEEEEE !}$$&& *z)Jr5FcP|}|rt|}|}|rtjdd|p|}tjdd|}|t vr|dz }t |r|drd|z}|S)Nz_id$rr^rar)stripr rr)r,RESERVED_WORDSrisdigit)rHr1rdres r6make_column_namezIntrospector.make_column_names  -$V,,F  :VFB//96F 3// ^ # # cMF v;; "6!9,,.. "6\F r5c |jj|j}|rD|jj|j}|d|Dfd|D}t |}i}i} i} i} i} |D];} |j| |j}|j| |j} |j | |j| | <H| | D]?}|j |vr4| |j | |j @n*#t$r}t|jg| | <Yd}~nd}~wwxYw|| || | <t d|D}t d| | D}|D]\}}|rt%jdd|}n||||v|}|}|dr||vr|}||_|D]J}t1|jd kr0|jd }||vr|j||_d ||_K|j| |j| | <||| <|| | <=i}d }|D]} t }t;| | | D]X} || |j}n#t>$rY#wxYw|j }||vr|d|jd||<C| |Y|D]}} | | D]r}||j |j} ||j |j!}n#t>$rd}YnwxYw|"|| ||#|s~tI|| | | | S)NrIcg|] }|j Sr4r)rPviews r6r<z+Introspector.introspect..-s77749777r5cg|]}|v| Sr4r4)rPrq table_namess r6r<z+Introspector.introspect..0s#HHH5K3G3Ge3G3G3Gr5c3>K|]}|VdSr:)r)rPr@s r6rRz*Introspector.introspect..YsJ"D"D&1#."3"3"5"5"D"D"D"D"D"Dr5c3$K|] }|jV dSr:r1)rPfk_cols r6rRz*Introspector.introspect..[s$FFfmFFFFFFr5r^ra_idrrTc|jSr:rt)ros r6z)Introspector.introspect..|s k&8r5)r~_set)rorrrsrF)%rr get_tablesr get_viewsextendrrrrrpr=addrLerrargsrgrzr)r,rlrendswithr;rrrBrArr|r1KeyErrorrq dest_columnrtrr9)rHrqliteral_column_names include_viewsretablesviews table_setrr5r6rrr7rq table_indexes table_columnsroexclower_col_namesfkscol_namer1new_name lower_namerA related_namessort_fnmodels_referencedrpsrcrss ` r6 introspectzIntrospector.introspect's'22$+2FF  9M*44DK4HHE MM77777 8 8 8  "HHHHHHHFKK    3 +3 +E M55eT[IIM M55eT[IIM B&*m&D&D4;'('( U#*'3E':BB &1BB"MM+*@AAA%MM+*@AAA ) ) )SX&( U###### )"&!5!5eZ!H!HK ""D"D5B"D"D"DDDOFF,u2EFFFFFC$1$7$7$9$9 ' ' &'A!vih??HH#44Xx35? A AH &^^-- &&u--0(o2M2M'~~//H& & ; ;u}%%**"]1-F..7<| f-46: f-3"&-"@"@t{#$#$L *GEN*GENN  88 6 6E # %l5&9wGGG 6 6 $U^K,>?FFH)3 !222"  -%M&))&))*5555 6 9 9E+E2 9 9 k/01CD ";#9:#/1DD   DDD ## + +!.!2!23!7!7 $9999 9       s<#E  E1E,,E1L L'&L'N N,+N,c ||| i}Gfddt t  fd t jD]\}}||vr  |||S)Nc.eZdZGfddZdS)/Introspector.generate_models..BaseModelc6eZdZjjZjZdS)4Introspector.generate_models..BaseModel.MetaN)r1r2r3rrrrisr6Metars =1r5rN)r1r2r3rrisr6 BaseModelrsG % % % % % % % % % % % %r5rchjD]>}|j}||vr1|kr+|vrtjdd|2||?gj}|D]&\}}|jr|j '  }Gfdd}d} tdkr| tdkr.tfd|D|_d } d|i} |D]S\}}|j} | t ur rt"} n| t$urt"} ||jd } |jr| r| t(urt*} d| d <n|jr| t(urd | d <|r^|rd | d <n(|jj} | |vr || | d <n t2} | | d<|jr |j| d<d|d| d<|jt9d|jz}|g| d<||vr;|s'||rd | d<n|sd | d<| di| | |j <U t=t?f| |<n#t@$rsYnwxYwvr!dSdS#vr!wwxYw)Nz'Possible reference cycle found between z and ceZdZZZdS)AIntrospector.generate_models.._create_model..MetaN)r1r2r3r7 table_name)r@rqsr6rrs." r5rFrrc,g|]\}}|v |jSr4r)rPcolr]r5s r6r<zGIntrospector.generate_models.._create_model..s42,2,2,#-3l**J***r5T)r@rYr?rHr\rel_model_namer]ra_relr^z DEFAULT %sr[rBrAr4)"r}r6rpwarningswarnrrzr?r=r;r@rBrkeys CompositeKeyr<rar-r0r>rcrrdrmroDeferredForeignKeyrGrCSQLrerSstrrLremove)rqmodelsrorsrr@r1rBr composite_keyrU FieldClassrfrp constraintr@r5r _create_model bare_fieldsrpending skip_invalids` @@r6rz3Introspector.generate_models.._create_models[ KK   '4U; 4 4 "-v%%$%--w 5:UUDD'BCCCC& dF333L&u-G'.}} 5 5# V%5 '' 444#+#@#@#G#G %44U;;N # # # # # # # # # # # "M<  A%%&||~~ <  1$$#/2,2,2,2,182,2,2,$- !% TNE'.}}+ :+ :# V#/ _444!*JJ<//!*J$/"O--%1-1!Y..%1 ,1F=))'1Ji,G,G,0F=)((**K4466B*0w%+%7%B %//.4Z.@F7OO);J7AF#34:*0/w8=uukkk(JF9%>-!$\FN%B!C!CJ-7LF=).00((**1%k2/+/x((#2244/*.w%/Z%9%9&%9%9fk"" * $SZZ)u E Eu    # G##NN5)))))$#5G##NN5))))$s*"K%$L% K52L4K55LL1)rModelrr|rrrz) rHrrqrrrrrqr\rrrrs `` ` @@@@r6generate_modelszIntrospector.generate_modelss??;0D#022 % % % % % % % % % % %%X *X *X *X *X *X *X *X *X *X *v#8#7#=#=#?#?@@ - -LE5F"" eV,,, r5r:)T)FT)NFFT)FNFFF)r1r2r3rcr pk_classesrIrW classmethodrQrTrVrYr\rgrlrrr4r5r6rDrDs\*J===,,,[,",,,///555 $AF37{{{{z?C@E&+mmmmmmr5rDcbt||}|S)NrI)rDrQr)rr introspectors r6rrs,--hv-FFL  " " $ $$r5c Tt||}|jdi|S)NrIr4)rDrQr)rroptionsrs r6rrs3--hv-FFL '< ' 2 2' 2 22r5TFct|jj|jjD]}d|jd|jg}|jr|dn;|r9|jr|dn|jr|dt|tr/|d|j j d|j jtd||r|j}|sdStd |D]U}dg}|jj}|d d 5|t)|j|jr/|d ||j|\}} dddn #1swxYwY|t3t5t6| z} || dd|jr|dtd|UdSdS)Nz  z PKz UNIQUEz INDEXz FK: .rz index(es)%sz"")paramquotez WHERE r)r(_metar; sorted_fields field_typer?r=rBrArrarEr1 rel_fieldrTfields_to_indexrget_sql_context scope_valuesrr _expressions_whereliteralquerytuplemaprreplace_unique) r\r7inline_indexesr]parts index_listrActxrrfcleans r6 print_modelrs %+ *  #jjj%*:*:;<   ' LL      '| ' Y'''' ' X&&& e_ - - @ LLL)A)A)A).)=)=? @ @ @ bggenn"[0022   F m " "EFE+&6688C!!D!99 * * e&899:::<*KK ***GGEL)))!iikk V  * * * * * * * * * * * * * * *%$8& A ABBBE LLsB// 0 0 0} ( Y''' "''%.. ! ! ! !+""  " "s&A5G''G+ .G+ c.|j\}}|jjjdkr%||jjjd}tjd|}| \}}}d d| dD}d |||f }|ttt|zS)Nrz^(.+?\()(.+)(\).*)z, c3 K|] }d|zV dS)z %sNr4)rPr1s r6rRz get_table_sql..Ns&LLf&6/LLLLLLr5rKr[)_schema _create_tablerrrrrr)matchgroupsrTrcrirrr) r\rrf match_objcreaterextraindentedrs r6 get_table_sqlrFs---//5577KC {!T))kk%+.4d;;-s33I&--//FGUzzLL d8K8KLLLLLH IIvx/ 0 0 6 6 8 8E 516::;; ;;r5c>tt|dSr:)r(r)r\s r6print_table_sqlrSs -  r5r:)TF)) collectionsr ImportErrordictrinspectrr)rpeeweerrr r r r pymysql.constantsr MySQLdb.constants playhouserplayhouse.cockroachdbrrrjobjectr0r8rrrrrr4r9rDrrrrrr4r5r6rs2'''''''KKK"""""" '''''' """""",,,,,,,0000000   &&&&&&&LLL7777777     6   lllllVlll^@8@8@8@8@8v@8@8@8FbJbJbJbJbJbJbJbJJ?????,???6+ + + + + H+ + + \7 7 7 7 7 X7 7 7 tJ25(&ooooo6oood %%%% 3333 %"%"%"%"P < < <     sf AA7 A'&A7'A1.A70A11A76A7;BB  B BB! B!