
    :Qgy(                         d dl Z d dlmZ d dlmZ  e j
                  e      ZdZdZ	 G d de
      Z G d d	e
      Zd
 ZdefZ ed      efd       ZddZd ZddZd ZedfdZddZedfdZy)    N)literal_eval)	lru_cacheGETATTRGETc                       e Zd Zy)PathExtractionErrorN__name__
__module____qualname__     J/var/www/html/answerous/venv/lib/python3.12/site-packages/deepdiff/path.pyr   r          r   r   c                       e Zd Zy)RootCanNotBeModifiedNr	   r   r   r   r   r      r   r   r   c                    |sy |j                  d      sYd}d|v sd|v rd}n	 t        |      }d}|r|d   |d   k(  r|d   dv r|d	d }|d
k(  rt        nt
        }| j                  ||f       y y # t        t        f$ r d}Y Rw xY w)N__F   𝆺𝅥𝅯\Tr      "'   .)
startswithr   
ValueErrorSyntaxErrorr   r   append)elementseleminsideremove_quotesactions        r   _add_to_elementsr&      s    ??4 T>TT\ M%#D) % T!WR0T!W
5J2;D"cMsv' ! , % $%s   A/ /BBrooti   )maxsizec                    t        | t        t        f      r| S g }|r|j                  |       d}d}d}| dd } g }d}d}| D ]  }	|dk(  r||	z  }n|	dv r&||	z  }|r||	k7  s| }|r|	}nt	        |||       d}d}n|r||	z  }n|	dk(  r8|dk(  rt	        |||       d}d}n|dk(  r||	z  }n~d}|j                  d       d}nh|	dk(  r%|dk(  r||	z  }nX|dk(  rt	        |||       d}nCd}d}n>|	d	k(  r4|r|d
   dk(  r|j                          |r||	z  }nt	        |||       d}d}n||	z  }|	} |rt	        |||       t        |      S )a>  
    Given a path, it extracts the elements that form the path and their relevant most likely retrieval action.

        >>> from deepdiff import _path_to_elements
        >>> path = "root[4.3].b['a3']"
        >>> _path_to_elements(path, root_element=None)
        [(4.3, 'GET'), ('b', 'GETATTR'), ('a3', 'GET')]
     FN   r   r   [r   ]r   )
isinstancetuplelistr    r&   pop)
pathroot_elementr!   r"   r#   	prev_charbracketsinside_quotes
quote_usedchars
             r   _path_to_elementsr9   *   s    $&H%DFI8DHMJ 0DLDZDLD Z4%7$1 1 !%J$XtV<D!#JDLDS[} 483$S[}3 48S[HRLC/ 48DLD	a0b 40?r   c                 d    |D ]*  \  }}|t         k(  r| |   } |t        k(  st        | |      } , | S N)r   r   getattr)objr!   next_elementr"   r%   s        r   _get_nested_objr?   v   s@    " %vS=d)Cw#t$C	%
 Jr   c                 P    |t        |       dz
  k  ri S t        |t              rg S i S )Nr   )lenr.   int)r!   r"   indexr>   s       r   _guess_typerD      s,    s8}q  	,$	Ir   c           	         d }d }| }t        |      D ]7  \  }\  }}| }	|t        k(  r		 | |   } |	}n|t        k(  rt        | |      } |	}|}|}9 | S # t        $ r t        ||||      | |<   | |   } |	}Y +t        $ r t        | t              rdt        |t              rT|t        |       k\  rF| j                  d g|t        |       z
  z         | j                  t        |||      |       | d   } |	}nQt        | t              rAt        |       dk(  r3|r1|t        ||||      i} |t        k(  r| ||<   nt        |||        | |   } Y w xY w)Nr   r   )	enumerater   KeyErrorrD   
IndexErrorr.   r0   rB   rA   extendr    setattrr   r<   )
r=   r!   r>   	prev_elemprev_actionprev_objrC   r"   r%   	_prev_objs
             r   _get_nested_obj_and_forcerO      sh   IKH!*8!4 ~f	S=$$i$( w#t$C H	;< J1  %'$|LD	$i$ $c4(Zc-BtsSVxGWJJvC9:JJ{8T5A<Pb'C(HT*s3x1}  XtUL!QRC"c).1+)S9d)C$s   A!E1CE Ec                 4    t        |d      }t        | |      S )as  
    Get the item from obj based on path.

    Example:

        >>> from deepdiff import extract
        >>> obj = {1: [{'2': 'b'}, 3], 2: [4, 5]}
        >>> path = "root[1][0]['2']"
        >>> extract(obj, path)
        'b'

    Note that you can use extract in conjunction with DeepDiff results
    or even with the search and :ref:`deepsearch_label` modules. For example:

        >>> from deepdiff import grep
        >>> obj = {1: [{'2': 'b'}, 3], 2: [4, 5]}
        >>> result = obj | grep(5)
        >>> result
        {'matched_values': ['root[2][1]']}
        >>> result['matched_values'][0]
        'root[2][1]'
        >>> path = result['matched_values'][0]
        >>> extract(obj, path)
        5


    .. note::
        Note that even if DeepDiff tried gives you a path to an item in a set,
        there is no such thing in Python and hence you will get an error trying
        to extract that item from a set.
        If you want to be able to get items from sets, use the SetOrdered module
        to generate the sets.
        In fact Deepdiff uses SetOrdered as a dependency.

        >>> from deepdiff import grep, extract
        >>> obj = {"a", "b"}
        >>> obj | grep("b")
        Set item detected in the path.'set' objects do NOT support indexing. But DeepSearch will still report a path.
        {'matched_values': SetOrdered(['root[0]'])}
        >>> extract(obj, 'root[0]')
        Traceback (most recent call last):
          File "<stdin>", line 1, in <module>
          File "deepdiff/deepdiff/path.py", line 126, in extract
            return _get_nested_obj(obj, elements)
          File "deepdiff/deepdiff/path.py", line 84, in _get_nested_obj
            obj = obj[elem]
        TypeError: 'set' object is not subscriptable
        >>> from orderly_set import SetOrdered
        >>> obj = SetOrdered(["a", "b"])
        >>> extract(obj, 'root[0]')
        'a'

    Nr3   )r9   r?   )r=   r2   r!   s      r   extractrR      s    l !D9H3))r   Fc                     t        | |      }t        |      }|rt        |       |du r|D cg c]  }|d   	 c}S |D cg c]  }|d   |d   d c}S c c}w c c}w )a  
    Parse a path to a format that is machine readable

    **Parameters**

    path : A string
    The path string such as "root[1][2]['age']"

    root_element: string, default='root'
        What the root is called in the path.

    include_actions: boolean, default=False
        If True, we return the action required to retrieve the item at each element of the path.  

    **Examples**

        >>> from deepdiff import parse_path
        >>> parse_path("root[1][2]['age']")
        [1, 2, 'age']
        >>> parse_path("root[1][2]['age']", include_actions=True)
        [{'element': 1, 'action': 'GET'}, {'element': 2, 'action': 'GET'}, {'element': 'age', 'action': 'GET'}]
        >>>
        >>> parse_path("root['joe'].age")
        ['joe', 'age']
        >>> parse_path("root['joe'].age", include_actions=True)
        [{'element': 'joe', 'action': 'GET'}, {'element': 'age', 'action': 'GETATTR'}]

    rQ   Fr   r   )elementr%   )r9   iternext)r2   r3   include_actionsresultis        r   
parse_pathrZ      sf    < t,?F&\FV%$%!%%7=>!!!->> &>s   AAc                    d| v }d| v }|rL|rJ|sHg }| D ](  }|dv r|j                  d       |j                  |       * ddj                  |      z   dz   }|S |rd|  d}|S |rd|  d}|S || n|j                  |       }|S )Nr   r   r   r   r*   )r    joinformat)param	quote_str	has_quotehas_double_quote	new_paramr8   rX   s          r   stringify_elementrc     s    uIe|%i	 	#Dz!  (T"	# rwwy))C/ M 
UG1
 M	 
UG1 M $+1A1A%1HMr   z'{}'c                    | s|d   S |d   g}d}	 | d   d   t         t        hv rd}|s%| D cg c]
  }|t         f } }| d   d   |d   f| d<   | D ]]  \  }}t        |t              r|t         k(  rt        ||      }|t         k(  r|j                  d| d       J|j                  d|        _ dj                  |      S # t        t        t        f$ r Y w xY wc c}w )	zh
    Gets the path as an string.

    For example [1, 2, 'age'] should become
    root[1][2]['age']
    r   Fr   Tr,   r-   r   r*   )
r   r   rG   rH   	TypeErrorr.   strrc   r    r\   )r2   r3   r_   rX   has_actionsrY   rT   r%   s           r   stringify_pathrh   "  s    A1oFK71:#w'K "&'QC''71:|A/Q )gs##';GS=MMAgYa.)MMAgY-() 776? j),  (s   C CCCr;   )loggingastr   	functoolsr   	getLoggerr
   loggerr   r   r   r   r   r&   DEFAULT_FIRST_ELEMENTr9   r?   rD   rO   rR   rZ   rc   rh   r   r   r   <module>ro      s      			8	$
	* 		: 	((  )  :)> H HV"J7*t #8 $?N& '<v r   