Ë
    3ýj,  ã                   ón   — d Z ddlmZmZ ddlmZmZmZmZm	Z	m
Z
mZmZ d„ Zdd„Zdd„Zd„ Zd„ Zd	„ Zd
„ Zy)aY  Shared HIMPORT wire-execution helpers for the synchronous clients.

The PREPARE / SET / DISCARD packed-write drain loops, per-connection version
bookkeeping, and ``NoSuchFieldsetError`` re-prepare-and-retry are identical for
the standalone (:class:`redis.Redis`) and cluster (:class:`redis.RedisCluster`)
sync clients, differing only in (a) which object provides ``parse_response`` and
(b) the cluster-only ASK-redirect handling. These functions take that object as
``node`` and an ``asking`` flag (``False`` -- and a no-op -- for standalone), so
both clients share one implementation instead of copy-pasting the logic. The
per-class ``_himport_*`` methods are thin delegators to these functions.

The async mirror lives in :mod:`redis.asyncio._himport_exec`; the two are kept
separate on purpose (the project maintains parallel sync/async stacks by hand).
é    )ÚNoSuchFieldsetErrorÚResponseError)ÚHIMPORT_DISCARDÚHIMPORT_PREPAREÚHIMPORT_SETÚHImportRegistryÚhimport_discard_commandÚhimport_prepare_commandÚhimport_set_commandÚparse_himport_set_argsc           
      óö  — |j                   }|�|j                  |j                  k(  ry|j                  }|j                  t	        |j
                  «      «      }|rw|j                  |j                  |D �cg c]  }t        |«      ‘Œ c}«      «       d}|D ]5  }	 | j                  |t        «       |j
                  j                  |d«       Œ7 |�|‚||_        yc c}w # t        $ r}|xs |}Y d}~ŒCd}~ww xY w)ai  DISCARD, on ``conn``, any prepared fieldset removed from the registry.

    Runs at most once per registry mutation: the connection records the registry
    ``revision`` it last reconciled against, so unchanged registries are a no-op.
    ``node`` supplies ``parse_response`` (the standalone client itself, or the
    owning node's client in cluster mode).
    N)Úhimport_registryÚ_himport_reconciled_revisionÚrevisionÚnames_to_discardÚlistÚ_himport_preparedÚsend_packed_commandÚpack_commandsr	   Úparse_responser   r   Úpop)ÚnodeÚconnÚregistryÚreconciled_toÚstaleÚnÚfirst_errorÚes           úM/root/telegram-saas/.venv/lib/python3.12/site-packages/redis/_himport_exec.pyÚreconcile_discardsr!      sþ   € ð ×$Ñ$€HØÐ˜4×<Ñ<À×@QÑ@QÒQØð ×%Ñ%€MØ×%Ñ%¤d¨4×+AÑ+AÓ&BÓC€EÙØ× Ñ Ø×ÑÀEÖJ¸qÔ 7¸Õ :ÒJÓKô	
ð ˆØò 	0ˆAð/Ø×#Ñ# D¬/Ô:ð ×"Ñ"×&Ñ& q¨$Õ/ð	0ð Ð"ØÐØ(5€DÕ%ùò  Køô !ò /Ø)Ò.¨Q•ûð/ús   Á5CÂCÃ	C8Ã(C3Ã3C8c                 óB  — t        ||j                  «      g}|r|j                  d«       |j                  t        |||«      «       |j	                  |j                  |«      «       dx}x}	}
d}	 | j                  |t        «       |r	 | j                  |d«       	 | j                  |t        «      }|r|‚|j                  |j                  |<   |	r|	‚|
r|
‚|S # t        $ r}|}Y d}~Œcd}~ww xY w# t        $ r}|}	Y d}~Œfd}~ww xY w# t        $ r}|}
Y d}~Œgd}~ww xY w)a  PREPARE ``fieldset`` bundled with the SET on ``conn`` (one packed write).

    When ``asking`` is set (an ASK-redirected cluster SET) the batch becomes
    ``[PREPARE, ASKING, SET]`` so the per-command ASKING allowance falls
    immediately before the SET -- the only slot-scoped command. PREPARE is a
    connection-session command the ASKING flag does not gate, so placing it
    before ASKING is safe. Every reply is drained even on a per-command error so
    the packed replies never desync the pooled socket.
    ©ÚASKINGNr$   )r
   ÚfieldsÚappendr   r   r   r   r   r   r   Úversionr   )r   r   ÚkeyÚfieldset_nameÚvaluesÚfieldsetÚaskingÚcommandsÚ
prep_errorÚ	ask_errorÚ	set_errorÚset_respr   s                r    Úprepare_and_setr2   D   s(  € ô (¨°x·±ÓGÐH€HÙØ�‰˜Ô$Ø‡O�OÔ'¨¨]¸FÓCÔDØ×Ñ˜T×/Ñ/°Ó9Ô:Ø)-Ð-€JÐ-�˜YØ€HðØ×Ñ˜D¤/Ô2ñ ð	Ø×Ñ  hÔ/ðØ×&Ñ& t¬[Ó9ˆñ ØÐà08×0@Ñ0@ˆ×Ñ˜}Ñ-áØˆÙØˆØ€Oøô+ ò Ø�
ûðûô
 ò 	Ø�Iûð	ûô ò Ø�	ûðúsH   Á0C Â	C1 ÂD	 Ã	C.Ã"C)Ã)C.Ã1	DÃ:DÄDÄ		DÄDÄDc           
      ó°  — t        | |«       |j                  }|�|j                  |«      nd}|�:|j                  j                  |«      |j                  k7  rt        | ||||||¬«      S |rA|j                  |j                  dt        |||«      g«      «       	 | j                  |d«       n |j                  t        |||«      Ž  	 | j                  |t        «      S # t        $ r.}	 | j                  |t        «       |‚# t        $ r Y |‚w xY wd}~ww xY w# t        $ r4 |€‚ |j                  j                  |d«       t        | ||||||¬«      cY S w xY w)a  Execute an ``HIMPORT SET`` on ``conn`` with the required session setup.

    Reconciles deferred discards, lazily bundles PREPARE with the SET on first
    use of a fieldset, and recovers once from a mid-connection fieldset loss
    (``NoSuchFieldsetError``) by re-PREPARE-and-retry. When ``asking`` is set the
    ASKING allowance is folded into the SET's own packed write so it immediately
    precedes the (slot-scoped) SET; the session setup runs first, since those are
    connection-session commands the flag does not gate.
    N)r,   r#   r$   )r!   r   Úgetr   r'   r2   r   r   r   r   r   r   Úsend_commandr   r   )	r   r   r(   r)   r*   r,   r   r+   r/   s	            r    Úexecute_setr6   o   s€  € ô �t˜TÔ"à×$Ñ$€HØ.6Ð.Bˆx�|‰|˜MÔ*È€Hð 	ÐØ×"Ñ"×&Ñ& }Ó5¸×9IÑ9IÒIäØ�$˜˜]¨F°HÀVô
ð 	
ñ Ø× Ñ Ø×ÑØÔ1°#°}ÀfÓMÐNóô	
ð
	Ø×Ñ  hÕ/ð 	ˆ×ÑÔ.¨s°MÀ6ÓJÑKð
Ø×"Ñ" 4¬Ó5Ð5øô ò 		ð
Ø×#Ñ# D¬+Ô6ð ˆOøô !ò ØØˆOðþð		ûô ò 

ð
 ÐØØ×Ñ×"Ñ" =°$Ô7ÜØ�$˜˜]¨F°HÀVô
ò 	
ð

úsH   ÂC ÃD Ã	DÃ(D Ã>DÄ 	DÄ	DÄDÄDÄDÄ:EÅEc                 ó˜   — t        | ||«      }|sy|j                  |j                  t        |«      «      «       t	        | ||«      }|�|‚y)aq  Pre-flight ``conn`` for a pipeline batch containing ``HIMPORT SET``s.

    The packed pipeline write bypasses the per-command lazy-PREPARE path, so the
    fieldsets referenced by the buffered SETs must be PREPAREd on ``conn`` first.
    Reconciles deferred discards, then PREPAREs every distinct registered fieldset
    the batch references that this connection has not already prepared, in one
    packed write. ``command_arg_lists`` is the batch's per-command positional-arg
    sequences (the caller extracts them from its own command representation).
    No-op when the batch has no registry-backed ``HIMPORT SET``.
    N)Úpipeline_preparesr   r   Úprepare_wire_commandsÚdrain_pipeline_prepares)r   r   Úcommand_arg_listsÚ
to_preparer   s        r    Úprepare_pipeliner=   «   sY   € ô # 4¨Ð/@ÓA€JÙØØ×Ñ˜T×/Ñ/Ô0EÀjÓ0QÓRÔSô *¨$°°jÓA€KØÐØÐð ó    c                 óp  — t        |dd«      }t        |t        «      sg S t        | |«       g }t	        «       }|D ]y  }t        |«      }|€Œ|d   }||v rŒ|j                  |«       |j                  |«      }	|	€Œ@|j                  j                  |«      |	j                  k7  sŒi|j                  |	«       Œ{ |S )a  Return the fieldsets that must be PREPAREd on ``conn`` for this batch.

    Like :func:`prepare_pipeline`, but does **not** send the PREPAREs: the caller
    folds them into the same packed write as the queued commands (see the pipeline
    executors), so the first pipeline use of a fieldset on a fresh or reconnected
    connection stays a single round trip instead of a separate PREPARE exchange
    followed by the batch. Deferred-discard reconciliation is still performed here,
    but it only touches the socket when discards are actually pending (rare); the
    common warm-up cost -- the first-use PREPARE -- is what gets folded. Returns an
    empty list when the batch references no not-yet-prepared registered fieldset,
    or when ``conn`` carries no real HIMPORT registry.
    r   Né   )ÚgetattrÚ
isinstancer   r!   Úsetr   Úaddr4   r   r'   r&   )
r   r   r;   r   r<   ÚseenÚargsÚparsedr)   r+   s
             r    r8   r8   Å   sÂ   € ô �tÐ/°Ó6€HÜ�h¤Ô0Øˆ	Ü�t˜TÔ"Ø€JÜ‹5€DØ!ò (ˆÜ'¨Ó-ˆØˆ>ØØ˜q™	ˆØ˜DÑ ØØ�‰�ÔØ—<‘< Ó.ˆàÑ Ø×&Ñ&×*Ñ*¨=Ó9¸X×=MÑ=MÓMà×Ñ˜hÕ'ð(ð Ðr>   c                 óh   — | D �cg c]"  }t        |j                  |j                  «      ‘Œ$ c}S c c}w )zLThe leading ``HIMPORT PREPARE`` wire commands the caller folds into a batch.)r
   Únamer%   )Ú	fieldsetsÚfss     r    r9   r9   é   s&   € àBKÖL¸BÔ# B§G¡G¨R¯Y©YÕ7ÒLÐLùÒLs   …'/c                 óÄ   — d}|D ]<  }	 | j                  |t        «       |j                  |j                  |j
                  <   Œ> |S # t        $ r}|xs |}Y d}~ŒUd}~ww xY w)ar  Drain the ``len(fieldsets)`` leading PREPARE replies of a folded pipeline
    write, marking each fieldset prepared on success.

    Returns the first ``ResponseError`` (or ``None``). The caller must still drain
    the queued command replies and only then surface this error: every reply on
    the wire has to be read before raising, or the pooled socket desyncs.
    N)r   r   r   r'   r   rI   )r   r   rJ   r   rK   r   s         r    r:   r:   î   sn   € ð €KØò 5ˆð	Ø×Ñ ¤oÔ6ð +-¯*©*ˆ×Ñ˜rŸw™wÒ'ð5ð Ðøô	 ò 	Ø%Ò*¨ˆKÜûð	ús   ‰AÁ	AÁAÁAN)F)Ú__doc__Úredis.exceptionsr   r   Úredis.himportr   r   r   r   r	   r
   r   r   r!   r2   r6   r=   r8   r9   r:   © r>   r    ú<module>rQ      sG   ðñ÷ @÷	÷ 	ó 	ò$6óN(óV9
òxò4!òHMó
r>   