Hacked By AnonymousFox

Current Path : /opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/ext/__pycache__/
Upload File :
Current File : //opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/ext/__pycache__/baked.cpython-311.pyc

�

�܋f�U��X�dZddlZddlZddlmZddlmZddlmZddlm	Z	ddl
mZddlm
Z
dd	lmZdd
lmZddlmZeje��ZGd�de��ZGd
�de��ZGd�de��Zejdd��d���Zejdd��d���Ze	j��d���Zejejdd��d�����Zejejdd��d�����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�"�eZdZdZdZd�Zd�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�cachec�"�||_||_dS�Nr
)�self�cls_rs   �K/opt/cloudlinux/venv/lib64/python3.11/site-packages/sqlalchemy/ext/baked.py�__init__zBakery.__init__/s�������
�
�
�c�:�|�|j||��Srr
)r�
initial_fn�argss   r�__call__zBakery.__call__3s���x�x��
�J��5�5�5rN)�__name__�
__module__�__qualname__�__doc__�	__slots__rr�rrrr!sC������	�	��I����6�6�6�6�6rrc��eZdZdZdZdd�Zedd���Zd�Zdd	�Z	d
�Z
d�Zd�Zd
�Z
d�Zd�Zdd�Zd�Zdd�Zdd�Zd�Zd�Zd�Zd�Zd�Zd�ZdS)�
BakedQueryz3A builder object for :class:`.query.Query` objects.)�steps�_bakery�
_cache_key�_spoiledr c�l�d|_|�||��|g|_d|_||_dS)Nr F)r%�_update_cache_keyr#r&r$)r�bakeryrrs    rrzBakedQuery.__init__<s:��������z�4�0�0�0� �\��
���
�����r��Nc�J�t|tj||�����S)zSConstruct a new bakery.

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

        )�
size_alert)rr�LRUCache)r�size�_size_alerts   rr)zBakedQuery.bakeryCs#���c�4�=��+�F�F�F�G�G�Grc��t�t��}|j|_t|j��|_|j|_|j|_|Sr)r"�__new__r%�listr#r$r&)r�b1s  r�_clonezBakedQuery._cloneMsF��
�
�
�
�
+�
+�����
���
�#�#����\��
��m����	rc�8�|xj|jf|zz
c_dSr)r%�__code__�r�fnrs   rr(zBakedQuery._update_cache_keyUs�����B�K�>�D�0�0����rc�p�t|t��r|j|�n|�|��|Sr)�
isinstance�tuple�add_criteria�r�others  r�__iadd__zBakedQuery.__iadd__Xs@���e�U�#�#�	%��D��u�%�%�%����e�$�$�$��rc�j�t|t��r
|j|�S|�|��Sr)r:r;�
with_criteriar=s  r�__add__zBakedQuery.__add___s8���e�U�#�#�	-�%�4�%�u�-�-��%�%�e�,�,�,rc�f�|�||��|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.

        )r(r#�appendr7s   rr<zBakedQuery.add_criteriaes5��	
���r�4�(�(�(��
���"�����rc�B�|���j|g|�R�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.

        )r4r<r7s   rrAzBakedQuery.with_criteriaps'��*�t�{�{�}�}�)�"�4�t�4�4�4�4rc�"�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�sessions  r�for_sessionzBakedQuery.for_sessionys���d�G�$�$�$rc�,�|�|��Sr)rJrHs  rrzBakedQuery.__call__�s������(�(�(rFc��|s8|js1|���}|xjdz
c_|jg|_d|_|S)a�Cancel 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.Query` object is built from scratch each
         time, with all creational functions being called on each
         invocation.

        )�_query_onlyT)r&r4r%�_retrieve_baked_queryr#)r�full�_spoil_points   r�spoilzBakedQuery.spoil�sP��(�	>�D�M�	>��;�;�=�=�L��#�#�'7�7�#�#�&�<�=�D�J���
��rc�"�|j|jfzS)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.Query` object is part of what's cached
        and needs to match the type of :class:`_query.Query` that a later
        session will want to use.

        )r%�
_query_clsrHs  r�_effective_keyzBakedQuery._effective_key�s����'�"4�!6�6�6rc�^�|���}|�|||���|S)z)Cloning version of _add_lazyload_options.)�
cache_path)r4�_add_lazyload_options)r�options�effective_pathrV�qs     r�_with_lazyload_optionsz!BakedQuery._with_lazyload_options�s/���K�K�M�M��	�����J��O�O�O��rc� ���d}|s�}|jdjr|�d���n<�D]9}|�|��}|dur|�d����2|�||z
}�:|���fd�|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.

        r rT)rOFNc�>��|����j��Sr)�_with_current_path�_conditional_options)rZrYrXs ��r�<lambda>z2BakedQuery._add_lazyload_options.<locals>.<lambda>�s)���#�a�*�*����"�G�-�r)�path�is_aliased_classrQ�_generate_cache_keyr<)rrXrYrV�key�opt�	cache_keys ``    rrWz BakedQuery._add_lazyload_options�s��������	(�'�J��?�1��.�
	%�
�J�J�D�J�!�!�!�!��
%�
%���3�3�J�?�?�	���%�%��J�J�D�J�)�)�)�)��*��9�$�C�����
-�
-�
-�
-�
-�
�O��	
�	
�	
�	
�	
rc��|j�|�|��d��}|�E|�|��}|�d��|j|�|��<|�|��Sr)r$�getrT�	_as_query�with_session)rrI�querys   rrNz BakedQuery._retrieve_baked_query�s����� � ��!4�!4�W�!=�!=�t�D�D���=��N�N�7�+�+�E�9>�9K�9K��:�:�D�L��,�,�W�5�5�6��!�!�'�*�*�*rc��|�|��}|���}|�||��d|_|j�d��x|_}|j�d|ji��|_dD]}|j	�
|d���|jjr||j|�|��<|S)N�compiled_cache)�
_correlate�	_from_obj�_mapper_adapter_map�	_joinpath�
_joinpoint)
ri�_compile_context�_bake_subquery_loadersrIrkrj�_execution_options�unionr$�__dict__�pop�_bake_okrT)rrIrk�context�attrs     r�_bakezBakedQuery._bake�s������w�'�'���(�(�*�*���#�#�G�W�5�5�5���� '�
� :� :�4� @� @�@��
��#(�#;�#A�#A�
�t�|�,�$
�$
�� �
�	+�	+�D�
�N���t�T�*�*�*�*�
�=�!�	A�9@�D�L��,�,�W�5�5�6��rc��t|t��r|}nRt|t��r|j}|�t	jd���nt
dt|��z���|�|��S)a5Return the :class:`_query.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.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.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:rrrI�sa_exc�
ArgumentError�	TypeError�typeri)r�query_or_sessionrIs   r�to_queryzBakedQuery.to_query�s���J�&��0�0�	�&�G�G�
�(�%�
0�
0�
	�&�.�G����*�G�����
�;��'�(�(�)���
��~�~�g�&�&�&rc�l�|jd|��}|jdd�D]
}||��}�|S�Nr�)r#)rrIrk�steps    rrizBakedQuery._as_query2sD����
�1�
�g�&�&���J�q�r�r�N�	 �	 �D��D��K�K�E�E��rc�l��gx|jd<}t|j�����D]\}�t�t��red|vrYt|j�fd���}|j|z|_|�|��|�	||j�f��|j|=��dS)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_queries�subqueryc����Srr )r�vs �rr`z3BakedQuery._bake_subquery_loaders.<locals>.<lambda>Fs����rN)
�
attributesr2�itemsr:rr"r$r%r|rD)rrIrzr��k�bkr�s      @rrtz!BakedQuery._bake_subquery_loaders9s����?A�@���?�+�m���+�1�1�3�3�4�4�	*�	*�D�A�q��!�U�#�#�
*���?�?�#�D�L�/�/�/�/�B�B�B�$(�O�a�$7�B�M��H�H�W�%�%�%�!�(�(�!�R�]�A�)>�?�?�?��&�q�)��	*�	*rc�
�d|jvrdS|jdD]i\}}}t|j|fd���}||_|�|��}	|D]}
|	�|
��}	�|	jdi|��|j|<�jdS)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.

        r�Nc�,�|�|��Sr)rj)�sessrZs  rr`z5BakedQuery._unbake_subquery_loaders.<locals>.<lambda>Ys��A�N�N�4�4H�4H�rr )r�r"r$r%rJ�with_post_criteria�params)rrIrzr��
post_criteriar�rfrkr�rZr8s           r�_unbake_subquery_loadersz#BakedQuery._unbake_subquery_loadersLs����'�"4�4�4��F�#*�#5�o�#F�	7�	7��A�y�%����U�H�H�H���B�&�B�M����w�'�'�A�#�
-�
-���(�(��,�,���$,�A�H�$6�$6�v�$6�$6�G��q�!�!�	7�	7r)r )r*N)Fr)rrrrrr�classmethodr)r4r(r?rBr<rArJrrQrTr[rWrNr|r�rirtr�r rrr"r"7s{������=�=�<�I������H�H�H��[�H����1�1�1�1����-�-�-�	�	�	�5�5�5�%�%�%�)�)�)�����67�7�7�����!
�!
�!
�!
�F+�+�+����>2'�2'�2'�h���*�*�*�&7�7�7�7�7rr"c�p�eZdZdZdZd�Zd�Zd�Zd�Zd�Z	d�Z
d	�Zd
�Zd�Z
d�Zd
�Zd�Zd�Zd�Zd�ZdS)rGaInvokes 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.

    ��bqrI�_params�_post_criteriac�>�||_||_i|_g|_dSrr�)rr�rIs   rrzResult.__init__ms%����������� ����rc���t|��dkr|�|d��n't|��dkrtjd���|j�|��|S)z@Specify parameters to be replaced into the string SQL statement.r�rzFparams() takes zero or one positional argument, which is a dictionary.)�len�updater~rr�)rr�kws   rr�z
Result.paramsssr���t�9�9��>�>��I�I�d�1�g�����
��Y�Y��]�]��&�)���
�	
����B�����rc�>�|r|j�|��|Sr)r��extend)r�fnss  r�_using_post_criteriazResult._using_post_criteria�s&���	,���&�&�s�+�+�+��rc�.�|�|g��S)a'Add a criteria function that will be applied post-cache.

        This adds a function that will be run against the
        :class:`_query.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.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


        )r�)rr8s  rr�zResult.with_post_criteria�s��(�(�(�"��.�.�.rc��|j�|j���|j��}|jD]
}||��}�|Sr)r�rirIr�r�r�)rrZr8s   rrizResult._as_query�sO���G���d�l�+�+�2�2�4�<�@�@���%�	�	�B���1���A�A��rc�D�t|�����Sr)�strri�rs r�__str__zResult.__str__�s���4�>�>�#�#�$�$�$rc��|j}|jjr|jr!t	|�����S|j�|�|j��d��}|�|�	|j��}tj
|��}|j|_|j�
��|_|�|j||j
|j��d|j_|jr |js|j���|j�|j
���|j��}|jD]
}||��}�|�|��S�NT)r�rI�enable_baked_queriesr&�iterrir$rhrTr|�copyr�r�r�r��	statement�
use_labels�	autoflush�populate_existing�
_autoflushrkr�rj�_execute_and_instances)rr��
baked_contextrzrZr8s      r�__iter__zResult.__iter__�s^��
�W���|�0�	*�B�K�	*�����(�(�)�)�)��
���r�'8�'8���'F�'F��M�M�
�� ��H�H�T�\�2�2�M��)�M�*�*���,���$�/�4�4�6�6���
�#�#��L�'�4�<��1D�	
�	
�	
�(,���$���	&�W�%>�	&��L�#�#�%�%�%��M� � ���.�.�;�;�D�L�I�I���%�	�	�B���1���A�A��'�'��0�0�0rc���tjtd�����|j��fd���}|�|j���|j���	��S)z�return the 'count'.

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

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

        .. versionadded:: 1.1.6

        �*c�.��|����Sr)�	from_self)rZ�cols �rr`zResult.count.<locals>.<lambda>�s���Q�[�[��-=�-=�r)
r	�countr
r�rArJrIr�r��scalar)rr�r�s  @rr�zResult.count�sk����j���,�,�-�-��
�W�
"�
"�#=�#=�#=�#=�
>�
>���~�~�d�l�+�+�2�2�4�<�@�@�G�G�I�I�Irc��	|���}t|t��s|S|dS#tj$rYdSwxYw)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.Query.scalar`.

        .. versionadded:: 1.1.6

        rN)�oner:r;�orm_exc�
NoResultFound)r�rets  rr�z
Result.scalar�sY��	��(�(�*�*�C��c�5�)�)�
��
��q�6�M���$�	�	�	��4�4�	���s�*5�5�A�Ac� �|j�d���}t|�|j���|j���|j����}t|��dkr|dSdS)zRReturn the first row.

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

        c�.�|�dd��Sr�)�slice)rZs rr`zResult.first.<locals>.<lambda>�s��Q�W�W�Q��]�]�rrN)
r�rAr2rJrIr�r�r�r�r�)rr�r�s   r�firstzResult.first�s|���W�
"�
"�#:�#:�
;�
;����N�N�4�<�(�(�
�V�D�L�
!�
!�
!�
!�$�"5�
6�
6�
�
��
�s�8�8�a�<�<��q�6�M��4rc���	|���}|�tjd���|S#tj$r3}t	jtjd��|���Yd}~dSd}~wwxYw)zkReturn exactly one result or raise an exception.

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

        NzNo row was found for one()z"Multiple rows were found for one())�replace_context)�one_or_noner�r��MultipleResultsFoundr�raise_)rr��errs   rr�z
Result.one�s���	��"�"�$�$�C��{��+�,H�I�I�I��J���+�	�	�	��K��,�8���!$�	
�
�
�
�
�
�
�
�
�
�����	���s�.�A0�(A+�+A0c��t|��}t|��}|dkr|dS|dkrdStjd���)z�Return one or zero results, or raise an exception for multiple
        rows.

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

        .. versionadded:: 1.0.9

        r�rNz*Multiple rows were found for one_or_none())r2r�r�r�)rr��ls   rr�zResult.one_or_nonesR���4�j�j����H�H����6�6��q�6�M�
�!�V�V��4��.�<���
rc� �t|��S)zKReturn all rows.

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

        )r2r�s r�allz
Result.alls���D�z�z�rc�x�|jjd|j��}|�||j��S)z`Retrieve an object based on identity.

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

        r)r�r#rI�	_get_impl�_load_on_pk_identity)r�identrks   rrhz
Result.get"s5��!���
�a� ���.�.�����u�d�&?�@�@�@rc�4����	�
�|����
�
j\��	��	�
��fd�}�j}|���}|xj�fz
c_|�|t
d��D������}t�	fd�t��
j	��D����}t|��j��j
di|����}t|��}|dkrtj���|r|dSdS)z6Load the given primary key identity from the database.c�^���}|���}|���d|_d�vrCt�fd�t	�j���D����}t
j||��}|�|dd��}||_	�	j
D]
}||��}�|S)Nc�4��g|]\}}|��|j��Sr�rd)�.0r��value�_get_paramss   �r�
<listcomp>z>Result._load_on_pk_identity.<locals>.setup.<locals>.<listcomp>=s6������&�C��!�=�	$�C�(�,�)�=�=rTF)r4�_get_condition�	_order_by�set�zip�primary_key�sql_util�adapt_criterion_to_null�
_adapt_clause�
_criterionr�)
rk�_lcl_get_clauserZ�nonesr8�_get_clauser��mapper�primary_key_identityrs
     �����r�setupz*Result._load_on_pk_identity.<locals>.setup3s����)�O������A�
�������A�K��+�+�+������*-�"�.�0D�+�+�������#+�"B�#�U�#�#�� �o�o�o�t�U�K�K�O�*�A�L��)�
�
���B�q�E�E����Hrc3�K�|]}|duV��	dSrr )r��elems  r�	<genexpr>z.Result._load_on_pk_identity.<locals>.<genexpr>[s&����G�G�$����G�G�G�G�G�Grc�4��g|]\}}�|j|f��Sr r�)r��id_valr�r�s   �rr�z/Result._load_on_pk_identity.<locals>.<listcomp>_s:���
�
�
�'�F�K��[�)�-�v�6�
�
�
rr�rNr )�_mapper_zeror�r�r4r%rAr;�dictr�r�r2rJrIr�r�r�r�)rrkr�r�r�r��resultr�r�r�r�s` `     @@@rr�zResult._load_on_pk_identity,sd��������#�#�%�%��#)�#5� ��[�	�	�	�	�	�	�	�	�	�>�W��
�Y�Y�[�[��
�
�
�+��'�
�
�
�
�
��5�G�G�2F�G�G�G�G�G�
�
���
�
�
�
�+.�(�&�*<�,�,�
�
�
�
�
���9�b�n�n�T�\�2�2�9�C�C�F�C�C�D�D����K�K���q�5�5��.�0�0�0�
�	��!�9���4rN)rrrrrrr�r�r�rir�r�r�r�r�r�r�r�rhr�r rrrGrGbs��������=�I�!�!�!�������
/�/�/�,���%�%�%�1�1�1�4J�J�J� ���$���"���(���*���A�A�A�B�B�B�B�BrrGz1.2z5Baked lazy loading is now the default implementation.c��dS)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.

    Nr r rr�bake_lazy_loadersr�qs	��	�Drc� �td���)aHDisable 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:`_orm.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 implementation)�NotImplementedErrorr rr�unbake_lazy_loadersr�~s���>���rc�2�|�|ddi��S)zxIndicate that the given attribute should be loaded using "lazy"
    loading with a "baked" query used in the load.

    �lazy�baked_select)�set_relationship_strategy)�loadoptr{s  r�baked_lazyloadr�s���,�,�T�F�N�3K�L�L�LrzFBaked lazy loading is now the default implementation for lazy loading.c�d�tj�tjj|di��S)NF�r�_UnboundLoad�
_from_keysr��keyss rrr�s.���(�3�3��%�4�d�E�2���rc�d�tj�tjj|di��Sr�rrs r�baked_lazyload_allr	�s.���(�3�3��%�4�d�D�"���r)$rr��logging�rr~r�ormr�r�	orm.queryr�orm.sessionr�sqlr	r
r��	getLoggerr�log�objectrr"rG�
deprecatedr�r��
loader_optionr�_add_unbound_fn�_add_unbound_all_fnr	�_unbound_fn�_unbound_all_fnr)r rr�<module>rs������������������������� � � � � � �"�"�"�"�"�"�������!�!�!�!�!�!������� � � � � � �"�"�"�"�"�"��g���!�!��6�6�6�6�6�V�6�6�6�,h7�h7�h7�h7�h7��h7�h7�h7�V	L�L�L�L�L�V�L�L�L�^���	�B���	�	���	����	�B�������� ���!�!�M�M�"�!�M������	�'���
���� ����#����	�'���
����$�#�� �+��'�7��	�	���r

Hacked By AnonymousFox1.0, Coded By AnonymousFox