
    :QgY                     b   d dl Z d dlZd dlZd dlZd dlZd dlZd dlZd dlZd dlZd dl	Z	d dl
Z
d dlZd dlZ	 d dlZ	 ej                  dk\  rd dlZnd dlZ	 d dlZ	 d dlZdZ	 d dlZ	 d dlmZ d dlmZ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+  ejX                  e-      Z.	 d dl/Z/ G d	 d
e0      Z1 e2d      Z3dZ4dZ5dZ6dZ7dZ8h dZ9i de:de;de<de=de>de?de@deAdeBdeCdeDdeEdeFdeGddd dd!e	j                  e	j                  e	j                  e
j                  e)ej                  ej                  ej                  d"ZN G d# d$e      ZO G d% d&e      ZP G d' d(      ZQ G d) d*e j                        ZS G d+ d,e j                        ZUdAd-ZVdBd.ZWd/ ZXd0 ZYdCd1ZZdDd2Z[dEd3Z\d4 Z]d5 Z^e
j                  e]e)eAej                  eAe<eAe2d6 e@d7 e	j                  d8 ej                  d9 e#eDe$eDe%eCe&eCe'd: eBe^eeEiZaerd; eae<   dCd<Zb G d= d>ej                        ZcdCd?Zd eej                  ec@      Zfy# e$ r dZY w xY w# e$ r dZY w xY w# e$ r dZY w xY w# e$ r
 d dlZdZY $w xY w# e$ r dZY -w xY w# e$ r dZY 4w xY w# e$ r dZ/Y w xY w)F    N)      )	BaseModel)deepcopycopy)partial)Mapping)
stringsget_type	TEXT_VIEW
np_float32
np_float64np_int32np_int64
np_ndarrayOpcode
SetOrdered)DeltaResultc                       e Zd Zy)UnsupportedFormatErrN)__name__
__module____qualname__     S/var/www/html/answerous/venv/lib/python3.12/site-packages/deepdiff/serialization.pyr   r   E   s    r   r   i   zXDeepDiff Delta did not find {} in your modules. Please make sure it is already imported.z^Module '{}' is forbidden. You need to explicitly pass it by passing a safe_to_import parameterz[report_repetition must be set to True when ignore_order is True to create the delta object.zkDelta can not be made when group_by is used since the structure of data is modified from the original form.>   	uuid.UUID
re.Patternbuiltins.binbuiltins.intbuiltins.setbuiltins.strbuiltins.Nonebuiltins.boolbuiltins.dictbuiltins.listdatetime.timebuiltins.bytesbuiltins.floatbuiltins.rangebuiltins.slicebuiltins.tupledecimal.Decimalbuiltins.complexdatetime.datetimebuiltins.frozensetdatetime.timedeltacollections.namedtupledeepdiff.helper.Opcodecollections.OrderedDictdeepdiff.helper.SetOrderedorderly_set.sets.OrderedSetorderly_set.sets.OrderlySetorderly_set.sets.StableSetEqrangecomplexset	frozensetslicestrbyteslisttupleintfloatdictboolbinNoneNoneTypedatetime)time	timedeltaDecimalr   
namedtupleOrderedDictPatternc                       e Zd ZdZy)ModuleNotFoundErrorz<
    Raised when the module is not found in sys.modules
    Nr   r   r   __doc__r   r   r   rQ   rQ           	r   rQ   c                       e Zd ZdZy)ForbiddenModulezG
    Raised when a module is not explicitly allowed to be imported
    NrR   r   r   r   rV   rV      rT   r   rV   c                   @    e Zd Zd Zed        ZddZddZd	dZd Z	y)
SerializationMixinc                     t         r%| j                         }t        j                  |      S t        j	                  d       y)z
        :ref:`to_json_pickle_label`
        Get the json pickle of the diff object. Unless you need all the attributes and functionality of DeepDiff, running to_json() is the safer option that json pickle.
        zGjsonpickle library needs to be installed in order to run to_json_pickleN)
jsonpickler   encodeloggererror)selfcopieds     r   to_json_picklez!SerializationMixin.to_json_pickle   s0    
 YY[F$$V,,LLbcr   c                 d    t         rt        j                  |      S t        j                  d       y)z
        :ref:`from_json_pickle_label`
        Load DeepDiff object with all the bells and whistles from the json pickle dump.
        Note that json pickle dump comes from to_json_pickle
        zIjsonpickle library needs to be installed in order to run from_json_pickleN)rZ   decoder\   r]   )clsvalues     r   from_json_picklez#SerializationMixin.from_json_pickle   s%     $$U++LLder   Nc                 J    | j                  t              }t        |fd|i|S )aT  
        Dump json of the text view.
        **Parameters**

        default_mapping : dictionary(optional), a dictionary of mapping of different types to json types.

        by default DeepDiff converts certain data types. For example Decimals into floats so they can be exported into json.
        If you have a certain object type that the json serializer can not serialize it, please pass the appropriate type
        conversion through this dictionary.

        kwargs: Any other kwargs you pass will be passed on to Python's json.dumps()

        **Example**

        Serialize custom objects
            >>> class A:
            ...     pass
            ...
            >>> class B:
            ...     pass
            ...
            >>> t1 = A()
            >>> t2 = B()
            >>> ddiff = DeepDiff(t1, t2)
            >>> ddiff.to_json()
            TypeError: We do not know how to convert <__main__.A object at 0x10648> of type <class '__main__.A'> for json serialization. Please pass the default_mapping parameter with proper mapping of the object to a basic python type.

            >>> default_mapping = {A: lambda x: 'obj A', B: lambda x: 'obj B'}
            >>> ddiff.to_json(default_mapping=default_mapping)
            '{"type_changes": {"root": {"old_type": "A", "new_type": "B", "old_value": "obj A", "new_value": "obj B"}}}'
        )view_overridedefault_mapping)to_dictr   
json_dumps)r^   rh   kwargsdics       r   to_jsonzSerializationMixin.to_json   s*    @ lll3#II&IIr   c                 V    |r|n| j                   }t        | j                  |            S )aP  
        convert the result to a python dictionary. You can override the view type by passing view_override.

        **Parameters**

        view_override: view type, default=None,
            override the view that was used to generate the diff when converting to the dictionary.
            The options are the text or tree.
        )viewrD   _get_view_results)r^   rg   ro   s      r   ri   zSerializationMixin.to_dict   s'     !.}499D**4011r   c           
      l   | j                   t        t              |r|si }| j                  j	                         D ]r  \  }}g ||<   |D ]c  }t        |j                  |j                  |j                  |j                  |j                  |j                        }||   j                  |       e t n| j                  }t        | j                  | j                  ||      }	|	j!                          |r'| j                  r| j"                  st        t$              |rZ|	j	                         D ]G  \  }
}t'        |t(              s|j	                         D ]  \  }}t'        |t(              sd|v s|d=   I | j*                  r| j*                  |	d<   | j,                  rd|	d<   t/        t1        |	            S )a  
        Dump to a dictionary suitable for delta usage.
        Unlike to_dict, this is not dependent on the original view that the user chose to create the diff.

        **Parameters**

        directed : Boolean, default=True, whether to create a directional delta dictionary or a symmetrical

        Note that in the current implementation the symmetrical delta (non-directional) is ONLY used for verifying that
        the delta is being applied to the exact same values as what was used to generate the delta and has
        no other usages.

        If this option is set as True, then the dictionary will not have the "old_value" in the output.
        Otherwise it will have the "old_value". "old_value" is the value of the item in t1.

        If delta = Delta(DeepDiff(t1, t2)) then
        t1 + delta == t2

        Note that it the items in t1 + delta might have slightly different order of items than t2 if ignore_order
        was set to be True in the diff object.

        )tagt1_from_indext1_to_indext2_from_indext2_to_index
new_values)tree_resultsignore_orderalways_include_values_iterable_opcodes	old_value_numpy_pathsT_iterable_compare_func_was_used)group_by
ValueErrorDELTA_ERROR_WHEN_GROUP_BYr{   itemsr   rr   rs   rt   ru   rv   rw   appendr   treery   remove_empty_keysreport_repetition*DELTA_IGNORE_ORDER_NEEDS_REPETITION_REPORT
isinstancer	   r}   iterable_compare_funcr   rD   )r^   directedreport_repetition_requiredrz   r{   pathop_codesop_codenew_op_coderesult
report_keyreport_valuerd   s                r   _to_delta_dictz!SerializationMixin._to_delta_dict   s   . ==$6771 ""&"8"8">">"@ @h*,!$'' 	@G"(#KK&-&;&;$+$7$7&-&;&;$+$7$7#*#5#5#K &d+22;?	@@ !% 6 6**"7/	
 	  "%$*;*;DDZDZGHH,2LLN 3(
LlG4'3'9'9'; 3e%eW5+:N %k 233
  &*%6%6F>"%%8<F45V%%r   c                     g }t        | j                  j                               }|D ]%  }| j                  |   D ]  }|t        |      gz  } ' dj	                  |      S )a  
        The pretty human readable string output for the diff object
        regardless of what view was used to generate the diff.

        Example:
            >>> t1={1,2,4}
            >>> t2={2,3}
            >>> print(DeepDiff(t1, t2).pretty())
            Item root[3] added to set.
            Item root[4] removed from set.
            Item root[1] removed from set.
        
)sortedr   keyspretty_print_diffjoin)r^   r   r   keyitem_keys        r   prettyzSerializationMixin.pretty+  sh     diinn&' 	8C IIcN 8,X6778	8 yy  r   N)TTF)
r   r   r   r`   classmethodre   rm   ri   r   r   r   r   r   rX   rX      s6    	d 	f 	f!JF2B&H!r   rX   c                   *     e Zd Z fdZd Zd Z xZS )_RestrictedUnpicklerc                    |j                  dd       | _        | j                  rt        | j                  t              rt	        | j                  g      | _        n;t        | j                  t        t
        f      rnt	        | j                        | _        | j                  t        z  | _        nt        | _        t        |    |i | y )Nsafe_to_import)	popr   r   r
   r;   r<   SAFE_TO_IMPORTsuper__init__)r^   argsrk   	__class__s      r   r   z_RestrictedUnpickler.__init__C  s    $jj)94@$--w7&)4+>+>*?&@#D//#y1AB&)$*=*=&>#"&"5"5"FD"0D$)&)r   c                    dj                  ||      }|| j                  v r 	 t        j                  |   }t        ||      S t        t        j                  |            d # t        $ r  t        t        j                  |            d w xY w)Nz{}.{})
formatr   sysmodulesKeyErrorrQ   MODULE_NOT_FOUND_MSGgetattrrV   FORBIDDEN_MODULE_MSG)r^   modulenamemodule_dot_class
module_objs        r   
find_classz_RestrictedUnpickler.find_classQ  s    ">>&$7t222c [[0
 :t,,299:JKLRVV	  c)*>*E*EFV*WX^bbcs   A   )B	c                 $    |dk(  rt        d       S y Nz<<NoneType>>)type)r^   persistent_ids     r   persistent_loadz$_RestrictedUnpickler.persistent_load]  s    N*: +r   )r   r   r   r   r   r   __classcell__)r   s   @r   r   r   A  s    *
Wr   r   c                       e Zd Zd Zy)_RestrictedPicklerc                     |t         u ryy r   )	NONE_TYPE)r^   objs     r   r   z _RestrictedPickler.persistent_idc  s    )!r   N)r   r   r   r   r   r   r   r   r   b  s    r   r   c                     t        |      }|xs t        j                         }t        ||d      j	                  |        |s|j                         S y)a  
    **pickle_dump**
    Dumps the obj into pickled content.

    **Parameters**

    obj : Any python object

    file_obj : (Optional) A file object to dump the contents into

    **Returns**

    If file_obj is passed the return value will be None. It will write the object's pickle contents into the file.
    However if no file_obj is passed, then it will return the pickle serialization of the obj in the form of bytes.
    F)protocolfix_importsN)rE   ioBytesIOr   dumpgetvalue)r   file_objr   file_obj_passeds       r   pickle_dumpr   i  sK      8nO'2::<Hx(FKKCP  "" r   c                     | s|st        d      t        | t              r| j                  d      } | rt	        j
                  |       }t        ||      j                         S )a  
    **pickle_load**
    Load the pickled content. content should be a bytes object.

    **Parameters**

    content : Bytes of pickled object. 

    file_obj : A file object to load the content from

    safe_to_import : A set of modules that needs to be explicitly allowed to be loaded.
        Example: {'mymodule.MyClass', 'decimal.Decimal'}
        Note that this set will be added to the basic set of modules that are already allowed.
        The set of what is already allowed can be found in deepdiff.serialization.SAFE_TO_IMPORT

    **Returns**

        A delta object that can be added to t1 to recreate t2.

    **Examples**

    Importing
        >>> from deepdiff import DeepDiff, Delta
        >>> from pprint import pprint


    z>Please either pass the content or the file_obj to pickle_load.utf-8)r   )r   r   r>   r[   r   r   r   load)contentr   r   s      r   pickle_loadr     sT    8 8YZZ'3..)::g&HMMOOr   c                 \    ddddddddd	d
dd}| dk(  r|j                  ddddddd       |S )NzdType of {diff_path} changed from {type_t1} to {type_t2} and value changed from {val_t1} to {val_t2}.z7Value of {diff_path} changed from {val_t1} to {val_t2}.z%Item {diff_path} added to dictionary.z)Item {diff_path} removed from dictionary.z#Item {diff_path} added to iterable.z'Item {diff_path} removed from iterable.zAttribute {diff_path} added.zAttribute {diff_path} removed.z!Item root[{val_t2}] added to set.z%Item root[{val_t1}] removed from set.z'Repetition change for item {diff_path}.)type_changesvalues_changeddictionary_item_addeddictionary_item_removediterable_item_addediterable_item_removedattribute_addedattribute_removedset_item_addedset_item_removedrepetition_change   z0Item {diff_path} ({val_t2}) added to dictionary.z4Item {diff_path} ({val_t1}) removed from dictionary.z.Item {diff_path} ({val_t2}) added to iterable.z2Item {diff_path} ({val_t1}) removed from iterable.z'Attribute {diff_path} ({val_t2}) added.z)Attribute {diff_path} ({val_t1}) removed.)r   r   r   r   r   r   )update)verbose_levelpretty_form_textss     r   _get_pretty_form_textr     sb    ~S!H#ND!J9==CF   )[+a'W)]#L%P		
 r   c                     t        | j                        j                  }t        | j                        j                  }|dk(  r$dj	                  t        | j                              nt        | j                        }|dk(  r$dj	                  t        | j                              nt        | j                        }| j                  d      }t        | j                        j                  | j                  d      j	                  |||||      S )Nr>   z"{}"root)r    )	diff_pathtype_t1type_t2val_t1val_t2)r   t1r   t2r   r>   r   r   r   getreport_type)diffr   r   r   r   r   s         r   r   r     s    tww((Gtww((G,3u,<V]]3tww<(#dgg,F,3u,<V]]3tww<(#dgg,F		v	&I !3!34889I9I2NUU V  r   c                 J   || j                  d      d   }|dk(  r0t        | d      5 }t        |j                               }ddd       |S |dv r=t        t        d      t        | d      5 }t	        j                  |      }ddd       |S |dk(  r=t        t        d	      t        | d
      5 }t        j                  |      }ddd       |S |dk(  r2t        | d
      5 }|j                         }t        |      }ddd       |S |dv rt        rt        j                  |       }n3t        | d      5 }t        t        j                  |            }ddd       t        j!                  d|         D ]O  }|j#                         D ]:  \  }}|j%                         }t&        t(        t*        fD ]  }	  ||      }|||<    : < Q |S t/        d| d      # 1 sw Y   S xY w# 1 sw Y   S xY w# 1 sw Y   S xY w# 1 sw Y   S xY w# 1 sw Y   xY w# t,        $ r Y tw xY w)z9
    Loads and deserializes the content of the path.
    N.jsonr>   ymlyamlPyyaml needs to be installed.tomlz,On python<=3.10 tomli needs to be installed.rbpickle>   csvtsvzNOTE: CSV content was empty in ?Only json, yaml, toml, csv, tsv and pickle are supported.
 The  extension is not known.)splitopen
json_loadsreadr   ImportError	safe_loadtomlir   r   	clevercsv
read_dictsr@   r   
DictReaderr\   infor   striprB   rC   r:   	Exceptionr   )r   	file_typethe_filer   rowr   rd   type_s           r   load_path_contentr    s\    JJsOB'	F$_ 	2 1G	2N NK 
o	%<=>>$_ 	/nnX.G	/D NA 
f	=LMM$ 	+jj*G	+: N7 
h	$ 	+mmoG!'*G	+4 N/ 
n	$**40GdC 9Hs~~h7895dV<=  
	C!iik 	
U!5'2 E %e $)C	
	 N # &++4+5M$O P 	PK	2N NE	/D N;	+: N5	+4 N'9 9 % sM   G-G#/G0 G=2H
1HG #G-0G:=H
H	H"	!H"	c                     | d}t        j                  ||       	 t        | |||       |st        j                  |       yy# t        $ r t        j                  ||        w xY w)z7
    Saves and serializes the content of the path.
    z.bak)r   r   r
  keep_backupN)osrename_save_contentremover	  )r   r   r
  r  backup_paths        r   save_content_to_pathr    sl    
 F$-KIIdK 	#$[	: IIk" 	  
		+t$s   A !A&c                    |dk(  r3t        |d      5 }t        |       } |j                  |        d d d        | S |dv r?t        t	        d      t        |d      5 }t        j
                  | |      } d d d        | S |dk(  r>t        t	        d      t        |d      5 }t        j                  | |      } d d d        | S |d	k(  r$t        |d      5 }t        | |
      } d d d        | S |dv rt        rt        j                  }nt        j                  }t        |dd      5 }t        | d   j                               } |||      }|j                          |j                  |        d d d        | S t!        d| d      # 1 sw Y   | S xY w# 1 sw Y   | S xY w# 1 sw Y   | S xY w# 1 sw Y   | S xY w# 1 sw Y   | S xY w)Nr   w>   r   r   r   )streamr   zTomli-w needs to be installed.wbr   )r   >   r   r   r   )newliner   )
fieldnamesr   r   )r   rj   writer   r  	safe_dumptomli_wr   r   r  
DictWriterr   r@   r   writeheader	writerowsr   )	r   r   r
  r  r  dict_writercsvfiler  writers	            r   r  r    s   F$_ 	$ )GNN7#	$: N5 
o	%<=>>$_ 	?nnWX>G	?. N+ 
f	?>??$ 	6ll7H5G	6$ N! 
h	$ 	>!'H=G	> N 
n	$#..K..K$R( 	&Ggajoo/0J Z@F W%		& N # $++4+5M$O P 	P7	$: N/	?. N%	6$ N	> N	& Ns<   FFFF)!AF6FFF&)F36G c                 h    | j                         j                  dk(  rt        |       S t        |       S )Nr   )as_tupleexponentrB   rC   rd   s    r   _serialize_decimalr*  8  s+    ~~  A%5zU|r   c                 >    t        | d      r| j                         S | S )N_asdict)hasattrr,  r)  s    r   _serialize_tupler.  ?  s    ui }}Lr   c                     | j                   S r   )r   xs    r   <lambda>r2  J  s
    AJJ r   c                 $    | j                  d      S )Nr   )rb   r0  s    r   r2  r2  K  s    QXXg& r   c                 "    | j                         S r   )	isoformatr0  s    r   r2  r2  L  s     r   c                     t        |       S r   )r>   r0  s    r   r2  r2  M  s
    Q r   c                 "    | j                         S r   )tolistr0  s    r   r2  r2  R  s    !((* r   c                 "    | j                         S r   )rD   r0  s    r   r2  r2  X  s    !&&( r   c                 n    | r&t         j                         j                  |        nt         fd}|S )Nc                    j                         D ]  \  }}t        | |      s ||       c S  | j                  j                  dk(  rt	        t        |             S t        dj                  | t        |                   )Nlist_reverseiteratorzWe do not know how to convert {} of type {} for json serialization. Please pass the default_mapping parameter with proper mapping of the object to a basic python type.)	r   r   r   r   r@   r   	TypeErrorr   r   )r   original_type
convert_to_convertor_mappings      r   
_convertorz*json_convertor_default.<locals>._convertorb  s    );)A)A)C 	'%M:#}-!#&	' ==!!%;;S	?"  B  I  I  JM  OS  TW  OX  Y  Z  	Zr   )JSON_CONVERTORr   r   )rh   rA  r@  s     @r   json_convertor_defaultrC  [  s7    +002!!/2+Z r   c                       e Zd Zd Zd Zy)JSONDecoderc                 b    t        j                  j                  | g|d| j                  i| y )Nobject_hook)r   rE  r   rG  )r^   r   rk   s      r   r   zJSONDecoder.__init__p  s+    !!$VtVD4D4DVvVr   c                 `    d|v r)d|v r%dD ]   }||   }t         j                  ||      ||<   " |S )Nold_typenew_type)rI  rJ  )TYPE_STR_TO_TYPEr   )r^   r   type_keytype_strs       r   rG  zJSONDecoder.object_hooks  sH    s!24 Ix= 0 4 4Xx HHI 
r   N)r   r   r   r   rG  r   r   r   rE  rE  n  s    Wr   rE  c                    t         rY|j                  dd      }|rt         j                  |d<   t        j                  | fdt	        |      i|j                  d      S t        j                  | fdt	        |      i|S )zN
    Dump json with extra details that are not normally json serializable
    indentNoptiondefault)rh   r   )encoding)orjsonr   OPT_INDENT_2dumpsrC  rb   r   )itemrh   rk   rO  s       r   rj   rj   |  s     Hd+%22F8||*?K  fgf.	/
 zz*?K  	r   )rc   )N   )NNNr   )NT)T)gr   r   r   r  r   uuidloggingrebuiltinsrI   decimalorderly_setcollectionsr   r  version_infotomllibr  r  r  r   rS  pydanticr   PydanticBaseModelr   r   	functoolsr   collections.abcr	   deepdiff.helperr
   r   r   r   r   r   r   r   r   r   deepdiff.modelr   	getLoggerr   r\   rZ   r=  r   r   r   CSV_HEADER_MAX_CHUNK_SIZEr   r   r   r   r   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rJ   rK   rL   rM   rN   rO   rK  rQ   rV   rX   	Unpicklerr   Picklerr   r   r   r   r   r  r  r  r*  r.  StableSetEqUUIDrB  rC  rE  rj   loadsr   r   r   r   <module>rn     s    
 	 	    	     
7"
C7    #   '			8	$
	9 	 J	   r w  .K * J @Uw 
3 	
 U 
3 U D U 
3 U D D 
3 D  !" !!#$ MM##((**zz1 8	+ 		k 	a! a!H6++ B #."PJ8 .b#(D OO'T
	&.IIcc$	T$ (:N$%&$"" & TZZ[1
  D  E  G
  I
  F  0  Js|   I I I' I5  J %J 0J# III$#I$'I21I25JJJJJ J #J.-J.