
    Ihk=                         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y)    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
      fdZ	 	 d<dedede
d	ee
   d
ee
   deee
      fdZdedede
dee	   deee
      f
dZ ej
                         fdedee   deee
      fdZ ej
                         dfdedee   dee
   deee      fdZdeded	e
d
e
deee
      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         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
      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,y)@JSONCommandszjson commands.namepathargsreturnc                     |t        |      g}|D ]"  }|j                  | j                  |             $  | j                  dg| 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         U/var/www/html/planif/env/lib/python3.12/site-packages/redis/commands/json/commands.py	arrappendzJSONCommands.arrappend   sN     D	" 	+AMM$,,q/*	+#t##$4>v>>    Nscalarstartstopc                     |t        |      | j                  |      g}|$|j                  |       ||j                  |        | j                  dg|d|gi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>`_.
        zJSON.ARRINDEXkeys)r   r   r   r   )r   r   r   r"   r#   r$   r   s          r   arrindexzJSONCommands.arrindex   s`    " D	4<<#78MM% d##t##OJfJD6JJr!   indexc                     |t        |      |g}|D ]"  }|j                  | j                  |             $  | j                  dg| 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   sP     D	5) 	+AMM$,,q/*	+#t##$4>v>>r!   c                 @    | j                  d|t        |      |g      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   r   s      r   arrlenzJSONCommands.arrlenC   $     ##M4T$#PPr!   c                 <    | j                  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Jr!   c                 >    | j                  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Qr!   c                 @    | j                  d|t        |      |g      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-   r.   s      r   typezJSONCommands.typed   $    
 ##Ks4yv#NNr!   c                 @    | j                  d|t        |      |g      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-   r.   s      r   respzJSONCommands.respk   r8   r!   c                 @    | j                  d|t        |      |g      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-   r.   s      r   objkeyszJSONCommands.objkeysr   s$     ##ND#d)4&#QQr!   c                 @    | j                  d|t        |      |g      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-   r.   s      r   objlenzJSONCommands.objlen|   r0   r!   numberc                 Z    | j                  d|t        |      | j                  |            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   s-     ##dCIt||F/C
 	
r!   z4.0.0z deprecated since redisjson 1.0.0)versionreasonc                 Z    | j                  d|t        |      | j                  |            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.NUMMULTBYrA   rB   s       r   	nummultbyzJSONCommands.nummultby   s-     ##dCIt||F/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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   rJ   r   s      r   deletezJSONCommands.delete   s    
 ##JSY??r!   F)	no_escaperM   c                "   |g}|r|j                  d       t        |      dk(  r$|j                  t        j                                n!|D ]  }|j                  t	        |              	  | j
                  dg|d|giS # t        $ r Y y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.GETr&   N)r   lenr   	root_pathr   r   	TypeError)r   r   rM   r   r   ps         r   getzJSONCommands.get   s     MM*%t9>MM$..*+  &c!f%&
	'4''
IVI4&II 		s   +B 	BBr&   c                 p    g }||z  }|j                  t        |              | j                  dg|d|i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.MGETr&   r   r   r   )r   r&   r   r   s       r   mgetzJSONCommands.mget   s?     $c$i #t##KD&DtDDr!   objnxxxdecode_keysc                     |rt        |      }|t        |      | j                  |      g}|r|rt        d      |r|j	                  d       n|r|j	                  d        | j
                  dg| 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   rX   rY   rZ   r[   r   s           r   setzJSONCommands.set   s{    , "3'CD	4<<#45 "2  MM$MM$#t##J888r!   tripletsc           	          g }|D ]7  }|j                  |d   t        |d         | j                  |d         g       9  | j                  dg| 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   ra   r   triplets       r   msetzJSONCommands.mset  s^      	SGMM71:s71:WQZ8PQR	S#t##K9&99r!   c                 |    |rt        |      }|t        |      | j                  |      g} | j                  dg| 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   rX   r[   r   s         r   mergezJSONCommands.merge  sB      "3'CD	4<<#45#t##L:6::r!   	file_namec                     t        |      5 }t        |j                               }ddd       | j                  |||||      S # 1 sw Y    xY w)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.

        NrY   rZ   r[   )openr   readr`   )	r   r   r   ri   rY   rZ   r[   fpfile_contents	            r   set_filezJSONCommands.set_file)  sO    ( )_ 	, +L	, xxdLRBKxXX	, 	,s   AA	json_pathroot_folderc           
         i }t        j                  |      D ]^  \  }}}	|	D ]S  }
t         j                  j                  ||
      }	 |j	                  d      d   }| j                  ||||||       d||<   U ` |S # t        $ r d||<   Y jw xY w)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   rY   rZ   r[   set_files_resultrootdirsfilesfile	file_pathri   s                r   set_pathzJSONCommands.set_pathB  s    $ !#!5 	8D$ 8GGLLt4	8 ) 0 0 5a 8IMM!!!$/ "  37$Y/8	8"   ' 827$Y/8s   0A;;BBc                 n    |g}||j                  t        |              | j                  dg|d|gi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>`_.
        zJSON.STRLENr&   rV   )r   r   r   r   s       r   strlenzJSONCommands.strlenh  s@     MM#d)$#t##MHFH$HHr!   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  s     ##M4TCCr!   valuec                 b    |t        |      | j                  |      g} | j                  dg| 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}  s6     D	4<<#67#t##$4>v>>r!   
subcommandc                     ddg}||vrt        dt        |            |g}|dk(  r8|t        d      |j                  |       |j                  t        |              | j                  dg| 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 zNo key specifiedz
JSON.DEBUG)r
   r   r   r   )r   r   rJ   r   valid_subcommandsr   s         r   debugzJSONCommands.debug  s     &v...=sCT?UVV!{ 233MM#MM#d)$#t##L:6::r!   z/redisjson-py supported this, call get directly.c                 &     | j                   |i |S N)rT   r   r   kwargss      r   jsongetzJSONCommands.jsonget       txx(((r!   c                 &     | j                   |i |S r   )rW   r   s      r   jsonmgetzJSONCommands.jsonmget  s     tyy$)&))r!   c                 &     | j                   |i |S r   )r`   r   s      r   jsonsetzJSONCommands.jsonset  r   r!   )NN)FFF)Fr   )-__name__
__module____qualname____doc__r   rQ   r   r   r   r   intr    r'   r*   r/   r3   r5   r7   r:   r<   r>   rC   r   rG   rI   rL   forgetboolrT   rW   r`   r   rf   rh   rp   r   r   r   r	   r   r   r   r   r   r    r!   r   r   r      s    0>t~~/???'}?HLX?	hsm	?$  $"KK K 	K
 }K smK 
hsm	K2??"?+.?7;H~?	hsm	? 0>t~~/?QQ'}Q	hsm	Q -dnn.!	KK smK }	K
 
hsm	KRR"R+.R69R	hsm	R 5CDNN4D O OHSM Oc O 5CDNN4D O OHSM O O 0>t~~/?RR'}R	htCy!	"R 0>t~~/?QQ'}Q	hsm	Q
c 
 
c 
c 
 1ST
c 
 
c 
c 
 U
 6DT^^5E 	C# 	CXc] 	C# 	C 6DT^^5E @# @Xc] @# @ F =B+3D>	$x.	!<
Ec 
E# 
E$x. 
E" #"&+%9%9 %9 	%9
 TN%9 TN%9 d^%9 
#%9N:T%S((:";< :# :, ',;; ; 	;
 d^; 
#;8 #"&+YY Y 	Y
 TNY TNY d^Y 
#Y: #"&+$ $  $  TN	$ 
 TN$  d^$  
c4i$ L	I3 	Ihsm 	ItHSM?R 	I 0>t~~/?DD'}D	tT(3-((	)D <J4>>;K
?
? #
?+3C=
?	sD#''	(
? ",dnn.	;; 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 & +  & b) b)r!   