Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes14kdownloads
baked.cpython-313.pyc233 linesDownload Raw Back to __pycache__
1�

2��j�G����SrSSKJr SSKrSSKJr SSKJr SSK	Jr3 SSKJr SSK
Jr SSKJr SS	KJr SSKJr \R&"\5r"S4S5r"SS
5r"SS5r\R2rg)z�Baked query extension.5 6Provides a creational pattern for the :class:`.query.Query` object which7allows the fully constructed object, Core select statement, and string8compiled result to be fully cached.9 10 11�N�)�exc)�util)�Query)�Session)�func)�literal_columnc�(�\rSrSrSrSrSrSrSrg)�Bakery�#z�Callable which returns a :class:`.BakedQuery`.12 13This object is returned by the class method14:meth:`.BakedQuery.bakery`.  It exists as an object15so that the "cache" can be easily inspected.16 17.. versionadded:: 1.218 19 20��cls�cachec��XlX lg�Nr
)�self�cls_rs   �ZD:\code\apps\devtools\python\user_packages\Python313\site-packages\sqlalchemy/ext/baked.py�__init__�Bakery.__init__1s�����21�c�:�URURX5$rr
)r�22initial_fn�argss   r�__call__�Bakery.__call__5s���x�x��23�24�J�5�5r)rrN)	�__name__�25__module__�__qualname__�__firstlineno__�__doc__�	__slots__rr�__static_attributes__�rrrr#s��	��I��6rrc��\rSrSrSrSrSSjr\SSj5rSr	SSjr26S	rS27rSr
SrS
rSrSSjrSrSSjrSSjrSrSrSrSrSrg)�28BakedQuery�9z3A builder object for :class:`.query.Query` objects.)�steps�_bakery�29_cache_key�_spoiledc�^�SUlURX#5 U/UlSUlXlg)Nr$F)r*�_update_cache_keyr(r+r))r�bakeryrrs    rr�BakedQuery.__init__>s,��������z�0� �\��30���
��rNc�>�[U[R"XS95$)zCConstruct a new bakery.31 32:return: an instance of :class:`.Bakery`33 34)�35size_alert)rr�LRUCache)r�size�_size_alerts   rr.�BakedQuery.bakeryEs���c�4�=�=��F�G�Grc���[R[5nURUl[UR5UlUR36UlURUlU$r)r&�__new__r*�listr(r)r+)r�b1s  r�_clone�BakedQuery._cloneOsH��
�
�
�37�
+������
���38�39�#����\�\��40��m�m����	rc�J�U=RUR4U--
slgr)r*�__code__�r�fnrs   rr-�BakedQuery._update_cache_keyWs�����B�K�K�>�D�0�0�rc�t�[U[5(aUR"U6 U$URU5 U$r)�41isinstance�tuple�add_criteria�r�others  r�__iadd__�BakedQuery.__iadd__Zs9���e�U�#�#����u�%���
���e�$��rc�l�[U[5(aUR"U6$URU5$r)rBrC�
with_criteriarEs  r�__add__�BakedQuery.__add__as1���e�U�#�#��%�%�u�-�-��%�%�e�,�,rc�^�URX5 URRU5 U$)z�Add a criteria function to this :class:`.BakedQuery`.42 43This is equivalent to using the ``+=`` operator to44modify a :class:`.BakedQuery` in-place.45 46)r-r(�appendr>s   rrD�BakedQuery.add_criteriags)��	
���r�(��47�48���"���rc�D�UR5R"U/UQ76$)z�Add a criteria function to a :class:`.BakedQuery` cloned from this49one.50 51This is equivalent to using the ``+`` operator to52produce a new :class:`.BakedQuery` with modifications.53 54)r:rDr>s   rrJ�BakedQuery.with_criteriars ���{�{�}�)�)�"�4�t�4�4rc��[X5$)z�Return a :class:`_baked.Result` object for this55:class:`.BakedQuery`.56 57This is equivalent to calling the :class:`.BakedQuery` as a58Python callable, e.g. ``result = my_baked_query(session)``.59 60)�Result�r�sessions  r�for_session�BakedQuery.for_session|s���d�$�$rc�$�URU5$r)rVrTs  rr�BakedQuery.__call__�s������(�(rc��U(dHUR(d7UR5nU=RS-
slUR/UlSUlU$)aCancel any query caching that will occur on this BakedQuery object.61 62The BakedQuery can continue to be used normally, however additional63creational functions will not be cached; they will be called64on every invocation.65 66This is to support the case where a particular step in constructing67a baked query disqualifies the query from being cacheable, such68as a variant that relies upon some uncacheable value.69 70:param full: if False, only functions added to this71 :class:`.BakedQuery` object subsequent to the spoil step will be72 non-cached; the state of the :class:`.BakedQuery` up until73 this point will be pulled from the cache.   If True, then the74 entire :class:`_query.Query` object is built from scratch each75 time, with all creational functions being called on each76 invocation.77 78)�_query_onlyT)r+r:r*�_retrieve_baked_queryr()r�full�_spoil_points   r�spoil�BakedQuery.spoil�sF��(�D�M�M��;�;�=�L��#�#�'7�7�#�&�<�<�=�D�J���
��rc�6�URUR4-$)asReturn the key that actually goes into the cache dictionary for79this :class:`.BakedQuery`, taking into account the given80:class:`.Session`.81 82This basically means we also will include the session's query_class,83as the actual :class:`_query.Query` object is part of what's cached84and needs to match the type of :class:`_query.Query` that a later85session will want to use.86 87)r*�88_query_clsrTs  r�_effective_key�BakedQuery._effective_key�s�����'�"4�"4�!6�6�6rc�F�UR5nURXUS9 U$)z)Cloning version of _add_lazyload_options.)�89cache_path)r:�_add_lazyload_options)r�options�effective_pathrf�qs     r�_with_lazyload_options�!BakedQuery._with_lazyload_options�s%���K�K�M��	����J��O��rc�4^^�SnU(dTnTHcnUR(dUR(dM'UR5nUcURSS9 MKUS(aS5eXFS-
nMe UR	UU4SjUR90U5 g)	aUsed by per-state lazy loaders to add options to the91"lazy load" query from a parent query.92 93Creates a cache key based on given load path and query options;94if a repeatable cache key cannot be generated, the query is95"spoiled" so that it won't use caching.96 97r$NT)r]�z�loader options with variable bound parameters not supported with baked queries.  Please use new-style select() statements for cached ORM queries.rc�@>�URT5R"T6$r)�_with_current_pathrh)rjrirhs ��r�<lambda>�2BakedQuery._add_lazyload_options.<locals>.<lambda>�s���a�*�*�>�:�B�B�G�Lr)�_is_legacy_option�_is_compile_state�_generate_cache_keyr_rD�path)rrhrirf�key�opt�cks ``    rrg� BakedQuery._add_lazyload_options�s�������'�J��C��$�$��(=�(=�(=��,�,�.���:��J�J�D�J�)�!�!�u��'��9��a�5�L�C��	
���L��O�O��	98rc���URRURU5S5nUc>URU5nUR	S5URURU5'UR	U5$r)r)�getrc�	_as_query�with_session)rrU�querys   rr\� BakedQuery._retrieve_baked_query�sp����� � ��!4�!4�W�!=�t�D���=��N�N�7�+�E�9>�9K�9K��:�D�L�L��,�,�W�5�6��!�!�'�*�*rc���URU5nSUlUR5nURR(a UU4UR99UR
U5'X#4$r)r}rU�
_statement_20�_compile_options�_bake_okr)rc)rrUr�	statements    r�_bake�BakedQuery._bake�sd�����w�'����
��'�'�)�	��%�%�.�.���:�D�L�L��,�,�W�5�6�100��rc���[U[5(aUnOR[U[5(a&URnUc[R101"S5eO[
S[U5-5eURU5$)ahReturn the :class:`_query.Query` object for use as a subquery.102 103This method should be used within the lambda callable being used104to generate a step of an enclosing :class:`.BakedQuery`.   The105parameter should normally be the :class:`_query.Query` object that106is passed to the lambda::107 108    sub_bq = self.bakery(lambda s: s.query(User.name))109    sub_bq += lambda q: q.filter(User.id == Address.user_id).correlate(Address)110 111    main_bq = self.bakery(lambda s: s.query(Address))112    main_bq += lambda q: q.filter(sub_bq.to_query(q).exists())113 114In the case where the subquery is used in the first callable against115a :class:`.Session`, the :class:`.Session` is also accepted::116 117    sub_bq = self.bakery(lambda s: s.query(User.name))118    sub_bq += lambda q: q.filter(User.id == Address.user_id).correlate(Address)119 120    main_bq = self.bakery(121        lambda s: s.query(Address.id, sub_bq.to_query(q).scalar_subquery())122    )123 124:param query_or_session: a :class:`_query.Query` object or a class125 :class:`.Session` object, that is assumed to be within the context126 of an enclosing :class:`.BakedQuery` callable.127 128 129 .. versionadded:: 1.3130 131 132z1Given Query needs to be associated with a Sessionz)Query or Session object expected, got %r.)	rBrrrU�sa_exc�
ArgumentError�	TypeError�typer})r�query_or_sessionrUs   r�to_query�BakedQuery.to_query�s���D�&��0�0�&�G�
�(�%�
0�
0�&�.�.�G����*�*�G����133�;��'�(�)��
��~�~�g�&�&rc�l�URS"U5nURSSHnU"U5nM
 U$�Nrrn)r()rrUr�steps    rr}�BakedQuery._as_query-s8���134�135�1�
�g�&���J�J�q�r�N�D���K�E�#��r)r)r*r+r()r$)��N)Fr)rrrr r!r"r�classmethodr.r:r-rGrKrDrJrVrr_rcrkrgr\r�r�r}r#r$rrr&r&9sw��=�<�I���H��H��1��-�	�5�%�)��67��!136�F+� �2/'�brr&c�|�\rSrSrSrSrSrSrSrSr	Sr137S	rS138rSr
SrS
rSrSrSrSrSrSrSrg)rSi6aInvokes a :class:`.BakedQuery` against a :class:`.Session`.139 140The :class:`_baked.Result` object is where the actual :class:`.query.Query`141object gets created, or retrieved from the cache,142against a target :class:`.Session`, and is then invoked for results.143 144��bqrU�_params�_post_criteriac�8�XlX l0Ul/Ulgrr�)rr�rUs   rr�Result.__init__As��������� ��rc���[U5S:XaURUS5 O%[U5S:�a[R"S5eURRU5 U$)z@Specify parameters to be replaced into the string SQL statement.rnrzFparams() takes zero or one positional argument, which is a dictionary.)�len�updater�r�r�)rr�kws   r�params�
Result.paramsGs[���t�9��>��I�I�d�1�g��
��Y��]��&�&�)��
�	
�����B���rc�J�U(aURRU5 U$r)r��extend)r�fnss  r�_using_post_criteria�Result._using_post_criteriaTs������&�&�s�+��rc�&�URU/5$)a|Add a criteria function that will be applied post-cache.145 146This adds a function that will be run against the147:class:`_query.Query` object after it is retrieved from the148cache.    This currently includes **only** the149:meth:`_query.Query.params` and :meth:`_query.Query.execution_options`150methods.151 152.. warning::  :meth:`_baked.Result.with_post_criteria`153   functions are applied154   to the :class:`_query.Query`155   object **after** the query's SQL statement156   object has been retrieved from the cache.   Only157   :meth:`_query.Query.params` and158   :meth:`_query.Query.execution_options`159   methods should be used.160 161 162.. versionadded:: 1.2163 164 165)r�)rr?s  r�with_post_criteria�Result.with_post_criteriaYs��.�(�(�"��.�.rc��URRUR5RUR5nUR166HnU"U5nM
 U$r)r�r}rUr�r�r�)rrjr?s   rr}�Result._as_queryrsG���G�G���d�l�l�+�2�2�4�<�<�@���%�%�B��1��A�&��rc�4�[UR55$r)�strr}�rs r�__str__�Result.__str__xs���4�>�>�#�$�$rc�>�UR5R5$r)�_iter�__iter__r�s rr��Result.__iter__{s���z�z�|�$�$�&�&rc�~�URnURR(aUR(aUR	5R5$URRURUR5S5up#UcURUR5up#UR(aURUR5nOUnURHnU"U5nM
 URn[UR5nURUR URS.5 URR#X6US9nUR$RSS5(aUR'5nUR$RSS5(aUR)5nU$)N)NN)�_sa_orm_load_options�compiled_cache)�execution_options�is_single_entityF�filtered)r�rU�enable_baked_queriesr+r}r�r)r|rcr�r�r�r��dict�_execution_optionsr��load_options�execute�_attributes�scalars�unique)	rr�rr�rjr?r�r��results	         rr��Result._iter~s_��
�W�W���|�|�0�0�B�K�K��>�>�#�)�)�+�+��:�:�>�>����d�l�l�+�\�167����=�!�x�x����5��E��<�<����T�\�\�*�A��A��%�%�B��1��A�&����� ��!5�!5�6��� � �()���"$�*�*�
�	168����%�%��1B�&�169�����!�!�"4�e�<�<��^�^�%�F����!�!�*�e�4�4��]�]�_�F��
rc�^�[R"[S55mURR	U4Sj5nURUR5RUR5R5$)z�return the 'count'.170 171Equivalent to :meth:`_query.Query.count`.172 173Note this uses a subquery to ensure an accurate count regardless174of the structure of the original statement.175 176�*c�&>�URT5$r)�_legacy_from_self)rj�cols �rrq�Result.count.<locals>.<lambda>�s���Q�-@�-@��-Er)177r�countr	r�rJrVrUr�r��scalar)rr�r�s  @rr��Result.count�sX����j�j���,�-��
�W�W�
"�
"�#E�
F���~�~�d�l�l�+�2�2�4�<�<�@�G�G�I�Irc��UR5n[U[R5(dU$US$![R178a gf=f)z�Return the first element of the first result or None179if no rows present.  If multiple rows are returned,180raises MultipleResultsFound.181 182Equivalent to :meth:`_query.Query.scalar`.183 184rN)�onerB�collections_abc�Sequence�orm_exc�
NoResultFound)r�rets  rr��
Result.scalar�sK��	��(�(�*�C��c�?�#;�#;�<�<��185��q�6�M���$�$�	��	�s�08�8�A�Ac��URRS5nURUR5R	UR1865R
UR5R5R5$)zBReturn the first row.187 188Equivalent to :meth:`_query.Query.first`.189 190c�&�URSS5$r�)�slice)rjs rrq�Result.first.<locals>.<lambda>�s��Q�W�W�Q��]r)191r�rJrVrUr�r�r�r�r��first)rr�s  rr��Result.first�s[���W�W�
"�
"�#:�
;���N�N�4�<�<�(�
�V�D�L�L�
!�
!�
!�$�"5�"5�
6�
�U�W�
�U�W�	192rc�>�UR5R5$)z[Return exactly one result or raise an exception.193 194Equivalent to :meth:`_query.Query.one`.195 196)r�r�r�s rr��197Result.one�����z�z�|���!�!rc�>�UR5R5$)zwReturn one or zero results, or raise an exception for multiple198rows.199 200Equivalent to :meth:`_query.Query.one_or_none`.201 202)r��one_or_noner�s rr��Result.one_or_none�s���z�z�|�'�'�)�)rc�>�UR5R5$)z;Return all rows.203 204Equivalent to :meth:`_query.Query.all`.205 206)r��allr�s rr��207Result.all�r�rc��URRS"UR5nURXR5$)zPRetrieve an object based on identity.208 209Equivalent to :meth:`_query.Query.get`.210 211r)r�r(rU�	_get_impl�_load_on_pk_identity)r�identrs   rr|�212Result.get�s4�����
�
�a� ����.�����u�&?�&?�@�@rc�h^^^^
^�URSRSmTRumm
UU
UUU4SjnTRnUR	5nU=R213T4-
slUR
U[ST555n[TTR5VVs0sHupxT
URU_M n	nn[URTR5R"S0U	D65n214[U2155nUS:�a[ R""5eU(aU216S$gs snnf)z6Load the given primary key identity from the database.r�parententityc�>�TnUR5nUR5 SUlST217;aR[T	RT2185VVs1sHup4UbM219TUR220iM nnn[R"X5n[R"USS054Ul	TRHnU"U5nM
 U$s snnf)N�221_orm_adaptT)r:�_get_condition�	_order_by�zip�primary_keyrw�sql_util�adapt_criterion_to_null�_deep_annotate�_where_criteriar�)r�_lcl_get_clauserjr��value�nonesr?�_get_clause�_get_params�mapper�primary_key_identityrs       �����r�setup�*Result._load_on_pk_identity.<locals>.setup�s����)�O�����A�
�����A�K��+�+�'*��*�*�,@�'��'�222���	)�K��$�(�(�'���#+�"B�"B�#�#���'�'��,��9M�N�!�A���)�)���q�E��*��H��%s�223	B?�B?c3�(# �UHoSLv� M224 g7frr$)�.0�elems  r�	<genexpr>�.Result._load_on_pk_identity.<locals>.<genexpr>&s���G�2F�$���2F�s�rnNr$)�_raw_columns�_annotationsr�r�r:r*rJrCr�r�rwr8rVrUr�r�r��MultipleResultsFound)rrUrr�r�r�r��id_valr�r�r��lr�r�r�s`  `        @@@rr��Result._load_on_pk_identity�s(����#�#�A�&�3�3�N�C��#)�#5�#5� ��[�	�	�@�W�W��225�Y�Y�[��226�
�
�+��'�
�
�
�
��5�G�2F�G�G�227��(+�$�f�&8�&8�(�228�(�#��
��$�(�(�&�0�(�	�229��b�n�n�T�\�\�2�9�9�C�F�C�D����K���q�5��.�.�0�0�
��!�9����230s�(D.)r�r�r�rUN)rrrr r!r"rr�r�r�r}r�r�r�r�r�r�r�r�r�r|r�r#r$rrrSrS6sb���=�I�!���231/�2�%�'�%�NJ�� 232� "�*�"�A�ArrS)r!�collections.abc�abcr��logging�rr�r�ormr��	orm.queryr�orm.sessionr�sqlrr	r��	getLoggerr�logrr&rSr.r$rr�<module>rsm���*���� ��!�� �"�����!��6�6�,z�z�zA�A�H233�	�	�r
codekingpro/portable-devtools · Team Ai