
    Pf=                         d dl Z d dlmZmZ d dlmZmZmZmZm	Z	 d dl
mZ d dlmZ ddlmZ ddlmZ dd	lmZ  G d
 d          ZdS )    N)JSONDecodeErrorloads)DictListOptionalTupleUnion)	DataError)deprecated_function   )JsonType)decode_dict_keys)Pathc                       e Zd ZdZ ej                    fdedee         dee	         dee
edf                  fdZ	 	 d<dededed	ee         d
ee         dee
edf                  fdZdedededee	         dee
edf                  f
dZ ej                    fdedee         dee
edf                  fdZ ej                    dfdedee         dee         dee
edf                  fdZdeded	ed
edee
edf                  f
dZ ej                    fdedee         dee         fdZ ej                    fdedee         defdZ ej                    fdedee         dee
ee         df                  fdZ ej                    fdedee         deee                  fdZdedededefdZ edd          dedededefd            Z ej                    fdedee         defdZ ej                    fdedee         defdZeZdd ded!ee         deee	                  fd"Zd#ee         dedee	         fd$Z	 	 	 d=deded%e	d&ee         d'ee         d(ee         dee         fd)Zd*ee eee	f                  dee         fd+Z!	 d>deded%e	d(ee         dee         f
d,Z"	 	 	 d=deded-ed&ee         d'ee         d(ee         dee         fd.Z#	 	 	 d=d/ed0ed&ee         d'ee         d(ee         de$eef         fd1Z%d?dedee         dee
edf                  fd2Z& ej                    fdedee         de
eeee                  f         fd3Z' ej                    fded4edee         de
eeee                  f         fd5Z(d ej                    fd6edee         dee         de
eee         f         fd7Z) edd8          d9             Z* edd8          d:             Z+ edd8          d;             Z,dS )@JSONCommandszjson commands.namepathargsreturnNc                     |t          |          g}|D ]*}|                    |                     |                     + | j        dg|R  S )zAppend the objects ``args`` to the array under the
        ``path` in key ``name``.

        For more information see `JSON.ARRAPPEND <https://redis.io/commands/json.arrappend>`_..
        zJSON.ARRAPPENDstrappend_encodeexecute_command)selfr   r   r   piecesos         N/var/www/html/env/lib/python3.11/site-packages/redis/commands/json/commands.py	arrappendzJSONCommands.arrappend   s^     D		" 	+ 	+AMM$,,q//****#t#$4>v>>>>    scalarstartstopc                     |t          |          |                     |          g}|,|                    |           ||                    |            | j        dg|R  S )a:  
        Return the index of ``scalar`` in the JSON array under ``path`` at key
        ``name``.

        The search can be limited using the optional inclusive ``start``
        and exclusive ``stop`` indices.

        For more information see `JSON.ARRINDEX <https://redis.io/commands/json.arrindex>`_.
        NzJSON.ARRINDEX)r   r   r   r   )r   r   r   r"   r#   r$   r   s          r   arrindexzJSONCommands.arrindex   sm    " D		4<<#7#78MM%   d####t#O=f====r!   indexc                     |t          |          |g}|D ]*}|                    |                     |                     + | j        dg|R  S )zInsert the objects ``args`` to the array at index ``index``
        under the ``path` in key ``name``.

        For more information see `JSON.ARRINSERT <https://redis.io/commands/json.arrinsert>`_.
        zJSON.ARRINSERTr   )r   r   r   r'   r   r   r   s          r   	arrinsertzJSONCommands.arrinsert6   s`     D		5) 	+ 	+AMM$,,q//****#t#$4>v>>>>r!   c                 J    |                      d|t          |                    S )zReturn the length of the array JSON value under ``path``
        at key``name``.

        For more information see `JSON.ARRLEN <https://redis.io/commands/json.arrlen>`_.
        zJSON.ARRLENr   r   r   r   r   s      r   arrlenzJSONCommands.arrlenC   "     ##M4TCCCr!   c                 L    |                      d|t          |          |          S )zPop the element at ``index`` in the array JSON value under
        ``path`` at key ``name``.

        For more information see `JSON.ARRPOP <https://redis.io/commands/json.arrpop>`_.
        zJSON.ARRPOPr+   )r   r   r   r'   s       r   arrpopzJSONCommands.arrpopM   s$     ##M4TEJJJr!   c                 N    |                      d|t          |          ||          S )zTrim the array JSON value under ``path`` at key ``name`` to the
        inclusive range given by ``start`` and ``stop``.

        For more information see `JSON.ARRTRIM <https://redis.io/commands/json.arrtrim>`_.
        zJSON.ARRTRIMr+   )r   r   r   r#   r$   s        r   arrtrimzJSONCommands.arrtrimZ   s&     ##ND#d))UDQQQr!   c                 J    |                      d|t          |                    S )zGet the type of the JSON value under ``path`` from key ``name``.

        For more information see `JSON.TYPE <https://redis.io/commands/json.type>`_.
        z	JSON.TYPEr+   r,   s      r   typezJSONCommands.typed   "    
 ##Ks4yyAAAr!   c                 J    |                      d|t          |                    S )zReturn the JSON value under ``path`` at key ``name``.

        For more information see `JSON.RESP <https://redis.io/commands/json.resp>`_.
        z	JSON.RESPr+   r,   s      r   respzJSONCommands.respk   r6   r!   c                 J    |                      d|t          |                    S )zReturn the key names in the dictionary JSON value under ``path`` at
        key ``name``.

        For more information see `JSON.OBJKEYS <https://redis.io/commands/json.objkeys>`_.
        zJSON.OBJKEYSr+   r,   s      r   objkeyszJSONCommands.objkeysr   s"     ##ND#d))DDDr!   c                 J    |                      d|t          |                    S )zReturn the length of the dictionary JSON value under ``path`` at key
        ``name``.

        For more information see `JSON.OBJLEN <https://redis.io/commands/json.objlen>`_.
        zJSON.OBJLENr+   r,   s      r   objlenzJSONCommands.objlen|   r.   r!   numberc                 r    |                      d|t          |          |                     |                    S )zIncrement the numeric (integer or floating point) JSON value under
        ``path`` at key ``name`` by the provided ``number``.

        For more information see `JSON.NUMINCRBY <https://redis.io/commands/json.numincrby>`_.
        zJSON.NUMINCRBYr   r   r   r   r   r   r=   s       r   	numincrbyzJSONCommands.numincrby   s7     ##dCIIt||F/C/C
 
 	
r!   z4.0.0z deprecated since redisjson 1.0.0)versionreasonc                 r    |                      d|t          |          |                     |                    S )zMultiply the numeric (integer or floating point) JSON value under
        ``path`` at key ``name`` with the provided ``number``.

        For more information see `JSON.NUMMULTBY <https://redis.io/commands/json.nummultby>`_.
        zJSON.NUMMULTBYr?   r@   s       r   	nummultbyzJSONCommands.nummultby   s7     ##dCIIt||F/C/C
 
 	
r!   c                 J    |                      d|t          |                    S )a  Empty arrays and objects (to have zero slots/keys without deleting the
        array/object).

        Return the count of cleared paths (ignoring non-array and non-objects
        paths).

        For more information see `JSON.CLEAR <https://redis.io/commands/json.clear>`_.
        z
JSON.CLEARr+   r,   s      r   clearzJSONCommands.clear   s"     ##L$D		BBBr!   keyc                 J    |                      d|t          |                    S )zDelete the JSON value stored at key ``key`` under ``path``.

        For more information see `JSON.DEL <https://redis.io/commands/json.del>`_.
        zJSON.DELr+   )r   rH   r   s      r   deletezJSONCommands.delete   s"    
 ##JSYY???r!   F)	no_escaperK   c                8   |g}|r|                     d           t          |          dk    r'|                     t          j                               n'|D ]$}|                     t	          |                     %	  | j        dg|R  S # t          $ r Y dS w xY w)aD  
        Get the object stored as a JSON value at key ``name``.

        ``args`` is zero or more paths, and defaults to root path
        ```no_escape`` is a boolean flag to add no_escape option to get
        non-ascii characters

        For more information see `JSON.GET <https://redis.io/commands/json.get>`_.
        noescaper   zJSON.GETN)r   lenr   	root_pathr   r   	TypeError)r   r   rK   r   r   ps         r   getzJSONCommands.get   s      	&MM*%%%t99>>MM$.**++++  & &c!ff%%%%	'4'
<V<<<< 	 	 	44	s   =B 
BBkeysc                 p    g }||z  }|                     t          |                      | j        dg|R  S )z
        Get the objects stored as a JSON values under ``path``. ``keys``
        is a list of one or more keys.

        For more information see `JSON.MGET <https://redis.io/commands/json.mget>`_.
        z	JSON.MGETr   r   r   )r   rS   r   r   s       r   mgetzJSONCommands.mget   sE     $c$ii   #t#K9&9999r!   objnxxxdecode_keysc                    |rt          |          }|t          |          |                     |          g}|r|rt          d          |r|                    d           n|r|                    d            | j        dg|R  S )a  
        Set the JSON value at key ``name`` under the ``path`` to ``obj``.

        ``nx`` if set to True, set ``value`` only if it does not exist.
        ``xx`` if set to True, set ``value`` only if it exists.
        ``decode_keys`` If set to True, the keys of ``obj`` will be decoded
        with utf-8.

        For the purpose of using this within a pipeline, this command is also
        aliased to JSON.SET.

        For more information see `JSON.SET <https://redis.io/commands/json.set>`_.
        zNnx and xx are mutually exclusive: use one, the other or neither - but not bothNXXXzJSON.SET)r   r   r   	Exceptionr   r   )r   r   r   rW   rX   rY   rZ   r   s           r   setzJSONCommands.set   s    ,  	("3''CD		4<<#4#45  	 " 	 2    	 MM$ 	 MM$#t#J88888r!   tripletsc           	          g }|D ]L}|                     |d         t          |d                   |                     |d                   g           M | j        dg|R  S )a  
        Set the JSON value at key ``name`` under the ``path`` to ``obj``
        for one or more keys.

        ``triplets`` is a list of one or more triplets of key, path, value.

        For the purpose of using this within a pipeline, this command is also
        aliased to JSON.MSET.

        For more information see `JSON.MSET <https://redis.io/commands/json.mset>`_.
        r   r      z	JSON.MSET)extendr   r   r   )r   r`   r   triplets       r   msetzJSONCommands.mset  so      	S 	SGMM71:s71:WQZ8P8PQRRRR#t#K9&9999r!   c                     |rt          |          }|t          |          |                     |          g} | j        dg|R  S )aa  
        Merges a given JSON value into matching paths. Consequently, JSON values
        at matching paths are updated, deleted, or expanded with new children

        ``decode_keys`` If set to True, the keys of ``obj`` will be decoded
        with utf-8.

        For more information see `JSON.MERGE <https://redis.io/commands/json.merge>`_.
        z
JSON.MERGE)r   r   r   r   )r   r   r   rW   rZ   r   s         r   mergezJSONCommands.merge  sR       	("3''CD		4<<#4#45#t#L:6::::r!   	file_namec                     t          |d          5 }t          |                                          }ddd           n# 1 swxY w Y   |                     ||||||          S )ah  
        Set the JSON value at key ``name`` under the ``path`` to the content
        of the json file ``file_name``.

        ``nx`` if set to True, set ``value`` only if it does not exist.
        ``xx`` if set to True, set ``value`` only if it exists.
        ``decode_keys`` If set to True, the keys of ``obj`` will be decoded
        with utf-8.

        rNrX   rY   rZ   )openr   readr_   )	r   r   r   rh   rX   rY   rZ   fpfile_contents	            r   set_filezJSONCommands.set_file)  s    ( )S!! 	,R ++L	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, 	, xxdLRBKxXXXs   "?AA	json_pathroot_folderc           
      ,   i }t          j        |          D ]|\  }}}	|	D ]s}
t           j                            ||
          }	 |                    d          d         }|                     ||||||           d||<   _# t          $ r d||<   Y pw xY w}|S )au  
        Iterate over ``root_folder`` and set each JSON file to a value
        under ``json_path`` with the file name as the key.

        ``nx`` if set to True, set ``value`` only if it does not exist.
        ``xx`` if set to True, set ``value`` only if it exists.
        ``decode_keys`` If set to True, the keys of ``obj`` will be decoded
        with utf-8.

        .r   rk   TF)oswalkr   joinrsplitrp   r   )r   rq   rr   rX   rY   rZ   set_files_resultrootdirsfilesfile	file_pathrh   s                r   set_pathzJSONCommands.set_pathB  s    $ !#!5!5 	8 	8D$ 8 8GLLt44	8 ) 0 0 5 5a 8IMM!!!$/ "    37$Y//& 8 8 827$Y///88   s   ;A>>BBc                 l    |g}|"|                     t          |                      | j        dg|R  S )zReturn the length of the string JSON value under ``path`` at key
        ``name``.

        For more information see `JSON.STRLEN <https://redis.io/commands/json.strlen>`_.
        NzJSON.STRLENrU   )r   r   r   r   s       r   strlenzJSONCommands.strlenh  sD     MM#d))$$$#t#M;F;;;;r!   c                 J    |                      d|t          |                    S )zToggle boolean value under ``path`` at key ``name``.
        returning the new value.

        For more information see `JSON.TOGGLE <https://redis.io/commands/json.toggle>`_.
        zJSON.TOGGLEr+   r,   s      r   togglezJSONCommands.toggles  r.   r!   valuec                 h    |t          |          |                     |          g} | j        dg|R  S )aC  Append to the string JSON value. If two options are specified after
        the key name, the path is determined to be the first. If a single
        option is passed, then the root_path (i.e Path.root_path()) is used.

        For more information see `JSON.STRAPPEND <https://redis.io/commands/json.strappend>`_.
        zJSON.STRAPPEND)r   r   r   )r   r   r   r   r   s        r   	strappendzJSONCommands.strappend}  s>     D		4<<#6#67#t#$4>v>>>>r!   
subcommandc                 
   ddg}||vrt          dt          |                    |g}|dk    rH|t          d          |                    |           |                    t          |                      | j        dg|R  S )zReturn the memory usage in bytes of a value under ``path`` from
        key ``name``.

        For more information see `JSON.DEBUG <https://redis.io/commands/json.debug>`_.
        MEMORYHELPzThe only valid subcommands are NzNo key specifiedz
JSON.DEBUG)r
   r   r   r   )r   r   rH   r   valid_subcommandsr   s         r   debugzJSONCommands.debug  s     &v....=sCT?U?UVVV!!{ 2333MM#MM#d))$$$#t#L:6::::r!   z/redisjson-py supported this, call get directly.c                      | j         |i |S N)rR   r   r   kwargss      r   jsongetzJSONCommands.jsonget       tx((((r!   c                      | j         |i |S r   )rV   r   s      r   jsonmgetzJSONCommands.jsonmget  s     ty$)&)))r!   c                      | j         |i |S r   )r_   r   s      r   jsonsetzJSONCommands.jsonset  r   r!   )NN)FFF)Fr   )-__name__
__module____qualname____doc__r   rO   r   r   r   r   r	   intr    r&   r)   r-   r1   r3   r5   r8   r:   r<   rA   r   rE   rG   rJ   forgetboolrR   rV   r_   r   re   rg   rp   r   r   r   r   r   r   r   r   r    r!   r   r   r      s7	        0>t~/?/?? ??'}?HLX?	eCI	? ? ? ?$  $"> >> > 	>
 }> sm> 
eCI	> > > >2??"?+.?7;H~?	eCI	? ? ? ? 0>t~/?/?D DD'}D	eCI	D D D D -dn..!	K KK smK }	K
 
eCI	K K K KRR"R+.R69R	eCI	R R R R 5CDN4D4D B B BHSM Bc B B B B 5CDN4D4D B B BHSM B B B B B 0>t~/?/?E EE'}E	eDItO$	%E E E E 0>t~/?/?D DD'}D	hsm	D D D D
c 
 
c 
c 
 
 
 
 1STTT
c 
 
c 
c 
 
 
 UT
 6DT^5E5E 	C 	C# 	CXc] 	C# 	C 	C 	C 	C 6DT^5E5E @ @# @Xc] @# @ @ @ @ F =B  +3D>	$x.	!   <
:c 
:# 
:$x. 
: 
: 
: 
:" #"&+%9 %9%9 %9 	%9
 TN%9 TN%9 d^%9 
#%9 %9 %9 %9N:T%S((:";< :# : : : :, ',; ;; ; 	;
 d^; 
#; ; ; ;8 #"&+Y YY Y 	Y
 TNY TNY d^Y 
#Y Y Y Y: #"&+$  $ $  $  TN	$ 
 TN$  d^$  
c4i$  $  $  $ L	< 	<3 	<hsm 	<tE#t)DT?U 	< 	< 	< 	< 0>t~/?/?D DD'}D	tT(3-((	)D D D D <J4>;K;K
? 
?
? #
?+3C=
?	sD#''	(
? 
? 
? 
? ",dn..	; ;; c]; sm	;
 
sDI~	; ; ; ;,  Q  ) ) )  Q  * * *  Q  ) ) ) ) )r!   r   )ru   jsonr   r   typingr   r   r   r   r	   redis.exceptionsr
   redis.utilsr   _utilr   decodersr   r   r   r   r   r!   r   <module>r      s    				 ' ' ' ' ' ' ' ' 5 5 5 5 5 5 5 5 5 5 5 5 5 5 & & & & & & + + + + + +       & & & & & &      b) b) b) b) b) b) b) b) b) b)r!   