
    :Qg	Q                       d dl Z d dlZd dlZd dlmZ d dlmZ d dlmZ	 d dl
mZmZmZmZmZmZmZmZmZmZ d dl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 m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z'm(Z(m)Z)m*Z*m+Z+m,Z,m-Z-m.Z.m/Z/m0Z0m1Z1m2Z2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZCmDZDmEZE d dlFmGZG d dlHmIZImJZJ d dlKmLZLmMZMmNZNmOZOmPZPmQZQmRZRmSZSmTZTmUZUmVZVmWZWmXZXmYZY d dlZm[Z[m\Z\ d dl]m^Z^ d dl_m`Z`maZa  ej                  ec      ZddZedZf e'd ge&      Zg e0d      ZhdZid ZjdZkdZldZmdZndZodZpdZqdZrdZsd Ztd!Zud"Zvd#Zwd$Zxd%Zyd&Zzd'Z{ G d( d)eMeGeIe^      Z|ecd*k(  rd dl}Z} e}j                          yy)+    N)Enum)deepcopy)isclose)
ListDictIOCallableSetUnionAnyPatternTupleOptional)MappingIterableSequence)defaultdict)
getmembers)zip_longest)&strings
bytes_typenumbersuuids	datetimesListItemRemovedOrAdded
notpresentIndexedHashunprocessedadd_to_frozen_setbasic_types(convert_item_or_items_into_set_else_noneget_type5convert_item_or_items_into_compiled_regexes_else_nonetype_is_subclass_of_type_grouptype_in_type_groupget_docnumber_to_stringdatetime_normalizeKEY_TO_VAL_STRbooleans
np_ndarraynp_floatingget_numpy_ndarray_rowsRepeatedTimer	TEXT_VIEW	TREE_VIEW
DELTA_VIEWdetailed__dict__add_root_to_pathsnpget_truncate_datetimedict_CannotCompareENUM_INCLUDE_KEYSPydanticBaseModelOpcode
SetOrdered)SerializationMixin)DistanceMixinlogarithmic_similarity)	RemapDict
ResultDict
TextResult
TreeResult	DiffLevelDictRelationshipAttributeRelationshipREPORT_KEYS!SubscriptableIterableRelationship$NonSubscriptableIterableRelationshipSetRelationshipNumpyArrayRelationshipCUSTOM_FIELDFORCE_DEFAULT)DeepHashcombine_hashes_lists)Base)LFUCacheDummyLFUzDeepDiff has reached the max number of passes of {}. You can possibly get more accurate results by increasing the max_passes parameter.zDeepDiff has reached the max number of diffs of {}. You can possibly get more accurate results by increasing the max_diffs parameter.indexesitemzdiff_doc.rstz3DeepDiff {} seconds in progress. Pass #{}, Diff #{}c                 Z     |t         j                  || t           | t                        y)z0
    Report the progress every few seconds.
    N)PROGRESS_MSGformatPASSES_COUNT
DIFF_COUNT)_statsprogress_loggerdurations      J/var/www/html/answerous/venv/lib/python3.12/site-packages/deepdiff/diff.py_report_progressr^   =   s%     L''&2FzHZ[\    zDISTANCE CACHE HIT COUNTz
DIFF COUNTzPASSES COUNTzMAX PASS LIMIT REACHEDzMAX DIFF LIMIT REACHEDzDISTANCE CACHE ENABLEDzPREVIOUS DIFF COUNTz!PREVIOUS DISTANCE CACHE HIT COUNTzWUnable to import numpy. This must be a bug in DeepDiff since a numpy array is detected.zRThe only valid values for the view parameter are text and tree. But {} was passed.z=cutoff_distance_for_pairs needs to be a positive float max 1.z#verbose_level should be 0, 1, or 2.z'cache_purge_level should be 0, 1, or 2._ENABLE_CACHE_EVERY_X_DIFFg333333?gffffff?)exclude_typesexclude_pathsinclude_pathsexclude_regex_pathshashersignificant_digitsnumber_format_notationignore_string_type_changesignore_numeric_type_changesuse_enum_valueignore_type_in_groupsignore_type_subclassesignore_string_caseexclude_obj_callbackignore_private_variables	encodingsignore_encoding_errorsc            e       f    e Zd ZeZdZdddddeedddddddddddddddddddddddddddddddej                  dddd	d
ddde
dddf3dedededededeee      dededeee      dee   dee   deeee   f   deeee   ee   eee      df   deee      dedeeeeef   df   deeedf   dee   dee   deded ed!ed"ee   d#ed$ed%ed&eee      d'ed(ee   d)ee   d*eeee   f   d+ee   d,ed-ee   d.ee   d/ed0ed1ee   d2ed3ed4ee   d5ed6ed7ed8ee   d9ed:ed;ed<efd fd=Zd> Zdid?Zdid@ZedA        Z e       dfdBZ e       ddfdCZdD Z dE Z! eg       dddddfdFZ"didGZ#edH        Z$ e       ddfdIZ%	 	 djdJZ&	 	 djdKZ' e       ddfdLZ(dM Z) e       ddddddfdNZ* e       ddfdOZ+didPZ,didQZ-dR Z.dS Z/edT        Z0	 didUZ1dV Z2dkdWZ3didXZ4dldYZ5didZZ6did[Z7 e       dfd\Z8did]Z9d^ Z:d_ Z;d` Z<da Z= e       ddfdbZ>dc Z?edd        Z@de ZAdf ZBeCdg        ZDeCdh        ZE xZFS )mDeepDiffg      ?N   r   FTi fg?gQ?t1t2cache_purge_level
cache_sizecache_tuning_sample_sizecustom_operatorscutoff_distance_for_pairscutoff_intersection_for_pairsrp   rn   exclude_obj_callback_strictrb   rd   ra   get_deep_distancegroup_bygroup_by_sort_keyre   hashesrq   ignore_nan_inequalityri   ignore_orderignore_order_funcro   rm   rh   rk   rl   include_obj_callbackinclude_obj_callback_strictrc   iterable_compare_funclog_frequency_in_secmath_epsilon	max_diffs
max_passesrg   number_to_string_funcr[   report_repetitionrf   use_log_scalelog_scale_similarity_thresholdthreshold_to_diff_deepertruncate_datetimerj   verbose_levelviewzip_ordered_iterablesc6                    t         >|           |6r+t        ddj                  |6j	                               z        |4r| j
                  j                  |4       n|xs g | _        || _        || _	        |xs g }t        |k(  st        |v rd}|| _        t        |k(  st        |v rd}|0| _        |-| _        |,| _        |.| _        || _        | j%                  ||||      | _        |*| _        t+        t-        |            | _        t+        t-        |!            | _        t3        |      | _        |rt7        |      nd | _        |rt;        |      nd | _        || _        |rt@        ntB        | _"        || _#        || _$        || _%        || _&        | | _'        |(xs tP        | _(        |"| _)        |3| _*        || _+        || _,        || _-        || _.        || _/        ta              r| _1        nrfd}7|7| _1        nd | _1        |
| _2        || _3        | ji                  |+|      | _5        |$| _6        | jl                  !| j                  rtn        jq                  d       ts        |/      | _:        |'| _;        |1dv r|1| _<        nt        tz              |dvrt        t|              |2| _?        |&| _@        |%| _A        t        |      | _C        t        |	      | _D        | j                  dk  s| j                  d	kD  rt        t              |)| _F        || _G        | j
                  j                         }4d |4d
<   |5r,d| _I        |5| _J        | j
                  j                  |5       d }8nd| _I        |rt        |      n	t               | _M        t        dt        dt        dt        dt        dt        dt        dt        t        |      i| _W        |
t               n|| _Y        t               | _Z        d| j                  d| j                  d| j                  d| j                  t        | j\                  dz  i| _J        |#rt        |#t        | j                  |)      }8nd }8|4| _^        | j                         | _`        t               | _b        i | _c        |r8| j                  r,	 |}9| j                  ||d      }	 | j                  ||d      }|| _f        || _g        	 t        ||| jx                        }:| j                  |:t        t        |      h      |       |r+|2t        t        hv r| j                         | j                  d<   | j                  j                          | j                  | j~                        };| j                  |;       | j                  r|r| `M| `Y| `J| `^t        t        t        fD ]  }<| j                  |<=  |8rQ|8j                         }=|=| j                  d<   tn        j                  dj                  | j                                      |dk(  r| j
                  j                          y y y # t        t        f$ r |9}Y w xY w# t        t        f$ r Y w xY w# | j                  r|r| `M| `Y| `J| `^t        t        t        fD ]  }<| j                  |<=  |8rQ|8j                         }=|=| j                  d<   tn        j                  dj                  | j                                      |dk(  r| j
                  j                          w w w xY w)Na  The following parameter(s) are not valid: %s
The valid parameters are ignore_order, report_repetition, significant_digits, number_format_notation, exclude_paths, include_paths, exclude_types, exclude_regex_paths, ignore_type_in_groups, ignore_string_type_changes, ignore_numeric_type_changes, ignore_type_subclasses, truncate_datetime, ignore_private_variables, ignore_nan_inequality, number_to_string_func, verbose_level, view, hasher, hashes, max_passes, max_diffs, zip_ordered_iterables, cutoff_distance_for_pairs, cutoff_intersection_for_pairs, log_frequency_in_sec, cache_size, cache_tuning_sample_size, get_deep_distance, group_by, group_by_sort_key, cache_purge_level, math_epsilon, iterable_compare_func, use_enum_value, _original_type, threshold_to_diff_deeper, ignore_order_func, custom_operators, encodings, ignore_encoding_errors, use_log_scale, log_scale_similarity_threshold _parameters and _shared_parameters.z, T)rk   rh   ri   rl   c                     |    S N )xr   s    r]   _group_by_sort_keyz-DeepDiff.__init__.<locals>._group_by_sort_key   s    .//r_   zmath_epsilon in conjunction with ignore_order=True is only used for flat object comparisons. Custom math_epsilon will not have an effect when comparing nested objects.>   r   rt      r   rt   r   Fr   rZ   _distance_cache_numpy_paths
   rv   )	item_namerw   )r   )parents_ids_original_typedeep_distancezDURATION SECzstats {}r   )vsuper__init__
ValueErrorjoinkeys__dict__updater{   r   r   r   ri   r   rj   r   r   r   rh   get_ignore_types_in_groupsrk   r   r3   r!   rb   rc   r#   rd   setra   tupleexclude_types_tuplerl   r%   r$   type_check_funcrm   rn   r~   r   r   r'   r   r   ro   r   re   rz   r   callabler   rp   rq   get_significant_digitsrf   r   loggerwarningr5   r   rg   r   VERBOSE_LEVEL_RANGE_MSGPURGE_LEVEL_RANGE_MSGr   r   r   floatr|   r}   CUTOFF_RANGE_ERROR_MSGr[   ry   copyis_root_shared_parametersrP   rQ   r   rX   rY   DISTANCE_CACHE_HIT_COUNTPREVIOUS_DIFF_COUNT!PREVIOUS_DISTANCE_CACHE_HIT_COUNTMAX_PASS_LIMIT_REACHEDMAX_DIFF_LIMIT_REACHEDDISTANCE_CACHE_ENABLEDboolrZ   r6   r   r   r`   r.   r^   _parameters_get_deephash_paramsdeephash_parametersrB   tree_iterable_opcodes_group_iterable_to_dictKeyErrorrv   rw   rC   _diff	frozensetidr/   r0   _get_rough_distanceremove_empty_keys_get_view_resultsstopinforW   	get_statsclear)?selfrv   rw   r   rx   ry   rz   r{   r|   r}   rp   rn   r~   rb   rd   ra   r   r   r   re   r   rq   r   ri   r   r   ro   rm   rh   rk   rl   r   r   rc   r   r   r   r   r   rg   r   r[   r   rf   r   r   r   r   rj   r   r   r   r   r   kwargsr   progress_timeroriginal_t1rootview_resultskeyr\   	__class__s?                     `                                           r]   r   zDeepDiff.__init__t   s   n 	
6 :>6;;=9QR S S MM  -$4$:D! ,D%6D"$9$?R!//7>S3S.2+/JD,//7>S3S-1*"0D2PD/!.D,DD).HD+)-)H)H&;+E,G'=	 *I *?D&
 &7D"!23[\i3j!kD!23[\i3j!kD'\]p'qD$7D]!3$D?Lu]';RVD$*@D'9O#5UsD &8D#(<D%/JD,(<D%/JD,$9$M=MD!)>D&)>D&,DD))>D& DK,DD)$DM)*):&"0);&)-&&DN*@D'&*&A&ABTVq&rD# ,D  ,1B1B   I  J%:;L%MD"*@D'	)%2" !899 	1 !677DI(DO&DN-23L-MD*167T1UD.--1T5S5SVW5W !788
 $3D (DO--,,.K&*K
#  DL&8D#MM  !34!N  DL;E8J#78:D aA(!#Q11&&&Z(8	DK &,^%'DK %D$++$++!4#7#7 1 1*D,I,IB,N'D# $!./CEUW[WbWbds!t!%&#'#<#<#> L	!#	% 11"h$1O%55b(d5SB 	*R43E3EFD JJtBrF8)<^J\ Ti-C%C-1-E-E-G		/*II'')11$))<LKK%||$,+$/1R24 )CC() "-224H2:DKK/KK
 1 1$..2B CD$)MM'') * ) !*- %$B% j) 2 ||$,+$/1R24 )CC() "-224H2:DKK/KK
 1 1$..2B CD$)MM'') * s2   	X;  X# B2Y #X87X8;YYB/\ c                     t         D ci c]  }|| j                  |    }}| j                   |d<   | j                  |d<   |S c c}w )Nignore_repetitionr   )DEEPHASH_PARAM_KEYSr   r   r'   )r   r   results      r]   r   zDeepDiff._get_deephash_paramse  sU    8KL#t'',,LL*.*@*@&@"#*.*?*?&' Ms   Ac                 ~    | j                  |      s,||_        || j                  n|}||   j                  |       yy)a  
        Add a detected change to the reference-style result dictionary.
        report_type will be added to level.
        (We'll create the text-style report from there later.)
        :param report_type: A well defined string key describing the type of change.
                            Examples: "set_item_added", "values_changed"
        :param change_level: A DiffLevel object describing the objects in question in their
                       before-change and after-change object structure.

        :local_tree: None
        N)
_skip_thisreport_typer   add)r   r   change_level
local_treer   s        r]   _report_resultzDeepDiff._report_resultk  s@     |,'2L$ * 2499
D!!,/ -r_   c                     | j                  |      s9||_        ||j                  t        <   | j                  |   j                  |       yy)aI  
        Add a detected change to the reference-style result dictionary.
        report_type will be added to level.
        (We'll create the text-style report from there later.)
        :param report_type: A well defined string key describing the type of change.
                            Examples: "set_item_added", "values_changed"
        :param parent: A DiffLevel object describing the objects in question in their
                       before-change and after-change object structure.
        :param extra_info: A dict that describe this result
        :rtype: None
        N)r   r   
additionalrK   r   r   )r   r   level
extra_infos       r]   custom_report_resultzDeepDiff.custom_report_result}  sD     u% +E-7E\*IIk"&&u- &r_   c           
      X     fd}g }t         t              r j                  }n j                  j                  }|D ]E  }t	        |dd       }|st        |t
              r|j                  |       5|j                  |       G |D ci c]  }|t	          ||             c}S c c}w )Nc                     | j                  d      r+| dk7  r&dj                  t              j                  |       S | S )N____weakref__z_{type}{attribute})type	attribute)
startswithrW   r   __name__)r   objects    r]   unmanglez+DeepDiff._dict_from_slots.<locals>.unmangle  sH    ##D)i=.H+22f..' 3   r_   	__slots__)
isinstancer   __mro__r   getattrr   appendextend)r   r   	all_slotsmrotype_in_mroslotsis   `      r]   _dict_from_slotszDeepDiff._dict_from_slots  s    	 	fd#..C""**C 	,KKd;EeW-$$U+$$U+	, :CCA768A;//CCCs   
B'c           	          t        |j                  t              }t        |j                  t              }| j	                  ||dd|||       y )N)include_keysTprint_as_attributeoverrideoverride_t1override_t2r   )r2   rv   r8   rw   
_diff_dict)r   r   r   r   rv   rw   s         r]   
_diff_enumzDeepDiff._diff_enum  sJ    ehh5FGehh5FG#! 	 	
r_   c           	      "   d}	 |r6|j                   j                         }|j                  j                         }nt        d |D              rCt	        |j                   | j
                        }t	        |j                  | j
                        }nt        d |D              r7| j                  |j                         }| j                  |j                        }nht        |j                         D 	ci c]  \  }}	t        |	      r||	 }}}	t        |j                        D 	ci c]  \  }}	t        |	      r||	 }}}	|du r| j                  d||       y| j                  ||dd|	       yc c}	}w c c}	}w # t        $ r d}Y Kw xY w)
zDifference of 2 objectsFc              3   6   K   | ]  }d t        |      v   yw)r   Ndir.0ts     r]   	<genexpr>z%DeepDiff._diff_obj.<locals>.<genexpr>  s     9aZ3q6)9   )ro   c              3   6   K   | ]  }d t        |      v   yw)r   Nr  r  s     r]   r  z%DeepDiff._diff_obj.<locals>.<genexpr>  s     :q[CF*:r  Tr   r   Nr  )rv   _asdictrw   allr2   ro   r   r   r   AttributeErrorr   r  )
r   r   r   is_namedtupler   processing_errorrv   rw   kvs
             r]   	_diff_objzDeepDiff._diff_obj  s^    	$XX%%'XX%%'9599%ehhIfIfg%ehhIfIfg:E::**5884**5884'1%((';Otq!8A;adOO'1%((';Otq!8A;adOO t#uL#! 	 	
 PO 	$#	$s<   C.F  2E4E4F  &E::E:?F  4F   FFc                 j   |j                         }d}| j                  r|| j                  v rd}| j                  r5|dk7  r0|| j                  vr d}| j                  D ]  }||v s||v sd} |S  |S | j                  r6t	        | j                  D cg c]  }|j                  |       c}      rd}|S | j                  rDt        |j                  | j                        s t        |j                  | j                        rd}|S | j                  r<| j                  |j                  |      s| j                  |j                  |      rd}|S | j                  r<| j                  |j                  |      r | j                  |j                  |      rd}|S | j                  rC|dk7  r>d}| j                  |j                  |      s| j                  |j                  |      rd}|S | j                  rA|dk7  r<d}| j                  |j                  |      r| j                  |j                  |      rd}|S c c}w )z
        Check whether this comparison should be skipped because one of the objects to compare meets exclusion criteria.
        :rtype: bool
        FTr   )pathrb   rc   rd   anysearchr   r   rv   rw   rn   r~   r   r   )r   r   
level_pathskipprefixexclude_regex_paths         r]   r   zDeepDiff._skip_this  s)   
 ZZ\
*0B0B"BD*"6!3!33"00 F+zV/C$0 76 / %%#QUQiQij;M#**:6j+lD* ) %%EHHd&>&>?:ehhX\XpXpCqD$ # &&**588Z@DD]D]^c^f^fhrDsD  --11%((JG11%((JGD  &&:+?D))%((J?4C\C\]b]e]egqCr  --*2FD00:F44UXXzJ- ks   H0c           	         t               }|D ]-  }| j                  r"t        |t              r|j	                  d      }n| j
                  rt        |t              r|j                  }nut        |t              rc| j                  rdn|j                  j                  }| j                  || j                  | j                        }t        j                   ||      }n|}| j"                  r|j%                         }||v r9t&        j)                  dj!                  |||   |j+                                      )|||<   0 |S )a%  
        Get a dictionary of cleaned value of keys to the keys themselves.
        This is mainly used to transform the keys when the type changes of keys should be ignored.

        TODO: needs also some key conversion for groups of types other than the built-in strings and numbers.
        utf-8numberrf   rg   zv{} and {} in {} become the same key when ignore_numeric_type_changesor ignore_numeric_type_changes are set to be true.)r6   rh   r   bytesdecoderj   r   valuer   ri   r   r   r'   rf   rg   r)   rW   rm   lowerr   r   r  )r   r   r   r   r   	clean_keytype_s          r]   _get_clean_to_keys_mappingz#DeepDiff._get_clean_to_keys_mapping  s     	(C..:c53IJJw/	$$C)>II	C)$($D$D#--J`J` 11#$JaJaIMIdId 2 f	*11%C		&&%OO-	F" !UV\V\$'	):EJJLWJK %(y!'	(( r_   c           	      &   |r|}|}	n|j                   }|j                  }	|rd}
d}t        }n
d}
d}t        }| j                  rwt        |D cg c]&  }t        |t              r|j                  d      r%|( c}      }t        |	D cg c]&  }t        |t              r|j                  d      r%|( c}      }n2t        |j                               }t        |	j                               }| j                  s| j                  s| j                  rY| j                  ||      }| j                  ||      }t        |j                               }t        |j                               }ndx}}||z  }||z  }||z
  }||z
  }| j                  rGt        |      dkD  r9t        |      t        |      z  | j                  k  r| j!                  d	||
       y|D ]T  }| j#                         t$        u r y|r||   n|}|j'                  t(        |	|   |||      }| j!                  |
||
       V |D ]T  }| j#                         t$        u r y|r||   n|}|j'                  ||   t(        |||      }| j!                  |||
       V |D ]}  }| j#                         t$        u r y|r||   n|}|r||   n|}t+        ||         }|r||v rBt-        ||      }|j'                  ||   |	|   |||      }| j/                  |||
        yc c}w c c}w )zDifference of 2 dictionariesattribute_addedattribute_removeddictionary_item_addeddictionary_item_removedr   )r   r   Nrt   values_changedr  child_relationship_classchild_relationship_paramchild_relationship_param2)rv   rw   rE   rD   ro   r;   r   strr   r   rh   ri   rm   r/  r   lenr   _count_diffStopIterationbranch_deeperr   r   r   r   )r   r   r   r  r  r  r  r   rv   rw   item_added_keyitem_removed_key	rel_classr   t1_keyst2_keyst1_clean_to_keyst2_clean_to_keyst_keys_intersectt_keys_uniont_keys_addedt_keys_removedr   key1key2item_idparents_ids_added
next_levels                               r]   r  zDeepDiff._diff_dict  sa     BBBB.N2-I4N8(I(( !j#:c3;OTWTbTbcgTh#!jkG !j#:c3;OTWTbTbcgTh#!jkG +G +G**d.N.NRVRiRi#>>GSX>Y#>>GSX>Y !1!6!6!89G !1!6!6!89G266/"W,(!11 #33((< 1$-=)>\AR)RUYUrUr)r##$4e
#S 	UC!]2+;"3'C ..3)2),*- / L T	U " 	WC!]2+;"3'C ..3)2),*- / L  0,:V	W $ 	MC!]2,<#C(#D,<#C(#DDlGw+5 1+w G ,,44)2),*- - J JJz#4JL'	Me "k!js   &L	3L	&L.Lc                    | j                  |d      }| j                  |d      }t        |j                               }t        |j                               }||z
  }||z
  }|D 	cg c]  }	||	   j                   }
}	|D 	cg c]  }	||	   j                   }}	|
D ]J  }| j	                         t
        u r y|j                  t        |t              }| j                  d||       L |D ]J  }| j	                         t
        u r y|j                  |t        t              }| j                  d||       L yc c}	w c c}	w )zDifference of setsrv   rw   N)r7  set_item_addedr  set_item_removed)
_create_hashtabler   r   rT   r<  r=  r>  r   rI   r   )r   r   r   t1_hashtablet2_hashtable	t1_hashes	t2_hasheshashes_addedhashes_removedr   items_addeditems_removedrT   r   s                 r]   	_diff_setzDeepDiff._diff_set  sU   --eT:--eT:))+,	))+,	 9,"Y.5AB|A++BB7EF!a--FF 	WD!]2 ..D? / LL 0,:V	W " 	YD!]2 ..j? / LL 2LZX	Y CFs   %D8D=c                 V    	 t        | d      rt        |d      ryy# t        $ r Y yw xY w)N__getitem__TF)r   r  )rv   rw   s     r]   _iterables_subscriptablez!DeepDiff._iterables_subscriptable  s2    	r=)gb-.H 		s    	((c                     | j                   r| j                  |      s| j                  r| j                  ||||       y| j                  ||||       y)zDifference of iterablesr   r   N)r   r   _diff_iterable_with_deephash_diff_iterable_in_order)r   r   r   r   r   s        r]   _diff_iterablezDeepDiff._diff_iterable  sQ    ""t'='=e'DIZIZ--e[Q_lv-w((Ngq(rr_   c                 v   |Mt        t        |j                  |j                  t                    D cg c]  \  }\  }}||f||ff c}}}S |j                  || }	|j                  || }
t        t        |	|
t                    D cg c]  \  }\  }}||z   ||z   f||ff c}}}S c c}}}w c c}}}w )zz
        Default compare if `iterable_compare_func` is not provided.
        This will compare in sequence order.
        )	fillvalue)	enumerater   rv   rw   r   )r   r   t1_from_indext1_to_indext2_from_indext2_to_indexr   r   yt1_chunkt2_chunks              r]   _compare_in_orderzDeepDiff._compare_in_order  s      6?HHehh2HJ7K L LFQaVaV$ L L xxk:Hxxk:HV_h2HJWK L LFQPQa-']):;aVD L LLLs   B-B4c                 2   | j                   | j                  |||||      S 	 g }t               }t               }t        |j                        D ]  \  }	}
d}t        |j
                        D ]  \  }}||v r| j                  |
||      st        |f| j                  dd| j                  }|j                  |       |j                  ||          |j                  |	|f|
|ff       d} n |r|j                  |	df|
t        ff        t        |j
                        D ]K  \  }}t        |f| j                  dd| j                  }||   |vs1|j                  d|ft        |ff       M |S # t        $ r | j                  |||||      cY S w xY w)a#  
        Given a level get matching pairs. This returns list of two tuples in the form:
        [
          (t1 index, t2 index), (t1 item, t2 item)
        ]

        This will compare using the passed in `iterable_compare_func` if available.
        Default it to compare in order
        rg  rh  ri  rj  FT)r   
apply_hash)r   rn  r   rf  rv   rw   rM   r   r   r   r   r   r7   )r   r   rg  rh  ri  rj  matches	y_matchedy_index_matchedr   r   x_foundjrk  	deep_hashs                  r]   _get_matching_pairszDeepDiff._get_matching_pairs  s    %%-))++ *  
+	GI!eO!%((+ K1%ehh/ DAqO+ !11!Q>$,Q %/48KK8<%/ 04/G/G%/	
 (++A.!il3AA'78"&%( NNQGa1G-H#IJ/K0 "%((+ K1$Q ',0KK04' (,'?'?'	
 Q<y0NNRG.Da-H#IJK N 	))++ *  	s&   A&E4 A&E4 2A"E4 E4 4FFc                     | j                  |j                  |j                        }|rt        }nt        }| j
                  s6t        |j                  t              rt        |j                  t              r | j                  |j                        r| j                  |j                        r| j                  t               }| j                  |||||      }t        |      dkD  r]t               }	| j                  |||||	       t        |      t        |	      k\  r|	}n#|| j                  |j                  t               <   |j#                         D ]  \  }
}|s	| j$                  |
xx   |z  cc<   ! y | j                  |||||       y )N)r   r   r7  r   rt   )force)r^  rv   rw   rG   rH   r   r   r   _all_values_basic_hashabler   rB   !_diff_ordered_iterable_by_difflibr;  /_diff_by_forming_pairs_and_comparing_one_by_oner   r  rL   itemsr   )r   r   r   r   r   subscriptabler7  local_tree_passopcodes_with_valueslocal_tree_pass2r   levelss               r]   rb  z DeepDiff._diff_iterable_in_order
  sw   55ehhI'H$'K$ **588X.588X.//9//9**2(lO"&"H"H'-)A* #I # ?#a'#-< DD +#1-E/ E  '3/?+@@&6ONaD**5::M:+JK'6'<'<'> 5#VIIk*f4*5 @@'-)A% A r_   c                 l    t        |t        j                        ry|D ]  }t        |t              r y y)z\
        Are all items basic hashable types?
        Or there are custom types too?
        FT)r   typesGeneratorTyper    )r   iterablerT   s      r]   r|  z#DeepDiff._all_values_basic_hashable<  s8     h 3 34 	DdK0	 r_   c
                    | j                  |||||	      D ]0  \  \  }
}\  }}| j                         t        u r y |
}|}|t        u r/|j	                  |t
        |||      }| j                  d||       `|t        u r/|j	                  t
        ||||      }| j                  d||       |
|k7  rM||k(  s| j                  r<|j	                  |||||      }| j                  d||       | j                  r|}|
}nt        |      }|r||v rt        ||      }|j	                  |||||      }| j                  |||       3 y )Nrp  r6  iterable_item_removedr  iterable_item_addediterable_item_moved)ry  r<  r=  r   r>  r   r   r   r   r   r   )r   r   r   r   r   r7  rg  rh  ri  rj  r   rw  r   rk  reference_param1reference_param2r   rL  rM  rN  s                       r]   r~  z8DeepDiff._diff_by_forming_pairs_and_comparing_one_by_oneJ  s    #66'['[ 7 
 @	QNFQFQ
 !]2  **$22-E-=.>  3   ##$;\V`#a,,$22-E-=.>  3   ##$9<T^#_ FaD,F,F#(#6#61I1A2B $7 $L ''(=|Xb'c11 ,-(+,( Q%7k#9$5k7$K! #00-E-=.> 1 
 

:'8Z
PA@	Qr_   c                    t        j                  d |j                  |j                  d      }|j	                         }g }|D ]<  \  }	}
}}}|	dk(  r|j                  t        |	|
|||             .|j                  t        |	|
||||j                  |
| |j                  ||              |	dk(  r| j                  ||||||
|||	       |	dk(  rUt        |j                  |
|       D ]9  \  }}|j                  |t        |||
z   ||
z         }| j                  d	||
       ; |	dk(  st        |j                  ||       D ]9  \  }}|j                  t        ||||z   ||z         }| j                  d||
       ; ? |S )NF)isjunkabautojunkequal)
old_values
new_valuesreplace)r   r   r   r7  rg  rh  ri  rj  deleter6  r  r  insertr  )difflibSequenceMatcherrv   rw   get_opcodesr   r:   r~  rf  r>  r   r   )r   r   r   r   r   r7  seqopcodesr  tagrg  rh  ri  rj  indexr   r   rk  s                     r]   r}  z*DeepDiff._diff_ordered_iterable_by_difflib  s    %%TUXXTYZ//# 
 LS )	dGC]Kg~#**6]K,    &&v]K"XXm[A"XXm[A(  iDDjk#1Ld"/["/[	 E   )%((=*M N fHE1#(#6#6"1I161F27-2G $7 $L ''(?Zd'ef  )%((=*M N dHE1#(#6#6"1I161F27-2G $7 $L ''(=|Xb'cdC)	dT #"r_   c                 \   | j                   r>|j                  j                         |_        |j                  j                         |_        t	        |j                        t	        |j                        k(  r|j                  |j                  k(  ryd}|j                  }|j                  }t        |j                  t              r	 |j                  j                  d      }t        |j                  t              r	 |j                  j                  d      }t        |j                  t              r|j                  j                  }t        |j                  t              r|j                  j                  }||k(  ry|rwd|v st        |t              rcd|v r_t        j                  |j                         |j                         d      }t        |      }|rdj!                  |      |j"                  d<   | j%                  d	||
       y# t        $ r d}Y 8w xY w# t        $ r d}Y w xY w)zCompare stringsNTasciiF
 )linetermdiffr5  r  )rm   rv   r,  rw   r   r   r   r*  UnicodeDecodeErrorr   r+  r:  r  unified_diff
splitlineslistr   r   r   )r   r   r   do_difft1_strt2_strr  s          r]   	_diff_strzDeepDiff._diff_str  s   ""xx~~'EHxx~~'EH>T%((^+EHH0D ehh
+ 1 ehh
+ 1 ehh%XX^^Fehh%XX^^FVv~FC!8TV^++%%'):):)<rKDz/3yyE$$V,,e
K5 &    &   s$   H
 ;H 
HHH+*H+c                     	 |j                   j                   | j                  ||d|       y # t        $ r | j	                  |||       Y y w xY w)NT)r  r   r  )rv   r  r  r  rc  )r   r   r   r   s       r]   _diff_tuplezDeepDiff._diff_tuple  sS    	ZHH NN5+TjNY	  	K{zJ	Ks   . AAc                 l    ||v r||   j                   j                  |       y t        |g|      ||<   y )NrR   )rS   r   r   )r   r   	item_hashrT   r   s        r]   	_add_hashzDeepDiff._add_hash  s6    9%%,,Q/ +QCd CF9r_   c                 ^   t        ||      }t               }t        |      D ]  \  }}	 dj                  |j	                         |      }t        |f| j                  |dd| j                  }	 ||   }	|	t        u r't        j                  d|j	                         z         | j                  ||	||        	 t        |f| j                  |j	                         dd| j                   |S # t        $ r Y w xY w# t        $ r+}
d|j	                          d|
j                   |
_         d}
~
wt        $ r4}t        j!                  d|j	                         d	|       Y d}~Ed}~ww xY w# t        $ r4}t        j!                  d
|j	                         d|       Y d}~|S d}~ww xY w)z0Create hashtable of {item_hash: (indexes, item)}z{}[{}]T)r   parentrq  zFItem %s was not processed while hashing thus not counting this object.)r   r  rT   r   zCan not produce a hash for z: Nz.Not counting this object.
 z$Can not produce a hash for iterable z. )r   r6   rf  rW   r  rM   r   r   r   r   r   r  r   r  reason	Exceptionerror)r   r   r  objlocal_hashesr   rT   r  rx  r  erres               r]   rR  zDeepDiff._create_hashtable
  s   eQw"3  	aIQa!q9 %T ',0KK,204' (,'?'?	'	
a )$I !K/ (H',zz|(4 5 liVZ^_`A 	aF
	,{{zz|	
 ** -    & :5::<.3::,W
 0#jjlA/ 0 004  	,LL**,+ , ,	,sN   AC=.C.:2E/ .	C:9C:=	E,&D,,E,8)E''E,/	F,8)F''F,c                 &   | |kD  r| |fn|| f\  }}t        |t              r5t        |      j                  d      }t        |      j                  d      }n2t        |t              r"|j                  d      }|j                  d      }|dz   |z   dz   S )Nr&  s   --s   dc)r   inthexencoder:  )
added_hashremoved_hashrJ  rK  s       r]   _get_distance_cache_keyz DeepDiff._get_distance_cache_key?  s    3=3Lj,/S_akRl
ddC  t9##G,Dt9##G,Dc";;w'D;;w'De|d"U**r_   c           	         d x}}| j                   t           rV| j                  ||      }|| j                  v r6| j                   t        xx   dz  cc<   | j                  j                  |      }|t        |j                  |j                  | j                  | j                  t        || j                        }|j                         }|r0| j                   t           r| j                  j                  ||       |S )Nrt   )r   r   r   r   r   r+  )rZ   r   r  r   r   getrs   rT   r   r   r1   r   r   r   )	r   r  r  added_hash_objremoved_hash_objr   	_distance	cache_keyr  s	            r]   "_get_rough_distance_of_hashed_objsz+DeepDiff._get_rough_distance_of_hashed_objsL  s     !%$	I;;-.44ZNID00045:5 0044Y?	  %%~':': ,,#'#:#:-&*&@&@D 002IT[[)?@$$(()(Dr_   c           	         d}| j                   t           rFt        ||gd      }|| j                  v r)| j                  j	                  |      j                         S d }t        |      }	t               }
d}|r9|r7t        r1t        |      dkD  r#t        |      dkD  r| j                  |||||      }|r?|r=| j                  r1t        |      dkD  r#t        |      dkD  r| j                  |||||      }|D ]  }|D ]  }||   }||   }t        |j                        |v r%d}|r!|j	                  dj                  ||            }|| j!                  |||||      }|| j"                  k\  rq|	|   }||   j%                  |         t'               }t        t(              }|	j+                         D ]   \  }}|D ]  }||   j%                  |        " t-        |j/                               D ]i  }||   }|s|j1                         }||vrH|	|   |   }|r>|j1                         }||vr'|j%                  |       |j%                  |       ||
|<   |r>|r_k |
j+                         D ci c]  \  }}||
 }}}|
j3                  |       |r0| j                   t           r| j                  j'                  ||
       |
j                         S c c}}w )	a  
        Get the closest pairs between items that are removed and items that are added.

        returns a dictionary of hashes that are closest to each other.
        The dictionary is going to be symmetrical so any key will be a value too and otherwise.

        Note that due to the current reporting structure in DeepDiff, we don't compare an item that
        was added to an item that is in both t1 and t2.

        For example

        [{1, 2}, {4, 5, 6}]
        [{1, 2}, {1, 2, 3}]

        is only compared between {4, 5, 6} and {1, 2, 3} even though technically {1, 2, 3} is
        just one item different than {1, 2}

        Perhaps in future we can have a report key that is item duplicated and modified instead of just added.
        Npairs_cache)r  r#  c                       t        t              S r   )r   r;   r   r_   r]   defaultdict_orderedsetzODeepDiff._get_most_in_common_pairs_in_iterables.<locals>.defaultdict_orderedset  s    z**r_   rt   r   z{}--{}r  )rZ   r   rN   r   r  r   r   r6   r4   r;  #_precalculate_numpy_arrays_distancer   -_precalculate_distance_by_custom_compare_funcr   rT   rW   r  r|   r   r   r;   r  sortedr   popr   )r   rW  rX  rS  rT  r   r   r  r  most_in_common_pairspairspre_calced_distancesr  r  r  r  r  pairs_of_itemused_to_hashesdistances_to_from_hashes	from_hashdistances_to_to_hashesdistfrom_hashes	to_hashesto_hashr  r  inverse_pairss                                r]   &_get_most_in_common_pairs_in_iterablesz/DeepDiff._get_most_in_common_pairs_in_iterablesf  s   * 	;;-.,L.3QZghID000++//	:??AA	+*+AB#Nrc,6G!6KPSTbPcfgPg $(#K#KnlL.$Z  N..%)c..AA.E#'#U#UnlL.$Z  ' 	;J . ;!-j!9#/#=  &++,; 	' 4 8 8Ua9b cI$ $ G G"L.BRTb!dI
  > >> 4Z @i(,,\:);	;, #.z#: 1E1K1K1M 	>-I-. >(.229=>	>
 388:; 	7D248K'OO-	N2 4Y ? EI#"+--/".8*..y9*..w7 07E), $	 	7 +0++-8$!QA88]#%;<  $$Ye$<zz|	 9s   +Kc           	          | j                  |d      }| j                  |d      }t        |j                               }t        |j                               }||z
  ||z
  t              t              z   t        |      t        |      z   dz   z  | j                  kD  rd}	nd}	| j
                  r|| nR|j                         D 
ci c]  \  }
}|
v s|
| c}}
|j                         D 
ci c]  \  }
}|
v s|
| c}}
 | j                  t           | j                  k  r4|	r2| j                  t        xx   dz  cc<   | j                   ||      no|	rc| j                  t           sEd| j                  t        <   t        j                  t        j                  | j                               t!               n
t!               d fd	}| j
                  rD ]  }| j#                         t$        u r y ||      }t'        |j(                        }|j(                  t*        u r |   j,                  n|j,                  }t         |   j,                        dk(  r |   j,                  d   }nd}|D ]z  }|j/                  |j(                   |   j(                  t0        ||	      }|j(                  t*        u r| j3                  d
||       [t5        ||      }| j7                  |||       |  D ]  }| j#                         t$        u r y ||d      }t'        |j(                        }|j(                  t*        u st        |j,                  dkD        rd}n|j,                  d   }|   j,                  D ]z  }|j/                  |   j(                  |j(                  t0        ||	      }|j(                  t*        u r| j3                  d||       [t5        ||      }| j7                  |||       |  |j9                  |      }|D ]  }|   j,                  } |   j,                  }t        |      }t        |      }||k7  s=|j/                  |   j(                   |   j(                  t0        |   j,                  d         }t;        ||||      |j<                  d<   | j3                  d||        yD ]  }| j#                         t$        u r y ||      }t'        |j(                        }|j(                  t*        u r |   j,                  d   n|j,                  d   } |   j,                  d   }|j/                  |j(                   |   j(                  t0        ||	      }|j(                  t*        u r| j3                  d
||       t5        ||      }| j7                  |||        D ]  }| j#                         t$        u r y ||d      }t'        |j(                        }|   j,                  d   }|j(                  t*        u r|   j,                  d   n|j,                  d   }|j/                  |   j(                  |j(                  t0        ||	      }|j(                  t*        u r| j3                  d||       t5        ||      }| j7                  |||        yc c}}
w c c}}
w )zLDiff of hashable or unhashable iterables. Only used when ignoring the order.rv   rw   rt   FTc                     |r}}n	}}j                  | t              }|t        u rt        }|S |= |j                  |       ||   }|S )z
            Gets the other paired indexed hash item to the hash_value in the pairs dictionary
            in_t1: are we looking for the other pair in t1 or t2?
            )r  r   notpresent_indexedremove)

hash_valuein_t1	hashtablethe_other_hashesotherrW  rX  r  rS  rT  s
        r]   get_other_pairz=DeepDiff._diff_iterable_with_deephash.<locals>.get_other_pair  sh    
 (	#1 (	#/ IIj*5E
"* L %L ''.!%(Lr_   Nr   r6  r  r  )r  r  )r7  r8  )
old_repeat
new_repeatold_indexesnew_indexes
repetitionrepetition_change)T)rR  r;   r   r;  r}   r   r  rZ   rX   r   r  r   r   r   MAX_PASSES_REACHED_MSGrW   r6   r<  r=  r   rT   r   rS   r>  rG   r   r   r   intersectionr?   r   )!r   r   r   r   r   full_t1_hashtablefull_t2_hashtablerU  rV  	get_pairsr  r  r  r  r  rL  rS   index2r   r   rM  items_intersect
t1_indexes
t2_indexest1_indexes_lent2_indexes_lenrepetition_change_levelr  rW  rX  r  rS  rT  s!                               @@@@@r]   ra  z%DeepDiff._diff_iterable_with_deephash  s    !225$? 225$?05578	05578	 9,"Y. N 33<M8NQTUfQg8gjk8klos  pR  pR  RII !!,L,L->-D-D-F^TQ!~J]AqD^L->-D-D-F\TQ!|J[AqD\L;;|$t69KK%*%??nlL+WegE;;566:235<<T__MNGEGE	 	. !!* [
##%6&z2UZZ.>CjjJ>V,z2::\a\i\i |J/778A=)*5==a@F!F  [A#(#6#6

$Z0551R1228 $7 $L zzZ/++,A<\f+g,=k7,S)

<1Bz
Z[[4 - [
##%6&z?UZZ. ::+s5==13D/E!F"]]1-F%j199 [A#(#6#6$Z055

1R1228 $7 $L zzZ/++,C\^h+i
 ->k7,S)

<1Bz
Z[[: (44Y?O- X
)*5==
)*5==
!$Z!$Z!^3.3.A.A$Z055$Z0551R1=j1I 2$	 /B /%+ HQ#1#1$.$.	H0+66|D
 ''(;(?J ( X%X, + W
##%6&z2UZZ.?DzzZ?WZ088;]b]j]jkl]m%j199!<$22JJ ,11-N-2.4  3   ::+''(=|Xb'c(9+w(O%JJ|->:JV%W( - W
##%6&z?UZZ.$Z088;@E

j@Xj199!<^c^k^klm^n$22 ,11JJ-N-2.4  3   ::+''(?Zd'e ):+w(O%JJ|->:JV)WS _\s   [[7[
[
c                 `    |j                   |j                  k7  r| j                  d||       y y )Nr5  r  )rv   rw   r   r   r   r   s      r]   _diff_booleanszDeepDiff._diff_booleans  s-    88uxx 0%JO  r_   c                    |r]| j                   rdn|j                  j                  j                  }| j                   rdn|j                  j                  j                  }ndx}}| j
                  rBt        |j                  |j                  | j                        s| j                  d||       yy| j                  Bt        |j                  |j                  | j                        s| j                  d||       yy| j                  /|j                  |j                  k7  r| j                  d||       yy| j                  |j                  | j                  | j                        }| j                  |j                  | j                  | j                        }t        j                  ||      }t        j                  ||      }||k7  r| j                  d||       yy)	zDiff Numbersr'  r  )	thresholdr5  r  N)abs_tolr(  )ri   rv   r   r   rw   r   r>   r   r   r   is_closerf   r'   rg   r)   rW   )r   r   r   report_type_changet1_typet2_typet1_st2_ss           r]   _diff_numberszDeepDiff._diff_numbers  s   "&"B"BhHZHZHcHcG"&"B"BhHZHZHcHcG ""Gg)%((EHHHkHkl##$4e
#S m*EHHehh8I8IJ##$4e
#S K$$,xx588###$4e
#S $ ((<@<S<S@D@[@[ ) ]D ((<@<S<S@D@[@[ ) ]D "(($7D!(($7Dt|##$4e
#S r_   c                    | j                   rJt        | j                   |j                        |_        t        | j                   |j                        |_        |j                  |j                  k7  r| j	                  d||       yy)zDiff DateTimesr5  r  N)r   r(   rv   rw   r   r  s      r]   _diff_datetimeszDeepDiff._diff_datetimes  sf    !!)$*@*@%((KEH)$*@*@%((KEH88uxx 0%JO  r_   c                     |j                   j                  |j                  j                  k7  r| j                  d||       yy)z
Diff UUIDsr5  r  N)rv   r  rw   r   r  s      r]   _diff_uuidszDeepDiff._diff_uuids  s5    88<<588<<' 0%JO (r_   c                 Z   |j                         | j                  vr:t        |j                        j                  | j                  |j                         <   t
        t        t              | j                  r| j                  |      r| j                  s| j                  7t        j                  |j                  |j                  | j                        rCy	 t
        j                  j                  |j                  |j                  | j                         y|j                  j$                  }|j                  j&                  |j                  j&                  k7  rT|j                  j)                         |_        |j                  j)                         |_        | j+                  ||||       y|j                  j&                  }t-        |      }|dk(  r| j+                  ||||       y| j                  r| j                  |      s| j                  rT|j                  j)                         |_        |j                  j)                         |_        | j/                  ||||       yt1        t3        |j                  |      t3        |j                  |            D ]:  \  \  }}\  }	}
|j5                  ||
t6        ||	      }| j9                  ||||       < y# t         $ r: t        j                  |j                  |j                  | j                         Y t"        $ r Y w xY w)zDiff numpy arraysN)	equal_nan)decimalr`  rt   r6  )r  r   r"   rw   r   r4   ImportErrorCANT_FIND_NUMPY_MSGr   r   rf   array_equalrv   r   testingassert_almost_equal	TypeErrorAssertionErrordtypeshapetolistrc  r;  ra  zipr-   r>  rJ   rb  )r   r   r   r   r   r  
dimensionst1_patht1_rowt2_patht2_row	new_levels               r]   _diff_numpy_arrayzDeepDiff._diff_numpy_array  s   ::<t000.6uxx.@.I.IDejjl+: 122""4+A+A%+HQUQbQb&&.>>%((EHH@Z@Z[JJ22588UXXtOfOf2g  88>>UXX^^+ xx(EHxx(EH{>^hi HHNNEUJQ##E;~bl#m((T-C-CE-JtO`O` !88??, 88??,11%Ucpz1{<?.uxx?.uxx?=A 8%Wf'8 !& 3 31G1829 !4 !I 00KXfs}0~9 ! ]NN588UXXA[A[\\% s   A K ?L*L*)L*c                 :    d|_         | j                  d||       y)z
Diff typestype_changesr  N)r   r   r  s      r]   _diff_typeszDeepDiff._diff_types  s    *NEjIr_   c                    | j                   ~| j                  t           | j                   kD  r^| j                  t           sEd| j                  t        <   t        j                  t        j                  | j                                t        S | j                  t        xx   dz  cc<   | j                  r| j                  r| j                          y y y )NTrt   )r   rZ   rY   r   r   r   MAX_DIFFS_REACHED_MSGrW   r=  ry   rz   _auto_tune_cacher   s    r]   r<  zDeepDiff._count_diff  s    NN&4;;z+BT^^+S;;566:234;;DNNKL  J1$??t<<!!#  =?r_   c                    | j                   t           | j                  z  dk(  }| j                  r| j                   t           r|rz| j	                          ni| j                   t           | j
                  t           z  dk(  r?| j                  d       | j
                  t        xx   dz  cc<   d| j                   t        <   |r1t        t        fD ]!  }| j                   |dd     | j                   |<   # y y )Nr   z*Re-enabling the distance and level caches.r   T	   )
rZ   rY   rz   r   _auto_off_cacher   r`   r[   r   r   )r   take_sampler   s      r]   r)  zDeepDiff._auto_tune_cache  s    {{:.1N1NNRSS(({{12((*Z(4+B+BC]+^^bcc$$%QR''(BCrIC6:23+-NO 8#';;s12w#7C 8 r_   c                 n   | j                   t           r| j                   t           | j                   dj                  t                 z
  | j                   t           | j                   t
           z
  z  }|| j                  k  r4d| j                   t        <   | j                  dj                  d             yyy)z:
        Auto adjust the cache based on the usage
        zPREVIOUS {}Fz*Due to minimal cache hits, {} is disabled.zdistance cacheN)rZ   r   r   rW   rY   r   CACHE_AUTO_ADJUST_THRESHOLDr[   )r   angles     r]   r-  zDeepDiff._auto_off_cache  s     ;;-.[[!9:T[[I]I]^vIw=xx  ~B  ~I  ~I  JT  ~U  X\  Xc  Xc  dw  Xx  ~x  yEt7776;23$$%Q%X%XYi%jk 8 /r_   c                 x    | j                   D ]+  }|j                  |      s|j                  ||       }|s+ y y)a  
        For each level we check all custom operators.
        If any one of them was a match for the level, we run the diff of the operator.
        If the operator returned True, the operator must have decided these objects should not
        be compared anymore. It might have already reported their results.
        In that case the report will appear in the final results of this diff.
        Otherwise basically the 2 objects in the level are being omitted from the results.
        )r   diff_instanceTF)r{   matchgive_up_diffing)r   r   operatorprevent_defaults       r]   _use_custom_operatorzDeepDiff._use_custom_operator  sF     -- 	 H~~e$"*":":VZ":"["		  r_   c                    | j                         t        u ry| j                  |      ry|j                  |j                  u ry| j                  |      ryd}t        |j                        t        |j                        k7  r| j                  D ]?  }| j                  |j                  |      s | j                  |j                  |      s=d} n | j                  r7t        |j                  t              r|j                  j                  |_        d}| j                  r7t        |j                  t              r|j                  j                  |_        d}|r| j                  ||       y|j                  |j                  | j                  d||       y| j                  rSt        |j                  t         t"        f      r3t%        |j                        t%        |j                        cxk(  rdk(  ry t        |j                  t&              r| j)                  ||       yt        |j                  t*              r| j-                  ||       yt        |j                  t.              r| j1                  ||       yt        |j                  t2              r| j5                  ||       yt        |j                  t6              r| j9                  |||       yt        |j                  t:              r| j=                  |||       yt        |j                  t>              r| jA                  |||       yt        |j                  tB        tD        tF        f      r| jI                  ||       yt        |j                  tJ              r| jM                  |||       yt        |j                  tN              r| jQ                  |||       yt        |j                  tR              r| jU                  ||||       yt        |j                  t              r| jW                  |||       y| jQ                  ||       y)	aE  
        The main diff method

        **parameters**

        level: the tree level or tree node
        parents_ids: the ids of all the parent objects in the tree from the current node.
        _original_type: If the objects had an original type that was different than what currently exists in the level.t1 and t2
        NTFr  r5  nan)r   r  r`  ),r<  r=  r8  rv   rw   r   r"   rk   r   rj   r   r   r+  r&  r   r   r   r,   r:  r*   r   r   r  r   r  r   r  r   r
  r   r  r   r  r   r   r;   r[  r+   r#  r9   r  r   rc  r	  )r   r   r   r   r   r  
type_groups          r]   r   zDeepDiff._diff.  sR    .$$U+88uxx??5!!EHH%((!33"88 
''*=$BVBVW\W_W_akBl).& ""z%((D'A 88>>%*"""z%((D'A 88>>%*"!  : >xx588#3##$4e
#S%%*UXX{?S*TY\]b]e]eYfjmnsnvnvjw  ZA  |A  ZA ZA ehh)*='*NN5ZN8),  : >%(Uz:'*uPbc'*OOE;:OF%(UKJG3	:">?NN5ZN8*-""5+*"M"34NN5+*NE(+{>^hi$'OOE;:OF NN5+.r_   c                 X   | j                   }| j                  s|j                          |t        k(  r	 |S |t        k(  r3t        | j                   | j                        }|j                          |S |t        k(  r| j                  d      }|S t        t        j                  |            )z3
        Get the results based on the view
        )tree_resultsr   F)report_repetition_required)r   r   *mutual_add_removes_to_become_value_changesr0   r/   rA   r   r   r1   _to_delta_dictr   INVALID_VIEW_MSGrW   )r   r   r   s      r]   r   zDeepDiff._get_view_results  s     %%==?9  YTYYdFXFXYF$$&
 	 Z((E(JF  -44T:;;r_   c                     	 | j                  |      S # t        $ r( t        j                  dj	                  |||               w xY w)Nz2Unable to group {} by {}. The key is missing in {})r  r   r   r  rW   )rowr   r   s      r]   _get_key_for_group_byzDeepDiff._get_key_for_group_by  sG    	778$$ 	LLMTTU^`hjmno	s	    1Ac                 8   d}t        |t        t        f      r|d   }t        |      dkD  r|d   }n|}t        |t              rt        |t
              si }t        |      }|D ]  }t        |t
              r| j                  |||      }	|r_| j                  |||      }
|	|vri ||	<   | j                  r.|
||	   vrg ||	   |
<   ||	   |
   }||vsl|j                  |       ~|||	   |
<   | j                  r&|	|vrg ||	<   |||	   vs||	   j                  |       |||	<   dj                  |||      }t        j                  |       t        |       | j                  r|rN|j                         D ]9  \  }	}|j                         D ]!  \  }
}|j                  | j                         # ; |S |j                         D ]!  \  }}|j                  | j                         # |S dj                  ||      }t        j                  |       t        |      )z
        Convert a list of dictionaries into a dictionary of dictionaries
        where the key is the value of the group_by key in each dictionary.
        Nr   rt   z?Unable to group {} by {} since the item {} is not a dictionary.)r   zUnable to group {} by {})r   r  r   r;  r   r   r   rD  r   r   rW   r   r  r   r  sort)r   rT   r   r   group_by_level2group_by_level1r   	item_copyrC  rJ  rK  result_key1_key2msgrow1r   s                  r]   r   z DeepDiff._group_iterable_to_dict  s8   
 hu.&qkO8}q "*1+&OdH%jw.GF I  *c7+55c?IVD&#99#PYZv-+-F4L11#6$<757tT 2/5d|D/A,"*:: 0 7 7 <14F4L.11#61/1t"&,6 &t 3 3C 8+.F4L[bbcln}  @C  DCLL%$S/)5*6 %%"&,lln A
d)- AID#HH)?)?H@AA M %+LLN =ST%;%;<=M(//	8DSor_   c                     | j                   S )zB
        Get some stats on internals of the DeepDiff run.
        )rZ   r*  s    r]   r   zDeepDiff.get_stats  s     {{r_   c                     t               }t        D ]H  }| j                  |      }|st        |t               r||z  }-|t        |j	                               z  }J |S )a'  
        Get the list of paths that were affected.
        Whether a value was changed or they were added or removed.

        Example
            >>> t1 = {1: 1, 2: 2, 3: [3], 4: 4}
            >>> t2 = {1: 1, 2: 4, 3: [3, 4], 5: 5, 6: 6}
            >>> ddiff = DeepDiff(t1, t2)
            >>> ddiff
            >>> pprint(ddiff, indent=4)
            {   'dictionary_item_added': [root[5], root[6]],
                'dictionary_item_removed': [root[4]],
                'iterable_item_added': {'root[3][1]': 4},
                'values_changed': {'root[2]': {'new_value': 4, 'old_value': 2}}}
            >>> ddiff.affected_paths
            SetOrdered(['root[3][1]', 'root[4]', 'root[5]', 'root[6]', 'root[2]'])
            >>> ddiff.affected_root_keys
            SetOrdered([3, 4, 5, 6, 2])

        )r;   rF   r  r   r   )r   r   r   r+  s       r]   affected_pathszDeepDiff.affected_paths  sY    ,  	7CHHSMEeZ0eOFj66F	7 r_   c           	      f   t               }t        D ]  }| j                  j                  |      }|s!t	        |t               r+|t        |D cg c]  }|j                          c}      z  }\|t        |j                         D cg c]  }|j                          c}      z  } |S c c}w c c}w )a*  
        Get the list of root keys that were affected.
        Whether a value was changed or they were added or removed.

        Example
            >>> t1 = {1: 1, 2: 2, 3: [3], 4: 4}
            >>> t2 = {1: 1, 2: 4, 3: [3, 4], 5: 5, 6: 6}
            >>> ddiff = DeepDiff(t1, t2)
            >>> ddiff
            >>> pprint(ddiff, indent=4)
            {   'dictionary_item_added': [root[5], root[6]],
                'dictionary_item_removed': [root[4]],
                'iterable_item_added': {'root[3][1]': 4},
                'values_changed': {'root[2]': {'new_value': 4, 'old_value': 2}}}
            >>> ddiff.affected_paths
            SetOrdered(['root[3][1]', 'root[4]', 'root[5]', 'root[6]', 'root[2]'])
            >>> ddiff.affected_root_keys
            SetOrdered([3, 4, 5, 6, 2])
        )r;   rF   r   r  r   get_root_keyr   )r   r   r   r+  r   s        r]   affected_root_keyszDeepDiff.affected_root_keys  s    *  	SCIIMM#&EeZ0jE)Jq!..*:)JKKFjEJJL)Qq!..*:)QRRF	S  *K)Qs   B)B.r   )NNNN)NN)NT)Gr   
__module____qualname__doc__doc__r0  !CUTOFF_DISTANCE_FOR_PAIRS_DEFAULT%CUTOFF_INTERSECTION_FOR_PAIRS_DEFAULTr   r   r/   r   r  r   r   r   r:  r	   r   r   r   r   r   r   r   r   r   staticmethodr   r   r	  r  r   r/  r  r[  r^  rc  rn  ry  rb  r|  r~  r}  r  r  r  rR  r  r  r  ra  r   r
  r  r  r#  r&  r<  r)  r-  r8  r   r   rD  r   r   propertyrO  rR  __classcell__)r   s   @r]   rs   rs   o   s   G"&
 !%()!"/08<2S6[04:>AE6:dh48).=A?C,0(,.3-238$)7;04*/27>B.3:>AE6:;?+,/3*.!)-0;?+1;;).37%*7:3726&+$%$-2!$(ko*o*o* %(	o*
 !o* ,/o* $,DI#6o* -2o* 16o* %T#Y/o* (0'9o* /7x.@o* !&c49n 5o* ',CcGCL$wWZ|J\^b,b&co* !)c 3o*  %)!o*" !eCHot!;<#o*$ %*#x*=$>%o*& "(+'o*( "$)o** *.+o*, )--o*. /3/o*0  $1o*2 %-X$63o*4 ,05o*6 &*7o*8 .29o*: )1e(=;o*< *.=o*> (0'9?o*@ /7x.@Ao*B !&c49n 5Co*D )1(:Eo*F (+Go*H  (Io*J %SMKo*L !Mo*N *-Oo*P )1(:Qo*R #+So*T %)Uo*V &.c]Wo*X !%Yo*Z 27[o*\ ,1]o*^ %-SM_o*` "&ao*b !$co*d eo*f )-go*b0$.$ D D4 -6KD 
 ,5;eX\ 
@'RB bM cMJY<   1:D]a s )-(,L, )-(,AF :CUYfj 0d .7[d	FQR .7[hl6#r+LZ
ZD3j 
+ 
+ ^b4dLrWhP$TLPP
 4=;4 9vJ
$8 l$ (1{4TX R/h$  5n  >  r_   rs   __main__)r  loggingr  enumr   r   r   mathr   r  typingr   r   r   r	   r
   r   r   r   r   r   collections.abcr   r   r   collectionsr   inspectr   	itertoolsr   deepdiff.helperr   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   r4   r5   r6   r7   r8   r9   r:   r;   deepdiff.serializationr<   deepdiff.distancer=   r>   deepdiff.modelr?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   deepdiff.deephashrM   rN   deepdiff.baserO   deepdiff.lfucacherP   rQ   	getLoggerr   r   r  r(  r  rU  rV   r^   r   rY   rX   r   r   r   r   r   r  rA  r   r   r   r`   rW  rX  r   rs   doctesttestmodr   r_   r]   <module>ro     s        $ V V V 7 7 #  !	D 	D 	D 	D 	D 	D 	D 	D 	D 	D 6 C    =  0			8	$Y 
X 
 !!:> n E] 6 
1 1 1 + $G !o g X ? A 9  %( ! ), % *gz-}d gT5 zGOO r_   