403Webshell
Server IP : 192.158.238.246  /  Your IP : 18.118.99.234
Web Server : LiteSpeed
System : Linux uniform.iwebfusion.net 4.18.0-553.27.1.lve.1.el8.x86_64 #1 SMP Wed Nov 20 15:58:00 UTC 2024 x86_64
User : jenniferflocom ( 1321)
PHP Version : 8.1.32
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : OFF  |  Pkexec : OFF
Directory :  /opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/ext/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/ext/__pycache__/baked.cpython-37.pyc
B

��4]�S�@s<dZddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
dd	lmZdd
lmZddlmZe�e�ZGdd�de�ZGd
d�de�ZGdd�de�Ze�dd�dd��Ze�dd�dd��Ze	��dd��Zeje�dd�dd���Zeje�dd�dd���Z ej!Ze j"Z ej#Z#dS)z�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.


�N�)�exc)�util)�strategy_options)�Query)�Session)�func)�literal_columnc@s$eZdZdZdZdd�Zdd�ZdS)�Bakeryz�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


    )�cls�cachecCs||_||_dS)N)rr)�selfZcls_r�r�G/opt/alt/python37/lib64/python3.7/site-packages/sqlalchemy/ext/baked.py�__init__/szBakery.__init__cGs|�|j||�S)N)rr)r
�
initial_fn�argsrrr�__call__3szBakery.__call__N)�__name__�
__module__�__qualname__�__doc__�	__slots__rrrrrrr
!s
r
c@s�eZdZdZdZd/dd�Zed0dd	��Zd
d�Zd1dd
�Z	dd�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zd2dd�Zdd�Zd3dd �Zd4d!d"�Zd#d$�Zd%d&�Zd'd(�Zd)d*�Zd+d,�Zd-d.�ZdS)5�
BakedQueryz3A builder object for :class:`.query.Query` objects.)�steps�_bakery�
_cache_key�_spoiledrcCs*d|_|�||�|g|_d|_||_dS)NrF)r�_update_cache_keyrrr)r
�bakeryrrrrrr<s
zBakedQuery.__init__��NcCst|tj||d��S)zSConstruct a new bakery.

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

        )Z
size_alert)r
rZLRUCache)r�sizeZ_size_alertrrrrCszBakedQuery.bakerycCs2t�t�}|j|_t|j�|_|j|_|j|_|S)N)r�__new__r�listrrr)r
Zb1rrr�_cloneMs
zBakedQuery._clonecCs|j|jf|7_dS)N)r�__code__)r
�fnrrrrrUszBakedQuery._update_cache_keycCs$t|t�r|j|�n
|�|�|S)N)�
isinstance�tuple�add_criteria)r
�otherrrr�__iadd__Xs

zBakedQuery.__iadd__cCs"t|t�r|j|�S|�|�SdS)N)r'r(�
with_criteria)r
r*rrr�__add___s

zBakedQuery.__add__cGs|�||�|j�|�|S)z�Add a criteria function to this :class:`.BakedQuery`.

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

        )rr�append)r
r&rrrrr)eszBakedQuery.add_criteriacGs|��j|f|��S)z�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&rrrrr,pszBakedQuery.with_criteriacCs
t||�S)z�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)``.

        )�Result)r
�sessionrrr�for_sessionyszBakedQuery.for_sessioncCs
|�|�S)N)r1)r
r0rrrr�szBakedQuery.__call__FcCs4|s*|js*|��}|jd7_|jg|_d|_|S)azCancel 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.

        )Z_query_onlyT)rr$r�_retrieve_baked_queryr)r
�fullZ_spoil_pointrrr�spoil�s

zBakedQuery.spoilcCs|j|jfS)a�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.

        )rZ
_query_cls)r
r0rrr�_effective_key�szBakedQuery._effective_keycCs|��}|j|||d�|S)z2Cloning version of _add_lazyload_options.
        )�
cache_path)r$�_add_lazyload_options)r
�options�effective_pathr6�qrrr�_with_lazyload_options�sz!BakedQuery._with_lazyload_optionscszd}|s�}|jdjr"|��n:x8�D]0}|�|�}|dkrH|��q(|dk	r(||7}q(W|���fdd�|j|�dS)a*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.

        rrFNcs|���j��S)N)Z_with_current_pathZ_conditional_options)r:)r9r8rr�<lambda>�sz2BakedQuery._add_lazyload_options.<locals>.<lambda>)�pathZis_aliased_classr4Z_generate_cache_keyr))r
r8r9r6�key�opt�	cache_keyr)r9r8rr7�s




z BakedQuery._add_lazyload_optionscCsF|j�|�|�d�}|dkr<|�|�}|�d�|j|�|�<|�|�S)N)r�getr5�	_as_query�with_session)r
r0�queryrrrr2�s
z BakedQuery._retrieve_baked_querycCsz|�|�}|��}|�||�d|_|j�d�|_}|j�d|ji�|_xdD]}|j	�
|d�qPW||j|�|�<|S)NZcompiled_cache)Z
_correlateZ	_from_objZ_mapper_adapter_mapZ	_joinpathZ
_joinpoint)rBZ_compile_context�_bake_subquery_loadersr0rDrCZ_execution_options�unionr�__dict__�popr5)r
r0rD�context�attrrrr�_bake�s
zBakedQuery._bakecCsNt|t�r|}n4t|t�r4|j}|dkrDt�d��ntdt|���|�|�S)a#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


        Nz1Given Query needs to be associated with a Sessionz)Query or Session object expected, got %r.)	r'rrr0�sa_exc�
ArgumentError�	TypeError�typerB)r
Zquery_or_sessionr0rrr�to_query�s%

zBakedQuery.to_querycCs2|jd|�}x|jdd�D]}||�}qW|S)Nr�)r)r
r0rD�steprrrrB,szBakedQuery._as_querycs�g|jd<}xpt|j���D]^\}�t�t�rd|krtt|j�fdd��}|j||_|�|�|�	||j�f�|j|=qWdS)abconvert 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.

        �
baked_queriesZsubquerycs�S)Nr)r)�vrrr<@�z3BakedQuery._bake_subquery_loaders.<locals>.<lambda>N)
�
attributesr#�itemsr'rrrrrKr.)r
r0rIrS�k�bkr)rTrrE3s	

z!BakedQuery._bake_subquery_loaderscCslxf|jdD]X\}}}t|j|fdd��}||_|�|�}	x|D]}
|	�|
�}	q@W|	jf|�|j|<qWdS)z�Retrieve subquery eager loaders stored by _bake_subquery_loaders
        and turn them back into Result objects that will iterate just
        like a Query object.

        rScSs
|�|�S)N)rC)Zsessr:rrrr<PrUz5BakedQuery._unbake_subquery_loaders.<locals>.<lambda>N)rVrrrr1�with_post_criteria�params)r
r0rIr[Z
post_criteriarXr@rDrYr:r&rrr�_unbake_subquery_loadersFs

z#BakedQuery._unbake_subquery_loaders)r)r N)r)F)N)N)rrrrrr�classmethodrr$rr+r-r)r,r1rr4r5r;r7r2rKrPrBrEr\rrrrr7s.
	
		


#	4rc@s�eZdZdZdZdd�Zdd�Zdd�Zd	d
�Zdd�Z	d
d�Z
dd�Zdd�Zdd�Z
dd�Zdd�Zdd�Zdd�Zdd�Zdd �Zd!S)"r/aInvokes 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.

    )�bqr0�_params�_post_criteriacCs||_||_i|_g|_dS)N)r^r0r_r`)r
r^r0rrrrdszResult.__init__cOsBt|�dkr|�|d�nt|�dkr2t�d��|j�|�|S)z@Specify parameters to be replaced into the string SQL statement.rQrzFparams() takes zero or one positional argument, which is a dictionary.)�len�updaterLrMr_)r
r�kwrrrr[jsz
Result.paramscCs|r|j�|�|S)N)r`�extend)r
�fnsrrr�_using_post_criteriawszResult._using_post_criteriacCs|�|g�S)aAdd 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


        )rf)r
r&rrrrZ|szResult.with_post_criteriacCs2|j�|j��|j�}x|jD]}||�}qW|S)N)r^rBr0r[r_r`)r
r:r&rrrrB�szResult._as_querycCst|���S)N)�strrB)r
rrr�__str__�szResult.__str__cCs�|j}|jjr|jr t|���S|j�|�|j�d�}|dkrJ|�	|j�}t
�
|�}|j|_|j�
�|_|�|j||j
|j�d|j_|jr�|js�|j��|j�|j
��|j�}x|jD]}||�}q�W|�|�S)NT)r^r0Zenable_baked_queriesr�iterrBrrAr5rK�copyrVr\r_r`�	statementZ
use_labelsZ	autoflushZpopulate_existingZ
_autoflushrDr[rCZ_execute_and_instances)r
r^Z
baked_contextrIr:r&rrr�__iter__�s$

zResult.__iter__cs:t�td���|j��fdd��}|�|j��|j��	�S)z�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

        �*cs
|���S)N)Z	from_self)r:)�colrrr<�rUzResult.count.<locals>.<lambda>)
r�countr	r^r,r1r0r[r_�scalar)r
r^r)rnrro�szResult.countcCs:y|��}t|t�s|S|dStjk
r4dSXdS)z�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

        rN)�oner'r(�orm_exc�
NoResultFound)r
�retrrrrp�s

z
Result.scalarcCsL|j�dd��}t|�|j��|j��|j��}t	|�dkrD|dSdSdS)zLReturn the first row.

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

        cSs|�dd�S)NrrQ)�slice)r:rrrr<�rUzResult.first.<locals>.<lambda>rN)
r^r,r#r1r0r[r_rfr`ra)r
r^rtrrr�first�s
zResult.firstcCsHy|��}Wn tjk
r,t�d��YnX|dkr@t�d��|SdS)zeReturn exactly one result or raise an exception.

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

        z"Multiple rows were found for one()NzNo row was found for one())�one_or_nonerr�MultipleResultsFoundrs)r
rtrrrrq�s
z
Result.onecCs:t|�}t|�}|dkr |dS|dkr,dSt�d��dS)z�Return one or zero results, or raise an exception for multiple
        rows.

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

        .. versionadded:: 1.0.9

        rQrNz*Multiple rows were found for one_or_none())r#rarrrx)r
rt�lrrrrw�s	zResult.one_or_nonecCst|�S)zEReturn all rows.

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

        )r#)r
rrr�all
sz
Result.allcCs |jjd|j�}|�||j�S)zZRetrieve an object based on identity.

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

        r)r^rr0Z	_get_impl�_load_on_pk_identity)r
�identrDrrrrAsz
Result.getcs�|����j\�������fdd�}�j}|��}|j�f7_|�|tdd��D���}t�fdd�t��j	�D��}t
|��j�j
f|��}t|�}|dkr�t���n|r�|dSd	Sd	S)
z6Load the given primary key identity from the database.cs|�}|��}|��d|_d�krLt�fdd�t�j��D��}t�||�}|�|dd�}||_	x�j
D]}||�}qhW|S)Ncs"g|]\}}|dkr�|j�qS)N)r>)�.0rn�value)�_get_paramsrr�
<listcomp>1sz>Result._load_on_pk_identity.<locals>.setup.<locals>.<listcomp>TF)r$Z_get_conditionZ	_order_by�set�zip�primary_key�sql_utilZadapt_criterion_to_nullZ
_adapt_clauseZ
_criterionr`)rDZ_lcl_get_clauser:Znonesr&)�_get_clauser�mapper�primary_key_identityr
rr�setup&s 
z*Result._load_on_pk_identity.<locals>.setupcss|]}|dkVqdS)Nr)r}�elemrrr�	<genexpr>Nsz.Result._load_on_pk_identity.<locals>.<genexpr>csg|]\}}�|j|f�qSr)r>)r}Zid_valr�)rrrr�Ssz/Result._load_on_pk_identity.<locals>.<listcomp>rQrN)Z_mapper_zeror�r^r$rr,r(�dictr�r�r#r1r0r[rarrrx)r
rDr�r�r^r[�resultryr)r�rr�r�r
rr{s&


zResult._load_on_pk_identityN)rrrrrrr[rfrZrBrhrlrorprvrqrwrzrAr{rrrrr/Ys"

r/z1.2z5Baked lazy loading is now the default implementation.cCsdS)z�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.

    Nrrrrr�bake_lazy_loadersds
r�cCstd��dS)aDDisable 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.

    z4Baked lazy loading is now the default implementationN)�NotImplementedErrorrrrr�unbake_lazy_loadersqsr�cCs|�|ddi�S)zxIndicate that the given attribute should be loaded using "lazy"
    loading with a "baked" query used in the load.

    ZlazyZbaked_select)Zset_relationship_strategy)ZloadoptrJrrr�baked_lazyload�sr�zFBaked lazy loading is now the default implementation for lazy loading.cGstj�tjj|di�S)NF)r�_UnboundLoad�
_from_keysr�)�keysrrrr��scGstj�tjj|di�S)NT)rr�r�r�)r�rrr�baked_lazyload_all�sr�)$rrj�logging�rrLrZormrrrZ	orm.queryrZorm.sessionrZsqlrr	r��	getLoggerr�log�objectr
rr/Z
deprecatedr�r�Z
loader_optionr�Z_add_unbound_fnZ_add_unbound_all_fnr�Z_unbound_fnZ_unbound_all_fnrrrrr�<module>sF
$
			

Youez - 2016 - github.com/yon3zu
LinuXploit