%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /proc/227033/root/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/
Upload File :
Create Path :
Current File : //proc/227033/root/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyc

�
��4]c@s�dZddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
dd	lmZdd
lmZddlmZeje�Zdefd��YZd
efd��YZdefd��YZejdd�d��Zejdd�d��Ze	j�d��Zejejdd�d���Zejejdd�d���Z ej!Ze j"Z ej#Z#dS(s�Baked query extension.

Provides a creational pattern for the :class:`.query.Query` object which
allows the fully constructed object, Core select statement, and string
compiled result to be fully cached.


i����Ni(texc(tutil(tstrategy_options(tQuery(tSession(tfunc(tliteral_columntBakerycBs&eZdZdZd�Zd�ZRS(s�Callable which returns a :class:`.BakedQuery`.

    This object is returned by the class method
    :meth:`.BakedQuery.bakery`.  It exists as an object
    so that the "cache" can be easily inspected.

    .. versionadded:: 1.2


    tclstcachecCs||_||_dS(N(RR	(tselftcls_R	((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt__init__/s	cGs|j|j||�S(N(RR	(R
t
initial_fntargs((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt__call__3s(RR	(t__name__t
__module__t__doc__t	__slots__RR(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR!s
	t
BakedQuerycBs�eZdZdZdd�Zeddd��Zd�Zdd	�Z	d
�Z
d�Zd�Zd
�Z
d�Zd�Zed�Zd�Zdd�Zdd�Zd�Zd�Zd�Zd�Zd�Zd�ZRS(s3A builder object for :class:`.query.Query` objects.tstepst_bakeryt
_cache_keyt_spoiledcCs;d|_|j||�|g|_t|_||_dS(N((Rt_update_cache_keyRtFalseRR(R
tbakeryR
R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR<s
		i�cCst|tj|d|��S(sSConstruct a new bakery.

        :return: an instance of :class:`.Bakery`

        t
size_alert(RRtLRUCache(Rtsizet_size_alert((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRCscCsItjt�}|j|_t|j�|_|j|_|j|_|S(N(Rt__new__RtlistRRR(R
tb1((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt_cloneMscCs|j|jf|7_dS(N(Rt__code__(R
tfnR((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRUscCs0t|t�r|j|�n
|j|�|S(N(t
isinstancettupletadd_criteria(R
tother((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt__iadd__Xs
cCs-t|t�r|j|�S|j|�SdS(N(R&R't
with_criteria(R
R)((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt__add___s
cGs$|j||�|jj|�|S(s�Add a criteria function to this :class:`.BakedQuery`.

        This is equivalent to using the ``+=`` operator to
        modify a :class:`.BakedQuery` in-place.

        (RRtappend(R
R%R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR(escGs|j�j||�S(s�Add a criteria function to a :class:`.BakedQuery` cloned from this one.

        This is equivalent to using the ``+`` operator to
        produce a new :class:`.BakedQuery` with modifications.

        (R#R((R
R%R((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR+pscCs
t||�S(s�Return a :class:`.Result` object for this :class:`.BakedQuery`.

        This is equivalent to calling the :class:`.BakedQuery` as a
        Python callable, e.g. ``result = my_baked_query(session)``.

        (tResult(R
tsession((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pytfor_sessionyscCs
|j|�S(N(R0(R
R/((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR�scCsK|r>|jr>|j�}|jd7_|jg|_nt|_|S(szCancel any query caching that will occur on this BakedQuery object.

        The BakedQuery can continue to be used normally, however additional
        creational functions will not be cached; they will be called
        on every invocation.

        This is to support the case where a particular step in constructing
        a baked query disqualifies the query from being cacheable, such
        as a variant that relies upon some uncacheable value.

        :param full: if False, only functions added to this
         :class:`.BakedQuery` object subsequent to the spoil step will be
         non-cached; the state of the :class:`.BakedQuery` up until
         this point will be pulled from the cache.   If True, then the
         entire :class:`.Query` object is built from scratch each
         time, with all creational functions being called on each
         invocation.

        t_query_only(R1(RR#Rt_retrieve_baked_queryRtTrue(R
tfullt_spoil_point((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pytspoil�s	cCs|j|jfS(s�Return the key that actually goes into the cache dictionary for
        this :class:`.BakedQuery`, taking into account the given
        :class:`.Session`.

        This basically means we also will include the session's query_class,
        as the actual :class:`.Query` object is part of what's cached
        and needs to match the type of :class:`.Query` that a later
        session will want to use.

        (Rt
_query_cls(R
R/((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt_effective_key�scCs&|j�}|j||d|�|S(s2Cloning version of _add_lazyload_options.
        t
cache_path(R#t_add_lazyload_options(R
toptionsteffective_pathR9tq((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt_with_lazyload_options�scs�d}|s�}n|jdjr2|j�nRxO�D]G}|j|�}|tkrg|j�q9|dk	r9||7}q9q9W|j��fd�|j|�dS(s*Used by per-state lazy loaders to add options to the
        "lazy load" query from a parent query.

        Creates a cache key based on given load path and query options;
        if a repeatable cache key cannot be generated, the query is
        "spoiled" so that it won't use caching.

        ics|j��j��S(N(t_with_current_patht_conditional_options(R=(R<R;(sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt<lambda>�s	N((tpathtis_aliased_classR6t_generate_cache_keyRtNoneR((R
R;R<R9tkeytoptt	cache_key((R<R;sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR:�s
	


cCsh|jj|j|�d�}|dkr[|j|�}|jd�|j|j|�<n|j|�S(N(RtgetR8REt	_as_querytwith_session(R
R/tquery((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR2�scCs�|j|�}|j�}|j||�d|_|jjd�|_}|jji|j	d6�|_x!dD]}|j
j|d�qsW||j	|j|�<|S(Ntcompiled_cachet
_correlatet	_from_objt_mapper_adapter_mapt	_joinpatht
_joinpoint(RNRORPRQRR(
RJt_compile_contextt_bake_subquery_loadersRER/RLRKt_execution_optionstunionRt__dict__tpopR8(R
R/RLtcontexttattr((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt_bake�s 		
cCstt|t�r|}nOt|t�rQ|j}|dkrgtjd��qgntdt|���|j	|�S(s#Return the :class:`.Query` object for use as a subquery.

        This method should be used within the lambda callable being used
        to generate a step of an enclosing :class:`.BakedQuery`.   The
        parameter should normally be the :class:`.Query` object that
        is passed to the lambda::

            sub_bq = self.bakery(lambda s: s.query(User.name))
            sub_bq += lambda q: q.filter(
                User.id == Address.user_id).correlate(Address)

            main_bq = self.bakery(lambda s: s.query(Address))
            main_bq += lambda q: q.filter(
                sub_bq.to_query(q).exists())

        In the case where the subquery is used in the first callable against
        a :class:`.Session`, the :class:`.Session` is also accepted::

            sub_bq = self.bakery(lambda s: s.query(User.name))
            sub_bq += lambda q: q.filter(
                User.id == Address.user_id).correlate(Address)

            main_bq = self.bakery(
                lambda s: s.query(Address.id, sub_bq.to_query(q).as_scalar())
            )

        :param query_or_session: a :class:`.Query` object or a class
         :class:`.Session` object, that is assumed to be within the context
         of an enclosing :class:`.BakedQuery` callable.


         .. versionadded:: 1.3


        s1Given Query needs to be associated with a Sessions)Query or Session object expected, got %r.N(
R&RRR/REtsa_exct
ArgumentErrort	TypeErrorttypeRJ(R
tquery_or_sessionR/((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pytto_query�s%		cCs;|jd|�}x!|jdD]}||�}q!W|S(Nii(R(R
R/RLtstep((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRJ,scs�g|jd<}x�t|jj��D]�\}�t�t�r'd|kr�t|j�fd��}|j||_|j|�|j	||j�f�n|j|=q'q'WdS(sbconvert subquery eager loaders in the cache into baked queries.

        For subquery eager loading to work, all we need here is that the
        Query point to the correct session when it is run.  However, since
        we are "baking" anyway, we may as well also turn the query into
        a "baked" query so that we save on performance too.

        t
baked_queriestsubquerycs�S(N((R(tv(sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRA@tN(
t
attributesR!titemsR&RRRRR[R-(R
R/RYRctktbk((ResG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRT3s	"
cCs�x�|jdD]u\}}}t|j|d��}||_|j|�}	x|D]}
|	j|
�}	qTW|	j|�|j|<qWdS(s�Retrieve subquery eager loaders stored by _bake_subquery_loaders
        and turn them back into Result objects that will iterate just
        like a Query object.

        RccSs
|j|�S(N(RK(tsessR=((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRAPRfN(RgRRRR0twith_post_criteriatparams(R
R/RYRmt
post_criteriaRiRHRLRjR=R%((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt_unbake_subquery_loadersFs	
(RRRR(N((RRRRRtclassmethodRERR#RR*R,R(R+R0RRR6R8R>R:R2R[RaRJRTRo(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR7s.											
#				4		R.cBs�eZdZdZd�Zd�Zd�Zd�Zd	�Zd
�Z	d�Z
d�Zd
�Zd�Z
d�Zd�Zd�Zd�Zd�ZRS(sInvokes a :class:`.BakedQuery` against a :class:`.Session`.

    The :class:`.Result` object is where the actual :class:`.query.Query`
    object gets created, or retrieved from the cache,
    against a target :class:`.Session`, and is then invoked for results.

    tbqR/t_paramst_post_criteriacCs(||_||_i|_g|_dS(N(RqR/RrRs(R
RqR/((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRds			cOs^t|�dkr&|j|d�n$t|�dkrJtjd��n|jj|�|S(s@Specify parameters to be replaced into the string SQL statement.iisFparams() takes zero or one positional argument, which is a dictionary.(tlentupdateR\R]Rr(R
Rtkw((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRmjscCs|r|jj|�n|S(N(Rstextend(R
tfns((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt_using_post_criteriawscCs|j|g�S(sAdd a criteria function that will be applied post-cache.

        This adds a function that will be run against the
        :class:`.Query` object after it is retrieved from the
        cache.    Functions here can be used to alter the query in ways
        that **do not affect the SQL output**, such as execution options
        and shard identifiers (when using a shard-enabled query object)

        .. warning::  :meth:`.Result.with_post_criteria` functions are applied
           to the :class:`.Query` object **after** the query's SQL statement
           object has been retrieved from the cache.   Any operations here
           which intend to modify the SQL should ensure that
           :meth:`.BakedQuery.spoil` was called first.

        .. versionadded:: 1.2


        (Ry(R
R%((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRl|scCsE|jj|j�j|j�}x|jD]}||�}q+W|S(N(RqRJR/RmRrRs(R
R=R%((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRJ�s!cCst|j��S(N(tstrRJ(R
((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt__str__�scCs:|j}|jjs|jr/t|j��S|jj|j|j�d�}|dkrq|j
|j�}ntj|�}|j|_|jj�|_|j
|j||j|j�t|j_|jr�|jr�|jj�n|jj|j�j|j�}x|jD]}||�}qW|j|�S(N(RqR/tenable_baked_queriesRtiterRJRRIR8RER[tcopyRgRoRrRsR3t	statementt
use_labelst	autoflushtpopulate_existingt
_autoflushRLRmRKt_execute_and_instances(R
Rqt
baked_contextRYR=R%((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt__iter__�s$	!!csRtjtd���|jj�fd��}|j|j�j|j�j	�S(s�return the 'count'.

        Equivalent to :meth:`.Query.count`.

        Note this uses a subquery to ensure an accurate count regardless
        of the structure of the original statement.

        .. versionadded:: 1.1.6

        t*cs
|j��S(N(t	from_self(R=(tcol(sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRA�Rf(
RtcountRRqR+R0R/RmRrtscalar(R
Rq((R�sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR��scCsGy+|j�}t|t�s"|S|dSWntjk
rBdSXdS(s�Return the first element of the first result or None
        if no rows present.  If multiple rows are returned,
        raises MultipleResultsFound.

        Equivalent to :meth:`.Query.scalar`.

        .. versionadded:: 1.1.6

        iN(toneR&R'torm_exct
NoResultFoundRE(R
tret((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR��s
cCsg|jjd��}t|j|j�j|j�j|j��}t	|�dkr_|dSdSdS(sLReturn the first row.

        Equivalent to :meth:`.Query.first`.

        cSs|jdd�S(Nii(tslice(R=((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRA�RfiN(RqR+R!R0R/RmRrRyRsRtRE(R
RqR�((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pytfirst�scCs\y|j�}Wn#tjk
r5tjd��n#X|dkrTtjd��n|SdS(seReturn exactly one result or raise an exception.

        Equivalent to :meth:`.Query.one`.

        s"Multiple rows were found for one()sNo row was found for one()N(tone_or_noneR�tMultipleResultsFoundRER�(R
R�((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR��s
cCsOt|�}t|�}|dkr,|dS|dkr<dStjd��dS(s�Return one or zero results, or raise an exception for multiple
        rows.

        Equivalent to :meth:`.Query.one_or_none`.

        .. versionadded:: 1.0.9

        iis*Multiple rows were found for one_or_none()N(R!RtRER�R�(R
R�tl((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR��s	cCs
t|�S(sEReturn all rows.

        Equivalent to :meth:`.Query.all`.

        (R!(R
((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pytall
scCs,|jjd|j�}|j||j�S(sZRetrieve an object based on identity.

        Equivalent to :meth:`.Query.get`.

        i(RqRR/t	_get_implt_load_on_pk_identity(R
tidentRL((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyRIsc
s|j���j\�������fd�}�j}|j�}|j�f7_|j|td��D���}tgt��j	�D]\}}�|j
|f^q��}t|j�j
�j|��}t|�}	|	dkrtj��n|	r|dSdSdS(s6Load the given primary key identity from the database.cs��}|j�}|j�d|_d�kr�tgt�j��D]%\}}|dkrG�|j^qG�}tj	||�}n|j
|tt�}||_
x�jD]}||�}q�W|S(N(R#t_get_conditionREt	_order_bytsettziptprimary_keyRFtsql_utiltadapt_criterion_to_nullt
_adapt_clauseR3Rt
_criterionRs(RLt_lcl_get_clauseR=R�tvaluetnonesR%(t_get_clauset_get_paramstmappertprimary_key_identityR
(sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pytsetup&s"
	"	css|]}|dkVqdS(N(RE(t.0telem((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pys	<genexpr>NsiiN(t_mapper_zeroR�RqR#RR+R'tdictR�R�RFR!R0R/RmRtR�R�RE(
R
RLR�R�Rqtid_valR�RmtresultR�((R�R�R�R�R
sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR�s&	5!(RqR/RrRs(RRRRRRmRyRlRJR{R�R�R�R�R�R�R�RIR�(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR.Ys"		
												
s1.2s5Baked lazy loading is now the default implementation.cCsdS(s�Enable the use of baked queries for all lazyloaders systemwide.

    The "baked" implementation of lazy loading is now the sole implementation
    for the base lazy loader; this method has no effect except for a warning.

    N((((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pytbake_lazy_loadersds
cCstd��dS(sDDisable the use of baked queries for all lazyloaders systemwide.

    This method now raises NotImplementedError() as the "baked" implementation
    is the only lazy load implementation.  The
    :paramref:`.relationship.bake_queries` flag may be used to disable
    the caching of queries on a per-relationship basis.

    s4Baked lazy loading is now the default implementationN(tNotImplementedError(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pytunbake_lazy_loadersqscCs|j|idd6�S(sxIndicate that the given attribute should be loaded using "lazy"
    loading with a "baked" query used in the load.

    tbaked_selecttlazy(tset_relationship_strategy(tloadoptRZ((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pytbaked_lazyload�ssFBaked lazy loading is now the default implementation for lazy loading.cGstjjtjj|ti�S(N(Rt_UnboundLoadt
_from_keysR�R(tkeys((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyR��s	cGstjjtjj|ti�S(N(RR�R�R�R3(R�((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pytbaked_lazyload_all�s	($RR~tloggingRfRR\RtormR�Rt	orm.queryRtorm.sessionRtsqlRRR�t	getLoggerRtlogtobjectRRR.t
deprecatedR�R�t
loader_optionR�t_add_unbound_fnt_add_unbound_all_fnR�t_unbound_fnt_unbound_all_fnR(((sG/opt/alt/python27/lib64/python2.7/site-packages/sqlalchemy/ext/baked.pyt<module>sB�#�					

Zerion Mini Shell 1.0