Sh3ll
OdayForums


Server : LiteSpeed
System : Linux premium84.web-hosting.com 4.18.0-553.44.1.lve.el8.x86_64 #1 SMP Thu Mar 13 14:29:12 UTC 2025 x86_64
User : claqxcrl ( 523)
PHP Version : 8.1.32
Disable Function : NONE
Directory :  /opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/sql/__pycache__/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : //opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/sql/__pycache__/lambdas.cpython-312.pyc
�

���g,����UddlmZddlmZddlZddlZddlZddlZddl	Z	ddl	m
Z
ddlmZddlm
Z
ddlmZddlmZddlmZdd	lmZdd
lmZddlmZddlmZdd
lmZddlmZddlZddlmZddlmZddlmZddlmZddlmZddlmZddl m!Z!ddl m"Z"ddl m#Z#ddlm$Z$ddl%m&Z&ddlm'Z'ddlm(Z(ddlm)Z)ddl*m+Z+erdd lm,Z,dd!lm-Z-dd"lm.Z.dd#lm/Z/eeed$fed%fZ0e
d$efZ1e)jdd&�Z3d'e4d(<e
gefZ5e
d$efZ6e
gefZ7ed)e"�*�Z8e
e8gefZ9Gd+�d,e#�Z:						dA															dBd.�Z;Gd/�d0ejZ�Z<Gd1�d2e<�Z=Gd3�d-ej|e<e"�Z?Gd4�d5ej|ejZ�Z@Gd6�d7e?�ZAGd8�d9�ZBGd:�d;�ZCGd<�d=�ZDGd>�d?e&�ZEe(j�e<�d@��ZGy)C�)�annotationsN)�CodeType)�Any)�Callable)�cast)�List)�MutableMapping)�Optional)�Tuple)�Type)�
TYPE_CHECKING)�TypeVar)�Union�)�	cache_key)�	coercions)�elements)�roles)�schema)�visitors)�_clone)�
Executable)�Options)�
CacheConst)�ColumnOperators�)�exc)�
inspection)�util)�Literal)�
BindParameter)�
ClauseElement)�SQLRole)�_CloneCallableType.)�NonAnalyzedFunction�AnalyzedFunctioni��_LambdaCacheType�_closure_per_cache_key�_E)�boundc�:�eZdZUdZdZdZded<dZdZdZ	ded<y)�
LambdaOptionsTN�Optional[object]�track_on�Optional[_LambdaCacheType]�lambda_cache)
�__name__�
__module__�__qualname__�enable_tracking�track_closure_variablesr.�__annotations__�global_track_bound_values�track_bound_valuesr0���G/opt/hc_python/lib64/python3.12/site-packages/sqlalchemy/sql/lambdas.pyr,r,Hs/���O�"��!%�H��%� $����/3�L�,�3r:r,�StatementLambdaElementc�V�t|tjt||||||���S)ahProduce a SQL statement that is cached as a lambda.

    The Python code object within the lambda is scanned for both Python
    literals that will become bound parameters as well as closure variables
    that refer to Core or ORM constructs that may vary.   The lambda itself
    will be invoked only once per particular set of constructs detected.

    E.g.::

        from sqlalchemy import lambda_stmt

        stmt = lambda_stmt(lambda: table.select())
        stmt += lambda s: s.where(table.c.id == 5)

        result = connection.execute(stmt)

    The object returned is an instance of :class:`_sql.StatementLambdaElement`.

    .. versionadded:: 1.4

    :param lmb: a Python function, typically a lambda, which takes no arguments
     and returns a SQL expression construct
    :param enable_tracking: when False, all scanning of the given lambda for
     changes in closure variables or bound parameters is disabled.  Use for
     a lambda that produces the identical results in all cases with no
     parameterization.
    :param track_closure_variables: when False, changes in closure variables
     within the lambda will not be scanned.   Use for a lambda where the
     state of its closure variables will never change the SQL structure
     returned by the lambda.
    :param track_bound_values: when False, bound parameter tracking will
     be disabled for the given lambda.  Use for a lambda that either does
     not produce any bound values, or where the initial bound values never
     change.
    :param global_track_bound_values: when False, bound parameter tracking
     will be disabled for the entire statement including additional links
     added via the :meth:`_sql.StatementLambdaElement.add_criteria` method.
    :param lambda_cache: a dictionary or other mapping-like object where
     information about the lambda's Python code as well as the tracked closure
     variables in the lambda itself will be stored.   Defaults
     to a global LRU cache.  This cache is independent of the "compiled_cache"
     used by the :class:`_engine.Connection` object.

    .. seealso::

        :ref:`engine_lambda_caching`


    )r4r.r5r7r8r0)r<r�
StatementRoler,)�lmbr4r5r.r7r8r0s       r;�lambda_stmtr@Qs8��v"��
����+��$;�&?�1�%�
	
��r:c�\�eZdZUdZdZdZdejjfgZ	dZ
ded<ded	<d
Zded<d
ed<ded<ded<ded<ded<d�Z
ed
f							d$d�Zd�Zd�Zed��Zed��Zed��Zd�Zd�Zed
f							d%d �Zej6d!��Zd"�Zd&d#�Zy
)'�
LambdaElementa�A SQL construct where the state is stored as an un-invoked lambda.

    The :class:`_sql.LambdaElement` is produced transparently whenever
    passing lambda expressions into SQL constructs, such as::

        stmt = select(table).where(lambda: table.c.col == parameter)

    The :class:`_sql.LambdaElement` is the base of the
    :class:`_sql.StatementLambdaElement` which represents a full statement
    within a lambda.

    .. versionadded:: 1.4

    .. seealso::

        :ref:`engine_lambda_caching`

    �lambda_elementT�	_resolvedr9zTuple[_CloneCallableType, ...]�_transformszList[BindParameter[Any]]�_resolved_bindparamsNz Optional[StatementLambdaElement]�
parent_lambdaz4Union[Tuple[Any, ...], Literal[CacheConst.NO_CACHE]]�closure_cache_key�
Type[SQLRole]�rolez,Union[AnalyzedFunction, NonAnalyzedFunction]�_rec�_AnyLambdaType�fnzTuple[CodeType, ...]�tracker_keyc�b�|jj�d|jj�d�S)N�(�))�	__class__r1rM�__code__��selfs r;�__repr__zLambdaElement.__repr__�s&���N�N�#�#��G�G���
�	
r:c���||_||_|jf|_||_|�|t
jur|}|j|||�}|�|j}|r||_	yyy�N)
rMrJrSrN�optsrr>�_retrieve_tracker_rec�propagate_attrs�_propagate_attrs)rUrMrJrY�apply_propagate_attrs�recr[s       r;�__init__zLambdaElement.__init__�s|�������	��K�K�>�����	� �(�d�e�6I�6I�.I�$(�!��(�(��-B�D�I�� �,�!�1�1�O��9H�%�6��-r:c�V�|j}|�t}|j}|j}|j}t
j
|||�}gx|_}|j�|jj}	nd}	|	tjur{tj�}
t|jD�cgc]
}||||
|���c}�}tj|
vr|	|z}||_		|||z}
n%tj}d}
ntj}d}
||_	|
�y|tjurLt
j"5||z}||vr$t%||||�}
t'|�|
_|
||<n||}
ddd�nbt+|j-|��}
nGt/|
j(|�D��cgc]"\}}|j1|j2d����$c}}|dd|
|_|tjur�|j�|jj|dd|}|�X|j4}
|
j6r1|
j8}|
j6D]}||j||��|j}|��X|
Scc}w#t $rd}
Y��xwxYw#1swY��xYwcc}}w)Nr9T��maintain_keyr)r0r(rNrM�__closure__�AnalyzedCode�getrFrGrH�
_cache_key�NO_CACHEr�anon_map�tuple�closure_trackers�KeyError�_generation_mutexr&�list�closure_bindparamsr%�_invoke_user_fn�zip�_with_value�valuerK�bindparam_trackers�tracker_instrumented_fn)rUrMr]rYr0rN�closure�tracker�
bindparams�parent_closure_cache_keyrh�getterrr^�key�	orig_bind�new_bindrCrts                   r;rZz#LambdaElement._retrieve_tracker_rec�s����(�(����1�L��&�&��
�W�W���.�.���"�"����
��24�3��!�J����)�'+�'9�'9�'K�'K�$�')�$�$�:�+>�+>�>��(�(�*�H��#*�":�":��":���7�D�(�J�?�":���I��"�"�(�2�4�y�@�	�)2��&��&�{�Y�'>�?�C�'�/�/�	���#�+�+�I��C�!*����;��
� 3� 3�3�!�3�3�%�	�1�C��,�.�.�#�T�+@�"���26�j�1A��.�,/��S�)�*�3�/��4�3�*�$�*>�*>�r�*B�C��
,/��*�*�J�,��,�'�I�x��%�%�h�n�n�4�%�H�,��J�q�M���	��J�/�/�/��!�!�-�!%�!3�!3�!H�!H�
�2�A��6:�N� �,�$�)�)���)�)�.1�.I�.I�+�#&�#9�#9���*�-�-�3�&��$:�"0�!=�!=��!�,��
��G�� ���C���4�3��s*�7J�/J�3J�8'J%�J�J�J"c�B�t|jj|�SrX)�getattrrK�
expected_expr�rUrzs  r;�__getattr__zLambdaElement.__getattr__=s���t�y�y�.�.��4�4r:c�.�|jjSrX)rK�is_sequencerTs r;�_is_sequencezLambdaElement._is_sequence@s���y�y�$�$�$r:c���|jrAtjj|jD�cgc]}|j
��c}�S|jj
Scc}wrX)r��	itertools�chain�
from_iterablerD�_select_iterable�rU�elements  r;r�zLambdaElement._select_iterableDsV������?�?�0�0�9=���H��g��)�)��H��
�
�>�>�2�2�2��	I��A$c���|jrAtjj|jD�cgc]}|j
��c}�S|jj
Scc}wrX)r�r�r�r�rD�
_from_objectsr�s  r;r�zLambdaElement._from_objectsNsV������?�?�0�0�6:�n�n�E�n�7��&�&�n�E��
�
�>�>�/�/�/��	Fr�c�j�|jD�cic]}|j|j��c}Scc}wrX)rFrzrr)rU�bs  r;�_param_dictzLambdaElement._param_dictXs.��(,�(A�(A�B�(A�1����q�w�w��(A�B�B��Bs�0c�>��|jD�cic]}|j|��c}�						d�fd�}|jjr&|D�cgc]}t	j
|i|���}}|St
|dd�rt	j
|i|�}|Scc}wcc}w)Nc����t|tj�rT|j�vrF�|j}|jr)d|_|j
|_|j|_|Sy�NT)�
isinstancerr!rz�	expanding�	expand_op�type)r��kw�bind�bindparam_lookups   �r;�replacez<LambdaElement._setup_binds_for_tracked_expr.<locals>.replace^s`����'�8�#9�#9�:��;�;�"2�2�+�G�K�K�8�D��(�(�)-���)0�):�):���$+�L�L��	��K�r:�is_clause_elementF)r��(Optional[visitors.ExternallyTraversible]r�r�returnr�)rFrzrKr�r�replacement_traverser~)rU�exprr�r��sub_exprr�s     @r;�_setup_binds_for_tracked_exprz+LambdaElement._setup_binds_for_tracked_expr[s����.2�.G�.G�H�.G��A�E�E�1�H�.G�H��	�=�	�EH�	�
5�	��9�9� � �!%�� $�H��-�-�h��G�D� $�
�����T�.��
6��0�0��r�7�C�D����1I��"s�B�
Bc�8�||jfd|i|��|_y)N�deferred_copy_internals)rD)rU�cloner�r�s    r;�_copy_internalszLambdaElement._copy_internalsvs)����N�N�
�$;�
��
��r:c�l�|jj}|jr|j|�}|SrX)rKrrFr��rUr�s  r;rDzLambdaElement._resolved�s/���y�y�&�&���$�$��5�5�d�;�D��r:c���|jtjurd|tj<y|jj|j
f|jz}|j}|�V|jtjusJ�|j}|jjf|z|z}|j}|��V|jr|j|j�|Sr�)
rHrfrgrMrSrRrGrrF�extend)rUrhrwr�parentrxs      r;�_gen_cache_keyzLambdaElement._gen_cache_key�s����!�!�Z�%8�%8�8�,0�H�Z�(�(�)��
�G�G����N�N�
�
�"�"�#�	�
�#�#��� ��+�+�:�3F�3F�F�F�F��(�(�
%�
���#�#�%�(@�@�9�L�
��)�)�F�� ��$�$����d�7�7�8��r:c��|�SrXr9�rUrM�args   r;rozLambdaElement._invoke_user_fn�s	���t�r:)rM�_LambdaTyperJrIrY�)Union[Type[LambdaOptions], LambdaOptions]r]�Optional[ClauseElement])r�r$r�zOptional[_CloneCallableType]r�rr��None)rMrLr�rr�r")r1r2r3�__doc__�__visit_name__�_is_lambda_elementr�InternalTraversal�dp_clauseelement�_traverse_internalsrEr6rGrVr,r_rZr��propertyr�r�r�r�r�rr�r�memoized_propertyrDr�ror9r:r;rBrB�sV���&&�N���
�h�0�0�A�A�B���35�K�/�4�2�2�6:�M�3�:�K�K�
��
6�6���%�%�
�;H�9=�I��I��I�8�	I�
 7�I�,_�B5��%��%��3��3��0��0�C��:%+�@D�
�!�
�">�
��	
�

�
�
�������8r:rBc�V��eZdZdZedf							d�fd�
Zd�Zd	d�Zedf�fd�	Z	�xZ
S)
�DeferredLambdaElementa>A LambdaElement where the lambda accepts arguments and is
    invoked within the compile phase with special context.

    This lambda doesn't normally produce its real SQL expression outside of the
    compile phase.  It is passed a fixed set of initial arguments
    so that it can generate a sample expression.

    r9c�6��||_t�|�	|||�yrX)�lambda_args�superr_)rUrMrJrYr�rRs     �r;r_zDeferredLambdaElement.__init__�s���'���
����T�4�(r:c� �||j�SrX)r�r�s   r;roz%DeferredLambdaElement._invoke_user_fn�s���4�#�#�$�$r:c��t|jt�sJ�|jj}||�}t	j
|j|�}|j|�}|jD]
}||�}�|SrX)	r�rKr&rtr�expectrJr�rE)rUr��
tracker_fnr�r�s     r;�_resolve_with_argsz(DeferredLambdaElement._resolve_with_args�sz���$�)�)�%5�6�6�6��Y�Y�6�6�
��;�'������	�	�4�0���1�1�$�7��0(,�'7�'7�#�*�4�0�D�(8��r:Nc�\��t�|�|||��|r|xj|fz
c_yy)N)r�r�rY)r�r�rE)rUr�r�r�rRs    �r;r�z%DeferredLambdaElement._copy_internals�s?���	����$;��	 �	
�#����!8� :�:��#r:)rMrLrJzType[roles.SQLRole]rYr�r�zTuple[Any, ...])r�rr�r")r1r2r3r�r,r_ror�rr��
__classcell__)rRs@r;r�r��sX����;H�')�)��)�"�)�8�	)�
%�)�%�"�J�D�;�;r:r�c�(�eZdZdZeredf							dd�Z				dd�Z				d											dd�Zd�Z	e
dd��Ze
d��Ze
d	��Z
e
d
��Ze
d��Ze
d��Ze
d
��Ze
d��Ze
d��Ze
d��Ze
d��Zdd�Zy)r<a_Represent a composable SQL statement as a :class:`_sql.LambdaElement`.

    The :class:`_sql.StatementLambdaElement` is constructed using the
    :func:`_sql.lambda_stmt` function::


        from sqlalchemy import lambda_stmt

        stmt = lambda_stmt(lambda: select(table))

    Once constructed, additional criteria can be built onto the statement
    by adding subsequent lambdas, which accept the existing statement
    object as a single parameter::

        stmt += lambda s: s.where(table.c.col == parameter)

    .. versionadded:: 1.4

    .. seealso::

        :ref:`engine_lambda_caching`

    Nc��yrXr9)rUrMrJrYr]s     r;r_zStatementLambdaElement.__init__s��r:c�$�|j|�SrX)�add_criteria)rU�others  r;�__add__zStatementLambdaElement.__add__s��� � ��'�'r:c��|jt|||jj||��z}t|||��S)a(Add new criteria to this :class:`_sql.StatementLambdaElement`.

        E.g.::

            >>> def my_stmt(parameter):
            ...     stmt = lambda_stmt(
            ...         lambda: select(table.c.x, table.c.y),
            ...     )
            ...     stmt = stmt.add_criteria(lambda: table.c.x > parameter)
            ...     return stmt

        The :meth:`_sql.StatementLambdaElement.add_criteria` method is
        equivalent to using the Python addition operator to add a new
        lambda, except that additional arguments may be added including
        ``track_closure_values`` and ``track_on``::

            >>> def my_stmt(self, foo):
            ...     stmt = lambda_stmt(
            ...         lambda: select(func.max(foo.x, foo.y)),
            ...         track_closure_variables=False,
            ...     )
            ...     stmt = stmt.add_criteria(lambda: self.where_criteria, track_on=[self])
            ...     return stmt

        See :func:`_sql.lambda_stmt` for a description of the parameters
        accepted.

        )r4r5r7r.r8)rGrY)rY�dictr7�LinkedLambdaElement)rUr�r4r.r5r8rYs       r;r�z#StatementLambdaElement.add_criteria sD��J�y�y�4�+�$;�&*�i�i�&I�&I��1�
�
��#�5��4�H�Hr:c���tr&t|jjt�sJ�|jjj
r|j
|||�Stj|��rX)	r
r�rKrr"�supports_execution�_execute_clauseelementr�ObjectNotExecutableError�rU�
connection�distilled_params�execution_optionss    r;�_execute_on_connectionz-StatementLambdaElement._execute_on_connectionOsc����d�i�i�5�5�}�E�E�E��9�9�"�"�5�5��4�4��&�(9��
��.�.�t�4�4r:c��|jSrX)�_rec_expected_exprrTs r;�_proxiedzStatementLambdaElement._proxied[s���&�&�&r:c�.�|jjSrX)r��
_with_optionsrTs r;r�z$StatementLambdaElement._with_options_s���}�}�*�*�*r:c�.�|jjSrX)r��_effective_plugin_targetrTs r;r�z/StatementLambdaElement._effective_plugin_targetcs���}�}�5�5�5r:c�.�|jjSrX)r��_execution_optionsrTs r;r�z)StatementLambdaElement._execution_optionsgs���}�}�/�/�/r:c�.�|jjSrX)r��_all_selected_columnsrTs r;r�z,StatementLambdaElement._all_selected_columnsks���}�}�2�2�2r:c�.�|jjSrX)r��	is_selectrTs r;r�z StatementLambdaElement.is_selecto����}�}�&�&�&r:c�.�|jjSrX)r��	is_updaterTs r;r�z StatementLambdaElement.is_updatesr�r:c�.�|jjSrX)r��	is_insertrTs r;r�z StatementLambdaElement.is_insertwr�r:c�.�|jjSrX)r��is_textrTs r;r�zStatementLambdaElement.is_text{s���}�}�$�$�$r:c�.�|jjSrX)r��	is_deleterTs r;r�z StatementLambdaElement.is_deleter�r:c�.�|jjSrX)r��is_dmlrTs r;r�zStatementLambdaElement.is_dml�s���}�}�#�#�#r:c�4�t|j��S)ztReturn a new :class:`.StatementLambdaElement` that will run
        all lambdas unconditionally each time.

        )�NullLambdaStatementrMrTs r;�spoilzStatementLambdaElement.spoil�s��
#�4�7�7�9�-�-r:)rM�_StmtLambdaTyperJrIrYr�r]r�)r��_StmtLambdaElementType[Any]r�r<)TNTT)r�r�r4�boolr.z
Optional[Any]r5r�r8r�r�r<)r�r)r�r�)r1r2r3r�r
r,r_r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r�r9r:r;r<r<�s����0�?L�=A�	��	� �	�<�		�
$;�	�(�0�(�	�(�!%�"&�(,�#'�
-I�*�-I��-I� �	-I�
"&�-I�!�
-I�
 �-I�^
5��'��'��+��+��6��6��0��0��3��3��'��'��'��'��'��'��%��%��'��'��$��$�.r:c�h�eZdZdZdZdZdejjfgZ	d�Z
d�Zd�Zd�Z
d	�Zy
)r�z�Provides the :class:`.StatementLambdaElement` API but does not
    cache or analyze lambdas.

    the lambdas are instead invoked immediately.

    The intended use is to isolate issues that may arise when using
    lambda statements.

    rCTrDc�4�||_|j|_yrX)rDr\)rU�	statements  r;r_zNullLambdaStatement.__init__�s��"��� )� :� :��r:c�.�t|j|�SrX)r~rDr�s  r;r�zNullLambdaStatement.__getattr__�s���t�~�~�s�+�+r:c�<�||j�}t|�SrX�rDr�)rUr�r�s   r;r�zNullLambdaStatement.__add__�����$�.�.�)�	�"�9�-�-r:c�<�||j�}t|�SrXr�)rUr�r�r�s    r;r�z NullLambdaStatement.add_criteria�r�r:c�~�|jjr|j|||�Stj|��rX)rDr�r�rr�r�s    r;r�z*NullLambdaStatement._execute_on_connection�s@���>�>�,�,��4�4��&�(9��
��.�.�t�4�4r:N)r1r2r3r�r�r�rr�r�r�r_r�r�r�r�r9r:r;r�r��sK���&�N���
�h�0�0�A�A�B���;�,�.�
.�
5r:r�c�6�eZdZUdZded<						dd�Zd�Zy)r�zARepresent subsequent links of a :class:`.StatementLambdaElement`.r<rGc��||_||_||_|j|jfz|_|j|||�|j|_yrX)rYrMrGrNrSrZr\)rUrMrGrYs    r;r_zLinkedLambdaElement.__init__�sS����	����*���(�4�4����~�E����"�"�2�t�T�2� -� >� >��r:c�:�||jj�SrX)rGrDr�s   r;roz#LinkedLambdaElement._invoke_user_fn�s���$�$�$�.�.�/�/r:N)rMr�rGr<rYr�)r1r2r3r�r6r_ror9r:r;r�r��s1��K�)�)�?�'�?�.�?�8�	?�0r:r�c���eZdZUdZej
�Zded<ej�Z
ed��Zd�Z
d�Zd�Zd�Zd	�Zed
��Zd�Zd�Zd
�Z		dd�Z	dd�Zd�Zy)rd)r5r8rsrj�build_py_wrappersz1weakref.WeakKeyDictionary[CodeType, AnalyzedCode]�_fnsc�^�	|j|jS#t$rYnwxYw|j5|j|jvr"|j|jcddd�St	|||fi|��x|j|j<}|cddd�S#1swYyxYwrX)rrSrkrlrd)�clsrMrC�	lambda_kwr��analyzeds      r;rezAnalyzedCode.get�s���	��8�8�B�K�K�(�(���	��	���
"�
"��{�{�c�h�h�&��x�x����,�#�
"�0<��N�I�0�13�0�
�C�H�H�R�[�[�!�H��#�
"�
"�s��	'�'�1B#�1(B#�#B,c���tj|�rtjd|z��|j}|j
xr|j|_|j}|j}|j}|xr||_	g|_
g|_g|_|r7|r|j|�|j|�|r|j|�|j!|||�y)Nz/Method %s may not be passed as a SQL expression)�inspect�ismethodr�
ArgumentErrorrcr8r7r4r.r5rsrjr�_init_track_on�
_init_globals�
_init_closure�"_setup_additional_closure_trackers)rUrMrCrYrur4r.r5s        r;r_zAnalyzedCode.__init__�s������B���#�#�A�B�F��
��.�.��
�#�#�F��(F�(F�	
���.�.���=�=��"&�">�">��'>�'O�x�<��$�
#%���
!#���!#������#�#�H�-����r�"���"�"�2�&��/�/��N�D�Ir:c�`���jj�fd�t|�D��y)Nc3�H�K�|]\}}�j||����y�wrX)�_cache_key_getter_track_on)�.0�idx�elemrUs   �r;�	<genexpr>z.AnalyzedCode._init_track_on.<locals>.<genexpr>s*�����%
�0�	��T�
�+�+�C��6�0�s�")rjr��	enumerate)rUr.s` r;rzAnalyzedCode._init_track_ons)������$�$�%
�&�x�0�%
�	
r:c�t�|j}|j}|j}|jjD]{}||j
vr�|j
|j
|�}tj|�s�F|j|df�|s�\|j|j|���}yrX)rrsr8rS�co_names�__globals__�_roll_down_to_literalr�_deep_is_literal�append�$_bound_parameter_getter_func_globals)rUrMrrsr8�name�_bound_values       r;rzAnalyzedCode._init_globals#s��� �2�2��!�4�4��!�4�4���K�K�(�(�D��2�>�>�)���5�5�b�n�n�T�6J�K�L��)�)�,�7�!�(�(�$���6�%�&�-�-��A�A�$�G��)r:c	�,�|j}|j}|j}|j}|j}|j
}t
t|jj|��D]�\}\}	}
|j|
j�}tj|�r8|j|	|f�|s�O|j|j|	|���q|s�t|j|j!||	||
j����yrX)rrcr8r5rsrjrrprS�co_freevarsr�
cell_contentsrr r!�$_bound_parameter_getter_func_closure�"_cache_key_getter_closure_variable)rUrMrrur8r5rsrj�
closure_index�fv�cellr$s            r;rzAnalyzedCode._init_closure5s�� �2�2���.�.��!�4�4��"&�">�">��!�4�4���0�0��)2�����'�'��1�*
�%�M�:�B�� �5�5�d�6H�6H�I�L��)�)�,�7�!�(�(�"�m�)<�=�%�&�-�-��A�A��
���+�$�+�+��?�?���M�4�3E�3E���)*
r:c��t||d|�}|j}|jD]0}|jr�|j	|j||���2yrX)r&rj�closure_pywrappers�_sa__has_paramr!�!_cache_key_getter_tracked_literal)rUrMrCrY�analyzed_functionrj�	pywrappers       r;rz/AnalyzedCode._setup_additional_closure_trackersXs`��-�����	
�� �0�0��*�=�=�I��+�+� �'�'��:�:�2�y�I��>r:c��t|d�}|rpt|tjtj
tf�sA	|j�}t|tjtj
tf�s�A|s,tj|d��}|�	|j�S|S|S#t$rY�;wxYw#t$r|cYSwxYw)N�__clause_element__F��raiseerr)�hasattrr�rr"r�
SchemaItemr�r4�AttributeErrorrr
)r	r�r��insps    r;rz"AnalyzedCode._roll_down_to_literalns���#�G�-A�B��� ��(�0�0�&�2C�2C�T�J���%�8�8�:�G�	!��(�0�0�&�2C�2C�T�J��!��%�%�g��>�D��� ��2�2�4�4�
�N��N��&�����&� ��K� �s#�B/�B>�/	B;�:B;�>C�Cc����fd�}|S)z�Return a getter that will extend a list of bound parameters
        with new entries from the ``__globals__`` collection of a particular
        lambda.

        c�v��|j�}tj|d�|j�|�y�N�_extract_bound_parameters)r�object�__getattribute__)�
current_fnrt�result�wrapperr#s    �r;�extract_parameter_valuezRAnalyzedCode._bound_parameter_getter_func_globals.<locals>.extract_parameter_value�s;���.�9�9�$�?�G��#�#�G�-H�I��&�&�t�,�f�
r:r9)rUr#rDs ` r;r"z1AnalyzedCode._bound_parameter_getter_func_globals�s���	�'�&r:c����fd�}|S)z�Return a getter that will extend a list of bound parameters
        with new entries from the ``__closure__`` collection of a particular
        lambda.

        c���|j�j}tj|d�|j�j|�yr=)rcr'r?r@)rArtrBrCr*s    �r;rDzRAnalyzedCode._bound_parameter_getter_func_closure.<locals>.extract_parameter_value�sN���.�9�9����m�
�
�#�#�G�-H�I��&�&�}�5�C�C�V�
r:r9)rUr#r*rDs  ` r;r(z1AnalyzedCode._bound_parameter_getter_func_closure�s���	�'�&r:c���t|t�r�fd�}|St|tj�r�fd�}|S�fd�}|S)z�Return a getter that will extend a cache key with new entries
        from the "track_on" parameter passed to a :class:`.LambdaElement`.

        c�L����t��fd�|j�D��S)Nc3�B�K�|]}|j������y�wrX�r�)r�tup_elemrhrws  ��r;rzGAnalyzedCode._cache_key_getter_track_on.<locals>.get.<locals>.<genexpr>�s&������$6���+�+�H�j�A�$6���)rir.�rurYrhrwrs  ``�r;rez4AnalyzedCode._cache_key_getter_track_on.<locals>.get�s&�����$(�M�M�#�$6���r:c�B��|j�j||�SrX)r.r�rMs    �r;rez4AnalyzedCode._cache_key_getter_track_on.<locals>.get�s����}�}�S�)�8�8��:�N�Nr:c�"��|j�SrX)r.rMs    �r;rez4AnalyzedCode._cache_key_getter_track_on.<locals>.get�s����}�}�S�)�)r:)r�rirf�HasCacheKey)rUrrres `  r;rz'AnalyzedCode._cache_key_getter_track_on�sF����d�E�"�
� �
���j�4�4�
5�
O��
�
*��
r:c��������t|tj�r	���fd�}|St|tj�r�fd�}|St|t
j�r
����fd�}|S|}d}	t|d�r.d}	t|dd�s|j�}nn
t|d�r�.|	s/tj|d��}
|
�,�j���|
d�	�S�j���|d�
�S�j���S)z�Return a getter that will extend a cache key with new entries
        from the ``__closure__`` collection of a particular lambda.

        c����|�j}�rtj|�}n8�r6t|d�r*t	|dd�s|j�}t|d�r�*|j
||�S)Nr4r�F)r'rr
r7r~r4r�)rurYrhrw�objr�use_clause_element�use_inspects     ���r;rez<AnalyzedCode._cache_key_getter_closure_variable.<locals>.get�sp����c�l�0�0���$�,�,�S�1�C�'�!�#�';�<�&�s�,?��G�"%�"8�"8�":�C�"�#�';�<��)�)�(�J�?�?r:c�6��|�jjSrX)r'rSrMs    �r;rez<AnalyzedCode._cache_key_getter_closure_variable.<locals>.get�s����s�|�1�1�:�:�:r:c�����|�j}	t��fd�|D��S#t$r}�j�	�|��Yd}~yd}~wwxYw)Nc3�B�K�|]}|j������y�wrXrJ)rrrhrws  ��r;rzOAnalyzedCode._cache_key_getter_closure_variable.<locals>.get.<locals>.<genexpr>�s&�����!�$,�D��+�+�H�j�A�$,�rL)�from_)r'rir9�'_raise_for_uncacheable_closure_variable)
rurYrhrw�contents�aerMrrU�
variable_names
  ``  ����r;rez<AnalyzedCode._cache_key_getter_closure_variable.<locals>.get�sc���"�3�<�5�5��� �!�$,�!����&���@�@�%�r��A�����s�)�	A�A�AFr4Tr�r5)rU)rT)r�rfrP�types�FunctionType�collections_abc�Sequencer7r~r4rr
r)rZ)rUrMr]rr'rTrUrer�r�r:s```` ``    r;r)z/AnalyzedCode._cache_key_getter_closure_variable�s)����m�Z�%;�%;�<�	
@�t�
�_�
�u�'9�'9�
:�
;�Z�
�U�
��'?�'?�
@�
�P�
�-$�G� %���'�#7�8�$(�!��w�(;�U�C�%�8�8�:�G���'�#7�8�%�!�)�)�'�E�B���#��B�B��M�3��$�C����>�>��
�s�G��?���
�8�8���K��
r:Nc�P�tjd|�d|j�d��|�)NzClosure variable named 'z' inside of lambda callable a does not refer to a cacheable SQL element, and also does not appear to be serving as a SQL literal bound value based on the default SQL expression returned by the function.   This variable needs to remain outside the scope of a SQL-generating lambda so that a proper cache key may be generated from the lambda's state.  Evaluate this variable outside of the lambda, set track_on=[<elements>] to explicitly select closure elements to track, or set track_closure_variables=False to exclude closure variables from being part of the cache key.)r�InvalidRequestErrorrS)rUr]rMrYs    r;rZz4AnalyzedCode._raise_for_uncacheable_closure_variables,���%�%��b�k�k�
+�
��	r:c�r�|j}|j}|j}|j||||�S)a�Return a getter that will extend a cache key with new entries
        from the ``__closure__`` collection of a particular lambda.

        this getter differs from _cache_key_getter_closure_variable
        in that these are detected after the function is run, and PyWrapper
        objects have recorded that a particular literal value is in fact
        not being interpreted as a bound parameter.

        )�_sa__to_evaluate�_sa__closure_index�	_sa__namer))rUrM�	pytrackerrr*r]s      r;r0z.AnalyzedCode._cache_key_getter_tracked_literal%sA���)�)��!�4�4�
�!�+�+�
��6�6��
�}�d�
�	
r:)FFrX)r1r2r3�	__slots__�weakref�WeakKeyDictionaryrr6�	threading�RLockrl�classmethodrer_rrrrrr"r(rr)rZr0r9r:r;rdrd�s����I�	"��!�!�#�	�
;��(�	���)������$%J�N
��$!�F�,����2'�"'�&�@!��J�Z(,��&
r:rdc�V�eZdZUdZdZded<dZded<dZded	<dd
�Ze	d
d��Z
y)r%�r�N�"Optional[List[BindParameter[Any]]]rn�%Optional[List[_BoundParameterGetter]]rsFr"r�c��||_yrXrpr�s  r;r_zNonAnalyzedFunction.__init__Cs	����	r:c��|jSrXrprTs r;rz!NonAnalyzedFunction.expected_exprFs���y�y�r:)r�r")r�r")r1r2r3rirnr6rsr�r_r�rr9r:r;r%r%9sC���I�=A��:�A�@D��=�D��K�
������r:r%c�H�eZdZUdZded<ded<ded<d�Zd	�Zd
�Zd�Zy)
r&)
�
analyzed_coderMr.rtr�rsrr�r[rnrqrnz)Union[ClauseElement, List[ClauseElement]]rrrrsc��||_||_|j|_|j|�|j	||�yrX)rvrMrs�_instrument_and_run_function�_coerce_expression)rUrvrCr]rMs     r;r_zAnalyzedFunction.__init__]s@��+������"/�"B�"B����)�)�.�9�����0E�Fr:c�>�|j}|j}gx|_}|j}|s |x|_}|j|�|_y|j}|j}|r>t|jj|�D�	�
cic]\}	}
|	|
j��}}	}
ni}|jj�}|D]u\}
}|�M||j}t||
|||jj ��x||
<}|s�C|j#|��U|j|
}t||
|�x||
<}�w|j%||jjD�
cgc]}
||
��	c}
|�x|_}|j|�|_ycc}
}	wcc}
w)N)r*r8)rvrMr.rrtror�r5rcrprSr&r'r�copy�	PyWrapperr8r!�_rewrite_code_obj)rUrCrvrMr.rrtr5rur+r,�new_closure�new_globalsr#r*rrr�s                 r;rxz-AnalyzedFunction._instrument_and_run_functionms����*�*�
�
�W�W��79�9���"4�)�;�;�� �EG�G�D�(�+B�&�6�6�7N�O�D�I�&3�&K�&K�#��n�n�G��%(����(?�(?��$I��$I���D���*�*�*�$I���
!���.�.�-�-�/�K�'8�#��m� �,�#�M�2�@�@�E�/8����&3� �.�.�A�A�
0��K��%��/�*�1�1�$�7��N�N�4�0�E�/8��T�5�/I�I�K��%��!(9�*�&�&��35�;�;�3J�3J�K�3J�4�[��&�3J�K���
�D�(�+B�&'�6�6�7N�O�D�I��c��BLs�
F�"F
c���|j}|j}|��t|tj�rG|D�cgc].}tdt
j|j||�����0c}|_	d|_
nGtdt
j|j||���|_	d|_
n||_	d|_
|�|j|_ytj|_ycc}w)a,Run the tracker-generated expression through coercion rules.

        After the user-defined lambda has been invoked to produce a statement
        for re-use, run it through coercion rules to both check that it's the
        correct type of object and also to coerce it to its useful form.

        Nr")r]TF)rGr�r�r`rarrr�rJrr�r\r[r�
EMPTY_DICT)rUrCr]rGr�r�s      r;ryz#AnalyzedFunction._coerce_expression�s���'�4�4�
��y�y��� ��$�� 8� 8�9�%)�
&�%)���'�!�(�(�*�/�/�$�2G���%)�
&��"�$(�� �%)�#��$�$�&�+�+��.C��&��"�$)�� �!%�D��$�D�� �,�#8�#I�#I�D� �#'�?�?�D� ��;
&s�3C-c�H�tt|��}d}|r8|ddjd�|D���ddjd�|D���d�z
}|dz
}|d	djd
�|D��zz
}|dz
}|D�cic]}d|z||��
}}t|||�|d
�}t	|�|j
||j|j|�}	|j|	_|j|	_	|j|	_
|j|	_|	Scc}w)zaReturn a copy of f, with a new closure and new globals

        yes it works in pypy :P

        zdef make_cells():
z    (z, c3�&K�|]	}d|z���y�w�zi%dNr9�r�is  r;rz5AnalyzedFunction._rewrite_code_obj.<locals>.<genexpr>������6�X��%�!�)�X���z) = (c3�&K�|]	}d|z���y�w)�o%dNr9r�s  r;rz5AnalyzedFunction._rewrite_code_obj.<locals>.<genexpr>�r�r�z)
z    def closure():
z        return %s
c3�&K�|]	}d|z���y�wr�r9r�s  r;rz5AnalyzedFunction._rewrite_code_obj.<locals>.<genexpr>�s����1N�X��%�!�)�X�r�z    return closure.__closure__r��
make_cells)�range�len�join�execr�rSr1�__defaults__r6�__kwdefaults__r�r2)
rU�f�cell_values�globals_�argrange�coder��vars_ru�funcs
          r;r}z"AnalyzedFunction._rewrite_code_obj�s&����[�)�*��$�����	�	�6�X�6�6��	�	�6�X�6�6��
�D�	
�&�&���%��	�	�1N�X�1N�(N�N�N���0�0��4<�=�H�q����K��N�*�H��=��T�5�%� �%�%��%�'���t�A�w�
�J�J��!�*�*�a�n�n�g�
�� !�0�0����.�.����y�y����,�,������>s�=DN)	r1r2r3rir6r_rxryr}r9r:r;r&r&Ks6���I�;�:�<�<�=�=�G� BP�H+3�Zr:r&c�\�eZdZdZ			dd�Zd�Zd�Zd�Zd�Zdd�Z	d	�Z
d
�Zd�Zd�Z
d
�Zy)r|a�A wrapper object that is injected into the ``__globals__`` and
    ``__closure__`` of a Python function.

    When the function is instrumented with :class:`.PyWrapper` objects, it is
    then invoked just once in order to set up the wrappers.  We look through
    all the :class:`.PyWrapper` objects we made to find the ones that generated
    a :class:`.BindParameter` object, e.g. the expression system interpreted
    something as a literal.   Those positions in the globals/closure are then
    ones that we will look at, each time a new lambda comes in that refers to
    the same ``__code__`` object.   In this way, we keep a single version of
    the SQL expression that this lambda produced, without calling upon the
    Python function that created it more than once, unless its other closure
    variables have changed.   The expression is then transformed to have the
    new bound values embedded into it.

    Nc��||_||_||_d|_d|_i|_||_||_||_y)NF)	rM�_name�_to_evaluate�_param�
_has_param�_bind_paths�_getter�_closure_indexr8)rUrMr#�to_evaluater*ryr8s       r;r_zPyWrapper.__init__sG�������
�'���������������+���"4��r:c�D�tj|d�}||i|��}|jrutj|�r`t|tj�sFtj|d�}tjd|�d|jj�d���|S)Nr�r�zCan't invoke Python callable z+() inside of lambda expression argument at a�; lambda SQL constructs should not invoke functions from closure variables to produce literal values since the lambda SQL system normally extracts bound values without actually invoking the lambda or any functions within it.  Call the function outside of the lambda and assign to a local variable that is used in the lambda as a closure variable, or set track_bound_values=False if the return value of this function is used in some other way other than a SQL bound value.)r?r@�_sa_track_bound_valuesrr r�rfrPrrc�_sa_fnrS)rUr�r�rrrr#s      r;�__call__zPyWrapper.__call__$s����&�&�t�^�<���c� �R� ���'�'��*�*�5�1����&�&���*�*�4��9�D��)�)�!�$�+�+�"6�"6�8��
� �Lr:c�N�tj|d��}||g|��i|��S�N�_py_wrapper_literal�r?r@�rU�opr��kwargsrs     r;�operatezPyWrapper.operateCs-���&�&�t�-B�C�E���$�)��)�&�)�)r:c�J�tj|d��}|||fi|��Sr�r�r�s     r;�reverse_operatezPyWrapper.reverse_operateGs*���&�&�t�-B�C�E���%��(��(�(r:c�.�tj|d�}|�$|j|d��}|j|�tj|d�j	�D]2}tj|d�}||�}|j||��4y)Nr�Trar�r�)r?r@rqr!�values�_sa__extract_bound_parameters)rU�starting_point�result_list�paramr2ryr�s       r;r>z#PyWrapper._extract_bound_parametersKs����'�'��h�7�����%�%�n�4�%�H�E����u�%��0�0��}�E�L�L�N�I��,�,�Y�	�B�F��^�,�G��3�3�G�[�I�Or:c��tj|d�}tj|d�}|�Ltj|d�}tj|dd||�|jnd��x|_}d|_|j|d��S)Nr�r�r�FT)�required�unique�_compared_to_operator�_compared_to_typera)r?r@rr!r�r�r�rq)rUr��operatorr�r�r�r#s       r;r�zPyWrapper._py_wrapper_literalUs����'�'��h�7���-�-�d�N�C���=��*�*�4��9�D�"*�"8�"8����&.�/3�/?�$�)�)�T�#�
�D�K�%�#�D�O�� � ��4� �@�@r:c�D�tj|d�}t|�S�Nr�)r?r@r�)rUr�s  r;�__bool__zPyWrapper.__bool__ds���-�-�d�N�C���K� � r:c�0�|jd�rtj||dd�S|dvrtj||�S|jd�r"tj|d�}t||�S|j	|t
j�S)N�_sa_�)r4r�r�r�rR�__dict__�__r�)�
startswithr?r@r~�_sa__add_getterr��
attrgetter�rUrzrs   r;r@zPyWrapper.__getattribute__hs����>�>�&�!��*�*�4��Q�R��9�9�
�
�
��*�*�4��5�5��>�>�$���*�*�4��@�D��4��%�%��'�'��X�-@�-@�A�Ar:c�D�tj|d�}t|�Sr�)r?r@�iter)rUrs  r;�__iter__zPyWrapper.__iter__{s���&�&�t�^�<���D�z�r:c���tj|d�}t|d�std��t	|t
�rt
jd��|j|tj�S)Nr��__getitem__zUDictionary keys / list indexes inside of a cached lambda must be Python literals only)r?r@r7r9r�r|rrcr�r��
itemgetterr�s   r;r�zPyWrapper.__getitem__sf���&�&�t�^�<���t�]�+� ��/�/��c�9�%��)�)�6��
��#�#�C��)<�)<�=�=r:c�,�tj|d�}||f}||vr||S||�}tj|d�}||�}tj|�}t	j
|�r t
|j|||��}	|	||<|	S|S)Nr�r�)ry)r?r@rdrrr r|r�)
rUrz�	getter_fn�
bind_paths�
bind_path_keyryrrr�rolled_down_valuerCs
          r;�_add_getterzPyWrapper._add_getter�s����,�,�T�=�A�
��i�(�
��J�&��m�,�,��3����&�&�t�^�<���t���(�>�>�u�E���%�%�&7�8�����S�%��G�G�(/�J�}�%��N��Lr:)NNT)NN)r1r2r3r�r_r�r�r�r>r�r�r@r�r�r�r9r:r;r|r|�sL���,���5�&�>*�)�J�
A�!�B�&�>�r:r|c�@�tj|j�SrX)rr
rD)r?s r;r:r:�s�����c�m�m�,�,r:)TTNTTN)r?r�r4r�r5r�r.r-r7r�r8r�r0r/r�r<)H�
__future__r�collections.abc�abcr`r
r�r�rlr^r�typingrrrrr	r
rrr
rrrj�rrfrrrrr�baserrrr�	operatorsrrrr�util.typingr r!r"r#r$r'�_BoundParameterGetter�LRUCacher(r6r�rLr�r)�_StmtLambdaElementTyper,r@rBr��AllowsLambdaRoler<r�r�rdr%r&r|�	_inspectsr:r9r:r;�<module>r�sH��#�)�����������!���� ����%���������!�&����!��'�'��,�!�	�#�s�(�O�U�D�E�E���!��c��*��+8�4�=�=��+>��(�>��r�3�w����#�s�(�#���2�s�7�#���T��$��!�2�$��)�,��4�G�4�!�$(�!%�&*�#�/3�F�	�F��F�"�F��	F�
 $�F��
F�-�F��F�RO�H�*�*�O�dG;�M�G;�TV.�	���M�:�V.�r,5�%�0�0�(�2H�2H�,5�^0�0�0�.a
�a
�H��$q�q�h_��_�D����m�$�-�%�-r:

ZeroDay Forums Mini