Ë
    3ýjÈ2  ã                   ó:  — d dl Z d dlZd dlmZmZmZmZ d dlmZ d dl	Z	ddl
mZmZmZmZ ddlmZmZ ddlmZmZ  G d	„ d
e«      Z G d„ dee	j,                  j.                  «      Z G d„ dee	j0                  j2                  «      Z G d„ de«      Z G d„ de«      Zy)é    N)ÚJSONDecodeErrorÚJSONDecoderÚJSONEncoderÚloads)ÚLiteralé   )Úapply_module_callbacksÚget_legacy_responsesÚget_protocol_versionÚ	nativestré   )ÚFPHATypeÚJSONCommands)Úbulk_of_jsonsÚdecode_listc                   ó~   — e Zd ZdZd e«        e«       fd„Zd„ Zd„ Zd„ Z	d„ Z
d„ Zed	„ «       Zed
„ «       Zd„ Zdd„Zy)Ú	_JSONBasezÐ
    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           
      ó>  ‡ — ‰ j                   ‰ j                   ‰ j                   d„ t        ‰ j                   «      d„ ‰ j                   d„ ‰ j                   dœ	}i d‰ j                   “d‰ j                   “d‰ j                   “d‰ j                   “d	‰ j                   “d
t        “dt        “dt        “d‰ j                   “dˆ fd„“dˆ fd„“d‰ j                   “d‰ j                   “d‰ j                   “d‰ j                   “d‰ j                   “}i }t        t        t        ‰ j                  ‰ j                  ‰ j                  d„ dœ}dd„ i}	‰ j
                  ‰ j
                  ‰ j                   ‰ j                  d„ dœ}
|‰ _        |j                  ‰ _        |‰ _	        t        t        ‰ j                  «      t        ‰ j                  «      |||||	|
¬«      ‰ _        ‰ j                  j                  «       D ]!  \  }}‰ j                  j                  ||«       Œ# |‰ _        |‰ _        y)zè
        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
        c                 ó&   — | xr t        | «      dk(  S ©NÚOK©r   ©Úrs    úV/root/telegram-saas/.venv/lib/python3.12/site-packages/redis/commands/json/__init__.pyú<lambda>z$_JSONBase.__init__.<locals>.<lambda>.   s   €  AÒ$>¬)°A«,¸$Ñ*>€ ó    c                 ó&   — | xr t        | «      dk(  S r   r   r   s    r   r   z$_JSONBase.__init__.<locals>.<lambda>0   s   €  1Ò#=¬°1«¸Ñ)=€ r   c                 ó&   — | xr t        | «      dk(  S r   r   r   s    r   r   z$_JSONBase.__init__.<locals>.<lambda>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                 ó&   •— ‰j                  | «      S ©N©Ú_decode©r   ÚkwargsÚselfs     €r   r   z$_JSONBase.__init__.<locals>.<lambda>@   ó   ø€ °$·,±,¸q³/€ r   úJSON.NUMMULTBYc                 ó&   •— ‰j                  | «      S r(   r)   r+   s     €r   r   z$_JSONBase.__init__.<locals>.<lambda>A   r.   r   úJSON.OBJKEYSzJSON.STRAPPENDzJSON.OBJLENzJSON.STRLENr"   c                 ó   — | �| gS | S r(   © r   s    r   r   z$_JSONBase.__init__.<locals>.<lambda>U   s   € ¨!¨- A 3€ ¸Q€ r   )r#   r$   r%   r&   r/   r!   ú	JSON.TYPEr4   c                 ó   — | d gk(  rd S | S r(   r3   r   s    r   r   z$_JSONBase.__init__.<locals>.<lambda>X   s   € ¨1°°ª; 4€ ¸A€ r   c                 óL   — t        | t        «      rt        | «      dk(  r| d   S | S )Nr   r   )Ú
isinstanceÚlistÚlenr   s    r   r   z$_JSONBase.__init__.<locals>.<lambda>e   s"   € ¬:°a¼Ô+>Ä3ÀqÃ6ÈQÂ; 1 Q¡4€ ÐTU€ r   )r&   r/   r1   r!   r4   )Ú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__)r-   rE   ÚversionÚdecoderÚencoderrH   Ú_RESP2_MODULE_CALLBACKSÚ_RESP3_MODULE_CALLBACKSÚ_RESP2_UNIFIED_MODULE_CALLBACKSÚ_RESP3_UNIFIED_MODULE_CALLBACKSÚ'_RESP3_TO_RESP2_LEGACY_MODULE_CALLBACKSÚkeyÚvalues   `            r   Ú__init__z_JSONBase.__init__   sO  ø€ ð  Ÿ<™<ØŸ,™,ØŸ™Ù>Ü& t§|¡|Ó4Ù=ØŸ™Ù<ØŸ<™<ñ

Ðð#
Ø˜dŸl™lð#
à˜TŸ\™\ð#
ð ˜dŸl™lð#
ð ˜4Ÿ<™<ð	#
ð
 ˜DŸL™Lð#
ð œ#ð#
ð œð#
ð œ3ð#
ð ˜Ÿ™ð#
ð ÓAð#
ð ÓAð#
ð ˜DŸL™Lð#
ð ˜dŸl™lð#
ð ˜4Ÿ<™<ð#
ð ˜4Ÿ<™<ð#
ð  ˜4Ÿ<™<ð!#
Ðð& #%Ðô ÜÜØ"×5Ñ5Ø"×5Ñ5Ø×:Ñ:Ù>ñ+
Ð'ð Ñ=ð+
Ð'ð #×=Ñ=Ø"×=Ñ=Ø ŸL™LØ×9Ñ9ÙUñ3
Ð/ð ˆŒØ%×5Ñ5ˆÔØ%ˆÔä!7Ü  §¡Ó-Ü  §¡Ó-Ø$Ø)Ø)Ø9Ø9Ø"Iô	"
ˆÔð ×0Ñ0×6Ñ6Ó8ò 	:‰JˆC�Ø�K‰K×-Ñ-¨c°5Õ9ð	:ð #ˆÔØ"ˆÕr   c                 ó6  — |€|S 	 | j                   j                  |«      }|€t        ‚|S # t        $ rI 	 | j                   j                  |j                  «       «      cY S # t        $ r t	        |«      cY cY S w xY wt        t
        f$ r t	        |«      cY S w xY w)zGet the decoder.)rL   ÚdecodeÚ	TypeErrorÚAttributeErrorr   r   )r-   ÚobjÚxs      r   r*   z_JSONBase._decode}   s™   € àˆ;ØˆJð	$Ø× Ñ ×'Ñ'¨Ó,ˆAØˆyÜ�ØˆHøÜò 	(ð(Ø×'Ñ'×.Ñ.¨s¯z©z«|Ó<Ò<øÜ!ò (Ü" 3Ó'Ô'ð(úä¤Ð0ò 	$Ü˜sÓ#Ò#ð	$ús2   †$+ «	Bµ(A ÁBÁ A9Á4BÁ8A9Á9BÂBc                 óÚ   — |€|S 	 | j                   j                  t        |t        «      r|n|j                  «       «      }t        |t        «      s|g}|S # t        t
        f$ r |cY S w xY w)u9  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.
        )rL   rY   r7   Ústrr[   r   r8   )r-   r\   r,   Úresults       r   rA   z_JSONBase._decode_json_numop�   sp   € ð ˆ;ØˆJð	Ø×%Ñ%×,Ñ,Ü! #¤sÔ+‘°·±³óˆFô
 ˜&¤$Ô'Ø�XˆFØˆøô	 ¤Ð0ò 	ØŠJð	ús   †;A ÁA*Á)A*c                 óÒ   — | j                  |«      }|j                  d«      }t        |t        «      r4|j	                  d«      s#t        |t
        «      rt        |«      dk(  r|d   S |S )aj  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*   Úgetr7   r_   Ú
startswithr8   r9   )r-   r\   r,   r`   Úpaths        r   rC   z$_JSONBase._decode_resp3_legacy_numop£   s[   € ð —‘˜cÓ"ˆØ�z‰z˜,Ó'ˆä�tœSÔ!Ø—O‘O CÔ(Ü˜6¤4Ô(Ü�F“˜qÒ à˜!‘9ÐØˆr   c                 óB   — | j                  | j                  |«      «      S )z«Decode 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*   ©r-   r\   s     r   rB   z&_JSONBase._decode_resp_command_unified¶   s   € ð
 ×(Ñ(¨¯©°cÓ):Ó;Ð;r   c                 óB   — | j                  | j                  |«      «      S )z¨Decode 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*   ri   s     r   rD   z%_JSONBase._resp_floats_to_str_command½   s   € ð
 ×'Ñ'¨¯©°SÓ(9Ó:Ð:r   c                 ó,  — t        | t        «      r#| D �cg c]  }t        j                  |«      ‘Œ c}S t        | t        t
        f«      r.t        | t
        «      r| j                  «       n| }	 t        |«      S | S c c}w # t        t        f$ r | cY S w xY w)a2  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.
        )
r7   r8   r   rh   r_   ÚbytesrY   ÚfloatÚ
ValueErrorÚOverflowError)r\   ÚitemrV   s      r   rh   z_JSONBase._convert_resp_floatsÄ   s…   € ô �cœ4Ô ØEHÖI¸T”I×2Ñ2°4Õ8ÒIÐIÜ�cœC¤˜<Ô(Ü$.¨s´EÔ$:�C—J‘J”LÀˆEðÜ˜U“|Ð#ð ˆ
ùò Jøô
 ¤Ð.ò Ø’
ðús   •A:Á-
A? Á?BÂBc                 ó¬   — t        | t        «      r#| D �cg c]  }t        j                  |«      ‘Œ c}S t        | t        «      rt        | «      S | S c c}w )zÀRecursively walk ``obj`` and convert native ``float`` values
        back to their string-encoded form. Lists are walked
        element-wise; non-float leaves are returned unchanged.
        )r7   r8   r   rk   rn   r_   )r\   rq   s     r   rk   z_JSONBase._resp_floats_to_str×   sH   € ô �cœ4Ô ØDGÖH¸D”I×1Ñ1°$Õ7ÒHÐHÜ�cœ5Ô!Ü�s“8ˆOØˆ
ùò Is   •Ac                 ó8   — | j                   j                  |«      S )zGet the encoder.)rK   Úencoderi   s     r   Ú_encodez_JSONBase._encodeã   s   € à×Ñ×&Ñ& sÓ+Ð+r   c                 óÔ  — t        | j                  t        j                  «      rát	        | j                  j
                  | j                  j                  | j                  j
                  j                  | j                  j                  | j                  j                  | j                  j                  j                  «       | j                  j                  | j                  j                  | j                  j                  ¬«	      }n@t        | j                  j                   t#        | j                  j$                  «      ||¬«      }| j&                  |_        | j(                  |_        |S )aP  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)r7   rE   ÚredisÚRedisClusterÚClusterPipelinerw   rx   ry   rz   r{   ÚretryÚget_retriesr}   r~   Ú_lockÚPipeliner€   Údictr�   ru   r*   )r-   r‚   rƒ   Úps       r   Úpipelinez_JSONBase.pipelineç   sô   € ô �d—k‘k¤5×#5Ñ#5Ô6ÜØ"Ÿk™k×7Ñ7Ø $§¡× ;Ñ ;Ø"Ÿk™k×7Ñ7×EÑEØ!%§¡×!=Ñ!=Ø+/¯;©;×+QÑ+QØ-1¯[©[×->Ñ->×-JÑ-JÓ-LØ#'§;¡;×#AÑ#AØ#'§;¡;×#AÑ#AØ—[‘[×&Ñ&ô
‰Aô Ø $§¡× ;Ñ ;Ü#'¨¯©×(FÑ(FÓ#GØ'Ø%ô	ˆAð —L‘LˆŒ	Ø—L‘LˆŒ	Øˆr   )TN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   rW   r*   rA   rC   rB   rD   Ústaticmethodrh   rk   ru   r�   r3   r   r   r   r      sf   „ ñð #©K«MÁ;Ã=ó^#ò@$ò$ò(ò&<ò;ð ñó ðð$ ñ	ó ð	ò,ô#r   r   c                   ó   — e Zd ZdZy)r†   z Cluster pipeline for the module.N©rŽ   r�   r�   r‘   r3   r   r   r†   r†     s   „ Ú*r   r†   c                   ó   — e Zd ZdZy)rŠ   zPipeline for the module.Nr”   r3   r   r   rŠ   rŠ     s   „ Ú"r   rŠ   c                   ó"   — e Zd ZU dZed   ed<   y)ÚJSONFÚ_is_async_clientN)rŽ   r�   r�   r˜   r   Ú__annotations__r3   r   r   r—   r—     s   … Ø',Ð�g˜e‘nÔ,r   r—   c                   óÎ   — e Zd ZU dZed   ed<   	 	 	 	 ddededededz  dedz  d	edz  d
eez  dz  dedz  fd„Z		 	 	 	 ddedededz  dedz  d	edz  d
eez  dz  de
eef   fd„Zy)Ú	AsyncJSONTr˜   NÚnamerf   Ú	file_nameÚnxÚxxÚdecode_keysÚfphaÚreturnc           	   ƒ   ó®   K  — dt         dt        fd„}t        j                  ||«      ƒ d{  –—† }	| j	                  |||	||||¬«      ƒ d{  –—† S 7 Œ$7 Œ­w)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                 óv   — t        | «      5 }t        |j                  «       «      cd d d «       S # 1 sw Y   y xY wr(   )Úopenr   Úread)r¤   Úfs     r   Ú
_read_filez&AsyncJSON.set_file.<locals>._read_file.  s-   € Ü�b“ð '˜QÜ˜QŸV™V›X“÷'÷ 'ò 'ús   Œ/¯8N©rž   rŸ   r    r¡   )r_   r‹   ÚasyncioÚ	to_threadÚset)
r-   rœ   rf   r�   rž   rŸ   r    r¡   r©   Úfile_contents
             r   Úset_filezAsyncJSON.set_file  sl   è ø€ ð$	'œ3ð 	'¤4ó 	'ô %×.Ñ.¨z¸9ÓE×EˆØ—X‘XØØØØØØ#Øð ó 
÷ 
ð 	
ð Føð
ús!   ‚*A¬A­AÁAÁAÁAÚ	json_pathÚroot_folderc           
   ƒ   ó.  K  — dt         dt        t            fd„}i }t        j                  ||«      ƒ d{  –—† }	|	D ]<  }
	 |
j	                  d«      d   }| j                  |||
||||¬«      ƒ d{  –—†  d||
<   Œ> |S 7 ŒG7 Œ# t        $ r d	||
<   Y ŒUw xY w­w)
a  
        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                 ó²   — g }t        j                  | «      D ]<  \  }}}|D ]1  }|j                  t         j                  j	                  ||«      «       Œ3 Œ> |S )zCWalk directory and return list of file paths (runs in thread pool).)ÚosÚwalkÚappendrf   Újoin)r³   Ú
file_pathsÚrootÚdirsÚfilesÚfiles         r   Ú_walk_directoryz+AsyncJSON.set_path.<locals>._walk_directoryN  s]   € àˆJÜ%'§W¡W¨V£_ò @Ñ!��d˜EØ!ò @�DØ×%Ñ%¤b§g¡g§l¡l°4¸Ó&>Õ?ñ@ð@ð Ðr   Nú.r   rª   TF)r_   r8   r«   r¬   Úrsplitr¯   r   )r-   r°   r±   rž   rŸ   r    r¡   r¾   Úset_files_resultr¹   Ú	file_pathr�   s               r   Úset_pathzAsyncJSON.set_path=  sÓ   è ø€ ð"	¤Cð 	¬D´©Ió 	ð Ðô #×,Ñ,¨_¸kÓJ×Jˆ
à#ò 	4ˆIð4ð &×,Ñ,¨SÓ1°!Ñ4�	Ø—m‘mØØØØØØ +Øð $ó ÷ ð ð /3Ð  Ò+ð	4ð&  Ðð+ Køðùô #ò 4Ø.3Ð  Ó+ð4üsE   ‚3BµA=¶	BÁ /BÁ/A?Á0	BÁ9BÁ?BÂBÂBÂBÂB)FFFN)rŽ   r�   r�   r˜   r   r™   r_   Úboolr   r¯   r‹   rÃ   r3   r   r   r›   r›     s   … Ø&*Ð�g˜d‘mÓ*ð  ØØ#(Ø&*ñ
àð
ð ð
ð ð	
ð
 �4‰Kð
ð �4‰Kð
ð ˜D‘[ð
ð ˜‰n˜tÑ#ð
ð 
�‰ó
ðJ  ØØ#(Ø&*ñ1 àð1 ð ð1 ð �4‰Kð	1 ð
 �4‰Kð1 ð ˜D‘[ð1 ð ˜‰n˜tÑ#ð1 ð 
ˆc�4ˆi‰ô1 r   r›   )r«   rµ   Újsonr   r   r   r   Útypingr   r„   Úhelpersr	   r
   r   r   Úcommandsr   r   Údecodersr   r   r   Úclusterr†   rE   rŠ   r—   r›   r3   r   r   ú<module>rË      s‚   ðÛ Û 	ß AÓ AÝ ã ÷ó ÷ -ß 0ôx�ô xôv+�l E§M¡M×$AÑ$Aô +ô#ˆ|˜UŸ\™\×2Ñ2ô #ô-ˆ9ô -ôU �	õ U r   