U ÇÏ a|ã@s¦ddlZddlZddlmZddlmZmZddlmZddl m Z dd„Z e  d ¡Z d d „ZGd d „d eƒZGdd„deƒZGdd„deeeƒZGdd„deƒZdS)éN)Úinspect)ÚDeclarativeMetaÚ declared_attr)Ú_get_table_keyé©Úto_strcCs†|j dd¡s*tdd„|jdd…Dƒƒs.dS|jD]L}d|jkrDq4t|jdtƒrZdS||kpz|j dd¡pzt|tƒ SdS) a@Determine whether ``__tablename__`` should be automatically generated for a model. * If no class in the MRO sets a name, one should be generated. * If a declared attr is found, it should be used instead. * If a name is found, it should be used if the class is a mixin, otherwise one should be generated. * Abstract models should not have one generated. Later, :meth:`._BoundDeclarativeMeta.__table_cls__` will determine if the model looks like single or joined-table inheritance. If no primary key is found, the name will be unset. Z __abstract__Fcss|]}t|tƒVqdS©N)Ú isinstancer)Ú.0Úb©r úWC:\Users\vtejo\AppData\Local\Temp\pip-unpacked-wheel-eq0tl_ss\flask_sqlalchemy\model.pyÚ sz'should_set_tablename..rNÚ __tablename__T)Ú__dict__ÚgetÚanyÚ__mro__r rr)ÚclsÚbaser r rÚshould_set_tablename s  ÿþ   ÿ ýrz([A-Z]+)(?=[a-z0-9])cCsdd„}t ||¡ d¡S)NcSs<| ¡}t|ƒdkr0d|dd…|df ¡Sd| ¡S)Nrz_%s_%séÿÿÿÿÚ_)ÚgroupÚlenÚlower)ÚmatchÚwordr r rÚ_join3s z"camel_to_snake_case.._joinr)Ú camelcase_reÚsubÚlstrip)Únamerr r rÚcamel_to_snake_case2sr$cs$eZdZ‡fdd„Zdd„Z‡ZS)Ú NameMetaMixincsRt|ƒrt|jƒ|_tt|ƒ |||¡d|jkrNd|jkrN|jddkrN|`dS)NrÚ __table__) rr$Ú__name__rÚsuperr%Ú__init__rr&)rr#ÚbasesÚd©Ú __class__r rr)?s ÿþ ýzNameMetaMixin.__init__cOs¤t|d| d¡ƒ}||jjkr,tj||ŽS|D]2}t|tjƒrF|jsRt|tj ƒr0tj||ŽSq0|j dd…D]}d|j krrq’qrtj||ŽSd|j kr |` dS)aThis is called by SQLAlchemy during mapper setup. It determines the final table object that the model will use. If no primary key is found, that indicates single-table inheritance, so no table will be created and ``__tablename__`` will be unset. rZschemarrr&rN) rrÚmetadataZtablesÚsaZTabler ZColumnZ primary_keyZPrimaryKeyConstraintrrr)rÚargsÚkwargsÚkeyÚargrr r rÚ __table_cls__Ns"    ÿÿ þ   zNameMetaMixin.__table_cls__)r'Ú __module__Ú __qualname__r)r4Ú __classcell__r r r,rr%>s r%cseZdZ‡fdd„Z‡ZS)Ú BindMetaMixincsT| dd¡pt|ddƒ}tt|ƒ |||¡|dk rPt|ddƒdk rP||jjd<dS)NZ __bind_key__r&Úbind_key)ÚpopÚgetattrr(r8r)r&Úinfo)rr#r*r+r9r,r rr)ss   þzBindMetaMixin.__init__)r'r5r6r)r7r r r,rr8rsr8c@s eZdZdS)Ú DefaultMetaN)r'r5r6r r r rr=sr=c@s eZdZdZdZdZdd„ZdS)ÚModelzóBase class for SQLAlchemy declarative base model. To define models, subclass :attr:`db.Model `, not this class. To customize ``db.Model``, subclass this and pass it as ``model_class`` to :class:`SQLAlchemy`. NcCsHt|ƒj}|dkr"d t|ƒ¡}nd dd„|Dƒ¡}d t|ƒj|¡S)Nz(transient {0})z, css|]}t|ƒVqdSr r)r Úvaluer r rr™sz!Model.__repr__..z <{0} {1}>)rÚidentityÚformatÚidÚjoinÚtyper')Úselfr@Úpkr r rÚ__repr__”s  zModel.__repr__)r'r5r6Ú__doc__Z query_classÚqueryrGr r r rr>ƒs r>)ÚreZ sqlalchemyr/rZsqlalchemy.ext.declarativerrZsqlalchemy.schemarÚ_compatrrÚcompiler r$rDr%r8r=Úobjectr>r r r rÚs   $  4