HEX
Server: LiteSpeed
System: Linux us-phx-web1284.main-hosting.eu 4.18.0-553.109.1.lve.el8.x86_64 #1 SMP Thu Mar 5 20:23:46 UTC 2026 x86_64
User: u300739242 (300739242)
PHP: 8.2.30
Disabled: system, shell_exec, passthru, mysql_list_dbs, ini_alter, dl, symlink, link, chgrp, leak, popen, apache_child_terminate, virtual, mb_send_mail
Upload Files
File: //opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyc
�
���ec@s�dZddlmZddlmZddlmZddlmZddlmZddlm	Z	dd	gZ
d	efd
��YZde	fd��YZd�Z
d
S(sHorizontal sharding support.

Defines a rudimental 'horizontal sharding' system which allows a Session to
distribute queries and persistence operations across multiple databases.

For a usage example, see the :ref:`examples_sharding` example included in
the source distribution.

i(tevent(texc(tinspect(tutil(tQuery(tSessiontShardedSessiontShardedQuerycBseZd�Zd�ZRS(cOsStt|�j||�|jj|_|jj|_|jj|_d|_dS(N(	tsuperRt__init__tsessiont
id_choosert
query_choosertexecute_choosertNonet	_shard_id(tselftargstkwargs((sP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR	s
cCs|jd|�S(s�Return a new query, limited to a single shard ID.

        All subsequent operations with the returned query will
        be against the single shard regardless of other state.

        The shard_id can be passed for a 2.0 style execution to the
        bind_arguments dictionary of :meth:`.Session.execute`::

            results = session.execute(
                stmt,
                bind_arguments={"shard_id": "my_shard"}
            )

        t_sa_shard_id(texecution_options(Rtshard_id((sP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyt	set_shard$s(t__name__t
__module__R	R(((sP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyRs	cBsbeZdded�Zddd�Zd�Zdddd�Zddddd�Zd�Z	RS(cs�|jdd	��tt|�jd||�tj|dtdt�||_	||_
�r�tjdd�|r�t
jd��n�fd�}||_n	||_�|_i|_|d	k	r�x%|D]}|j|||�q�Wnd	S(
s�Construct a ShardedSession.

        :param shard_chooser: A callable which, passed a Mapper, a mapped
          instance, and possibly a SQL clause, returns a shard ID.  This id
          may be based off of the attributes present within the object, or on
          some round-robin scheme. If the scheme is based on a selection, it
          should set whatever state on the instance to mark it in the future as
          participating in that shard.

        :param id_chooser: A callable, passed a query and a tuple of identity
          values, which should return a list of shard ids where the ID might
          reside.  The databases will be queried in the order of this listing.

        :param execute_chooser: For a given :class:`.ORMExecuteState`,
          returns the list of shard_ids
          where the query should be issued.  Results from all shards returned
          will be combined together into a single listing.

          .. versionchanged:: 1.4  The ``execute_chooser`` parameter
             supersedes the ``query_chooser`` parameter.

        :param shards: A dictionary of string shard names
          to :class:`~sqlalchemy.engine.Engine` objects.

        Rt	query_clstdo_orm_executetretvalsMThe ``query_choser`` parameter is deprecated; please use ``execute_chooser``.s1.4s>Can't pass query_chooser and execute_chooser at the same time.cs
�|j�S(N(t	statement(torm_context(R(sP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR
nsN(tpopRRRR	Rtlistentexecute_and_instancestTruet
shard_chooserRRtwarn_deprecatedRt
ArgumentErrorR
Rt_ShardedSession__bindst
bind_shard(RR"RR
tshardsRRtk((RsP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR	7s*"					
c		Ks�|dk	r.tt|�j||d||�S|j|�}|rU|j|�}nxT|j||�D]@}tt|�j||d|d||�}|dk	rh|SqhWdSdS(s_override the default :meth:`.Session._identity_lookup` method so
        that we search for a given non-token primary key identity across all
        possible identity tokens (e.g. shard ids).

        .. versionchanged:: 1.4  Moved :meth:`.Session._identity_lookup` from
           the :class:`_query.Query` object to the :class:`.Session`.

        tidentity_tokentlazy_loaded_fromN(RRRt_identity_lookuptqueryt_set_lazyload_fromR(	Rtmappertprimary_key_identityR)R*tkwtqRtobj((sP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR+zs&	cKs�|dk	rWt|�}|jrD|jd}|dk	s@t�|S|jrW|jSn|j|||�}|dk	r�||_n|S(Ni(RRtkeytAssertionErrorR)R"(RR.tinstanceR0tstatettokenR((sP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyt_choose_shard_and_assign�s	
	
cKsl|dkr!|j||�}n|j�rF|j�j|d|�S|j|d|d|�j|�SdS(saProvide a :class:`_engine.Connection` to use in the unit of work
        flush process.

        RR5N(RR8tin_transactiontget_transactiont
connectiontget_bindtconnect(RR.R5RR((sP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pytconnection_callable�scKs2|dkr'|j||d|�}n|j|S(Ntclause(RR8R%(RR.RR5R?R0((sP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR<�scCs||j|<dS(N(R%(RRtbind((sP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR&�sN(
RRRRR	R+R8R>R<R&(((sP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR6sA$	c	sF�jr�j}}d}n6�js1�jrGd}�j}}nd}}}�j}�fd�}|r�|jdk	r�|j}nDd�jkr��jd}n%d�j	kr��j	d}nd}|dk	r�||||�Sg}x6|j
��D]%}||||�}|j|�qW|dj|d�SdS(Ncs�t�j�}t�j�}||d<�jrO|i|d67}||d<n0�jsa�jr|i|d67}||d<n�jd|d|�S(NRt_refresh_identity_tokent_sa_orm_load_optionst_sa_orm_update_optionstbind_argumentsR(tdicttlocal_execution_optionsRDt	is_selectt	is_updatet	is_deletetinvoke_statement(Rtload_optionstupdate_optionsRRD(R(sP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pytiter_for_shard�s
	

	RRii(
RGRKRRHRItupdate_delete_optionsR
RARRDR
tappendtmerge(	RRKtactive_optionsRLR
RMRtpartialtresult_((RsP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyR �s.	
		N(t__doc__tRRRRt	orm.queryRtorm.sessionRt__all__RRR (((sP/opt/alt/python27/lib/python2.7/site-packages/sqlalchemy/ext/horizontal_shard.pyt<module>s�