Ë
    3ýjß,  ã                   óp   — 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)a[  Shared HIMPORT wire-execution helpers for the asynchronous clients.

Async mirror of :mod:`redis._himport_exec`. 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.asyncio.Redis`) and cluster (async ``ClusterNode``) clients,
differing only in (a) which object provides ``parse_response`` and (b) the
cluster-only ASK-redirect handling. These coroutines take that object as
``node`` and an ``asking`` flag (``False`` -- and a no-op -- for standalone), so
both clients share one implementation. The per-class ``_himport_*`` methods are
thin delegators to these coroutines.

The sync version lives in :mod:`redis._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           
   ƒ   ó&  K  — |j                   }|�|j                  |j                  k(  ry|j                  }|j                  t	        |j
                  «      «      }|r‡|j                  |j                  |D �cg c]  }t        |«      ‘Œ c}«      «      ƒ d{  –—†  d}|D ]=  }	 | j                  |t        «      ƒ d{  –—†  |j
                  j                  |d«       Œ? |�|‚||_        yc c}w 7 ŒY7 Œ5# t        $ r}|xs |}Y d}~ŒGd}~ww xY w­w)ak  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 ``ClusterNode`` 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           úU/root/telegram-saas/.venv/lib/python3.12/site-packages/redis/asyncio/_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ð/Ø×)Ñ)¨$´Ó@×@Ð@ð ×"Ñ"×&Ñ& q¨$Õ/ð	0ð Ð"ØÐØ(5€DÕ%ùò  Kð	
øð AùÜ ò /Ø)Ò.¨Q•ûð/üsZ   ‚A5DÁ7C,Â	DÂC1ÂDÂ$C5Â=C3Â>C5Ã0DÃ3C5Ã5	DÃ>D	ÄDÄ	DÄDc              ƒ   óš  K  — t        ||j                  «      g}|r|j                  d«       |j                  t        |||«      «       |j	                  |j                  |«      «      ƒ d{  –—†  dx}x}	}
d}	 | j                  |t        «      ƒ d{  –—†  |r	 | j                  |d«      ƒ d{  –—†  	 | j                  |t        «      ƒ d{  –—† }|r|‚|j                  |j                  |<   |	r|	‚|
r|
‚|S 7 ŒŽ7 Œi# t        $ r}|}Y d}~Œwd}~ww xY w7 Œf# t        $ r}|}	Y d}~Œtd}~ww xY w7 Œa# t        $ r}|}
Y d}~Œod}~ww xY w­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   F   sS  è ø€ ô (¨°x·±ÓGÐH€HÙØ�‰˜Ô$Ø‡O�OÔ'¨¨]¸FÓCÔDØ
×
"Ñ
" 4×#5Ñ#5°hÓ#?Ó
@×@Ð@Ø)-Ð-€JÐ-�˜YØ€HðØ×!Ñ! $¬Ó8×8Ð8ñ ð	Ø×%Ñ% d¨HÓ5×5Ð5ðØ×,Ñ,¨T´;Ó?×?ˆñ ØÐà08×0@Ñ0@ˆ×Ñ˜}Ñ-áØˆÙØˆØ€Oð5 Aøð 	9ùÜò Ø�
ûðúð 6ùÜò 	Ø�Iûð	úð @ùÜò Ø�	ûðüsÀ   ‚A*EÁ,C;Á-EÁ:C? ÂC=ÂC? ÂEÂD Â0DÂ1D Â6D3 ÃD1ÃD3 Ã(EÃ=C? Ã?	DÄDÄ
EÄDÄEÄD Ä	D.Ä"D)Ä$EÄ)D.Ä.EÄ1D3 Ä3	EÄ<EÄ>EÅEÅEc           
   ƒ   óT  K  — t        | |«      ƒ d{  –—†  |j                  }|�|j                  |«      nd}|�B|j                  j                  |«      |j                  k7  rt        | ||||||¬«      ƒ d{  –—† S |rQ|j                  |j                  dt        |||«      g«      «      ƒ d{  –—†  	 | j                  |d«      ƒ d{  –—†  n" |j                  t        |||«      Ž ƒ d{  –—†  	 | j                  |t        «      ƒ d{  –—† S 7 Œý7 Œš7 Œe7 ŒL# t        $ r7}	 | j                  |t        «      ƒ d{  –—†7   |‚# t        $ r Y |‚w xY wd}~ww xY w7 Œn7 ŒQ# t        $ r= |€‚ |j                  j                  |d«       t        | ||||||¬«      ƒ d{  –—†7  cY S w xY w­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   s   sÖ  è ø€ ô ˜T 4Ó
(×(Ð(à×$Ñ$€HØ.6Ð.Bˆx�|‰|˜MÔ*È€Hð 	ÐØ×"Ñ"×&Ñ& }Ó5¸×9IÑ9IÒIä$Ø�$˜˜]¨F°HÀVô
÷ 
ð 	
ñ Ø×&Ñ&Ø×ÑØÔ1°#°}ÀfÓMÐNóó
÷ 	
ð 	
ð
	Ø×%Ñ% d¨HÓ5×5Ñ5ð  ˆd×ÑÔ!4°S¸-ÈÓ!PÐQ×QÐQð
Ø×(Ñ(¨¬{Ó;×;Ð;ðI )øð
øð	
øð 6ùÜò 		ð
Ø×)Ñ)¨$´Ó<×<Ñ<ð ˆOøô !ò ØØˆOðþð		úð 	Røà;ùÜò 

ð
 ÐØØ×Ñ×"Ñ" =°$Ô7Ü$Ø�$˜˜]¨F°HÀVô
÷ 
ð 
ò 	
ð

üsâ   ‚F(’D“A$F(Á7DÁ86F(Â.DÂ/F(Â4D Ã	DÃ
D ÃF(Ã,EÃ-F(Ã2E ÄEÄE ÄF(ÄF(ÄF(ÄD Ä	EÄ"EÄ;D>Ä<EÅEÅ	EÅEÅEÅEÅEÅF(ÅE Å=F%ÆFÆF%Æ"F(Æ$F%Æ%F(c              ƒ   óÜ   K  — t        | ||«      ƒ d{  –—† }|sy|j                  |j                  t        |«      «      «      ƒ d{  –—†  t	        | ||«      ƒ d{  –—† }|�|‚y7 ŒR7 Œ 7 Œ­w)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=   ¯   sƒ   è ø€ ô )¨¨tÐ5FÓG×G€JÙØØ
×
"Ñ
"Ø×ÑÔ0°Ó<Ó=ó÷ ð ô
 0°°d¸JÓG×G€KØÐØÐð ð Høðøð
 Hús3   ‚A,“A&”3A,ÁA(ÁA,ÁA*Á
A,Á(A,Á*A,c              ƒ   óŒ  K  — t        |dd«      }t        |t        «      sg S t        | |«      ƒ d{  –—†  g }t	        «       }|D ]y  }t        |«      }|€Œ|d   }||v rŒ|j                  |«       |j                  |«      }	|	€Œ@|j                  j                  |«      |	j                  k7  sŒi|j                  |	«       Œ{ |S 7 Œ�­w)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 4Ó
(×(Ð(Ø€JÜ‹5€DØ!ò (ˆÜ'¨Ó-ˆØˆ>ØØ˜q™	ˆØ˜DÑ ØØ�‰�ÔØ—<‘< Ó.ˆàÑ Ø×&Ñ&×*Ñ*¨=Ó9¸X×=MÑ=MÓMà×Ñ˜hÕ'ð(ð Ðð# )ús   ‚/C±C²ACÂ(CÂ-C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              ƒ   óà   K  — d}|D ]D  }	 | j                  |t        «      ƒ d{  –—†  |j                  |j                  |j
                  <   ŒF |S 7 Œ+# t        $ r}|xs |}Y d}~Œ_d}~ww xY w­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   rH   )r   r   rI   r   rJ   r   s         r    r:   r:   ô   sz   è ø€ ð €KØò 5ˆð	Ø×%Ñ% d¬OÓ<×<Ð<ð +-¯*©*ˆ×Ñ˜rŸw™wÒ'ð5ð Ðð =ùÜò 	Ø%Ò*¨ˆKÜûð	üs=   ‚A.‹A¤A¥A©'A.ÁAÁ	A+Á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    ú<module>rQ      sM   ðñ÷  @÷	÷ 	ó 	ò%6ðR >Có*óZ9
òxò8!òHMó
rP   