
    jtl                     6   d Z ddlZddlZddlZddlZddlmZmZ ddlm	Z	m
Z
mZ dej                  fdedeeef   fdZ ed ej                   d	d
            Z G d de      Z G d de      Z G d d      Z G d d      Z e       ZdZdedefdZd Zd Zy)a8  JSONPath implementation for Python.

This module provides a lightweight JSONPath implementation with support for:
- Standard JSONPath operators ($, @, ., .., *, [])
- Filter expressions with comparison, membership, and regex operators
- Sorter expressions for ordering results
- Field extractor expressions
- Value updates via JSONPath

Example:
    >>> from jsonpath import JSONPath, search
    >>> data = {"store": {"book": [{"price": 10}, {"price": 20}]}}
    >>> JSONPath("$..price").parse(data)
    [10, 20]
    >>> search("$.store.book[0].price", data)
    [10]
    N)OrderedDictdefaultdict)AnyCallableUnionnamelevelc                 2   t        j                  |       }|j                  r|S t        j                  d|  dd      }t        j                         }|j                  |       |j                  |       |j                  |       |j                  |       |S )z,Get or create a logger used for local debug.z%(asctime)s-%(levelname)s-[z] %(message)sz[%Y-%m-%d %H:%M:%S])datefmt)logging	getLoggerhandlers	FormatterStreamHandlersetLevelsetFormatter
addHandler)r   r	   logger	formatterhandlers        /home/cube/projects/richard/traning coach/.omo/evidence/nutricoach-v150-combined/st_01a0560c-r63-installed-wheel-first-claim-qa/venv/lib/python3.12/site-packages/jsonpath/jsonpath.pycreate_loggerr      s    t$F !!$?v]"S]rsI##%GU#
OOE
gM    jsonpath
PYLOGLEVELINFOc                       e Zd ZdZy)ExprSyntaxErrorzRaised when a JSONPath expression has invalid syntax.

    Examples of invalid syntax:
    - Using sorter on non-collection types
    - Using field-extractor on non-dict types
    N__name__
__module____qualname____doc__ r   r   r   r   2       r   r   c                       e Zd ZdZy)JSONPathTypeErrorzRaised when type-related errors occur during JSONPath operations.

    Examples:
    - Comparing incompatible types during sorting (e.g., str vs int)
    - Sorting with missing keys that result in None comparisons
    Nr   r$   r   r   r'   r'   ;   r%   r   r'   c                      e Zd ZdZdddZ e       ZdZdZ e	j                  d      Z e	j                  d      Z e	j                  d	      Z e	j                  d
      Z e	j                  d      Z e	j                  d      Z e	j                  d      Z e	j                  d      Z e	j                  d      Z e	j                  d      Z e	j                  d      Z e	j                  d      Z e	j                  d      Z e	j                  d      Z e	j                  d      Z e	j                  d      Z e	j                  d      Z e	j                  d      ZdZ eh ej@                  ejB                  ejD                  ejF                  ejH                  ejJ                  ejL                  ejN                  ejP                  ejR                  ejT                  ejV                  ejX                  ejZ                  ej\                  ej^                  ej`                  ejb                  ejd                  ejf                  ejh                  ejj                  ejl                  ejn                  ejp                  ejr                  ejt                  ejv                  ejx                  ejz                  ej|                  ej~                  ej                  ej                  ej                  ej                  ej                  dD  ch c]#  }t        t>        |      st        t>        |      % c}}}}} z        ZG eh d      ZH eddh      ZIdeJfdZKdHd!ZLdId"ZMd# ZNdJd$eJd%eJd&eJd'eJfd(ZOdJd$eJd)eJd&eJd'eJfd*ZPd+ ZQd, ZRd- ZSd. ZTd/ ZUd0 ZVd1 ZWd2 ZXeYd3        ZZeYd4eJd'eJfd5       Z[eYd6e\fd7       Z]eYd8e^d4eJfd9       Z_eYd:d;d<e`d4eJfd=       ZaeYd>        ZbeYdKd?       ZceYdKd@       ZdeYdA        ZeeYdBeJfdC       ZfdKd8e^d4eJdBeJfdDZgd8e^fdEZhd<eieje\f   dFeie`eke`ge`f   f   d'e`fdGZly c c}}}}} w )LJSONPatha  JSONPath expression parser and evaluator.

    A JSONPath expression is used to navigate and extract data from JSON objects.
    This implementation supports extended syntax including filters, sorters, and
    field extractors.

    Attributes:
        RESULT_TYPE: Supported result types ('VALUE' or 'PATH').

    Example:
        >>> jp = JSONPath("$.store.book[?(@.price < 10)].title")
        >>> jp.parse({"store": {"book": [{"title": "A", "price": 5}]}})
        ['A']
    zA list of specific values.zAll path of specific values.)VALUEPATH;z;..;z\.\.z(?<!\.)\.(?!\.)z['](.*?)[']z#Q(\d+)z[`](.*?)[`]z#BQ(\d+)z[\[](.*?)[\]]z#B(\d+)z[\(](.*?)[\)]z#P(\d+)z^(-?\d*)?:(-?\d*)?(:-?\d*)?$z^([\w.']+)(, ?[\w.']+)+$zF@([.\[].*?)(?=<=|>=|==|!=|>|<| in| not| is|\s|\)|$)|len\(@([.\[].*?)\)zB(?:\.|^)(?P<dot>\w+)|\[['\"](?P<quote>.*?)['\"]\]|\[(?P<int>\d+)\]z=~\s*/(.*?)/z\.(\w+|'[^']*'|\"[^\"]*\")z\.(\.#B)z(?<!\w)@(?![.\[\w])__jsonpath_regex_)IndexNumStrBytesNameConstant>   len__objRegexPatternr3   r5   exprc                    t        t              | _        g | _        d| _        g | _        d| _        d| _        | j                  |      }|j                  t        j                        D cg c]  }|s|	 c}| _        t        | j                        | _        t        j                  t        j                         r#t        j#                  d| j                          yyc c}w )zInitialize JSONPath with an expression.

        Args:
            expr: JSONPath expression string (e.g., "$.store.book[*].price")
        r   r*   Nzsegments  : )r   listsubxsegmentslpathresultresult_type_custom_eval_func_parse_exprsplitr)   SEPr3   r   isEnabledForr   DEBUGdebug)selfr6   ss      r   __init__zJSONPath.__init__   s      %	
"!%%$(JJx||$<B$<q$<B'
w}}-LL<78 . Cs   *C2CNc                 6   t        |t        t        f      st        d      |t        j
                  vr3t        dt        t        j
                  j                                      || _	        || _
        g | _        | j                  |dd       | j                  S )a  Parse JSON object using the JSONPath expression.

        Args:
            obj: JSON object (dict or list) to parse
            result_type: Type of result to return
                - 'VALUE': Return matched values (default)
                - 'PATH': Return JSONPath strings of matched locations
            eval_func: Custom eval function for filter expressions.
                If None (default), uses a safe expression evaluator that
                prevents code injection. Pass a custom function only if
                you trust the JSONPath expressions being evaluated.

        Returns:
            List of matched values or paths depending on result_type

        Raises:
            TypeError: If obj is not a dict or list
            ValueError: If result_type is invalid
        zobj must be a list or a dict.zresult_type must be one of r   $)
isinstancer8   dict	TypeErrorr)   RESULT_TYPE
ValueErrortuplekeysr=   r>   r<   _trace)rE   objr=   	eval_funcs       r   parsezJSONPath.parse   s    ( #d|,;<<h222:5AUAUAZAZA\;]:^_``&!* CC {{r   c                 &    | j                  ||      S )zDAlias for parse(). Search JSON object using the JSONPath expression.)rT   )rE   rR   r=   s      r   searchzJSONPath.search   s    zz#{++r   c                    t         j                  t        j                        rt         j	                  d|        t
        j                  j                  | j                  |      }t
        j                  j                  | j                  |      }t
        j                  j                  | j                  |      }t
        j                  j                  | j                  |      }t
        j                  j                  d|      }t
        j                   j                  t
        j"                  |      }t
        j$                  j                  t
        j&                  |      }t
        j(                  j                  | j*                  |      }t
        j,                  j                  | j.                  |      }t
        j0                  j                  | j2                  |      }t
        j4                  j                  | j6                  |      }|dk(  rd}n|j9                  d      r|dd }t         j                  t        j                        rt         j	                  d|        |S )	zParse and normalize JSONPath expression into segments.

        Handles special patterns (quotes, brackets, parentheses) by temporarily
        replacing them with placeholders, then splits by dots and restores.
        zbefore expr : z\1rI    z$;   Nzafter expr  : )r   rB   r   rC   rD   r)   REP_GET_QUOTEsub
_get_quoteREP_GET_BACKQUOTE_get_backquoteREP_GET_PAREN
_get_parenREP_GET_BRACKET_get_bracketREP_DOTDOT_BRACKETREP_DOUBLEDOTSEP_DOUBLEDOTREP_DOTrA   REP_PUT_BRACKET_put_bracketREP_PUT_PAREN
_put_parenREP_PUT_BACKQUOTE_put_backquoteREP_PUT_QUOTE
_put_quote
startswith)rE   r6   s     r   r?   zJSONPath._parse_expr   s    w}}-LL>$01%%))$//4@))--d.A.A4H%%))$//4@''++D,=,=tD**..ud;%%))(*@*@$G##HLL$7''++D,=,=tD%%))$//4@))--d.A.A4H%%))$//4@3;D__T"8Dw}}-LL>$01r   pattern_typecontentwrapperreturnc                     t        | j                  |         }| j                  |   j                  |       |r|j                  | |       S | | S )a2  Save pattern content and return placeholder.

        Args:
            pattern_type: Pattern identifier (e.g., '#Q', '#BQ', '#B', '#P')
            content: Content to save
            wrapper: Optional wrapper format string (e.g., "'{}'", "`{}`")

        Returns:
            Placeholder string
        )r3   r9   appendformat)rE   rp   rq   rr   ns        r   _save_patternzJSONPath._save_pattern  sX     		,'(		,&&w/>>\N1#"677s##r   indexc                 b    | j                   |   t        |         }|r|j                  |      S |S )aA  Restore pattern content from placeholder.

        Args:
            pattern_type: Pattern identifier (e.g., '#Q', '#BQ', '#B', '#P')
            index: Index as string
            wrapper: Optional wrapper format string (e.g., "'{}'", "`{}`")

        Returns:
            Original content with optional wrapper
        )r9   intrv   )rE   rp   ry   rr   rq   s        r   _restore_patternzJSONPath._restore_pattern  s2     ))L)#e*5>>'**r   c                 D    | j                  d|j                  d            S )N#Q   rx   grouprE   ms     r   r\   zJSONPath._get_quote)  s    !!$
33r   c                 F    | j                  d|j                  d      d      S )Nr~   r   z'{}'r|   r   r   s     r   rn   zJSONPath._put_quote,  s    $$T1771:v>>r   c                 F    | j                  d|j                  d      d      S )N#BQr   z`{}`r   r   s     r   r^   zJSONPath._get_backquote/  s    !!%V<<r   c                 D    | j                  d|j                  d            S )Nr   r   r   r   s     r   rl   zJSONPath._put_backquote2  s    $$UAGGAJ77r   c                 J    d| j                  d|j                  d            z   S )N.#Br   r   r   s     r   rb   zJSONPath._get_bracket5  s"    T''aggaj999r   c                 D    | j                  d|j                  d            S )Nr   r   r   r   s     r   rh   zJSONPath._put_bracket8      $$T1771:66r   c                 P    d| j                  d|j                  d            z   dz   S )N(#Pr   )r   r   s     r   r`   zJSONPath._get_paren;  s'    T''aggaj99C??r   c                 D    | j                  d|j                  d            S )Nr   r   r   r   s     r   rj   zJSONPath._put_paren>  r   r   c                     | j                  d      d u}| j                  d      xs | j                  d      }d }t        j                  j                  ||      }d|z   }|rd| d}|S )NrY   r   c                 J    | j                  d      }|d   dv rd| dS d| dS )Nr   r   )'"[]['']r   )r   gs     r   replzJSONPath._gen_obj.<locals>.replF  s6    
Atz!1#Qxs":r   r4   zlen(r   )r   r)   REP_ATTR_PATHr[   )r   is_lenrq   r   r<   s        r   _gen_objzJSONPath._gen_objA  sm    4'''!**
	 ((,,T7;7"F81%Fr   pathc                     t        |t              r|  d| dS |j                         s"|r'|j                  dd      j	                         r|  d| S |  d| dS )zBuild JSON path string for a given key.

        Args:
            path: Current path string
            key: Key (string) or index (int)

        Returns:
            Formatted path string
        r   r   _ar   r   r   )rJ   r{   isidentifierreplaceisalnum)r   keys     r   _build_pathzJSONPath._build_pathR  sh     c3V1SE####++c3*?*G*G*IV1SE?"r#b!!r   r   c                 R    | d   r| d   S | d   r| d   S | d   rt        | d         S y)zExtract key from regex match group dictionary.

        Args:
            group: Match group dictionary with 'dot', 'quote', or 'int' keys

        Returns:
            Key as string or int
        dotquoter{   N)r{   r   s    r   _extract_key_from_groupz JSONPath._extract_key_from_groupd  s?     <<>>!<uU|$$r   ic           	         t        |t              r3t        |      D ]$  \  }} | ||t        j	                  ||      g|  & yt        |t
              r8|j                         D ]$  \  }} | ||t        j	                  ||      g|  & yy)aC  Traverse object children and apply function to each.

        Args:
            f: Function to apply to each child element
            obj: Object to traverse (list or dict)
            i: Current segment index
            path: Current JSONPath string
            *args: Additional arguments to pass to function f
        N)rJ   r8   	enumerater)   r   rK   items)frR   r   r   argsidxvks           r   	_traversezJSONPath._traversev  s     c4 #C.Q!Q,,T37?$? )T"		1!Q,,T15== $ #r   Fconvert_number_strrR   c                   d|vr*t        | t              r
|| v r| |   }net        j                  S | }|j	                  d      D ]?  }t        |t              r||v r||   }t        j                  c S t        j                  c S  |r7t        |t
              r'	 |j                         rt        |      S t        |      S |S # t        $ r Y |S w xY w)aZ  Get attribute value from object by dot-notation path.

        Args:
            obj: Source object (dict)
            path: Dot-separated path string (e.g., "author.name")
            convert_number_str: If True, convert numeric strings to int/float

        Returns:
            The value at the path, or _MISSING sentinel if not found
        r   )
rJ   rK   r)   _MISSINGr@   strisdigitr{   floatrN   )rR   r   r   rr   s        r   _getattrzJSONPath._getattr  s     d?#t$I((( AZZ_a&AvaD'000#,,, % *Q"499;q6MQx   s   B? 2
B? ?	CCc                 (   d 	 |j                  d      ddd   D ]S  }|j                         }|j                  d      r| j                  |ffd	d       =| j                  |ffd		
       U y# t        $ r}t        d|       |d}~ww xY w)z2Sort objects by multiple fields using stable sort.c                 d    t         j                  | d   |d      }|t         j                  ur|S d S )Nr   Tr   )r)   r   r   )tr   r   s      r   key_funcz"JSONPath._sorter.<locals>.key_func  s5    !!!A$d!CA!2!221<<r   ,N~c                      | |dd        S )Nr   r$   r   r   r   s     r   <lambda>z"JSONPath._sorter.<locals>.<lambda>  s    AabE0Br   T)r   reversec                      | |      S Nr$   r   s     r   r   z"JSONPath._sorter.<locals>.<lambda>  s    Xa^r   )r   z2not possible to compare str and int when sorting: )r@   stripro   sortrL   r'   )rR   sortbyssortbyer   s       @r   _sorterzJSONPath._sorter  s    	=	e!--,TrT2$$S)HH(.B $  
 HHV!CHD 3  	e#&XYZX[$\]cdd	es   A-A4 4	B=BBc                    	 t        j                  | d      }t	        |xs d      }t        j
                  |      D ch c]  }t        |t         j                        rut        |j                  t         j                        rQt        |j                  t         j                        r-|j                  j                  |v rt        |j                         }}t        j
                  |      D ]_  }t        |      }|t        j                  vrt        d|j                          |t         j                  u rg|j                  |v r%t        |      |vrLt        d|j                         |j                  t        j"                  vrt        d|j                         |t         j$                  u r3|j&                  j)                  d	      rt        d
|j&                         |t         j*                  u st        |j,                  t         j                        r(|j,                  j                  t        j.                  v rWt        d       y# t        $ r}t        d|       |d}~ww xY wc c}w )a  Validate that a filter expression only contains safe AST constructs.

        Raises ValueError if the expression contains potentially dangerous
        constructs like function calls (except len/RegexPattern), attribute
        access to dunder names, or disallowed node types.
        eval)modez"Invalid filter expression syntax: Nr$   z!Disallowed expression construct: z2Regex binding is only allowed as a regex operand: z&Disallowed name in filter expression: r   zDisallowed attribute access: zEOnly len() and RegexPattern() calls are allowed in filter expressions)astrT   SyntaxErrorrN   	frozensetwalkrJ   BinOpopMatMultrightNameidtyper)   _ALLOWED_AST_NODESr    _ALLOWED_NAMES	Attributeattrro   Callfunc_ALLOWED_CALLS)r6   extra_namestreer   noderegex_operand_nodes	node_types          r   _validate_filter_exprzJSONPath._validate_filter_expr  s   	N99T/D   1r2 
&$		*477CKK04::sxx0

, tzzN& 	 
 HHTNDT
I ; ;; #DYEWEWDX!YZZCHH$77k)$x'::(+]^b^e^e]f)ghhWWH$;$;;$'MdggY%WXXCMM)dii.B.B3.G #@!LMMCHH$"499chh7DIILLHLcLc<c$%lmm #  	NA!EFAM	N
s   I BI0	I-I((I-c           
          |xs i }t         j                  | |       |t        t        d}|j	                  |j                         D ci c]  \  }}|t        |       c}}       t        | di i|      S c c}}w )uK  Safely evaluate a filter expression against an object.

        Validates the expression AST before evaluation and uses a restricted
        namespace with no access to Python builtins (defense-in-depth for
        the RCE fix — AST validation is the primary gate, restricted
        __builtins__ is the secondary gate).
        r4   r5   r3   __builtins__)r)   r   r5   r3   updater   r   )r6   rR   regex_patternseval_localsr   patterns         r   _safe_eval_filterzJSONPath._safe_eval_filter  sz     (-2&&t^< #\#N^MaMaMcdMcMD'D,w"77McdeD>2.<< es   	A6
c                     | j                  d      }d }t        |      dkD  r ||d         nd}t        |      dkD  r ||d         nd}t        |      dkD  r ||d         nd}t        |||      S )zParse a slice expression string into a slice object.

        Args:
            s: Slice string like '1:3', '::2', '-1:', etc.

        Returns:
            A slice object
        :c                 @    | j                         } | rt        |       S d S r   )r   r{   )r   s    r   to_intz%JSONPath._parse_slice.<locals>.to_int  s    	A3q6(D(r   r   Nr   rY   )r@   r3   slice)rF   partsr   startstopsteps         r   _parse_slicezJSONPath._parse_slice  su     	) %(JNuQx #&u:>veAht#&u:>veAhtUD$''r   r   c                 V    i fd}t         j                  j                  ||       fS )Nc                 p    t         j                   t               }| j                  d      |<   d| S )Nr   z@ )r)   REGEX_BINDING_PREFIXr3   r   )matchr   r   s     r   r   z1JSONPath._replace_regex_patterns.<locals>.replace  s<    334S5H4IJD#(;;q>N4 v;r   )r)   REP_REGEX_PATTERNr[   )r   r   r   s     @r   _replace_regex_patternsz JSONPath._replace_regex_patterns  s-    	
 ))--gt<nLLr   c           
      f   d}	 |xs i }| j                   ^|t        t        d}|j                  |j	                         D 	ci c]  \  }}	|t        |	       c}	}       | j                  |d|      }n| j                  |||      }|r| j                  |||       yyc c}	}w # t        $ r Y (w xY w)ap  Evaluate filter expression and continue trace if condition is true.

        Args:
            obj: Current object to evaluate against filter
            i: Next segment index to trace
            path: Current JSONPath string
            step: Python expression string to evaluate
            regex_patterns: Regex binding names mapped to raw pattern strings
        FNr   )r>   r5   r3   r   r   r   	ExceptionrQ   )
rE   rR   r   r   r   r   r   r   r   r   s
             r   _filterzJSONPath._filter  s     		+1rN%%1(+\RUV""UcUiUiUk#lUkMD'D,w*?$?Uk#lm**4{C**4nE KKQ%  $m  		s#   >B$ B
/B$ B$ $	B0/B0c           	      
   || j                   k\  r| j                  dk(  r| j                  j                  |       n*| j                  dk(  r| j                  j                  |       t        j                  t        j                        rt        j                  d| d|        y| j                  |   }|dk(  r"| j                  | j                  ||dz   |       y|dk(  r5| j                  ||dz   |       | j                  | j                  |||       yt        |t              rI|j                         r9t        |      }|t!        |      k  r| j                  ||   |dz   | d	| d
       yt!        |      dk\  r|d   dk(  r|d   dk(  r|dd n|}t        |t"              r.||v r*| j                  ||   |dz   | j%                  ||             yt        |t              rnt&        j(                  j+                  |      rOt        t-        |            }|| j/                  |         }|D ]!  \  }	}
| j                  |
|dz   | d	|	 d
       # yt        |t"              rtt&        j0                  j+                  |      rU|j3                  d      D ]@  }|j5                         }||v s| j                  ||   |dz   | j%                  ||             B y|r|d   dv r|j7                  d      r|j9                  d      r|dd }t&        j:                  j=                  | j>                  |      }t&        j@                  j=                  d|      }d}d|v rt&        jC                  |      \  }}t        |t"              r| jE                  ||dz   |||       | j                  | jD                  ||dz   |||       y|j9                  d      rt        |t              rZt        t-        |            }| jG                  ||dd        |D ]+  \  }	}
| j                  |
|dz   | j%                  ||	             - yt        |t"              r_t        |jI                               }| jG                  ||dd        |D ]+  \  }}
| j                  |
|dz   | j%                  ||             - ytK        d      |r|d   dk(  r|j7                  d      rt        |t"              rli }|dd j3                  d      D ]<  }|j5                         }| jM                  ||      }
|
t&        jN                  us8|
||<   > | j                  ||dz   |       ytK        d      yyy)a  Recursively traverse object following JSONPath segments.

        This is the core evaluation method that processes each segment of the
        parsed JSONPath expression and navigates through the object accordingly.

        Args:
            obj: Current object being traversed
            i: Index of current segment in self.segments
            path: JSONPath string representing current location
        r*   r+   zpath: z
 | value: N*r   z..r   r   rY   r   r   r   r   z?/r   z?(r4   z=~z/(z"sorter must acting on list or dictr   z#field-extractor must acting on dict)(r;   r=   r<   ru   r   rB   r   rC   rD   r:   r   rQ   rJ   r8   r   r{   r3   rK   r   r)   REP_SLICE_CONTENT	fullmatchr   r   REP_SELECT_CONTENTr@   r   endswithro   REP_FILTER_CONTENTr[   r   REP_BARE_ATr  r	  r   r   r   r   r   )rE   rR   r   r   r   ikeystep_keyindexedvalsr   r   r   r   obj_s                 r   rQ   zJSONPath._trace4  s    

?7*""3'!!V+""4(""7==1vdV:cU;<}}Q 3;NN4;;QUD9 4<KKQUD)NN4;;Q5 c4 T\\^t9Dc#hCIq1uavQ.?@ #&d)q.T!W^RTW4":^bc4 X_KKHq1ud.>.>tX.NO c4 X%?%?%I%I$%O9S>*G4,,T23DQAq1uauA&67  c4 X%@%@%J%J4%PZZ_GGI8KKAAt/?/?a/HI %  DGtOc(:t$Abz2266t}}dK  ++//>!%4<+3+K+KD+Q(D.c4(LLa!eT4Ht||S!a%t^Tt$c4(y~.CLLd1Rj1"%QAq1ud.>.>tS.IJ #&   T*syy{+CLLd1Rj1 #1Aq1ud.>.>tQ.GH !$  **NOO DGsNt}}S'9#t$a))#.A	Ac1-A 1 11"#Q	 /
 D!a%.  &&KLL (:N4r   value_or_funcc                    | j                  |d      }t        |      }t        |      dk(  r|d   dk(  r|r ||      S |S |D ]  }t        t        j
                  j                  |            }|s.|}|dd D ]&  }| j                  |j                               }	||	   }( | j                  |d   j                               }	|r |||	         n|||	<    |S )aI  Update values in JSON object using JSONPath expression.

        Args:
            obj: JSON object (dict or list) to update
            value_or_func: Static value or callable that transforms the current value

        Returns:
            Updated object (modified in-place for nested paths, returns new value for root)
        r+   )r=   r   r   rI   Nr   )	rT   callabler3   r8   r)   REP_PATH_SEGMENTfinditerr   	groupdict)
rE   rR   r  pathsis_funcr   matchestargetr  r   s
             r   r   zJSONPath.update  s     

3F
3=) u:?uQx3)0=%CmCD844==dCDGF "225??3DE &
 ..wr{/D/D/FGC8?-s4]F3K  
r   )r*   N)r*   )rX   r   )mr    r!   r"   r#   rM   objectr   rA   re   recompilerd   rf   rZ   rm   r]   rk   ra   rg   r_   ri   r  r  r  r  r  r   rc   r  r  r   r   
ExpressionBoolOpAndOrr   AddSubMultDivFloorDivModr   UnaryOpNotUAddUSubCompareEqNotEqLtLtEGtGtEIsIsNotInNotInConstantr   	SubscriptSliceListTupleDictr   r   Loadhasattrgetattrr   r   r   r   rG   rT   rV   r?   rx   r|   r\   rn   r^   rl   rb   rh   r`   rj   staticmethodr   r   rK   r   r{   r   r   r   r   r   r   r   r  r	  rQ   r   r8   r   r   ).0rw   rD  r   rE  s   00000r   r)   r)   D   s     ..K
 xH CMBJJw'Mbjj+,G BJJ~.MBJJz*M"

>2"

;/ bjj!12O bjj,OBJJ/0MBJJz*M #

#BC#$?@#$mn!rzz"gh"

?3BJJ<=M#K0"**34K. #0	
NN0	
 JJ0	
 GG	0	

 FF0	
 II0	
 GG0	
 GG0	
 HH0	
 GG0	
 LL0	
 GG0	
 KK0	
  KK!0	
" GG#0	
$ HH%0	
& HH'0	
* KK+0	
, FF-0	
. II/0	
0 FF10	
2 GG30	
4 FF50	
6 GG70	
8 FF90	
: II;0	
< FF=0	
> II?0	
B LLC0	
D HHE0	
H MMI0	
J IIK0	
N HHO0	
P IIQ0	
R HHS0	
V MMW0	
Z HH[0	
^ HH_0	
d %U
h$TqX_`cefXg73?$T
he2	i4j ?@N~67N9S 9( D,>$# $ $c $SV $"S  s TW  4?=8:7@7    "# "s " "" t  " >S > > >" <A $c $ $ $L e e( $n $nL = =  ( (( Mc M M&c & &C &0rS rh %d
+  E#xQTPUWZPZG[B[<\  ad  } is   $Q:Qr)   c                       e Zd ZdZd Zd Zy)r5   a<  Regex pattern wrapper for use with the =~ operator in filter expressions.

    This class enables regex matching syntax like: @.name =~ /pattern/
    The @ operator is overloaded to perform the regex search.

    Example:
        >>> pattern = RegexPattern(r"^test")
        >>> "testing" @ pattern
        True
    c                 F    || _         t        j                  |      | _        y)z'Initialize with a regex pattern string.N)r   r"  r#  	_compiled)rE   r   s     r   rG   zRegexPattern.__init__  s    G,r   c                 l    t        |t              r$t        | j                  j	                  |            S y)z@Right matmul operator (@) - checks if other matches the pattern.F)rJ   r   boolrJ  rV   )rE   others     r   __rmatmul__zRegexPattern.__rmatmul__  s)    eS!--e455r   N)r    r!   r"   r#   rG   rN  r$   r   r   r5   r5     s    	-
r   r5      r6   rs   c                     | t         v rt         j                  |        t         |    S t        t               t        k\  rt         j	                  d       t        |       t         | <   t         |    S )zGet or create a cached JSONPath instance.

    Args:
        expr: JSONPath expression string

    Returns:
        Cached or newly created JSONPath instance
    F)last)_jsonpath_cachemove_to_endr3   _CACHE_MAX_SIZEpopitemr)   r6   s    r   _get_cached_jsonpathrW    s`     ##D) 4   ?2###/ (4  r   c                     t        |       S )a  Compile a JSONPath expression for reuse.

    Returns a cached JSONPath instance when available, avoiding redundant parsing.

    Args:
        expr: JSONPath expression string

    Returns:
        JSONPath object that can be used to parse multiple JSON objects

    Example:
        >>> jp = compile("$.store.book[*].price")
        >>> jp.parse(data1)
        >>> jp.parse(data2)
    )rW  rV  s    r   r#  r#    s       %%r   c                 6    t        |       j                  |      S )zSearch JSON data using JSONPath expression with caching.

    Args:
        expr: JSONPath expression string
        data: JSON data (dict or list)

    Returns:
        List of matched values
    )rW  rT   )r6   datas     r   rV   rV     s      %++D11r   )r#   r   r   osr"  collectionsr   r   typingr   r   r   r   r   r{   r   getenvr   r  r   r'   r)   r5   rR  rT  rW  r#  rV   r$   r   r   <module>r_     s   $   	 	 0 ' ' #W\\  5c? ( 
z9299\6#B	Ci 	 D
 D
N 2 -!s !x !(&&
2r   