ÿØÿàJFIFÿþ ÿÛC       ÿÛC ÿÀÿÄÿÄ"#QrÿÄÿÄ&1!A"2qQaáÿÚ ?Øy,æ/3JæÝ¹È߲؋5êXw²±ÉyˆR”¾I0ó2—PI¾IÌÚiMö¯–þrìN&"KgX:Šíµ•nTJnLK„…@!‰-ý ùúmë;ºgµŒ&ó±hw’¯Õ@”Ü— 9ñ-ë.²1<yà‚¹ïQÐU„ہ?.’¦èûbß±©Ö«Âw*VŒ) `$‰bØÔŸ’ëXÖ-ËTÜíGÚ3ð«g Ÿ§¯—Jx„–’U/ÂÅv_s(Hÿ@TñJÑãõçn­‚!ÈgfbÓc­:él[ðQe 9ÀPLbÃãCµm[5¿ç'ªjglå‡Ûí_§Úõl-;"PkÞÞÁQâ¼_Ñ^¢SŸx?"¸¦ùY騐ÒOÈ q’`~~ÚtËU¹CڒêV  I1Áß_ÿÙ 4]c@sdZddlZddlZddlZddlmZddlmZddlmZddlmZddlm Z dd lm Z dd lm Z dd l mZdd l mZdd l mZddl mZddl mZddl mZddl mZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZddlmZ ddddgZ!ej"Z#dZ$de%fd YZ&ej'd!Z(ej'd"Z)ej'd#Z*ej'd$Z+ej'd%Z,de%fd&YZ-de&fd'YZ.de&fd(YZ/d)Z0d*Z1d+Z2d,Z3ej4Z5dS(-s1Provides the Session class and related utilities.iNi(t attributes(texc(tidentity(tloading(t persistence(tquery(tstate(t_class_to_mapper(t _none_set(t _state_mapper(t instance_str(t object_mapper(t object_state(t state_str(tSessionExtension(tUOWTransactioni(tengine(tsql(tutil(tinspect(t expressiontSessiontSessionTransactionRt sessionmakercCs3|jr/yt|jSWq/tk r+q/XndS(s_Given an :class:`.InstanceState`, return the :class:`.Session` associated, if any. N(t session_idt _sessionstKeyErrortNone(R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt_state_session.s   t_SessionClassMethodscBs\eZdZeejdddZeejddZedZ RS(sBClass-level methods for :class:`.Session`, :class:`.sessionmaker`.s1.3sThe :meth:`.Session.close_all` method is deprecated and will be removed in a future release. Please refer to :func:`.session.close_all_sessions`.cCs tdS(sClose *all* sessions in memory.N(tclose_all_sessions(tcls((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt close_all=s ssqlalchemy.orm.utilcOs|j||S(sZReturn an identity key. This is an alias of :func:`.util.identity_key`. (t identity_key(Rtorm_utiltargstkwargs((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR!IscCs t|S(sxReturn the :class:`.Session` to which an object belongs. This is an alias of :func:`.object_session`. (tobject_session(Rtinstance((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR%Ss( t__name__t __module__t__doc__t classmethodRt deprecatedR t dependenciesR!R%(((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR:s  tACTIVEtPREPAREDt COMMITTEDtDEACTIVEtCLOSEDcBseZdZdZdedZedZeZ edZ eeeddZ edZ ddZ edZdd Zd Zed Zd Zd ZdZdZdZedZedZdZdZRS(sA :class:`.Session`-level transaction. :class:`.SessionTransaction` is a mostly behind-the-scenes object not normally referenced directly by application code. It coordinates among multiple :class:`.Connection` objects, maintaining a database transaction for each one individually, committing or rolling them back all at once. It also provides optional two-phase commit behavior which can augment this coordination operation. The :attr:`.Session.transaction` attribute of :class:`.Session` refers to the current :class:`.SessionTransaction` object in use, if any. The :attr:`.SessionTransaction.parent` attribute refers to the parent :class:`.SessionTransaction` in the stack of :class:`.SessionTransaction` objects. If this attribute is ``None``, then this is the top of the stack. If non-``None``, then this :class:`.SessionTransaction` refers either to a so-called "subtransaction" or a "nested" transaction. A "subtransaction" is a scoping concept that demarcates an inner portion of the outermost "real" transaction. A nested transaction, which is indicated when the :attr:`.SessionTransaction.nested` attribute is also True, indicates that this :class:`.SessionTransaction` corresponds to a SAVEPOINT. **Life Cycle** A :class:`.SessionTransaction` is associated with a :class:`.Session` in its default mode of ``autocommit=False`` immediately, associated with no database connections. As the :class:`.Session` is called upon to emit SQL on behalf of various :class:`.Engine` or :class:`.Connection` objects, a corresponding :class:`.Connection` and associated :class:`.Transaction` is added to a collection within the :class:`.SessionTransaction` object, becoming one of the connection/transaction pairs maintained by the :class:`.SessionTransaction`. The start of a :class:`.SessionTransaction` can be tracked using the :meth:`.SessionEvents.after_transaction_create` event. The lifespan of the :class:`.SessionTransaction` ends when the :meth:`.Session.commit`, :meth:`.Session.rollback` or :meth:`.Session.close` methods are called. At this point, the :class:`.SessionTransaction` removes its association with its parent :class:`.Session`. A :class:`.Session` that is in ``autocommit=False`` mode will create a new :class:`.SessionTransaction` to replace it immediately, whereas a :class:`.Session` that's in ``autocommit=True`` mode will remain without a :class:`.SessionTransaction` until the :meth:`.Session.begin` method is called. The end of a :class:`.SessionTransaction` can be tracked using the :meth:`.SessionEvents.after_transaction_end` event. **Nesting and Subtransactions** Another detail of :class:`.SessionTransaction` behavior is that it is capable of "nesting". This means that the :meth:`.Session.begin` method can be called while an existing :class:`.SessionTransaction` is already present, producing a new :class:`.SessionTransaction` that temporarily replaces the parent :class:`.SessionTransaction`. When a :class:`.SessionTransaction` is produced as nested, it assigns itself to the :attr:`.Session.transaction` attribute, and it additionally will assign the previous :class:`.SessionTransaction` to its :attr:`.Session.parent` attribute. The behavior is effectively a stack, where :attr:`.Session.transaction` refers to the current head of the stack, and the :attr:`.SessionTransaction.parent` attribute allows traversal up the stack until :attr:`.SessionTransaction.parent` is ``None``, indicating the top of the stack. When the scope of :class:`.SessionTransaction` is ended via :meth:`.Session.commit` or :meth:`.Session.rollback`, it restores its parent :class:`.SessionTransaction` back onto the :attr:`.Session.transaction` attribute. The purpose of this stack is to allow nesting of :meth:`.Session.rollback` or :meth:`.Session.commit` calls in context with various flavors of :meth:`.Session.begin`. This nesting behavior applies to when :meth:`.Session.begin_nested` is used to emit a SAVEPOINT transaction, and is also used to produce a so-called "subtransaction" which allows a block of code to use a begin/rollback/commit sequence regardless of whether or not its enclosing code block has begun a transaction. The :meth:`.flush` method, whether called explicitly or via autoflush, is the primary consumer of the "subtransaction" feature, in that it wishes to guarantee that it works within in a transaction block regardless of whether or not the :class:`.Session` is in transactional mode when the method is called. Note that the flush process that occurs within the "autoflush" feature as well as when the :meth:`.Session.flush` method is used **always** creates a :class:`.SessionTransaction` object. This object is normally a subtransaction, unless the :class:`.Session` is in autocommit mode and no transaction exists at all, in which case it's the outermost transaction. Any event-handling logic or other inspection logic needs to take into account whether a :class:`.SessionTransaction` is the outermost transaction, a subtransaction, or a "nested" / SAVEPOINT transaction. .. seealso:: :meth:`.Session.rollback` :meth:`.Session.commit` :meth:`.Session.begin` :meth:`.Session.begin_nested` :attr:`.Session.is_active` :meth:`.SessionEvents.after_transaction_create` :meth:`.SessionEvents.after_transaction_end` :meth:`.SessionEvents.after_commit` :meth:`.SessionEvents.after_rollback` :meth:`.SessionEvents.after_soft_rollback` cCs||_i|_||_||_t|_| rL|rLtjdn|jjre|j n|jj j |j|dS(NsOCan't start a SAVEPOINT transaction when no existing transaction is in progress( tsessiont _connectionst_parenttnestedR-t_statetsa_exctInvalidRequestErrort_enable_transaction_accountingt_take_snapshottdispatchtafter_transaction_create(tselfR2tparentR5((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt__init__s         cCs|jS(sjThe parent :class:`.SessionTransaction` of this :class:`.SessionTransaction`. If this attribute is ``None``, indicates this :class:`.SessionTransaction` is at the top of the stack, and corresponds to a real "COMMIT"/"ROLLBACK" block. If non-``None``, then this is either a "subtransaction" or a "nested" / SAVEPOINT transaction. If the :attr:`.SessionTransaction.nested` attribute is ``True``, then this is a SAVEPOINT, and if ``False``, indicates this a subtransaction. .. versionadded:: 1.0.16 - use ._parent for previous versions (R4(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR>scCs|jdk o|jtkS(N(R2RR6R-(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt is_activessThis transaction is closedcCs|jtkr!tjdn|jtkrK|stjdqn|jtkr| r| r|jrtjd|jddq|stjdqqn!|jtkrtj|ndS(Ns\This session is in 'committed' state; no further SQL can be emitted within this transaction.s[This session is in 'prepared' state; no further SQL can be emitted within this transaction.sThis Session's transaction has been rolled back due to a previous exception during flush. To begin a new transaction with this Session, first issue Session.rollback(). Original exception was: %stcodet7s2asThis session is in 'inactive' state, due to the SQL transaction being rolled back; no further SQL can be emitted within this transaction.( R6R/R7R8R.R0t_rollback_exceptionR1tResourceClosedError(R=t prepared_okt rollback_okt deactive_okt closed_msg((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt_assert_active s&    cCs|jp|j S(N(R5R4(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt_is_transaction_boundary2scKs/|j|jj||}|j||S(N(RIR2tget_bindt_connection_for_bind(R=tbindkeytexecution_optionsR$tbind((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt connection6s cCs |jt|j|d|S(NR5(RIRR2(R=R5((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt_begin;s cCsk|}d}xX|rf||f7}|j|kr5Pq|jdkrZtjd|q|j}qW|S(Ns4Transaction %s is not on the active transaction list((R4RR7R8(R=tuptotcurrenttresult((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt_iterate_self_and_parents?s    cCs|jsI|jj|_|jj|_|jj|_|jj|_dS|jjse|jjnt j |_t j |_t j |_t j |_dS(N( RJR4t_newt_deletedt_dirtyt _key_switchesR2t _flushingtflushtweakreftWeakKeyDictionary(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR:Qs  cCsX|jstt|jj|jj}|jj|dtxa|jj D]P\}\}}|jj j |||_ ||krS|jj j |qSqSWx<t|jj|jjD]}|jj|dtqW|jj stxX|jj jD]D}| s1|js1||jkr |j|j|jj jq q WdS(smRestore the restoration state taken before a transaction began. Corresponds to a rollback. t to_transienttrevert_deletionN(RJtAssertionErrortsetRVtunionR2t_expunge_statestTrueRYtitemst identity_mapt safe_discardtkeytreplaceRWt _update_implt all_statestmodifiedRXt_expiretdictt _modified(R=t dirty_onlyt to_expungetstoldkeytnewkey((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt_restore_snapshotas"  %cCs|jst|j r|jjrx6|jjjD]"}|j|j|jjj q8Wt j j t |j|j|jjnd|jr|jjj|j|jjj|j|jjj|j|jjj|jndS(sjRemove the restoration state taken before a transaction began. Corresponds to a commit. N(RJR`R5R2texpire_on_commitRfRkRmRnRotstatelibt InstanceStatet_detach_statestlistRWtclearR4RVtupdateRXRY(R=Rr((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt_remove_snapshots   cCsg|j||jkr>|r/tjdn|j|dS|jrl|jj||}|js|SnKt|tj r|}|j|jkrt j dqn |j }|r|j |}n|jjr|jdkr|j}n$|jr|j}n |j}||||k f|j|<|j|j<|jjj|j|||S(NsOConnection is already established for the given bind; execution_options ignoredisMSession already has a Connection associated for the given Connection's Engine(RIR3RtwarnR4RLR5t isinstanceRt ConnectionR7R8t_contextual_connectRNR2ttwophaseRtbegin_twophaset begin_nestedtbeginR;t after_begin(R=RORNtconnt transaction((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRLs8       $cCs<|jdk s|jj r.tjdn|jdS(NsD'twophase' mode not enabled, or not root transaction; can't prepare.(R4RR2RR7R8t _prepare_impl(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pytprepares cCsV|j|jdks"|jr;|jjj|jn|jj}||k r}x'|jd|D]}|j qfWn|jj sxFt dD]&}|jj rPn|jj qWtjdn|jdkrI|jjrIy2x+t|jjD]}|djqWWqItj|jWdQXqIXnt|_dS(NRRidsrOver 100 subsequent flushes have occurred within session.commit() - is an after_flush() hook creating new objects?i(RIR4RR5R2R;t before_commitRRUtcommitRZtranget _is_cleanR[Rt FlushErrorRRaR3tvaluesRRt safe_reraisetrollbackR.R6(R=tstxtsubtransactiont _flush_guardtt((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRs,      cCs|jdt|jtk r,|jn|jdksD|jrx+t|j j D]}|dj qZWt |_|j jj|j |j jr|jqn|j|jS(NREi(RIRdR6R.RR4RR5RaR3RRR/R2R;t after_commitR9R}tclose(R=R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRs    c Cs|jdtdt|jj}||k rXx'|jd|D]}|jqAWn|}d}|jtt fkrXx|jD]}|j dks|j rHzkyQx+t |j jD]}|djqWt|_|jjj|jWntj}nXWdt|_|jjr=|jd|j nX|}Pqt|_qWn|j}| r|jr|j rtjd|jd|j n|j|j r|rtjd|j _n|rtj|n|jj|||j S(NRERFRRiRps\Session's state has been changed on a non-active transaction - this state will be discarded.(RIRdR2RRURRR6R-R.R4R5RaR3RRR0R;tafter_rollbacktsystexc_infoR9RuRRR~RCtreraisetafter_soft_rollback( R=t_capture_exceptionRRtboundaryt rollback_errRRtsess((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRsN          cCs|j|j_|jdkrzxYt|jjD]?\}}}|rV|jn|ri|jq4|jq4Wnt |_ |jj j |j||jdkr|jj s|jjqnd|_d|_dS(N(R4R2RRRaR3Rt invalidateRR1R6R;tafter_transaction_endt autocommitR(R=RRPRt autoclose((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR:s      cCs|S(N((R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt __enter__PscCs~|jdtdt|jjdkr,dS|dkrpy|jWqztj|jWdQXqzXn |jdS(NRGRE( RIRdR2RRRRRR(R=ttype_tvaluet traceback((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt__exit__Ss  N(R'R(R)RRCtFalseR?tpropertyR>R5R@RIRJRPRQRUR:RuR}RLRRRRRRR(((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRes2s "      ,   =  cBsneZdZdgZejddhddid!djdkeeeeedkdkdkedkdkd# Z dkZ dkZ ej d$Z eed%Zd&Zd'Zd(Zd)Zdkdkdkedkd*Zdkd+Zdkdkdkd,Zdkdkdkd-Zd.Zd/Zd0Zd1Zd2Zd3Zd4Zdkdkd5Zd6Ze ej!d7Z"d8Z#dkdkdkd9Z$d:Z%dkd;Z&d<Z'd=Z(ej)dd>d?Z*d@Z+edAZ,dBZ-dCZ.dDZ/edEZ0dFZ1dGZ2dHZ3dIZ4edJZ5edkdkdKZ6dLZ7dMZ8edNZ9dOZ:dPZ;dQZ<dRZ=dSZ>dTZ?dUZ@dkdVZAdWZBdXZCdkdYZDeeedZZEeed[ZFd\ZGd]ZHejd^dledkdaZIe dbZJdkZKe dcZLe ddZMe deZNe dfZORS(msManages persistence operations for ORM-mapped objects. The Session's usage paradigm is described at :doc:`/orm/session`. t __contains__t__iter__taddtadd_allRRRRRPtdeletetexecutetexpiret expire_alltexpunget expunge_allR[RKt is_modifiedtbulk_save_objectstbulk_insert_mappingstbulk_update_mappingstmergeRtrefreshRtscalartweak_identity_maps1.0sThe :paramref:`.Session.weak_identity_map` parameter as well as the strong-referencing identity map are deprecated, and will be removed in a future release. For the use case where objects present in a :class:`.Session` need to be automatically strong referenced, see the recipe at :ref:`session_referencing_behavior` for an event-based approach to maintaining strong identity references. R9s0.7sxThe :paramref:`.Session._enable_transaction_accounting` parameter is deprecated and will be removed in a future release.t extensions:class:`.SessionExtension` is deprecated in favor of the :class:`.SessionEvents` listener interface. The :paramref:`.Session.extension` parameter will be removed in a future release.c Cs|tdfkr!tj|_n tj|_|j|_i|_i|_||_ i|_ t |_ t |_ d|_t|_||_||_||_| |_||_||_| r| ntj|_| r|jj| n| r!x*tj| D]} tj|| qWn|dk r]x-|j D]\}}|j!||q:Wn|jss|j"n|t#|jClose this Session. This clears all items and ends any transaction in progress. If this session were created with ``autocommit=False``, a new transaction is immediately begun. Note that this new transaction does not use any connection resources until they are first needed. RN(t _close_implR(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRs cCs|jdtdS(sClose this Session, using connection invalidation. This is a variant of :meth:`.Session.close` that will additionally ensure that the :meth:`.Connection.invalidate` method will be called on all :class:`.Connection` objects. This can be called when the database is known to be in a state where the connections are no longer safe to be used. E.g.:: try: sess = Session() sess.add(User()) sess.commit() except gevent.Timeout: sess.invalidate() raise except: sess.rollback() raise This clears all items and ends any transaction in progress. If this session were created with ``autocommit=False``, a new transaction is immediately begun. Note that this new transaction does not use any connection resources until they are first needed. .. versionadded:: 0.9.9 RN(RRd(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR scCsG|j|jdk rCx'|jjD]}|j|q)WndS(N(RRRRUR(R=RR((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR,s cCsT|jjt|j}|j|_i|_i|_tjj||dS(sRemove all object instances from this ``Session``. This is equivalent to calling ``expunge(obj)`` on all objects in this ``Session``. N( RfRkRzRVRRWRwRxRy(R=Rk((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR2s   cCsyt|}WnFtjk rXt|tsHtjd|q||j||jr,|jStjdn|dk ryt|}Wqtjk rt|trtj |qqXn|j r?|rx.|j j D] }||j kr|j |SqW|dkr|j }qn|dk r?x:tj|dtD] }||j kr|j |SqWq?n|jrO|jSt|tjjrt|jrt|jS|r|j jr|j jSg}|dk r|jd|n|dk r|jdntjddj|dS(s Return a "bind" to which this :class:`.Session` is bound. The "bind" is usually an instance of :class:`.Engine`, except in the case where the :class:`.Session` has been explicitly bound directly to a :class:`.Connection`. For a multiply-bound or unbound :class:`.Session`, the ``mapper`` or ``clause`` arguments are used to determine the appropriate bind to return. Note that the "mapper" argument is usually present when :meth:`.Session.get_bind` is called via an ORM operation such as a :meth:`.Session.query`, each individual INSERT/UPDATE/DELETE operation within a :meth:`.Session.flush`, call, etc. The order of resolution is: 1. if mapper given and session.binds is present, locate a bind based first on the mapper in use, then on the mapped class in use, then on any base classes that are present in the ``__mro__`` of the mapped class, from more specific superclasses to more general. 2. if clause given and session.binds is present, locate a bind based on :class:`.Table` objects found in the given clause present in session.binds. 3. if session.bind is present, return that. 4. if clause given, attempt to return a bind linked to the :class:`.MetaData` ultimately associated with the clause. 5. if mapper given, attempt to return a bind linked to the :class:`.MetaData` ultimately associated with the :class:`.Table` or other selectable to which the mapper is mapped. 6. No bind can be found, :exc:`~sqlalchemy.exc.UnboundExecutionError` is raised. Note that the :meth:`.Session.get_bind` method can be overridden on a user-defined subclass of :class:`.Session` to provide any kind of bind resolution scheme. See the example at :ref:`session_custom_partitioning`. :param mapper: Optional :func:`.mapper` mapped class or instance of :class:`.Mapper`. The bind can be derived from a :class:`.Mapper` first by consulting the "binds" map associated with this :class:`.Session`, and secondly by consulting the :class:`.MetaData` associated with the :class:`.Table` to which the :class:`.Mapper` is mapped for a bind. :param clause: A :class:`.ClauseElement` (i.e. :func:`~.sql.expression.select`, :func:`~.sql.expression.text`, etc.). If the ``mapper`` argument is not present or could not produce a bind, the given expression construct will be searched for a bound element, typically a :class:`.Table` associated with bound :class:`.MetaData`. .. seealso:: :ref:`session_partitioning` :paramref:`.Session.binds` :meth:`.Session.bind_mapper` :meth:`.Session.bind_table` slThis session is not bound to a single Engine or Connection, and no context was provided to locate a binding.t include_cruds mapper %ssSQL expressions8Could not locate a bind configured on %s or this Sessions, N(RROR7tUnboundExecutionErrorRRRRRtUnmappedClassErrorRRt__mro__tpersist_selectabletsql_utilt find_tablesRdRRt ClauseElementtappendtjoin(R=RRRRtcontext((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRKsJG           cOs|j|||S(sTReturn a new :class:`.Query` object corresponding to this :class:`.Session`.(R(R=tentitiesR$((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRsccs,|j}t|_z |VWd||_XdS(sgReturn a context manager that disables autoflush. e.g.:: with session.no_autoflush: some_object = SomeClass() session.add(some_object) # won't autoflush some_object.related_thing = session.query(SomeRelated).first() Operations that proceed within the ``with:`` block will not be subject to flushes occurring upon query access. This is useful when initializing a series of objects which involve existing database queries, where the uncompleted object should not yet be flushed. N(RR(R=R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt no_autoflush s    cCs[|jrW|j rWy|jWqWtjk rS}|jdtj|qWXndS(Nsraised as a result of Query-invoked autoflush; consider using a session.no_autoflush block if this flush is occurring prematurely(RRZR[R7tStatementErrort add_detailRtraise_from_cause(R=te((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt _autoflush&sc Cs&ytj|}Wn#tjk r8tj|nX|j|||ikrgtjdn|rtj j |}nH|dk r|t krtj }q|rtj |}qd}nt j|jt||jd|d|d|dkr"tjdt|ndS(s9Expire and refresh the attributes on the given instance. A query will be issued to the database and all attributes will be refreshed with their current database value. Lazy-loaded relational attributes will remain lazily loaded, so that the instance-wide refresh operation will be followed immediately by the lazy load of that attribute. Eagerly-loaded relational attributes will eagerly load within the single refresh operation. Note that a highly isolated transaction will return the same values as were previously read in that same transaction, regardless of changes in database state outside of that transaction - usage of :meth:`~Session.refresh` usually only makes sense if non-ORM SQL statement were emitted in the ongoing transaction, or if autocommit mode is turned on. :param attribute_names: optional. An iterable collection of string attribute names indicating a subset of attributes to be refreshed. :param with_for_update: optional boolean ``True`` indicating FOR UPDATE should be used, or may be a dictionary containing flags to indicate a more specific set of FOR UPDATE flags for the SELECT; flags should match the parameters of :meth:`.Query.with_for_update`. Supersedes the :paramref:`.Session.refresh.lockmode` parameter. .. versionadded:: 1.2 :param lockmode: Passed to the :class:`~sqlalchemy.orm.query.Query` as used by :meth:`~sqlalchemy.orm.query.Query.with_lockmode`. Superseded by :paramref:`.Session.refresh.with_for_update`. .. seealso:: :ref:`session_expire` - introductory material :meth:`.Session.expire` :meth:`.Session.expire_all` sqwith_for_update should be the boolean value True, or a dictionary with options. A blank dictionary is ambiguous.t refresh_statetwith_for_updatetonly_load_propssCould not refresh instance '%s'N(Rtinstance_stateRtNO_STATEtUnmappedInstanceErrort _expire_stateR7RRt LockmodeArgtparse_legacy_queryRRdRt load_on_identR RhR8R (R=R&tattribute_namesRtlockmodeR((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR6s23       cCs7x0|jjD]}|j|j|jjqWdS(sExpires all persistent instances within this Session. When any attributes on a persistent instance is next accessed, a query will be issued using the :class:`.Session` object's current transactional context in order to load all expired attributes for the given instance. Note that a highly isolated transaction will return the same values as were previously read in that same transaction, regardless of changes in database state outside of that transaction. To expire individual objects and individual attributes on those objects, use :meth:`Session.expire`. The :class:`.Session` object's default behavior is to expire all state whenever the :meth:`Session.rollback` or :meth:`Session.commit` methods are called, so that new state can be loaded for the new transaction. For this reason, calling :meth:`Session.expire_all` should not be needed when autocommit is ``False``, assuming the transaction is isolated. .. seealso:: :ref:`session_expire` - introductory material :meth:`.Session.expire` :meth:`.Session.refresh` N(RfRkRmRnRo(R=R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRscCsMytj|}Wn#tjk r8tj|nX|j||dS(sExpire the attributes on an instance. Marks the attributes of an instance as out of date. When an expired attribute is next accessed, a query will be issued to the :class:`.Session` object's current transactional context in order to load all expired attributes for the given instance. Note that a highly isolated transaction will return the same values as were previously read in that same transaction, regardless of changes in database state outside of that transaction. To expire all objects in the :class:`.Session` simultaneously, use :meth:`Session.expire_all`. The :class:`.Session` object's default behavior is to expire all state whenever the :meth:`Session.rollback` or :meth:`Session.commit` methods are called, so that new state can be loaded for the new transaction. For this reason, calling :meth:`Session.expire` only makes sense for the specific case that a non-ORM SQL statement was emitted in the current transaction. :param instance: The instance to be refreshed. :param attribute_names: optional list of string attribute names indicating a subset of attributes to be expired. .. seealso:: :ref:`session_expire` - introductory material :meth:`.Session.expire` :meth:`.Session.refresh` N(RRRRRR(R=R&RR((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRs #cCs|j||r)|j|j|nUt|jjjd|}|j|x'|D]\}}}}|j|q[WdS(Nsrefresh-expire(t_validate_persistentt_expire_attributesRnRztmanagerRtcascade_iteratort_conditional_expire(R=RRtcascadedtotmtst_tdct_((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRs  cCsX|jr%|j|j|jjn/||jkrT|jj||j|ndS(s5Expire a state if persistent, else expunge if pendingN(RhRmRnRfRoRVtpopt_detach(R=R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR s  sThe :meth:`.Session.prune` method is deprecated along with :paramref:`.Session.weak_identity_map`. This method will be removed in a future release.cCs |jjS(sRemove unreferenced instances cached in the identity map. Note that this method is only meaningful if "weak_identity_map" is set to False. The default weak identity map is self-pruning. Removes any object in this Session's identity map that is not referenced in user code, modified, new or scheduled for deletion. Returns the number of objects pruned. (Rftprune(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRscCsytj|}Wn#tjk r8tj|nX|j|jk rgtjdt |nt |j j j d|}|j|gg|D]\}}}}|^qdS(sRemove the `instance` from this ``Session``. This will free all internal references to the instance. Cascading will be applied according to the *expunge* cascade rule. s*Instance %s is not present in this SessionRN(RRRRRRRR7R8R RzRRRRc(R=R&RR R R R R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRscCsx|D]}||jkr/|jj|q|jj|rg|jj||jj|dq|jr|jjj|dqqWtj j ||d|dS(NR^( RVRRftcontains_stateRgRWRRRwRxRy(R=tstatesR^R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRcs   cCs|jjpd}x7|D]/}t|}|j}|dk r|j|}tj|dro|j stj |drt j dt |n|j dkr||_ ns|j |kr,|jj|||jjkr|jj|d}n |j }||f|jj|<||_ n|jj|t|_qqWtjjd|D|j|j||dk rx0|j|jD]}|||jqWnx0t|j|jD]}|jj|qWdS(sRegister all persistent objects from a flush. This is used both for pending objects moving to the persistent state as well as already persistent objects. isOInstance %s has a NULL identity key. If this is an auto-generated value, check that the database table allows generation of new primary key values, and that the mapped Column object is configured to expect these generated values. Ensure also that this flush() is not occurring at an inappropriate time, such as within a load() event.icss|]}||jfVqdS(N(Rn(t.0R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pys asN(R;tpending_to_persistentRR tobjt_identity_key_from_stateRt intersectiontallow_partial_pkst issupersetRRR RhRfRgRRYRiRt_orphaned_outside_of_sessionRwRxt_commit_all_statest_register_alteredRVRaR(R=RRRRRt instance_keytorig_key((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt_register_persistent's@           cCs\|jrX|jrXxC|D]8}||jkrAt|jj|WdS(Ns save-updatethalt_on(RRt_save_or_update_implR Rt_contains_state(R=RRR R R R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR$s     %cCsl|jr|jdnytj|}Wn#tjk rQtj|nX|j||dtdS(sfMark an instance as deleted. The database delete operation occurs upon ``flush()``. sSession.delete()theadN( RR#RRRRRt _delete_implRd(R=R&R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRs c Cs|jdkr8|r1tjdt|q8dSn|j||}||jkr]dS|jj||r|j ||n|rt |j j j d|}n||j|<|rx0|D]%\}}}} |j||tqWndS(NsInstance '%s' is not persistedR(RhRR7R8R t_before_attachRWRfRt _after_attachRzRRRR+R( R=RRR*t to_attachtcascade_statesR R R R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR+s$ c Cs|jr|jdni}i}|r8|jnt||j}zAt|_|jtj|tj |d|d|d|SWd||_XdS(s Copy the state of a given instance into a corresponding instance within this :class:`.Session`. :meth:`.Session.merge` examines the primary key attributes of the source instance, and attempts to reconcile it with an instance of the same primary key in the session. If not found locally, it attempts to load the object from the database based on primary key, and if none can be located, creates a new instance. The state of each attribute on the source instance is then copied to the target instance. The resulting target instance is then returned by the method; the original source instance is left unmodified, and un-associated with the :class:`.Session` if not already. This operation cascades to associated instances if the association is mapped with ``cascade="merge"``. See :ref:`unitofwork_merging` for a detailed discussion of merging. .. versionchanged:: 1.1 - :meth:`.Session.merge` will now reconcile pending objects with overlapping primary keys in the same way as persistent. See :ref:`change_3601` for discussion. :param instance: Instance to be merged. :param load: Boolean, when False, :meth:`.merge` switches into a "high performance" mode which causes it to forego emitting history events as well as all database access. This flag is used for cases such as transferring graphs of objects into a :class:`.Session` from a second level cache, or to transfer just-loaded objects into the :class:`.Session` owned by a worker thread or process without re-querying the database. The ``load=False`` use case adds the caveat that the given object has to be in a "clean" state, that is, has no pending changes to be flushed - even if the incoming object is detached from any :class:`.Session`. This is so that when the merge operation populates local attributes and cascades to related objects and collections, the values can be "stamped" onto the target object as is, without generating any history or attribute events, and without the need to reconcile the incoming data with any existing related objects or collections that might not be loaded. The resulting objects from ``load=False`` are always produced as "clean", so it is only appropriate that the given objects should be "clean" as well, else this suggests a mis-use of the method. .. seealso:: :func:`.make_transient_to_detached` - provides for an alternative means of "merging" a single object into the :class:`.Session` sSession.merge()tloadt _recursivet_resolve_conflict_mapN( RR#RR RRt_mergeRRt instance_dict(R=R&R0R1R2R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRs"7       c Cst|}||kr ||St}|j}|dkr||jkrdtjdt|n|s|tj dn|j |}t j |dkot j|d p|jot j|d } nt} ||jkry|j|} Wqtk rd} qXnd} | dkr| rF||krF||} q|s|jrgtj dn|jj} t j| } || _|j| t}q| r|j|jj|d} qn| dkr|jj} t j| } t j| } t}|j| nt j| } t j| } | ||<| ||<|| k r]|jdk r|j|||jdt j } |j| | |jdt j }| t j!k r|t j!k r| |krt"j#d| t| |fqn|j$| _$|j%| _%| j&|x6|j'D](}|j(|||| | |||q.Wn|sy| j)| |jn|r| j*j+j,| dn| S(NsrInstance %s is already pending in this Session yet is being merged again; this is probably not what you want to dosmerge() with load=False option does not support objects transient (i.e. unpersisted) objects. flush() all changes on mapped instances before merging with load=False.ismerge() with load=False option does not support objects marked as 'dirty'. flush() all changes on mapped instances before merging with load=False.tpassivesVersion id '%s' on merged state %s does not match existing version '%s'. Leave the version attribute unset when merging to update the most recent version.(-R RRhRRVRR~R R7R8RRt NEVER_SETRRRRRdRfRRlt class_managert new_instanceRRjRRtgetR4R$tversion_id_colt_get_state_attr_by_columntPASSIVE_NO_INITIALIZEtPASSIVE_NO_RESULTRtStaleDataErrort load_patht load_optionst_copy_callablestiterate_propertiesRt _commit_allRR;R0(R=Rt state_dictR0R1R2RR8Rhtkey_is_persistenttmergedt merged_statet merged_dicttexisting_versiontmerged_versiontprop((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR32s               %             cCs2|jj|s.tjdt|ndS(Ns3Instance '%s' is not persistent within this Session(RfRR7R8R (R=R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRscCs|jdk r+tjdt|n|j}|j||}||jkrz||j|Object '%s' is already attached to session '%s' (this is '%s')( RRRRR7R8R R;t before_attachRd(R=RR((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR,F s"cCsy|j|_|jr0|jdkr0||_n|jj|||jrb|jj||n|jj ||dS(N( RRRlt _strong_objRR;t after_attachRhtdetached_to_persistentttransient_to_pending(R=RR((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR-U s   cCsFytj|}Wn#tjk r8tj|nX|j|S(sReturn True if the instance is associated with this session. The instance may be pending or persistent within the Session for a result of True. (RRRRRR)(R=R&R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR` s cCs,tt|jjt|jjS(sWIterate over all pending or persistent instances within this Session. (titerRzRVRRf(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRm scCs||jkp|jj|S(N(RVRfR(R=R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR)v scCsV|jrtjdn|jr+dSzt|_|j|Wdt|_XdS(sFlush all the object changes to the database. Writes out all pending object creations, deletions and modifications to the database as INSERTs, DELETEs, UPDATEs, etc. Operations are automatically ordered by the Session's unit of work dependency solver. Database operations will be issued in the current transactional context and do not affect the state of the transaction, unless an error occurs, in which case the entire transaction is rolled back. You may flush() as often as you like within a transaction to move changes from Python to the database's transaction buffer. For ``autocommit`` Sessions with no active manual transaction, flush() will create a transaction on the fly that surrounds the entire set of operations into the flush. :param objects: Optional; restricts the flush operation to operate only on elements that are in the given collection. This feature is for an extremely narrow set of use cases where particular objects may need to be operated upon before the full flush() occurs. It is not intended for general use. sSession is already flushingN(RZR7R8RRdt_flushR(R=tobjects((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR[y s   cCstjd|dS(NsUsage of the '%s' operation is not currently supported within the execution stage of the flush process. Results may not be consistent. Consider using alternative event listeners or connection-level operations instead.(RR~(R=tmethod((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR# scCs"|jj o!|j o!|j S(N(Rftcheck_modifiedRWRV(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR s cCs|j}| r8|j r8|j r8|jjjdSt|}|jjrr|jj||||j}nt |j}t |j}t |j |}|rt }x]|D]L}yt j |}Wn#t jk rt j|nX|j|qWnd}t } |rG|j|j|j |} n|j|j |} x| D]}t|j|} | o|j} | r| r|jr|j|gqf|j|d| } | std| j|qfW|r|j|j | } n|j | } x5| D]-}|j|dt} | s(tdq(W|jsfdS|jdt|_}yt|_z|j Wdt!|_X|jj"|||j#| r7|jjr7t$|jj}t%j&j'g|jjD]}||j(f^qd|jt)j*d|n|jj+|||j,Wn*t)j-|j.dtWdQXnXdS(Ntisdeletes*Failed to add object to the flush context!RR4sAttribute history events accumulated on %d previously clean instances within inner-flush event handlers have been reset, and will not result in database updates. Consider using set_committed_value() within inner-flush event handlers to avoid this warning.R(/t _dirty_statesRWRVRfRoR{RR;t before_flushRat differenceRRRRRRRRbRR t _is_orphant has_identityRRctregister_objectR`Rdthas_workRRRRRt after_flushtfinalize_flush_changesRLRwRxRRnRR~tafter_flush_postexecRRR(R=RZtdirtyt flush_contexttdeletedtnewtobjsetR Rt processedtproct is_orphantis_persistent_orphant_regRtlen_((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRY s       $         %   c Csd}td|D}|s:t|d|}nxEtj||D]1\\}}} |j|| |t||tqMWdS(sPerform a bulk save of the given list of objects. The bulk save feature allows mapped objects to be used as the source of simple INSERT and UPDATE operations which can be more easily grouped together into higher performing "executemany" operations; the extraction of data from the objects is also performed using a lower-latency process that ignores whether or not attributes have actually been modified in the case of UPDATEs, and also ignores SQL expressions. The objects as given are not added to the session and no additional state is established on them, unless the ``return_defaults`` flag is also set, in which case primary key attributes and server-side default values will be populated. .. versionadded:: 1.0.0 .. warning:: The bulk save feature allows for a lower-latency INSERT/UPDATE of rows at the expense of most other unit-of-work features. Features such as object management, relationship handling, and SQL clause support are **silently omitted** in favor of raw INSERT/UPDATES of records. **Please read the list of caveats at** :ref:`bulk_operations` **before using this method, and fully test and confirm the functionality of all code developed using these systems.** :param objects: a list of mapped object instances. The mapped objects are persisted as is, and are **not** associated with the :class:`.Session` afterwards. For each object, whether the object is sent as an INSERT or an UPDATE is dependent on the same rules used by the :class:`.Session` in traditional operation; if the object has the :attr:`.InstanceState.key` attribute set, then the object is assumed to be "detached" and will result in an UPDATE. Otherwise, an INSERT is used. In the case of an UPDATE, statements are grouped based on which attributes have changed, and are thus to be the subject of each SET clause. If ``update_changed_only`` is False, then all attributes present within each object are applied to the UPDATE statement, which may help in allowing the statements to be grouped together into a larger executemany(), and will also reduce the overhead of checking history on attributes. :param return_defaults: when True, rows that are missing values which generate defaults, namely integer primary key defaults and sequences, will be inserted **one at a time**, so that the primary key value is available. In particular this will allow joined-inheritance and other multi-table mappings to insert correctly without the need to provide primary key values ahead of time; however, :paramref:`.Session.bulk_save_objects.return_defaults` **greatly reduces the performance gains** of the method overall. :param update_changed_only: when True, UPDATE statements are rendered based on those attributes in each state that have logged changes. When False, all attributes present are rendered into the SET clause with the exception of primary key attributes. :param preserve_order: when True, the order of inserts and updates matches exactly the order in which the objects are given. When False, common types of objects are grouped into inserts and updates, to allow for more batching opportunities. .. versionadded:: 1.3 .. seealso:: :ref:`bulk_operations` :meth:`.Session.bulk_insert_mappings` :meth:`.Session.bulk_update_mappings` cSs|j|jdk fS(N(RRhR(R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRh} scss|]}tj|VqdS(N(RR(RR((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pys sRhN(ttupletsortedt itertoolstgroupbyt_bulk_save_mappingsRdR( R=RZtreturn_defaultstupdate_changed_onlytpreserve_orderRht obj_statesRtisupdateR((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR' sV %cCs#|j||tt|t|dS(sPerform a bulk insert of the given list of mapping dictionaries. The bulk insert feature allows plain Python dictionaries to be used as the source of simple INSERT operations which can be more easily grouped together into higher performing "executemany" operations. Using dictionaries, there is no "history" or session state management features in use, reducing latency when inserting large numbers of simple rows. The values within the dictionaries as given are typically passed without modification into Core :meth:`.Insert` constructs, after organizing the values within them across the tables to which the given mapper is mapped. .. versionadded:: 1.0.0 .. warning:: The bulk insert feature allows for a lower-latency INSERT of rows at the expense of most other unit-of-work features. Features such as object management, relationship handling, and SQL clause support are **silently omitted** in favor of raw INSERT of records. **Please read the list of caveats at** :ref:`bulk_operations` **before using this method, and fully test and confirm the functionality of all code developed using these systems.** :param mapper: a mapped class, or the actual :class:`.Mapper` object, representing the single kind of object represented within the mapping list. :param mappings: a list of dictionaries, each one containing the state of the mapped row to be inserted, in terms of the attribute names on the mapped class. If the mapping refers to multiple tables, such as a joined-inheritance mapping, each dictionary must contain all keys to be populated into all tables. :param return_defaults: when True, rows that are missing values which generate defaults, namely integer primary key defaults and sequences, will be inserted **one at a time**, so that the primary key value is available. In particular this will allow joined-inheritance and other multi-table mappings to insert correctly without the need to provide primary key values ahead of time; however, :paramref:`.Session.bulk_insert_mappings.return_defaults` **greatly reduces the performance gains** of the method overall. If the rows to be inserted only refer to a single table, then there is no reason this flag should be set as the returned default information is not used. :param render_nulls: When True, a value of ``None`` will result in a NULL value being included in the INSERT statement, rather than the column being omitted from the INSERT. This allows all the rows being INSERTed to have the identical set of columns which allows the full set of rows to be batched to the DBAPI. Normally, each column-set that contains a different combination of NULL values than the previous row must omit a different series of columns from the rendered INSERT statement, which means it must be emitted as a separate statement. By passing this flag, the full set of rows are guaranteed to be batchable into one batch; the cost however is that server-side defaults which are invoked by an omitted column will be skipped, so care must be taken to ensure that these are not necessary. .. warning:: When this flag is set, **server side default SQL values will not be invoked** for those columns that are inserted as NULL; the NULL value will be sent explicitly. Care must be taken to ensure that no server-side default functions need to be invoked for the operation as a whole. .. versionadded:: 1.1 .. seealso:: :ref:`bulk_operations` :meth:`.Session.bulk_save_objects` :meth:`.Session.bulk_update_mappings` N(RwR(R=RtmappingsRxt render_nulls((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR sXcCs#|j||tttttdS(sPerform a bulk update of the given list of mapping dictionaries. The bulk update feature allows plain Python dictionaries to be used as the source of simple UPDATE operations which can be more easily grouped together into higher performing "executemany" operations. Using dictionaries, there is no "history" or session state management features in use, reducing latency when updating large numbers of simple rows. .. versionadded:: 1.0.0 .. warning:: The bulk update feature allows for a lower-latency UPDATE of rows at the expense of most other unit-of-work features. Features such as object management, relationship handling, and SQL clause support are **silently omitted** in favor of raw UPDATES of records. **Please read the list of caveats at** :ref:`bulk_operations` **before using this method, and fully test and confirm the functionality of all code developed using these systems.** :param mapper: a mapped class, or the actual :class:`.Mapper` object, representing the single kind of object represented within the mapping list. :param mappings: a list of dictionaries, each one containing the state of the mapped row to be updated, in terms of the attribute names on the mapped class. If the mapping refers to multiple tables, such as a joined-inheritance mapping, each dictionary may contain keys corresponding to all tables. All those keys which are present and are not part of the primary key are applied to the SET clause of the UPDATE statement; the primary key values, which are required, are applied to the WHERE clause. .. seealso:: :ref:`bulk_operations` :meth:`.Session.bulk_insert_mappings` :meth:`.Session.bulk_save_objects` N(RwRdR(R=RR}((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR s/c Cst|}t|_|jdt}z}yL|rOtj|||||ntj|||||||jWn*tj |j dtWdQXnXWdt |_XdS(NRR( RRdRZRRt _bulk_updatet _bulk_insertRRRRR( R=RR}R|tisstatesRxRyR~R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRw$ s0    R5s0.8sThe :paramref:`.Session.is_modified.passive` flag is deprecated and will be removed in a future release. The flag is no longer used and is ignored.c Cst|}|jstS|j}x|jjD]o}| rNt|jds/t|jd rgq/n|jj||dtj \}}} |s| r/t Sq/WtSdS(sZ Return ``True`` if the given instance has locally modified attributes. This method retrieves the history for each instrumented attribute on the instance and performs a comparison of the current value to its previously committed value, if any. It is in effect a more expensive and accurate version of checking for the given instance in the :attr:`.Session.dirty` collection; a full test for each attribute's net "dirty" status is performed. E.g.:: return session.is_modified(someobject) A few caveats to this method apply: * Instances present in the :attr:`.Session.dirty` collection may report ``False`` when tested with this method. This is because the object may have received change events via attribute mutation, thus placing it in :attr:`.Session.dirty`, but ultimately the state is the same as that loaded from the database, resulting in no net change here. * Scalar attributes may not have recorded the previously set value when a new value was applied, if the attribute was not loaded, or was expired, at the time the new value was received - in these cases, the attribute is assumed to have a change, even if there is ultimately no net change against its database value. SQLAlchemy in most cases does not need the "old" value when a set event occurs, so it skips the expense of a SQL call if the old value isn't present, based on the assumption that an UPDATE of the scalar value is usually needed, and in those few cases where it isn't, is less expensive on average than issuing a defensive SELECT. The "old" value is fetched unconditionally upon set only if the attribute container has the ``active_history`` flag set to ``True``. This flag is set typically for primary key attributes and scalar object references that are not a simple many-to-one. To set this flag for any arbitrary mapped column, use the ``active_history`` argument with :func:`.column_property`. :param instance: mapped instance to be tested for pending changes. :param include_collections: Indicates if multivalued collections should be included in the operation. Setting this to ``False`` is a way to detect only local-column based properties (i.e. scalar columns or many-to-one foreign keys) that would result in an UPDATE for this instance upon flush. :param passive: not used tget_collectiont get_historyR5N( R RlRRnRRthasattrtimplRt NO_CHANGERd( R=R&tinclude_collectionsR5Rtdict_tattrtaddedt unchangedRj((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRL s<     cCs|jo|jjS(s+ True if this :class:`.Session` is in "transaction mode" and is not in "partial rollback" state. The :class:`.Session` in its default mode of ``autocommit=False`` is essentially always in "transaction mode", in that a :class:`.SessionTransaction` is associated with it as soon as it is instantiated. This :class:`.SessionTransaction` is immediately replaced with a new one as soon as it is ended, due to a rollback, commit, or close operation. "Transaction mode" does *not* indicate whether or not actual database connection resources are in use; the :class:`.SessionTransaction` object coordinates among zero or more actual database transactions, and starts out with none, accumulating individual DBAPI connections as different data sources are used within its scope. The best way to track when a particular :class:`.Session` has actually begun to use DBAPI resources is to implement a listener using the :meth:`.SessionEvents.after_begin` method, which will deliver both the :class:`.Session` as well as the target :class:`.Connection` to a user-defined event listener. The "partial rollback" state refers to when an "inner" transaction, typically used during a flush, encounters an error and emits a rollback of the DBAPI connection. At this point, the :class:`.Session` is in "partial rollback" and awaits for the user to call :meth:`.Session.rollback`, in order to close out the transaction stack. It is in this "partial rollback" period that the :attr:`.is_active` flag returns False. After the call to :meth:`.Session.rollback`, the :class:`.SessionTransaction` is replaced with a new one and :attr:`.is_active` returns ``True`` again. When a :class:`.Session` is used in ``autocommit=True`` mode, the :class:`.SessionTransaction` is only instantiated within the scope of a flush call, or when :meth:`.Session.begin` is called. So :attr:`.is_active` will always be ``False`` outside of a flush or :meth:`.Session.begin` block in this mode, and will be ``True`` within the :meth:`.Session.begin` block as long as it doesn't enter "partial rollback" state. From all the above, it follows that the only purpose to this flag is for application frameworks that wish to detect is a "rollback" is necessary within a generic error handling routine, for :class:`.Session` objects that would otherwise be in "partial rollback" mode. In a typical integration case, this is also not necessary as it is standard practice to emit :meth:`.Session.rollback` unconditionally within the outermost exception catch. To track the transactional state of a :class:`.Session` fully, use event listeners, primarily the :meth:`.SessionEvents.after_begin`, :meth:`.SessionEvents.after_commit`, :meth:`.SessionEvents.after_rollback` and related events. (RR@(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR@ s8cCs |jjS(sThe set of all persistent states considered dirty. This method returns all states that were modified including those that were possibly deleted. (RfR^(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR^ scCs8tjg|jD]!}||jkr|j^qS(sZThe set of all persistent instances considered dirty. E.g.:: some_mapped_object in session.dirty Instances are considered dirty when they were modified but not deleted. Note that this 'dirty' calculation is 'optimistic'; most attribute-setting or collection modification operations will mark an instance as 'dirty' and place it in this set, even if there is no net change to the attribute's value. At flush time, the value of each attribute is compared to its previously saved value, and if there's no net change, no SQL operation will occur (this is a more expensive operation so it's only done at flush time). To check if an instance has actionable net changes to its attributes, use the :meth:`.Session.is_modified` method. (Rt IdentitySetR^RWR(R=R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRh s cCstjt|jjS(sDThe set of all instances marked as 'deleted' within this ``Session``(RRRzRWR(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRj scCstjt|jjS(sAThe set of all instances marked as 'new' within this ``Session``.(RRRzRVR(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRk s(RRRRRRRRRPRRRRRRR[RKRRRRRRRRR(s1.0sThe :paramref:`.Session.weak_identity_map` parameter as well as the strong-referencing identity map are deprecated, and will be removed in a future release. For the use case where objects present in a :class:`.Session` need to be automatically strong referenced, see the recipe at :ref:`session_referencing_behavior` for an event-based approach to maintaining strong identity references. (s0.7sxThe :paramref:`.Session._enable_transaction_accounting` parameter is deprecated and will be removed in a future release.(s0.7s:class:`.SessionExtension` is deprecated in favor of the :class:`.SessionEvents` listener interface. The :paramref:`.Session.extension` parameter will be removed in a future release.N(s0.8sThe :paramref:`.Session.is_modified.passive` flag is deprecated and will be removed in a future release. The flag is no longer used and is ignored.(PR'R(R)tpublic_methodsRtdeprecated_paramsRRdRR?tconnection_callableRtmemoized_propertyRRRRRRRPRLRRRRRRRRRRKRRtcontextmanagerRRRRRRR R+RRRcR RR"RRR$RR+RR3RRNRjR(RRR,R-RRR)R[R#RRYRRRRwRR@RfR^RhRjRk(((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyRas  @   $  I  !     {   T ! )     G     " S   &  =   &   | da 3 ( K:  cBsDeZdZdeeeeddZdZdZ dZ RS(s'A configurable :class:`.Session` factory. The :class:`.sessionmaker` factory generates new :class:`.Session` objects when called, creating them given the configurational arguments established here. e.g.:: # global scope Session = sessionmaker(autoflush=False) # later, in a local scope, create and use a session: sess = Session() Any keyword arguments sent to the constructor itself will override the "configured" keywords:: Session = sessionmaker() # bind an individual session to a connection sess = Session(bind=connection) The class also includes a method :meth:`.configure`, which can be used to specify additional keyword arguments to the factory, which will take effect for subsequent :class:`.Session` objects generated. This is usually used to associate one or more :class:`.Engine` objects with an existing :class:`.sessionmaker` factory before it is first used:: # application starts Session = sessionmaker() # ... later engine = create_engine('sqlite:///foo.db') Session.configure(bind=engine) sess = Session() .. seealso: :ref:`session_getting` - introductory text on creating sessions using :class:`.sessionmaker`. cKsi||d<||d<||d<||d<|dk rA||d s(t __class__R'RRRRe(R=((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyt__repr__ s  N( R'R(R)RRRdRR?RRR(((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR s, )  cCs%xtjD]}|jq WdS(sOClose all sessions in memory. This function consults a global registry of all :class:`.Session` objects and calls :meth:`.Session.close` on them, which resets them to a clean state. This function is not for general use but may be useful for test suites within the teardown scheme. .. versionadded:: 1.3 N(RRR(R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR scCs{tj|}t|}|r4|j|gn|jj|jrS|`n|jre|`n|jrw|`ndS(sMAlter the state of the given instance so that it is :term:`transient`. .. note:: :func:`.make_transient` is a special-case function for advanced use cases only. The given mapped instance is assumed to be in the :term:`persistent` or :term:`detached` state. The function will remove its association with any :class:`.Session` as well as its :attr:`.InstanceState.identity`. The effect is that the object will behave as though it were newly constructed, except retaining any attribute / collection values that were loaded at the time of the call. The :attr:`.InstanceState.deleted` flag is also reset if this object had been deleted as a result of using :meth:`.Session.delete`. .. warning:: :func:`.make_transient` does **not** "unexpire" or otherwise eagerly load ORM-mapped attributes that are not currently loaded at the time the function is called. This includes attributes which: * were expired via :meth:`.Session.expire` * were expired as the natural effect of committing a session transaction, e.g. :meth:`.Session.commit` * are normally :term:`lazy loaded` but are not currently loaded * are "deferred" via :ref:`deferred` and are not yet loaded * were not present in the query which loaded this object, such as that which is common in joined table inheritance and other scenarios. After :func:`.make_transient` is called, unloaded attributes such as those above will normally resolve to the value ``None`` when accessed, or an empty collection for a collection-oriented attribute. As the object is transient and un-associated with any database identity, it will no longer retrieve these values. .. seealso:: :func:`.make_transient_to_detached` N( RRRRctexpired_attributesR{t callablesRhRW(R&RRr((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pytmake_transient s.       cCstj|}|js!|jr3tjdn|jj||_|jrZ|`n|j |j |j |j |j dS(sMake the given transient instance :term:`detached`. .. note:: :func:`.make_transient_to_detached` is a special-case function for advanced use cases only. All attribute history on the given instance will be reset as though the instance were freshly loaded from a query. Missing attributes will be marked as expired. The primary key attributes of the object, which are required, will be made into the "key" of the instance. The object can then be added to a session, or merged possibly with the load=False flag, at which point it will look as if it were loaded that way, without emitting SQL. This is a special use case function that differs from a normal call to :meth:`.Session.merge` in that a given persistent state can be manufactured without any SQL calls. .. versionadded:: 0.9.5 .. seealso:: :func:`.make_transient` :meth:`.Session.enable_relationship_loading` sGiven object must be transientN( RRRRhR7R8RRRWRCRnRtunloaded_expirable(R&R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pytmake_transient_to_detached s  cCsGytj|}Wn#tjk r8tj|n Xt|SdS(sReturn the :class:`.Session` to which the given instance belongs. This is essentially the same as the :attr:`.InstanceState.session` accessor. See that attribute for details. N(RRRRRR(R&R((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pyR% s (6R)RuRR\tRRRRRRRRwtbaseRRR R R R R tdeprecated_interfacesRt unitofworkRRR7RRt inspectionRRRt__all__tWeakValueDictionaryRRtobjectRtsymbolR-R.R/R0R1RRRRRRR%tcounterR(((sI/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/orm/session.pytsj     $  @ )