[Jc @sdZddkZddkZddkZddklZediZddkl Z l Z l Z l Z ddklZlZlZl ZddklZl Z lZddklZlZlZdd klZlZlZlZlZl Z l!Z!l"Z"d d d d fZ#ei$Z%e&a'e&a(gZ)e i*dZ+e i,i-Z.e/Z0e/Z1e/Z2e/Z3e/Z4e/Z5e/Z6d e7fdYZ8e i9e8dZ:dZ;dZ<dZ=dZ>dZ?dZ@dS(s5Logic to map Python classes to and from selectables. Defines the :class:`~sqlalchemy.orm.mapper.Mapper` class, the central configurational unit which associates a class with a database table. This is a semi-private module; the main configurational API of the ORM is available in :class:`~sqlalchemy.orm.`. iN(tchaint collections(tsqltutiltlogtexc(t expressiontvisitorst operatorsR(t attributesRtsync(tMapperPropertyt EXT_CONTINUEtPropComparator(tExtensionCarriert _INSTRUMENTORt_class_to_mappert_state_has_identityt _state_mappert class_mappert instance_strt state_strtMappert_mapper_registryRt object_mappert NO_ATTRIBUTEcBseZdZd?d?ed?d?d?d?eed?d?d?d?d?ed?d?eed?d?d?edZdZdZdZ dZ dZ dZ dZ eed Zd Zd Zd Zd ZdZdZdZdZdZdZeedZeedZedZdZdZedZe i!dZ"e i!dZ#d?edZ$d?dZ%edZ&e i!dZ'e i!d Z(d!Z)d"Z*d#Z+d$Z,d%Z-d&Z.d'Z/d(Z0d?d)Z1d*Z2d+Z3d,Z4d-Z5d.Z6d/Z7d0Z8d1Z9d2Z:ed3Z;d4Z<d?d5Z=e i!d6Z>ed?ed7Z?d8Z@d9ZAd:ZBd;ZCd?d?d?d?d?d<ZDd=ZEd>ZFRS(@sDefine the correlation of class attributes to database table columns. Instances of this class should be constructed via the :func:`~sqlalchemy.orm.mapper` function. cCs-ti|td|_d |_||_||_| oti| |_ n | |_ | |_ | |_ ||_ t |_||_||_||_||_| |_|ph|_||_g|_||_||_||_| |_g|_h|_d |_t |_d |_||_ |o:ti!d|ot"i#dnd|f|_$n|djo d |_$n}t%|t&t'fo=t%|dt(t&t'fo ||_$q|d f|_$n*|d j ot"i#dn d |_$t%|it)i*o'ti+d||ii,|_n|i$oAt%|i$dt)i*o'|i$d|i$di,f|_$n||_-|oti!d n|d jo h|_.n ||_.||_/||_0t |_1|i2|i3|i4|i5|i6t7a8|i9d d S( sConstruct a new mapper. Mappers are normally constructed via the :func:`~sqlalchemy.orm.mapper` function. See for details. tclass_sSselect_table option is deprecated. Use with_polymorphic=("*", selectable) instead.sSselect_table can't be used with with_polymorphic (they define conflicting settings)t*is$Invalid setting for with_polymorphicsmapper %s creating an alias for the given selectable. References to the original selectable may be misinterpreted by queries, polymorphic_on, etc. Consider passing an explicit selectable.alias() construct instead.ispolymorphic_fetch option is deprecated. Unloaded columns load as deferred in all cases; loading can be controlled using the "with_polymorphic" option.t constructedN(RN(:Rtassert_arg_typettypeRtNonet class_managertprimary_key_argumentt non_primarytto_listtorder_bytalways_refreshtversion_id_coltconcretetFalsetsingletinheritst local_tabletinherit_conditiontinherit_foreign_keyst extensiont_init_propertiestallow_null_pkstdelete_orphanstbatchteager_defaultst column_prefixtpolymorphic_ont_dependency_processorst _validatorst_clause_adaptert_requires_row_aliasingt_inherits_equated_pairst select_tabletwarn_deprecatedtsa_exct ArgumentErrortwith_polymorphict isinstancettupletlistt basestringRt_SelectBaseMixintwarntaliastpolymorphic_identitytpolymorphic_maptinclude_propertiestexclude_propertiestcompiledt_configure_inheritancet_configure_extensionst _configure_class_instrumentationt_configure_propertiest_configure_pkstTruet _new_mapperst_log(tselfRR+t propertiest primary_keyR"R*R,R-R.R$R%R&R5t_polymorphic_mapRGtpolymorphic_fetchR'R;R?R0R2R4RIRJR3((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt__init__Is!                                $'            c Cst|_|iot|itot|idt|_nt|i|iip,t i d|ii |iii fn|i |ii jo>|i odpd}t i d||ii |fn|i d jo+|ii |_ |ii|_t|_n|i |ii j o|io>|i |_x|iD]}|io t|_qRqRWq|ip"ti|ii |i |_nti|ii|i |i|_ti|i}ti|iid||_ n |i |_|i!o|i o|ii"|_"n |i|_"|i#d jo|ii#|_#nx4|iD]&}ti$|dti$|dqkW|i%tjo1|i o&|ii%tj o|ii%|_%n|ii&|_&|ii'|_'|iii(||ii)|_)|ii*|_*|i!d j o`||i&|i!<|ipBx?|iD]-}|io|ii+|i|_Pq\q\WqqnLt|_*||_)|i |_|i!o||i&|i!t__name__R"R+Rt mapped_tableRQR)R'titerate_to_rootR5R9R,tsqlutiltjoin_conditionRtjoinRtto_setR-tcriterion_as_pairstonclauseR:RGt_identity_classR&treset_memoizedR$RHR2taddt base_mappert _all_tablestcorresponding_column(RTtnptmappertfks((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRLsz  #       "$"   .        cCsti}|i}|o+x(ti|D]}|i|q,Wn|io9x|iiD]$}||jo|i|q^q^WnMxItD]A}t|to |}n||jo|i|qqWt |_x|D]}|ii |qWdS(sGo 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( Rt OrderedSetR.R#RmR*tglobal_extensionsR@RRtappend(RTtextlistR.text_objtext((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRM s*        cs4tii}ioC| p|idjotidn|_t t R.tinstrument_classtregister_classt_load_scalar_attributestinfotgetRR(teventst add_listenert_event_on_initt_event_on_init_failuret_event_on_resurrectRtiterate_attributesR@ttypest FunctionTypethasattrRR7(RTtmanagertevent_registrytkeytmethodtnameR((RTs9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRN=sP               cCsYt|_t|do |`n|i o'|ii|joti|i ndS(Nt_compile_failed( RQRKRRR"R RrR tunregister_classR(RT((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pytdisposes   c stii_ip tidtinh_h_t i t g}i D]}||i qh~}t i d|D}tiig}ii|xs|D]k}|io9|i|io&t i|ii|i|s c3sHxA|]:}t|d p|iijoi|VqqWdS(ttableN(RRt_cols_by_tablet_columntoproperty(Rtcol(RT(s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pys s isJMapper %s could not assemble any primary key columns for mapped table '%s'tignore_nonexistent_tabless Identified primary key columns: ($Ret find_tablesRcttablesR=Rtstrt _pks_by_tableRRt column_setRRt proxy_setR_RotupdateRVt issupersettordered_column_sett intersectionRt_readonly_propsR!RRtRmtlenR>t descriptionR*R'treduce_columnsRpRQRS( RTt_[1]Rtall_colstpk_colsRtttkt_[2]RRV((RTs9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRPsN    6&&   0   0   cCssti|_|_ti|_ti|_|io7x4|ii D]\}}|i ||t qNWn|i ohxe|i ii D]M\}}||ijo1|i ||dt  o|i||t qqWnx|iiD]}||ijoqn|ipd|i}|i |i|d|iii|oqnx8|iD]*}||ijo|i|i}qgqgW|i ||dt dtqW|io|i|ijo|ii|i}|pt}|i}nt }|i |i|idt otid|in|i |it|d|dt dtndS(Ntlocalttinitt setparents6Cannot exclude or override the discriminator column %rt_no_instrument(RtOrderedPropertiestcolumnsRt OrderedDictt_propst column_dictRR/t iteritemst_configure_propertyR(R*t_should_excludet_adapt_inherited_propertyRcR4RR+tcontains_columnRdRQR5RpR=RtColumnProperty(RTRtproptcolumnt column_keyRrRtdont_instrument((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyROsB    * +   cCsa|ip |i||dtdtn4||ijo#|i|td|dtndS(NRR(R'RR(RtConcreteInheritedPropertyRQ(RTRRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRs  c Csd|id||iift|tpQti|}|d}ti|pt i d||fn|i i |d}t|toE|i|j o|i}n|ii||id|q~|djpt|todg}xK|D]C}|ii|} | pt i d|n|i| qWt|}q~t i d|i|fnt|toW|ii|id} | djoY|id} t|do8t| d p| i|ijo|ii|qbnVt|d oE| i|ijo2| |i| ijo|i| ii| nt|d p-| |ijp|id|ij|_n| |i|Can't compile synonym '%s': no column on table '%s' named '%s'RR(2RSt __class__RbR@R RR#Rt is_columnR=R>RRRRtparenttcopyRRvRRcRpRRRRRRmR5RRRtComparablePropertytSynonymPropertyt descriptortgetattrRt_is_userland_descriptorR(RRRRt set_parentR"RR`RRtpost_instrument_class( RTRRRRRRt mapped_columnRtmcRtdescRr((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyR s     $:-    7     cCs|io t o|Stizyto|idStaz|io t o|SxYttD]K}t |dt ot i d|i n|ip|iqjqjWt a|SWdt aXWn/ddk}|id}||_ nXWdtiXdS(sCompile this mapper and all other non-compiled mappers. This method checks the local compiled status as well as for any new mappers that have been defined, and is safe to call repeatedly. NRsrOne or more mappers failed to compile. Exception was probably suppressed within a hasattr() call. Message was: %sii(RKRRt_COMPILE_MUTEXtacquiret_already_compilingt_post_configure_propertiesRQRBRRR(R=RRtsystexc_infotrelease(RTRrRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRZns8          cCs|idg}|iiD]\}}|||fq!~}xi|D]a\}}|id||i|jo|i o|in|io|i|qJqJW|idt|_ dS(sCall the ``init()`` method on all ``MapperProperties`` attached to this mapper. This is a deferred configuration step which is intended to execute once all mappers have been constructed. s$_post_configure_properties() startedsinitialize prop s%_post_configure_properties() completeN( RSRRRt_compile_startedRt_compile_finishedRRQRK(RTRRRtl((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRs 6   cCs1x*|iD]\}}|i||q WdS(s^Add the given dictionary of properties to this mapper, using `add_property`. N(Rt add_property(RTtdict_of_propertiesRtvalue((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pytadd_propertiess cCs*||i|<|i||d|idS(s;Add an individual 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(R/RRK(RTRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRs cCsq|ioc|iid|iid|io |iip t|i|iodpdd|ndS(Nt(t|s |non-primaryRs) ( t_should_log_infotloggerRRRbR+RRR"(RTtmsg((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRSs  NcCsq|ioc|iid|iid|io |iip t|i|iodpdd|ndS(NRRs |non-primaryRs) ( t_should_log_debugRtdebugRRbR+RRR"(RTR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt _log_debugs  NcCsdt||iifS(Ns(tidRRb(RT((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt__repr__scCsKd|iid|io |iip t|i|iodpdS(NsMapper|Rs |non-primaryR(RRbR+RRR"(RT((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt__str__s5cCs~t}xq|iD]c}xD|iD]9\}}ti|i||dt|otSq#W|p t|i}qW|S(Nt optimistic(R(RdR1R Rt has_parentRtbool(RTtstatetoRrRtcls((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt _is_orphans   cCs ||ijS(N(R(RTR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt has_propertyscCs#|i|i|d|d|S(s6return a MapperProperty associated with the given key.tresolve_synonymstraiseerr(RZt _get_property(RTRRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt get_propertys cCs|ii|d}|o4x1t|to|ii|id}qWn|djo*|o#tidt||fn|S(Ns Mapper '%s' has no property '%s'( RRRR@RRR=RR(RTRRRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRs!#cCs|i|iiS(s1return an iterator of all MapperProperty objects.(RZRt itervalues(RT((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pytiterate_propertiess c Cs|djot|i}n|org}ti|D]}|t|q>~}xE|D]3}|i|ptid||fqaqaWng}|oTtt i |dt }g}|D]!}|i |jo ||qq~}n|S(sgiven a with_polymorphic() argument, return the set of mappers it represents. Trims the list of mappers to just those represented within the given selectable, if present. This helps some more legacy-ish mappings. Rs%r does not inherit from %rtinclude_aliases( RBtpolymorphic_iteratorRR#RtisaR=RR_ReRRQR+(RTtspect selectabletmappersRtmRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_mappers_from_spec s 0%9cCsu|i}xe|D]]}||joqn|iotidq|ip|i|i|i}qqW|S(sgiven a list of mappers (assumed to be within this mapper's inheritance hierarchy), construct an outerjoin amongst those mapper's mapped tables. s^'with_polymorphic()' requires 'selectable' argument when concrete-inheriting mappers are used.(RcR'R=RR)t outerjoinR+R,(RTR tfrom_objR ((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_selectable_from_mappers$s     cCsW|ioE|io;|io1|idj o!|iid|iDSdSdS(Ncssx|]}|iVqWdS(N(RG(RR ((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pys <s (R)R*R5RGRtin_R(RT((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_single_table_criterion5s    cCs"|ip|gS|i|iS(N(R?R (RT((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_with_polymorphic_mappersBs cCsJ|ip|iS|i\}}|o|S|i|i||SdS(N(R?RcRR (RTRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_with_polymorphic_selectableHs  cCs|io:|p|id}n|tjo|id}qDn|i||}|o ||fS||i|fSdS(Nii(R?R(R R(RTRRR ((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_with_polymorphic_argsSs   ccs|djo |i}n|px|iD] }|Vq+Wnxtitg}|g|D]}|t|iq\~D]G}t|dto)|i p|i d|i j oqn|VqWdS(sMReturn an iterator of MapperProperty objects which will render into a SELECT.RiN( RRRRt unique_listRRBRR(R5R(RTR RRRr((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_iterate_polymorphic_properties`s     8"cCstddS(NsoPublic collection of MapperProperty objects is provided by the get_property() and iterate_properties accessors.(tNotImplementedError(RT((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRUuscCsg}|iD]%}||tidd|ifq~}tig}|D]\}}|||jqM~ti|fS(screate a "get clause" based on the primary key. this is used by query.get() and many-to-one lazyloads to load this item by primary key. ttype_N(RVRt bindparamRRtand_RR(RTRRVtparamsRRtv((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt _get_clausezs<csdtifd}xB|iiD]1}|io!ti|ihh|d6q+q+WS(sCreate a map of all *equivalent* columns, based on the determination of column pairs that are equated to one another based on inherit condition. This is designed to work with the queries that util.polymorphic_union comes up with, which often don't include the columns from the base table directly (including the subclass table columns only). The resulting structure is a dictionary of columns mapped to lists of equivalent columns, i.e. { tablea.col1: set([tableb.col1, tablec.col1]), tablea.col2: set([tabled.col2]) } cs|itijo|ijo|ii|inti|if|i<|ijo|ii|iqti|if|iReturn True if the this mapper inherits from the given mapper.(R*R(RTR*R ((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRs ccs'|}x|o|V|i}q WdS(N(R*(RTR ((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRds ccsCt|g}x-|o%|i}|V|i|iqWdS(sKIterate 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()``. N(tdequetpoplefttextendR`(RTtstacktitem((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRs  cCs |iiS(sKReturn the primary mapper corresponding to this mapper's class key (class).(R Rr(RT((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyR,scs_|i}|o,g}|D]}||i|q~}n|itfd|DfS(s&Return an identity-map key for use in storing/retrieving an item from the identity map. row A ``sqlalchemy.engine.base.RowProxy`` instance or a dictionary corresponding result-set ``ColumnElement`` instances to their values within a row. c3sx|]}|VqWdS(N((RR(trow(s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pys s (RVRRkRA(RTR5tadapterRRR((R5s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pytidentity_key_from_rows ,cCs|itti|fS(sReturn an identity-map key for use in storing/retrieving an item from an identity map. primary_key A list of values indicating the identifier. (RkRARR#(RTRV((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pytidentity_key_from_primary_key scCs|i|i|S(sReturn the identity key for the given instance, based on its primary key attributes. This value is typically also found on the instance state under the attribute name `key`. (R8tprimary_key_from_instance(RTR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pytidentity_key_from_instancescCs|i|i|S(N(R8t_primary_key_from_state(RTR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_identity_key_from_state scCsti|}|i|S(sOReturn the list of primary key values for the given instance. (R tinstance_stateR;(RTRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyR9#scCs.g}|iD]}||i||q~S(N(RVt_get_state_attr_by_column(RTRRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyR;+scCsy|i|SWntj ot|ii|id}|o5tid|ii |i |it |fqtid||fnXdS(NsDColumn '%s.%s' is not available, due to conflicting property '%s':%ss*No column %s is configured on mapper %s...( RtKeyErrorRRRRRtUnmappedColumnErrorRRtrepr(RTRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_get_col_to_prop.s5cCs|i|i||S(N(RBR(RTRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyR>9scCs|i|i|||S(N(RBtsetattr(RTRRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_set_state_attr_by_column<scCsti|}|i||S(N(R R=t#_get_committed_state_attr_by_column(RTR'RR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_get_committed_attr_by_column?scCs|i|i||d|S(Ntpassive(RBt getcommitted(RTRRRG((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRECsc s0itfd|DiijodSdtfdYfd}g}yt}xvtti D]\}|ijo t }n|o5|i o*|i t i|ihh|d6qqWWnj odSXti|}ti|dt S(svassemble a WHERE clause which retrieves a given state by primary key, using a minimized set of tables. Applies to a joined-table inheritance mapper where the requested attribute names are only present on joined tables, not the base table. The WHERE clause attempts to include only those tables to minimize joins. c3s#x|]}|iiVqWdS(N(RR+(RR(tprops(s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pys Ps tColumnsNotAvailablecBseZRS((Rbt __module__(((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRJTscs |i}|i}|djp |djodS|ijoZi|dt}|tijo nti d|d|ii |_nk|ijoZi|dt}|tijo nti d|d|ii |_ndS(NRGR( RR RRRERQR tPASSIVE_NORESULTRRR(R!tleftcoltrightcoltleftvaltrightval(RRTRRJ(s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyR#Ws   % R!t use_labelsN(RR_RnR+Rt ExceptionR(treversedRBRdRQR)RvRtcloned_traverseR,RRtselect(RTRtattribute_namesR#tallcondststartRrtcond((RRTRRJRIs9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_optimized_get_statementFs&  2c csti}|iid|fg}x|o|d\}}}y|djo8|i} |i| i||||ddfnQ|djoC|i\} } } | | fV|i| iid| fnWq*tj o|i q*Xq*WdS(sIterate each element and its mapper in an object graph, for all relations that meet the given cascade rule. ``type\_``: The name of the cascade rule (i.e. save-update, delete, etc.) ``state``: The lead InstanceState. child items will be processed per the relations defined for this object's mapper. the return value are object instances; this provides a strong reference so that they don't fall out of scope immediately. tpropertyiRrN( Rt IdentitySetRRtnextRvtcascade_iteratorRt StopIterationtpop( RTRRthalt_ontvisited_instancest visitablestiteratort item_typet parent_stateRRtinstance_mappertcorresponding_state((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyR^ws   ,  'cCsh}x5|iiD]$}x|iD]}|||||jo1||jo| i+||||i/||}!| i?|| |||!|!i@|| |!iA7} qW|!iBo6| tC|jo#tiDd| tC|fqX n|o9|iE}x*|D]\}}} } }| i=|i>||}!|!iF}"|"dj ooxltG| i|D]S\}#}| i+||djo.tC|"|#jo| iH|||"|#q q Wn| i?|| |||!|!iI|x>| iJD]0} | iKo tLiM|| || | iKq\ q\ Wqr WqqW|px|D] \}} } } } |iNiOd| iPD}$|$otQ||$n|iRoK|iSoA|i ||_ |iiT|iU|i d|d|iSn| p4d| ijo | iiV| | |i q q d| ijo | iiW| | |i q q WndS(sLIssue ``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. s_save_obj() start, s non-batchedtbatchedt postupdatetpost_update_colsR)Ntconnection_callablet before_insertt before_updatesJNew instance %s with identity key %s conflicts with persistent instance %ssPdetected row switch for identity %s. will update %s, remove %s from transactions._save_obj() table '%s' instance %s identity %sis6Using polymorphic identity '%s' for insert column '%s'RGiRs?Updated rowcount %d does not match number of objects updated %dcssx|]}|iVqWdS(N(R(Rtp((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pys s t refresh_statetonly_load_propst after_insertt after_update(XRRR2t _sort_statest _save_objRQtmapper_flush_optsRRvR'RRR<t transactiont connectionR.RrRsR_tsessiont identity_mapR R=t is_deletedRt FlushErrorRtset_row_switchRmR^RjRRRR(RR&R5tshares_lineageRGtdefaultRtserver_defaultR>R@Rt ClauseElementt_labelRRtget_state_historytaddedt get_col_valuetdeletedRtclausesRRRRRtexecutetvaluest _postfetchtlast_updated_paramstrowcounttsupports_sane_rowcountRtConcurrentModificationErrortinserttlast_inserted_idst enumerateRDtlast_inserted_paramsRdR:R tpopulatet unmodifiedRRt _expire_stateR3tunloadedtqueryt_getRwRx(%RTtstatestuowtransactionRoRpR)RttupsRqR R}Rrt has_identityt instance_keyt row_switchesRtexistingRkRRRtpkstisinsertRt value_paramsthasdataRRRthistorytclauset statementtrowsRRVtitreadonly((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRzsd # )    %   !$( #      - !                $  !$  / 5% '    ,#%  0 $c Cs%|i}t|i} |io.|i|i} | o| i| qVn|io| i|inxL| D]D} | i|jo.| |ijo|i || || iq{q{Wg} g} |D]} | |i| q~ D]}| |iq~ }|ot ||ndS(s<Expire attributes in need of newly persisted database state.N( tpostfetch_colsRBt prefetch_colsR5RpRvR&RRRDR(RTRR}RRt resultproxyRRRtgenerated_colstpoRRRRtdeferred_props((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRs    "FcCs|io|idnd|ijoV|id}g}t|D]+}||t||||ifqI~}nI|ii|}g}t|D]}||t||fq~}xG|D]?\}} }d| ijo | ii | ||iqqW|i } x0t | i D]} h} x|D]\}} }| | i joqBnh} t|pqBn| i|gi| x.| i | D]}| i||| |iRR&RRRRRRRRtdeleteRtsupports_sane_multi_rowcountRRRRR(RTRRRqRRRR}RRrRkRRRRt del_objectsRRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt _delete_objs`  I6$   '   /  )# %cCs2x+|ii|iD]}|i|qWdS(sRegister ``DependencyProcessor`` instances with a ``unitofwork.UOWTransaction``. This call `register_dependencies` on all attached ``MapperProperty`` instances. N(RRR6tregister_dependencies(RTt uowcommittdep((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_register_dependenciesscCs2x+|ii|iD]}|i|qWdS(N(RRR6tregister_processors(RTRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_register_processorssc si|po dn/|pitiii o\g} D]} | i| qj~ oin oi  qnifd ggfdi i |p i }n|i dd|i dd|i dd|i ddi pi   fd} | S( sYProduce a mapper level row processor callable which processes rows into mapped instances.cs tfdDfS(Nc3sx|]}|VqWdS(N((RR(R5(s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pys s (RA(R5(Rtidentity_class(R5s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt identity_keysc s|o?ioi|_n|ioii|_qFnp$i|\((n|o }n}|o:g}|D]"}|d|jo ||qq~}nx-|D]%\} } | |||d||qWdS(Nitisnew(toptionst load_optionsRt _current_patht load_patht _populators( Rtdict_R5RRvtflagst populatorsRRtRt populator(texisting_populatorstnew_populatorsRTtcontexttpathR6(s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pytpopulate_states  $ : t translate_rowtcreate_instancetpopulate_instancet append_resultc s o-  |}|tj o |}q4no>|}|dj o#|}|o|||Sqyn o- i}|djoi }qn  |}| jo |}ti|}ti|}ioidt ||n|i i j} | } t } | ojoc i oYi |i|jo9tidt|i |i|fqNn oC }|i}ti|}|i i j} t} t } n[ioid|nio/xB|dD]} | dj oPq'q'WdSnd|djodSt} t} t} o[ |i}|tjoii}qti|i} | i|nii}ioidt ||nti|}ti|}||_ ii|_ i|| pox| o i |_ | i|R&RRRR'RQR0RR t new_instanceRRtsetup_instanceR~thash_keyt session_idRmtprogresstpartialsRt _run_on_loadRv(R5R"Rmt discriminatort _instancet identitykeyRRRRt currentloadtloaded_instancetxRtd_tattrs(RRtpolymorphic_instancesR5RTRRvtpopulate_existingR&RRRutsession_identity_mapRR(s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyR6s            4              $ +N(RVRR5Rt PopulateDictt_configure_subclass_mapperR&RRkR~RR.RRR%( RTRRR6tpolymorphic_fromR.RvRutpolymorphic_discriminatorRRR((RRRRRRRuRTR5RRvRR&RRRRRR6RRs9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt_instance_processors6   (   9c Csgg}}xz|iiD]i}|i|||||\}} |o|i|i|fn| o|i|i| fqqW||fS(s@Produce a collection of attribute level row processor callables.(RRtcreate_row_processorRvR( RTRRR5R6RRRtnewpopt existingpop((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRs !csfd}|S(sVProduce a mapper level row processor callable factory for mappers inheriting this one.c sbyi|}Wn#tj otd|nX|jodS|idS(Ns*No such polymorphic_identity %r is definedR(RHR?RRR(RRr(RTRRR6(s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pytconfigure_subclass_mappers ((RTRRR6R((RRTR6Rs9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRsN(GRbRKt__doc__RR(RQRYRLRMRNRRPRORRRZRRRRSRRRRRRRR[RR RRRtmemoized_propertyRRRRRURR]RRR+R/RRdRR,R7R8R:R<R9R;RBR>RDRFRERZR^R^RzRRRRRRR(((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRAs l R  J < 8 c 2             &                 1 "   :  cCs t|_|S(sDecorate a method as the 'reconstructor' hook. Designates a method as the "reconstructor", an ``__init__``-like method that will be called by the ORM after the instance has been loaded from the database or otherwise reconstituted. The reconstructor will be invoked with no arguments. Scalar (non-collection) database-mapped attributes of the instance will be available for use within the function. Eagerly-loaded collections are generally not yet available and will usually only contain the first element. ORM state changes made to objects at this stage will not be recorded for the next flush() operation, so the activity within a reconstructor should be conservative. (RQR~(tfn((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt reconstructors csfd}|S(sDecorate a method as a 'validator' for one or more named properties. Designates a method as a validator, a method which receives the name of the attribute as well as a value to be assigned, or in the case of a collection to be added to the collection. The function can then raise validation exceptions to halt the process from continuing, or can modify or replace the value before proceeding. The function should otherwise return the given value. cs |_|S(N(R(R(tnames(s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pytwraps ((RR((Rs9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyt validatess cCs]|iit}|id|ijo/|ii||i|iii|||ndS(s7Trigger mapper compilation and run init_instance hooks.t init_instanceN( RRRRZR.RRRt original_init(RRtargstkwargstinstrumenting_mapper((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRs    cCsY|iit}d|ijo5ti|ii||i|iii |||ndS(sRun init_failed hooks.t init_failedN( RRRR.Rtwarn_exceptionRRRR(RRRRR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRs   cCsQ|iit}x:t|i|idD]\}}|i|||q*WdS(Ni(RRRtzipRVRRD(RRRRtval((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRs cCst|dtidS(NRtsort_key(tsortedRt attrgetter(R((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRyscCs>t|}t|}|ptidt|nt|}t}|ioY|i oN|i ||}|o1|i |i |i dd|d|}qn|tjoK|o |i}n|i|}|i |i |d|d|}n|o*|djotidt|ndS(s4initiate a column-based attribute refresh operation.sQInstance %s is not bound to a Session; attribute refresh operation cannot proceedRvRusInstance '%s' has been deleted.N(Rt_state_sessionR=tUnboundExecutionErrorRRR(R*R'RZRtfrom_statementRRRR<RtObjectDeletedError(RRVRrR~thas_keyR"RR((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pyRs$    5  ((ARRtweakrefRt itertoolsRt __import__R0t sqlalchemyRRRRR=tsqlalchemy.sqlRRRRetsqlalchemy.ormR R tsqlalchemy.orm.interfacesR R R tsqlalchemy.orm.utilRRRRRRRRt__all__tWeakKeyDictionaryRR(RRRRutsymbolRt threadingtRLockRRRRRtRelationPropertyRRR tobjectRt class_loggerRRRRRRyR(((s9/usr/lib/python2.6/site-packages/sqlalchemy/orm/mapper.pytsT   "":