
    :QgX0                         d dl Z d dlmZmZ d dlmZ d dlZd dlmZmZm	Z	m
Z
mZmZ  ej                  e      Z e
d      Z G d de      Z G d d	      Zed
k(  rd dlZ ej*                          yy)    N)MutableMappingIterable)
SetOrdered)stringsnumbersadd_to_frozen_setget_docdict_RE_COMPILED_TYPEzsearch_doc.rstc                       e Zd ZdZdZ e        e        e       dddddfdZd Zd Z e	       dfd	Z
d
 Z e	       dfdZd e	       fdZd Zd Zd Zd e	       fdZy)
DeepSearcha  
    **DeepSearch**

    Deep Search inside objects to find the item matching your criteria.

    **Parameters**

    obj : The object to search within

    item : The item to search for

    verbose_level : int >= 0, default = 1.
        Verbose level one shows the paths of found items.
        Verbose level 2 shows the path and value of the found items.

    exclude_paths: list, default = None.
        List of paths to exclude from the report.

    exclude_types: list, default = None.
        List of object types to exclude from the report.

    case_sensitive: Boolean, default = False

    match_string: Boolean, default = False
        If True, the value of the object or its children have to exactly match the item.
        If False, the value of the item can be a part of the value of the object or its children

    use_regexp: Boolean, default = False

    strict_checking: Boolean, default = True
        If True, it will check the type of the object to match, so when searching for '1234',
        it will NOT match the int 1234. Currently this only affects the numeric values searching.

    **Returns**

        A DeepSearch object that has the matched paths and matched values.

    **Supported data types**

    int, string, unicode, dictionary, list, tuple, set, frozenset, OrderedDict, NamedTuple and custom objects!

    **Examples**

    Importing
        >>> from deepdiff import DeepSearch
        >>> from pprint import pprint

    Search in list for string
        >>> obj = ["long somewhere", "string", 0, "somewhere great!"]
        >>> item = "somewhere"
        >>> ds = DeepSearch(obj, item, verbose_level=2)
        >>> print(ds)
        {'matched_values': {'root[3]': 'somewhere great!', 'root[0]': 'long somewhere'}}

    Search in nested data for string
        >>> obj = ["something somewhere", {"long": "somewhere", "string": 2, 0: 0, "somewhere": "around"}]
        >>> item = "somewhere"
        >>> ds = DeepSearch(obj, item, verbose_level=2)
        >>> pprint(ds, indent=2)
        { 'matched_paths': {"root[1]['somewhere']": 'around'},
          'matched_values': { 'root[0]': 'something somewhere',
                              "root[1]['long']": 'somewhere'}}

    r      FTc           	         |r+t        ddj                  |j                               z        || _        t	        |t
              r|nd| _        | j                  r|n|j                         }t        |      | _	        |D cg c]  }t        j                  |       c}| _        t        |      | _        t        |      | _        || _        | j#                  | j%                         | j%                         g        |	| _        |
st	        |t(              rt+        |      }| j&                  r	 t        j                  |      }|
| _        || _        | j3                  ||t5        t7        |      h             | j9                         D cg c]
  \  }}|r	| }}}|D ]  }| |=  y c c}w # t,        $ r}t-        d| d|       d d }~ww xY wc c}}w )NzThe following parameter(s) are not valid: %s
The valid parameters are obj, item, exclude_paths, exclude_types,
case_sensitive, match_string and verbose_level.z, T)matched_pathsmatched_valuesunprocessedzThe passed item of z is not usable for regex: )parents_ids)
ValueErrorjoinkeysobj
isinstancer   case_sensitivelowerr   exclude_pathsrecompileexclude_regex_pathsexclude_typestupleexclude_types_tupleverbose_levelupdate_DeepSearch__set_or_dict
use_regexpr   str	TypeErrorstrict_checkingmatch_string_DeepSearch__search	frozensetiditems)selfr   itemr   r   r   r"   r   r)   r%   r(   kwargsexclude_regex_pathekv
empty_keyss                    L/var/www/html/answerous/venv/lib/python3.12/site-packages/deepdiff/search.py__init__zDeepSearch.__init__U   s    B 		&++-(	) * * 0:40Int**t

'6]p#qGYBJJ/A$B#q '6#($ *,,.--/ 	 	 %:dG#<t9D??ezz$'  / )c4Y3y-AB$(JJL:DAqa:
: 	AQ	5 $r  e"5dV;UVWUX YZ`dde ;s*    F&,F+ 	
GG+	G4GGc                 H    | j                   dk\  r
t               S t               S N   )r"   r
   r   )r.   s    r6   __set_or_dictzDeepSearch.__set_or_dict   s    ,,1uwCz|C    c                 \    | j                   dk\  r	|| |   |<   y | |   j                  |       y r9   )r"   add)r.   
report_keykeyvalues       r6   __reportzDeepSearch.__report   s2    "$)DS!  %r<   c           	         d}||k(  rd}| j                  d||       	 |r|j                         }nEt        |      D ci c]1  }|j                  d      r|j	                  d      s|t        ||      3 }}| j                  ||||d	       yc c}w # t        $ rX 	 |j                  D ci c]  }|t        ||       nc c}w }}n)# t        $ r |s| d   j                  d|z         Y Y yw xY wY |w xY w)
zSearch objectsFTr   r?   r@   rA   __r   z%sN)print_as_attribute)
_DeepSearch__report_asdictdir
startswithendswithgetattrAttributeError	__slots__append_DeepSearch__search_dict)r.   r   r/   parentr   is_namedtuplefoundis           r6   __search_objzDeepSearch.__search_obj   s    $;E MM%56MM	kkm 47s8 Ia ||D1ajj6F '#q/) I I 	v{t 	 	EI 	36==Aaq'#q/)AAA! '..tf}=	 B	sR    B 6B5B B 	C4C+C ?CC4"C.*C4-C..C43C4c                     d}|| j                   v rd}|S | j                  r6t        | j                  D cg c]  }|j                  |       c}      rd}|S t	        || j
                        rd}|S c c}w )NFT)r   r   anysearchr   r!   )r.   r/   rQ   skipr1   s        r6   __skip_thiszDeepSearch.__skip_this   s    T'''D  %%#MQMeMef7I#**62f+hD
  $ 8 89 gs   A1c                    |rd}nd}t        |j                               }|D ]  }|st        |t              rd|z  }	n|}	||   }
t	        |
      }|r||v r4t        ||      }|||	fz  }| j                  r|n|j                         }t        |      }| j                  r||k(  s-| j                  s||v s| j                  r%|j                  |      r| j                  d||
       | j                  |
|||        y)zSearch dictionariesz%s.%sz%s[%s]z'%s'r   rD   )rQ   r   N)r   r   r   r   r,   r   r   r   r&   r)   r%   rX   rG   r*   )r.   r   r/   rQ   r   rF   parent_textobj_keysitem_keyitem_key_str	obj_childitem_idparents_ids_added
new_parentnew_parent_casedstr_items                   r6   __search_dictzDeepSearch.__search_dict   s    !K"Kchhj)  	/H%*Xw*G%0'HImGw+5 1+w G$'==J-1-@-@zjFVFVFX4yH!!h2B&B%%(6F*FDKK0@$A."#  %
 MM!-	  /7	/r<   rootc           	         t        |      D ]  \  }}dj                  ||      }| j                  ||      r,| j                  st	        |t
              s|}n|j                         }| j                  s||k(  r| j                  d||       t        |      }	|r|	|v rt        ||	      }
| j                  |||d|d|
        y)z7Search iterables except dictionaries, sets and strings.z{}[{}])rQ   r   rD   []N)	enumerateformat_DeepSearch__skip_thisr   r   r   r   r%   rG   r,   r   r*   )r.   r   r/   rQ   r   rT   thingrc   thing_casedra   rb   s              r6   __search_iterablezDeepSearch.__search_iterable   s     "# 	>HAu!3Jj9""*UG*D##kkm??{d':/Zu  N U)7k#9$5k7$K!eT%q,*+<>%	>r<   c                     | j                   r|n|j                         }d}| j                  r|j                  |      }n#| j                  r||k(  s| j                  s||v rd}|r| j                  d||       yy)zCompare stringsFTr   rD   N)r   r   r%   rX   r)   rG   )r.   r   r/   rQ   obj_text
is_matcheds         r6   __search_strzDeepSearch.__search_str  sr    --3399;
??X.JDH$4d>O>OTX\dTdJMM%56MM r<   c                     ||k(  s@| j                   sK|t        |      k(  s&| j                  r0|j                  t        |            r| j	                  d||       y y y y )Nr   rD   )r(   r&   r%   rX   rG   )r.   r   r/   rQ   s       r6   __search_numberszDeepSearch.__search_numbers  sV    CK((CH$DKKC,A
 MM%56MM -B )r<   c                     	 |j                    | j                  ||||d       y # t        $ r | j                  ||||       Y y w xY w)NT)rR   )rH   _DeepSearch__search_objrM   _DeepSearch__search_iterabler.   r   r/   rQ   r   s        r6   __search_tuplezDeepSearch.__search_tuple#  sW    	DKK T6;d  D	  	C""3fkB	Cs   % AAc                    | j                  ||      ryt        |t              r*t        |t        t        f      r| j	                  |||       yt        |t              rt        |t
              ryt        |t
              r| j                  |||       yt        |t              r| j                  ||||       yt        |t              r| j                  ||||       yt        |t        t        f      rN| j                  dk  r*t        j                  d       | xj                  dz  c_        | j!                  ||||       yt        |t"              r%t        |t              s| j!                  ||||       y| j%                  ||||       y)zThe main search methodN
   zmSet item detected in the path.'set' objects do NOT support indexing. But DeepSearch will still report a path.r   )rm   r   r   r   _DeepSearch__search_strr   _DeepSearch__search_numbersr   rP   r    _DeepSearch__search_tuplesetr+   warning_numloggerwarningry   r   rx   rz   s        r6   __searchzDeepSearch.__search0  sA   D&)W%*TGEU;V*Wc40W%*T7*CW%!!#tV4^,sD&+>U#T6;?c9-."$f   A% ""3fkBX&z#w/G""3fkB c4=r<   N)__name__
__module____qualname____doc__r   r   r7   r$   rG   r+   rx   rm   rP   ry   r~   r   r   r*    r<   r6   r   r      s    ?B K
  *|%/\)|  %#!!%2hD& "+#( ED" #,+).-/d "(&/k	>6
N
ND *0Y[ !>r<   r   c                       e Zd ZeZd Zd Zy)grepc                      || _         || _        y )N)r/   r0   )r.   r/   r0   s      r6   r7   zgrep.__init__W  s     	r<   c                 F    t        d|| j                  d| j                  S )N)r   r/   r   )r   r/   r0   )r.   others     r6   __ror__zgrep.__ror__]  s    Ce$))Ct{{CCr<   N)r   r   r   docr   r7   r   r   r<   r6   r   r   T  s    GDr<   r   __main__)r   collections.abcr   r   deepdiff.helperr   loggingr   r   r   r	   r
   r   	getLoggerr   r   r   dictr   r   doctesttestmodr   r<   r6   <module>r      su    	 4 &   
		8	$ @> @>F

D 
D zGOO r<   