
    ng\j2                     :   S SK r S SKrS SKJrJrJrJr  S SKJr  S SK	r	SSK
JrJrJrJr  SSKJrJr  SSKJrJr   " S	 S
\5      r " S S\\	R,                  R.                  5      r " S S\\	R0                  R2                  5      r " S S\5      r " S S\5      rg)    N)JSONDecodeErrorJSONDecoderJSONEncoderloads)Literal   )apply_module_callbacksget_legacy_responsesget_protocol_version	nativestr   )FPHATypeJSONCommands)bulk_of_jsonsdecode_listc                       \ rS rSrSrS\" 5       \" 5       4S jrS rS r	S r
S rS	 r\S
 5       r\S 5       rS rSS jrSrg)	_JSONBase   
Create a client for talking to json.

:param decoder:
:type json.JSONDecoder: An instance of json.JSONDecoder

:param encoder:
:type json.JSONEncoder: An instance of json.JSONEncoder
Nc                 <  ^  T R                   T R                   T R                   S [        T R                   5      S T R                   S T R                   S.	n0 ST R                   _ST R                   _ST R                   _ST R                   _S	T R                   _S
[        _S[        _S[        _ST R                   _SU 4S j_SU 4S j_ST R                   _ST R                   _ST R                   _ST R                   _ST R                   _n0 n[        [        [        T R                  T R                  T R                  S S.nSS 0n	T R
                  T R
                  T R                   T R                  S S.n
UT l        UR                  T l        UT l	        [        [        T R                  5      [        T R                  5      UUUUU	U
S9T l        T R                  R                  5        H   u  pT R                  R                  X5        M"     UT l        UT l        g)r   c                 0    U =(       a    [        U 5      S:H  $ NOKr   rs    W/home/edenadmin/noVNC/venv/lib/python3.13/site-packages/redis/commands/json/__init__.py<lambda>$_JSONBase.__init__.<locals>.<lambda>.   s    A$>)A,$*>$>    c                 0    U =(       a    [        U 5      S:H  $ r   r   r   s    r   r   r   0   s    1#=1)=#=r    c                 0    U =(       a    [        U 5      S:H  $ r   r   r   s    r   r   r   2   s    !"<	!(<"<r    )	zJSON.ARRPOPz
JSON.DEBUGJSON.GETz
JSON.MERGEz	JSON.MGETz	JSON.MSET	JSON.RESPzJSON.SETJSON.TOGGLEzJSON.ARRAPPENDzJSON.ARRINDEXzJSON.ARRINSERTzJSON.ARRLENzJSON.ARRTRIM
JSON.CLEARJSON.DELJSON.FORGETr#   JSON.NUMINCRBYc                 &   > TR                  U 5      $ N_decoder   kwargsselfs     r   r   r   @       $,,q/r    JSON.NUMMULTBYc                 &   > TR                  U 5      $ r+   r,   r.   s     r   r   r   A   r1   r    JSON.OBJKEYSzJSON.STRAPPENDzJSON.OBJLENzJSON.STRLENr%   c                     U b  U /$ U $ r+    r   s    r   r   r   U   s    !-A3#>Q#>r    )r&   r'   r(   r)   r2   r$   	JSON.TYPEr7   c                     U S /:X  a  S $ U $ r+   r6   r   s    r   r   r   X   s    1;4#=A#=r    c                 X    [        U [        5      (       a  [        U 5      S:X  a  U S   $ U $ )Nr   r   )
isinstancelistlenr   s    r   r   r   e   s'    :a+>+>3q6Q;1Q4#UTU#Ur    )r)   r2   r4   r$   r7   )commonresp2resp3resp2_unifiedresp3_unifiedresp3_to_resp2_legacyN)r-   r   int_decode_json_numop_decode_resp_command_unified_decode_resp3_legacy_numop_resp_floats_to_str_commandclientexecute_commandMODULE_VERSIONr	   r   r
   _MODULE_CALLBACKSitemsset_response_callback__encoder____decoder__)r0   rH   versiondecoderencoderrK   _RESP2_MODULE_CALLBACKS_RESP3_MODULE_CALLBACKS_RESP2_UNIFIED_MODULE_CALLBACKS_RESP3_UNIFIED_MODULE_CALLBACKS'_RESP3_TO_RESP2_LEGACY_MODULE_CALLBACKSkeyvalues   `            r   __init___JSONBase.__init__   sF     <<,,>&t||4=<<<

#
dll#
T\\#
 dll#
 4<<	#

 DLL#
 ##
 #
 3#
 #
 A#
 A#
 DLL#
 dll#
 4<<#
 4<<#
  4<<!#
& #% "55"55::>+
' =+
' #=="== LL99U3
/ %55%!7 - -$))99"I	"
 00668JCKK--c9 9 #"r    c                 @   Uc  U$  U R                   R                  U5      nUc  [        eU$ ! [         aJ     U R                   R                  UR                  5       5      s $ ! [         a    [	        U5      s s $ f = f[        [
        4 a    [	        U5      s $ f = f)zGet the decoder.)rO   decode	TypeErrorAttributeErrorr   r   )r0   objxs      r   r-   _JSONBase._decode}   s    ;J	$  '',AyH 	((''..szz|<<! ("3''(0 	$s##	$s2   %- 
B(A# B#A=8B<A==BBc                     Uc  U$  U R                   R                  [        U[        5      (       a  UOUR                  5       5      n[        U[        5      (       d  U/nU$ ! [        [
        4 a    Us $ f = f)u  Decode a JSON.NUMINCRBY / JSON.NUMMULTBY result and normalise
it to the unified array form.

RESP2 wire returns a JSON bulk string — a scalar for legacy
paths and a JSON-encoded list for dollar paths. RESP3 wire
returns a native list. The unified shape is always a list.
)rO   r]   r:   strr_   r   r;   )r0   r`   r/   results       r   rD   _JSONBase._decode_json_numop   sv     ;J	%%,,!#s++F
 &$''XF	 0 	J	s   A A! !A65A6c                     U R                  U5      nUR                  S5      n[        U[        5      (       a?  UR	                  S5      (       d)  [        U[
        5      (       a  [        U5      S:X  a  US   $ U$ )aB  Decode RESP3 JSON numeric operations back to legacy RESP2 shape.

RedisJSON returns a RESP3 array for both legacy paths (``.foo``)
and JSONPath paths (``$.foo``). The command builder records the
path so default RESP3-wire legacy clients can keep v8 scalar
results for legacy paths while leaving JSONPath results as lists.

_json_path$r   r   )r-   getr:   rd   
startswithr;   r<   )r0   r`   r/   re   paths        r   rF   $_JSONBase._decode_resp3_legacy_numop   sd     c"zz,'tS!!OOC((64((Fq !9r    c                 B    U R                  U R                  U5      5      $ )zDecode JSON.RESP and lift string-encoded floats inside the
nested response to native ``float`` values so the unified shape
matches the RESP3 wire.
)_convert_resp_floatsr-   r0   r`   s     r   rE   &_JSONBase._decode_resp_command_unified   s    
 ((c):;;r    c                 B    U R                  U R                  U5      5      $ )zDecode JSON.RESP and re-encode native ``float`` values back
to their string form so the legacy RESP2 shape is preserved
when the wire is RESP3.
)_resp_floats_to_strr-   rp   s     r   rG   %_JSONBase._resp_floats_to_str_command   s    
 ''S(9::r    c                 R   [        U [        5      (       a&  U  Vs/ s H  n[        R                  U5      PM     sn$ [        U [        [
        45      (       a3  [        U [
        5      (       a  U R                  5       OU n [        U5      $ U $ s  snf ! [        [        4 a    U s $ f = f)a
  Recursively convert string-encoded JSON floats.

RESP2 has no native double type, so JSON.RESP returns JSON floats as
bulk strings. Any string/bytes leaf that parses as ``float`` is the
unified representation of such a value; non-numeric strings are left
untouched.
)
r:   r;   r   ro   rd   bytesr]   float
ValueErrorOverflowError)r`   itemrY   s      r   ro   _JSONBase._convert_resp_floats   s     c4  EHISTI2248SIIcC<(($.sE$:$:CJJLEU|# 
 J
 . 
s   B?
B B&%B&c                     [        U [        5      (       a&  U  Vs/ s H  n[        R                  U5      PM     sn$ [        U [        5      (       a  [        U 5      $ U $ s  snf )zRecursively walk ``obj`` and convert native ``float`` values
back to their string-encoded form. Lists are walked
element-wise; non-float leaves are returned unchanged.
)r:   r;   r   rs   rw   rd   )r`   rz   s     r   rs   _JSONBase._resp_floats_to_str   sR     c4  DGHCDI11$7CHHc5!!s8O
 Is   Ac                 8    U R                   R                  U5      $ )zGet the encoder.)rN   encoderp   s     r   _encode_JSONBase._encode   s    &&s++r    c                    [        U R                  [        R                  5      (       a  [	        U R                  R
                  U R                  R                  U R                  R
                  R                  U R                  R                  U R                  R                  U R                  R                  R                  5       U R                  R                  U R                  R                  U R                  R                  S9	nO=[        U R                  R                   [#        U R                  R$                  5      UUS9nU R&                  Ul        U R(                  Ul        U$ )a  Creates a pipeline for the JSON module, that can be used for executing
JSON commands, as well as classic core commands.

Usage example:

r = redis.Redis()
pipe = r.json().pipeline()
pipe.jsonset('foo', '.', {'hello!': 'world'})
pipe.jsonget('foo')
pipe.jsonget('notakey')
)	nodes_managercommands_parserstartup_nodesresult_callbackscluster_response_callbackscluster_error_retry_attemptsread_from_replicasreinitialize_stepslock)connection_poolresponse_callbackstransaction
shard_hint)r:   rH   redisRedisClusterClusterPipeliner   r   r   r   r   retryget_retriesr   r   _lockPipeliner   dictr   r   r-   )r0   r   r   ps       r   pipeline_JSONBase.pipeline   s     dkk5#5#566"kk77 $ ; ;"kk77EE!%!=!=+/;;+Q+Q-1[[->->-J-J-L#';;#A#A#';;#A#A[[&&
A  $ ; ;#'(F(F#G'%	A LL	LL	r    )rJ   rK   rO   rN   rH   rI   )TN)__name__
__module____qualname____firstlineno____doc__r   r   rZ   r-   rD   rF   rE   rG   staticmethodro   rs   r   r   __static_attributes__r6   r    r   r   r      sf     #KM;=^#@$$(&<;  $ 	 	,#r    r   c                       \ rS rSrSrSrg)r   i  z Cluster pipeline for the module.r6   Nr   r   r   r   r   r   r6   r    r   r   r     s    *r    r   c                       \ rS rSrSrSrg)r   i  zPipeline for the module.r6   Nr   r6   r    r   r   r     s    "r    r   c                   *    \ rS rSr% Sr\S   \S'   Srg)JSONi  F_is_async_clientr6   N)r   r   r   r   r   r   __annotations__r   r6   r    r   r   r     s    ',gen,r    r   c                       \ rS rSr% Sr\S   \S'       SS\S\S\S\S-  S	\S-  S
\S-  S\	\-  S-  S\S-  4S jjr
    SS\S\S\S-  S	\S-  S
\S-  S\	\-  S-  S\\\4   4S jjrSrg)	AsyncJSONi  Tr   Nnamerl   	file_namenxxxdecode_keysfphareturnc           
         #    S[         S[        4S jn[        R                  " X5      I Sh  vN n	U R	                  UUU	UUUUS9I Sh  vN $  N! N7f)z
Set the JSON value at key ``name`` under the ``path`` to the content
of the json file ``file_name``.

This runs the blocking file read in a thread pool to avoid blocking
the event loop.
fpr   c                     [        U 5       n[        UR                  5       5      sS S S 5        $ ! , (       d  f       g = fr+   )openr   read)r   fs     r   
_read_file&AsyncJSON.set_file.<locals>._read_file.  s"    bQQVVX s   /
=Nr   r   r   r   )rd   r   asyncio	to_threadset)
r0   r   rl   r   r   r   r   r   r   file_contents
             r   set_fileAsyncJSON.set_file  sh     $	'3 	'4 	' %..zEEXX#  
 
 	
 F
s!   +AAA
AAA	json_pathroot_folderc                 .  #    S[         S[        [            4S jn0 n[        R                  " Xr5      I Sh  vN n	U	 H9  n
 U
R	                  S5      S   nU R                  UUU
UUUUS9I Sh  vN   SX'   M;     U$  NE N! [         a    S	X'    MT  f = f7f)
z
Iterate over ``root_folder`` and set each JSON file to a value
under ``json_path`` with the file name as the key.

This method runs blocking filesystem operations (os.walk and file reads)
in a thread pool to avoid blocking the event loop.
folderr   c                     / n[         R                  " U 5       H=  u  p#nU H1  nUR                  [         R                  R	                  X%5      5        M3     M?     U$ )zCWalk directory and return list of file paths (runs in thread pool).)oswalkappendrl   join)r   
file_pathsrootdirsfilesfiles         r   _walk_directory+AsyncJSON.set_path.<locals>._walk_directoryN  sK    J%'WWV_!E!D%%bggll4&>? " &5 r    N.r   r   TF)rd   r;   r   r   rsplitr   r   )r0   r   r   r   r   r   r   r   set_files_resultr   	file_pathr   s               r   set_pathAsyncJSON.set_path=  s     "	C 	DI 	  #,,_JJ
#I4 &,,S1!4	mm + $    /3 + $&  + K # 4.3 +4sE   4BA<	B,B -A>.B 6B>B  BBBBr6   )FFFN)r   r   r   r   r   r   r   rd   boolr   r   r   r   r   r6   r    r   r   r     s   &*gdm*  #(&*

 
 	

 4K
 4K
 D[
 nt#
 

J  #(&*1 1  1  4K	1 
 4K1  D[1  nt#1  
c4i1  1 r    r   )r   r   jsonr   r   r   r   typingr   r   helpersr	   r
   r   r   commandsr   r   decodersr   r   r   clusterr   rH   r   r   r   r6   r    r   <module>r      s     	 A A    - 0x xv+lEMM$A$A +#|U\\22 #-9 -U 	 U r    