m !&Gc@s^dklZlZlZlZlZdklZdklZ dkl Z dk l Z l Z lZdkZdddd d d d gZeiZgZeZeZdefd YZeiee_defdYZdefdYZd e fdYZdefdYZdZdZe dZ!e"e dZ#dS((ssqlsschemasutils exceptionsslogging(ssql_util(sutil(ssync(sMapperPropertys MapperOptionsOperationContextNtMappertMapperExtensiont class_mappert object_mappertEXT_PASStmapper_registrytExtensionOptioncBsxtZdZeeeeeeeeeeeeeeeeeeedZdZdZdZ dZ e e ddZ dZ d Zd Zd Zd Zd ZedZdZdZdZdZdZdZdZdZdZdZdZdZedZ eeedZ!dZ"dZ#dZ$d Z%d!Z&d"Z'd#Z(d$Z)d%Z*d&Z+d'Z,d(Z-d)Z.d*Z/d+Z0ed,Z1ed-Z2d.Z3eeed/Z4d0Z5d1Z6d2Z7d3Z8ed4Z9ed5Z:d6Z;ed7Z<d8Z=d9Z>d:Z?RS(;sDefines the correlation of class attributes to database table columns. Instances of this class should be constructed via the sqlalchemy.orm.mapper() function.cst|tptid|inxG||fD]9}|dj o&t |t i otidq7q7W|_| _t|| _|_|_| _| _| _|_t_|_|_|_|_|_|ph_| _|_g_|_ |_!|_"t#i$_%|_&|djo h_(n |_(dt#i)fdY}|_+i+_,h_-t#i$_.d_/t_0i1i2ddS(sSconstruct a new mapper. All arguments may be sent to the sqlalchemy.orm.mapper() function where they are passed through to here. class_ - the class to be mapped. local_table - the table to which the class is mapped, or None if this mapper inherits from another mapper using concrete table inheritance. properties - a dictionary mapping the string names of object attributes to MapperProperty instances, which define the persistence behavior of that attribute. Note that the columns in the mapped table are automatically converted into ColumnProperty instances based on the "key" property of each Column (although they can be overridden using this dictionary). primary_key - a list of Column objects which define the "primary key" to be used against this mapper's selectable unit. This is normally simply the primary key of the "local_table", but can be overridden here. non_primary - construct a Mapper that will define only the selection of instances, not their persistence. inherits - another Mapper for which this Mapper will have an inheritance relationship with. inherit_condition - for joined table inheritance, a SQL expression (constructed ClauseElement) which will define how the two tables are joined; defaults to a natural join between the two tables. extension - a MapperExtension instance or list of MapperExtension instances which will be applied to all operations by this Mapper. order_by - a single Column or list of Columns for which selection operations should use as the default ordering for entities. Defaults to the OID/ROWID of the table if any, or the first primary key column of the table. allow_column_override - if True, allows association relationships to be set up which override the usage of a column that is on the table (based on key/attribute name). entity_name - a name to be associated with the class, to allow alternate mappings for a single class. always_refresh - if True, all query operations for this mapped class will overwrite all data within object instances that already exist within the session, erasing any in-memory changes with whatever information was loaded from the database. version_id_col - a Column which must have an integer type that will be used to keep a running "version id" of mapped entities in the database. this is used during save operations to insure that no other thread or process has updated the instance during the lifetime of the entity, else a ConcurrentModificationError exception is thrown. polymorphic_on - used with mappers in an inheritance relationship, a Column which will identify the class/mapper combination to be used with a particular row. requires the polymorphic_identity value to be set for all mappers in the inheritance hierarchy. _polymorphic_map - used internally to propigate the full map of polymorphic identifiers to surrogate mappers. polymorphic_identity - a value which will be stored in the Column denoted by polymorphic_on, corresponding to the "class identity" of this mapper. concrete - if True, indicates this mapper should use concrete table inheritance with its parent mapper. select_table - a Table or (more commonly) Selectable which will be used to select instances of this mapper's class. usually used to provide polymorphic loading among several classes in an inheritance hierarchy. allow_null_pks - indicates that composite primary keys where one or more (but not all) columns contain NULL is a valid primary key. Primary keys which contain NULL values usually indicate that a result row does not contain an entity and should be skipped. batch - indicates that save operations of multiple entities can be batched together for efficiency. setting to False indicates that an instance will be fully saved before saving the next instance, which includes inserting/updating all table rows corresponding to the entity as well as calling all MapperExtension methods corresponding to the save operation. column_prefix - a string which will be prepended to the "key" name of all Columns when creating column-based properties from the given Table. does not affect explicitly specified column-based properties s#Class '%s' is not a new-style classsMapping against a Select object requires that it has a name. Use an alias to give it a name, i.e. s = select(...).alias('myselect')t LOrderedPropcs&tZdZdZeeZRS(spthis extends OrderedProperties to trigger a compile() before the members of the object are accessed.csi|idS(Nt_OrderedProperties__data(tselftcompiletst__dict__(R (R (t9/home/holguin2/public_html/spyce/sqlalchemy/orm/mapper.pyt _get_datas (t__name__t __module__t__doc__RtpropertyR((R (R Rs  t constructedN(3t issubclasstclass_tobjectt exceptionst ArgumentErrorRt local_tablet select_tablettabletNonet isinstancetsqlt_SelectBaseMixinR t entity_nametClassKeyt class_keyt primary_keyt non_primarytorder_bytalways_refreshtversion_id_coltconcretetFalsetsingletinheritstinherit_conditiont extensiont propertiestallow_column_overridetallow_null_pkstdelete_orphanstbatcht column_prefixtpolymorphic_ontutiltSett_eager_loaderstpolymorphic_identityt_polymorphic_maptpolymorphic_maptOrderedPropertiesRtcolumnstct_optionst_inheriting_mapperst_Mapper__surrogate_mappert_Mapper__is_compiledt_compile_classt _Mapper__log(R RRR.R#R$R+R,R-R%R/R R&R'R4R9R8R(RR0R2R3RR((R R t__init__"sV[                                cCs|iid|iid|idj od|ipd|io |iip t |i|i odpdd|dS(Nt(t|s/%sts |non-primarys) ( R tloggertinfoRRR RRtnametstrt_is_primary_mappertmsg(R RM((R t__logscCs|iid|iid|idj od|ipd|io |iip t |i|i odpdd|dS(NRERFs/%sRGs |non-primarys) ( R RHtdebugRRR RRRJRKRLRM(R RM((R t __log_debugsc Cst|}x|iD]3\}}t||i|d|ot SqqWt |iolt|pWt i d|di g}|iD] \}}|d|i|fq~fqtSnt SdS(Nt optimisticsTinstance %s is an unsaved, pending instance and is an orphan (is not attached to %s)s, nor s9any parent '%s' instance via that classes' '%s' attribute(t has_identitytobjRQR R1tkeytklasstgetattrt hasparentR)tlenRt FlushErrortjoint_[1]RtTrue(R RSR[RURTRQ((R t _is_orphans    WcCs|i|iS(N(R R t_Mapper__props(R ((R t _get_propss tdocsucompiles this mapper if needed, and returns the dictionary of MapperProperty objects associated with this mapper.cCsB|io|Sn|i|io|i|in|S(scompile this mapper into its final internal format. this is the 'external' version of the method which is not reentrant.N(R RAt _compile_allR$t _do_compilet_initialize_properties(R ((R R s    cCsbx,tiD]}|ip|iq q Wx,tiD]}|ip|iq<q<WdS(N(RtvaluestmapperRARbt_Mapper__props_initRc(R Re((R Ras    cCs&|io|i|in|S(N(R R$RbRc(R ((R t_check_compiles  cCst|io|Sn|idt|_t|_|i|i|i|i |i |id|S(scompile this mapper into its final internal format. this is the 'internal' version of the method which is assumed to be called within compile() and is reentrant. s_do_compile() starteds_do_compile() completeN( R RARCR\R)Rft_compile_extensionst_compile_inheritancet_compile_tablest_compile_propertiest_compile_selectable(R ((R Rbs          cCsti}x?tD]7}t|to|i|q|i|qW|i }|dj o+x(ti |D]}|i|qtWnt |_ x|D]}|i i|qWdS(sgoes through the global_extensions list as well as the list of MapperExtensions specified for this Mapper and creates a linked list of those extensions.N(R5R6textlisttglobal_extensionst ext_classRRtaddR R-Rtto_listtext_objt_ExtensionCarriertexttappend(R RrR-RtRoRm((R Rh(s     cCs|id j ot|ito"t|idti|_n|ii|_t|i |ii p,t i d|i i |ii i fn|i |ii jo@|i odpd}t i d||i i |fn|id jo|ii|_t|_n|i|iij o|iod |_|i|_q|id jo%ti|ii|ii|_nti|ii|i|i|_ti||ti|_|ii|iind |_|i|_|id j o|ii|i|n|id jo>|iid j o+|ii |iidtdt|_n|i!tjo|ii!|_!n|ii"|_"|ii#|_#|ii$i%|n=d |_|i|_|id j o|i|i|n|id jot i dt&|nxL|i"i'D];}t|i"|tot|i"||i"|Wn|i d j oNxK|i iiD]3\}}|ii|p|i||qqWnx|iiD]}|ii|oqn|ii|i p,|ii|dtdt|i|i |dj o*|ii}|tjo d}qnd}|dj o'|dj o||_|i|ndj oCy|||Wq;|dj o|i|nq;XndS(Nt_sa_entity_namet _sa_session(tkwargstpopRR RRR!R t __class__ReR tattribute_managert init_attrRtsessionR-t get_sessionRt _entity_namet_register_pendingtoldinittargstexpunge(R RRReR R(R(R Rs,       t_sa_mapper_init(R R$RRR"RRRR Rtreset_class_managedRDRRRthasattrR\RRRR=(R RR((RR RBs& #  $   cCs)|idj o|iiSn|SdS(s7return the ultimate base mapper in an inheritance chainN(R R+Rt base_mapper(R ((R REscCs|i|ijS(sOreturn true if the given mapper shares a common inherited parent as this mapperN(R Rtother(R R((R t common_parentLscCs>|}x+||j o|idj o |i}q W||jS(s9return True if the given mapper inherits from this mapperN(RtmR R+R(R RR((R tisaPs ccs,|}x|dj o|V|i}q WdS(N(R RRR+(R R((R titerate_to_rootWs  csd|S(s0iterates through the collection including this mapper and all descendant mappers. this includes not just the immediately inheriting mappers but all their inheriting mappers as well. To iterate through an entire hierarchy, use mapper.base_mapper().polymorphic_iterator().c#s7|Vx,|iD]!}x|D] }|Vq!WqWdS(N(RR?Retiteratetx(RReR(R(R Rcs   N(RR (R R((RR tpolymorphic_iterator]s cCs1x*|iD]\}}|i||q WdS(sKadds the given dictionary of properties to this mapper, using add_property.N(tdict_of_propertiesRRTtvalueR t add_property(R RRRT((R tadd_propertiesjs cCs?||i|<|io$|i|i||dtndS(s3add an indiviual MapperProperty to this mapper. If the mapper has not been compiled yet, just adds the property to the initial properties dictionary sent to the constructor. if this Mapper has already been compiled, then the given MapperProperty is compiled immediately.RN(RR R.RTRARaRR\(R RTR((R Ros    cCsti|o_y|ii|}Wn8tj o,|odSnti dt i nXt |Snt |toti|doy1g}|D]}||ii|q~}Wn>tj o2}|odSnti d|idnXt |SndSdS(Ns0Column '%s' is not represented in mapper's tablei(RRRR R|RRt skipmissingRRRt_labelRRRR[R=teRR(R RRR=RR[((R t_create_prop_from_column{s"$1c Csr|id||iift|tpC|i|d|}|djot i dt |qpn||i|<|o|i|nt|to|ii|iddtdt}|djo|id}n||i|x3|D]+|ig|d|d|dt q9WdSn|i i |}!|px|D]}t p7xgtiD]ii|!qWqx0tiD]ii|!qWqWnx|D]ti}| ot  o||iij}|o|ii|} |i| p8tidtit|ti| fn|id |titi| f|i| qqWt i!}t i!}h}x>|i%i&D]*x!i'D]}"|i)|"qFWq6Wxt*i+t,|i-i.d t/D]bg}g}x|D]xti'jpi3 oqni}|id i4tit|f||iijo| o t  }h}t/} xi8D]}#|#i:joM|p5i;|#||#i<<||#i<d ||#i=joX|pi;|#||#i<D]1}#|iQiM|#tNiR|#i<d|#iSjqRWi:dj o5|iQiMi:tNiRi:i<d|#iSjni2|}d}t } d}|i.|xk|D]c} | \}|!iY||}i[|!||i\|i]||i^i_7}q W|iVo6|tK|jo#ti`d|tK|fqntK|o)i1}d}|i.|x|D]} | \}|!iY||}|ia}|dj osd}xji>D]W}#i;|#djo.tK||joid|#||n|d 7}qBWni[|!||ied|i]qWqqW|pxA|D]9x0tiD]iig|!q Wq WxE|D]9x0tiD]iih|!q] WqD WndS(sissue INSERT and/or UPDATE statements for a list of objects. this is called within the context of a UOWTransaction during a flush operation. save_obj issues SQL statements not just for instances mapped directly by this mapper, but for instances mapped by all inheriting mappers as well. This is to maintain proper insert ordering among a polymorphic chain of instances. Therefore save_obj is typically called only on a "base mapper", or a mapper which does not inherit from any other mapper.ssave_obj() start, s non-batchedtbatchedt postupdatetpost_update_colsR*NsJNew instance %s with identity key %s conflicts with persistent instance %ssPdetected row switch for identity %s. will update %s, remove %s from transactiontreverses-save_obj() table '%s' instance %s identity %sis6Using polymorphic identity '%s' for insert column '%s'tpassiveiRycsVxOiD]@}t|d|i|d|i}|djo|SqqWdS(Nii( ReRRRtcmptaRtbR(RRRR(ReR(R t comparators %  s?Updated rowcount %d does not match number of objects updated %dcCst|di|diS(Ni(RRt_sa_insert_orderR(RR((R RscsO|i}|dj o|n|idj o|iindS(N(ReR+tinheritRR~R{texecuteRS(ReR(RSR~(R R~s   (iR t_Mapper__log_debugR*R2tobjectsRStsave_objtuowtransactionRRR\t transactiont connectionRRRRReR-t before_insertt before_updateRtuowt identity_mapt is_row_switchtexistingt is_deletedRRYRt instance_strRKtunregister_objectR5R6tinserted_objectstupdated_objectsttable_to_mapperRRRRRRtTableCollectionRRtsortR)Rtinserttupdatet_has_pksRJtisinserttparamsthasdataR<RR'RRRTRRRR4tshares_lineageR8tdefaultRRt get_historythistoryt added_itemsRRXRRuRtand_tclausetclausest bindparamRyt statementtrowstsupports_sane_rowcountRtrecRR=t _postfetchtlast_updated_paramsRpRtrowcounttConcurrentModificationErrortlast_inserted_idsR#tiRtlast_inserted_paramsR~t after_insertt after_update(%R RRRRR*RRR~RRRR RRRRRR RRRRR R#RReR=RSRR R RRRRR((R~RReRSR Rs() " (8,   ( !,(  #        /5   '      , c Cse|ioti}x7|i|D](} |i i | |i || jq'W|i|i|di} x|iD]=}|i ||tdjo|i||| |q~q~Wnx|iD]}|ip|i|i oqn|i ||t}|tjoqq||i|ijo#|i|||i|iqqWdS(s&after an INSERT or UPDATE, asks the returned result if PassiveDefaults fired off on the database side which need to be post-fetched, *or* if pre-exec defaults like ColumnDefaults were fired off and should be populated into the instance. this is only for non-primary key columns.N(t resultproxytlastrow_has_defaultsRRRR RRtpRRuRRSRRtselectRtfetchoneRR=R)RR#R RRJtvRt get_original( R RRRSR$R RR)R=R&R((R Rs(  &! #  c sid|ii} g} |D]} | ii | | q*~ t i }xi idtD]ipqrng}x|D]} h}t| dpqn|i|x.iD]} i| | || iReR[RR((R R<csf   &=6 (!+ H    &   (+ cCs2|ii|i}|i|_ti||S(N(R Rt__new__RSR RRR(R RRS((R RHs  cCsjti|}xT|iiD]F}|ii|dt dt }|i |o||||s cCs|iid|dS(sJinsert a MapperExtension at the beginning of this ExtensionCarrier's list.iN(R RSRR-(R R-((R RAscCs|ii|dS(sDappend a MapperExtension at the end of this ExtensionCarrier's list.N(R RSRuR-(R R-((R RuDscsotijoEyiSWqktj o#iidSqkXntti SdS(Ncsi||S(N(R t_doRTRR(RR(R RT(R tLs( RTRR R RTRRtsuperRst__getattribute__(R RT((R RTR RXGs %cOsixb|iD]S}||jotidnt||||}|t j o|Sq q Wt SdS(NsExtensionCarrier set to itself( R RStelemRtAssertionErrorRVtfuncnameRRtretR(R R[RRRYR\((R RUOs    (RRRDRRuRXRU(((R Rs=s     cBstZdZdZRS(NcCs ||_dS(N(RtR (R Rt((R RDZscCs|i|idS(N(ROt_insert_extensionR Rt(R RO((R t process_query\s(RRRDR^(((R RYs R!cBs;tZdZeiZdZdZdZdZ RS(sEkeys a class and an entity name to a mapper, via the mapper_registry.cCs||_||_dS(N(RR R (R RR ((R RDbs cCst|i|ifS(N(thashR RR (R ((R t__hash__escCs ||jS(N(R R(R R((R t__eq__gscCs dt|it|ifS(NsClassKey(%s, %s)(RR RR (R ((R t__repr__is( RRRR5t ArgSingletont __metaclass__RDR`RaRb(((R R!_s     cCs t|dS(NR+(RR(R((R RRlscCs t|dS(s9returns True if the given object has a mapper associationRN(RR(R((R t has_mapperoscCsy&tt|it|dd}WnSttfj oA|o/t i d|ii t|ddfq|dSnX|i S(sOgiven an object, returns the primary Mapper associated with the object instanceRs<Class '%s' entity name '%s' has no mapper associated with itN(RR!RRRVRReRtAttributeErrorRRRRR (RRRe((R Rus&/ cCslytt||}Wn5ttfj o#tid|i |fnX|o|i Sn|SdS(sEgiven a ClassKey, returns the primary Mapper associated with the key.s<Class '%s' entity name '%s' has no mapper associated with itN( RR!RR ReRRfRRRR (RR R Re((R Rs!($RRtschemaR5Rtloggingtsql_utilRtsqlalchemy.ormRR~tsqlalchemy.orm.interfacesRt MapperOptiontOperationContexttweakreft__all__tWeakKeyDictionaryRRnRRRRt class_loggerRHRRsRR!RRReR\RRR(RRRRRR~RRRoRRRgRRRRlRR!RnRRmR5RhRsReRnR((R t?s0%       m