
    60fRt                        d Z ddlmZ ddlZddlZ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mZ dZdZ	 ddlmZmZ d	Zd
ZdZdZej6                  dk\  reefZ G d de      Z G d de      Z  G d de      Z! G d dee"      Z#d Z$ ejJ                  ejL                  e$      Z'defdZ(efdZ) G d de*      Z+ G d de+      Z, G d d e+      Z- G d! d"e+      Z. G d# d$e+      Z/ G d% d&e+      Z0 G d' d(e+      Z1 G d) d*e*      Z2 G d+ d,e*      Z3d- Z4y# e
$ r
 ddlm	Z	 Y w xY w# e
$ r eZY w xY w# e
$ r ddlmZmZ eZY w xY w).z Apply JSON-Patches (RFC 6902)     )unicode_literalsN)Sequence)MappingProxyType)JsonPointerJsonPointerException   )MutableMappingMutableSequenceu    Stefan Kögl <stefan@skoegl.net>z1.33z0https://github.com/stefankoegl/python-json-patchzModified BSD License)   r   c                       e Zd ZdZy)JsonPatchExceptionzBase Json Patch exceptionN__name__
__module____qualname____doc__     )lib/python3.12/site-packages/jsonpatch.pyr   r   P       #r   r   c                       e Zd ZdZy)InvalidJsonPatchz, Raised if an invalid JSON Patch is created Nr   r   r   r   r   r   T   s    6r   r   c                       e Zd ZdZy)JsonPatchConflicta
  Raised if patch could not be applied due to conflict situation such as:
    - attempt to add object key when it already exists;
    - attempt to operate with nonexistence object key;
    - attempt to insert value to array at position beyond its size;
    - etc.
    Nr   r   r   r   r   r   X   s    r   r   c                       e Zd ZdZy)JsonPatchTestFailedz A Test operation failed Nr   r   r   r   r   r   a   r   r   r   c                     t        j                  t              }| D ]  \  }}||   j                  |        t	        d |j                         D              S )z'Convert duplicate keys values to lists.c              3   P   K   | ]  \  }}|t        |      d k(  r|d   n|f   yw)r   r   N)len).0keyvaluess      r   	<genexpr>zmultidict.<locals>.<genexpr>l   s4       C 
3v;!+fQi8s   $&)collectionsdefaultdictlistappenddictitems)ordered_pairsmdictr!   values       r   	multidictr-   e   s]     ##D)E# !
Uc
% !   !;;=  r   )object_pairs_hookFc                     t        |t              rt        j                  ||      }nt        ||      }|j	                  | |      S )a  Apply list of patches to specified json document.

    :param doc: Document object.
    :type doc: dict

    :param patch: JSON patch as list of dicts or raw JSON-encoded string.
    :type patch: list or str

    :param in_place: While :const:`True` patch will modify target document.
                     By default patch will be applied to document copy.
    :type in_place: bool

    :param pointer_cls: JSON pointer class to use.
    :type pointer_cls: Type[JsonPointer]

    :return: Patched document object.
    :rtype: dict

    >>> doc = {'foo': 'bar'}
    >>> patch = [{'op': 'add', 'path': '/baz', 'value': 'qux'}]
    >>> other = apply_patch(doc, patch)
    >>> doc is not other
    True
    >>> other == {'foo': 'bar', 'baz': 'qux'}
    True
    >>> patch = [{'op': 'add', 'path': '/baz', 'value': 'qux'}]
    >>> apply_patch(doc, patch, in_place=True) == {'foo': 'bar', 'baz': 'qux'}
    True
    >>> doc == other
    True
    pointer_cls)
isinstance
basestring	JsonPatchfrom_stringapply)docpatchin_placer1   s       r   apply_patchr:   x   sA    B %$%%e%E%[9;;sH%%r   c                 2    t         j                  | ||      S )a!  Generates patch by comparing two document objects. Actually is
    a proxy to :meth:`JsonPatch.from_diff` method.

    :param src: Data source document object.
    :type src: dict

    :param dst: Data source document object.
    :type dst: dict

    :param pointer_cls: JSON pointer class to use.
    :type pointer_cls: Type[JsonPointer]

    >>> src = {'foo': 'bar', 'numbers': [1, 3, 4, 8]}
    >>> dst = {'baz': 'qux', 'numbers': [1, 4, 7]}
    >>> patch = make_patch(src, dst)
    >>> new = patch.apply(src)
    >>> new == dst
    True
    r0   )r4   	from_diff)srcdstr1   s      r   
make_patchr?      s    * sC[AAr   c                   v    e Zd ZdZefdZd Zd Zd Zd Z	e
d        Ze
d        Zej                  d	        Zy
)PatchOperationz'A single operation inside a JSON Patch.c                 d   || _         |j                  d      st        d      t        |d   | j                         r&|d   j                  | _        |d   | _        || _        y |d   | _        	 | j                  | j
                        | _        || _        y # t        $ r}t        d      d }~ww xY w)Npathz#Operation must have a 'path' memberzInvalid 'path')	r1   __contains__r   r2   rC   locationpointer	TypeError	operation)selfrH   r1   exs       r   __init__zPatchOperation.__init__   s    &%%f-"#HIIi')9)9:%f-22DM$V,DL # &f-DM9#//> #  9&'7889s   . B 	B/B**B/c                     t        d      )zGAbstract method that applies a patch operation to the specified object.z%should implement the patch operation.)NotImplementedError)rI   objs     r   r6   zPatchOperation.apply   s    !"IJJr   c                 Z    t        t        | j                  j                                     S N)hash	frozensetrH   r)   rI   s    r   __hash__zPatchOperation.__hash__   s    Idnn224566r   c                 V    t        |t              sy| j                  |j                  k(  S NF)r2   rA   rH   rI   others     r   __eq__zPatchOperation.__eq__   s"    %0~~00r   c                     | |k(   S rP   r   rW   s     r   __ne__zPatchOperation.__ne__       5=!!r   c                 R    dj                  | j                  j                  d d       S )N/)joinrF   partsrS   s    r   rC   zPatchOperation.path   s"    xx**3B/00r   c                     	 t        | j                  j                  d         S # t        $ r | j                  j                  d   cY S w xY w)Nr_   )intrF   ra   
ValueErrorrS   s    r   r!   zPatchOperation.key   sE    	*t||))"-.. 	*<<%%b))	*s   !$ "A	A	c                     t        |      | j                  j                  d<   | j                  j                  | _        | j                  | j
                  d<   y )Nr_   rC   )strrF   ra   rC   rE   rH   )rI   r,   s     r   r!   zPatchOperation.key   s=    !$U2))!%vr   N)r   r   r   r   r   rK   r6   rT   rY   r[   propertyrC   r!   setterr   r   r   rA   rA      sb    1.9 #$K71
" 1 1 * * 	ZZ/ /r   rA   c                   "    e Zd ZdZd Zd Zd Zy)RemoveOperationz/Removes an object property or an array element.c                 $   | j                   j                  |      \  }}t        |t              r*t        |t              st        dj                  |            	 ||= |S # t        t        f$ r!}dj                  |      }t        |      d }~ww xY w)Nzinvalid array index '{0}'z(can't remove a non-existent object '{0}')
rF   to_lastr2   r   rc   r   formatKeyError
IndexErrorr   )rI   rN   subobjpartrJ   msgs         r   r6   zRemoveOperation.apply   s    ||++C0fh'
40E&'B'I'I$'OPP	)t
 
	 *% 	)<CCDIC#C((	)s   A B.B

Bc                 z    | j                   |k(  r+| j                  |k\  r| xj                  dz  c_        |S |dz  }|S Nr   rC   r!   rI   rC   r!   s      r   _on_undo_removezRemoveOperation._on_undo_remove   s=    99xx3A 
 q
r   c                 z    | j                   |k(  r+| j                  |kD  r| xj                  dz  c_        |S |dz  }|S rt   ru   rv   s      r   _on_undo_addzRemoveOperation._on_undo_add  =    99xx#~A 
 q
r   Nr   r   r   r   r6   rw   ry   r   r   r   rj   rj      s    9r   rj   c                   "    e Zd ZdZd Zd Zd Zy)AddOperationz,Adds an object property or an array element.c                    	 | j                   d   }| j                  j	                  |      \  }}t        |t              rJ|dk(  r|j                  |       |S |t        |      kD  s|dk  rt        d      |j                  ||       |S t        |t              r||}|S |||<   |S |#t        dj                  t        |                  t        dj                  | j                  |            # t        $ r}t        d      d }~ww xY w)Nr,   /The operation does not contain a 'value' member-r   zcan't insert outside of listinvalid document type {0}2unable to fully resolve json pointer {0}, part {1})rH   rn   r   rF   rl   r2   r
   r'   r   r   insertr	   rG   rm   typerE   )rI   rN   r,   rJ   rp   rq   s         r   r6   zAddOperation.apply  s#   	CNN7+E
 ||++C0fo.s{e$& 
# F#tax'(FGG dE* 
 /| 
  %t 
	 | ; B B4< PQQ'(\(c(cdhdqdqsw(xyy5  	C"AC C	Cs   C0 0	D	9DD	c                 z    | j                   |k(  r+| j                  |kD  r| xj                  dz  c_        |S |dz  }|S rt   ru   rv   s      r   rw   zAddOperation._on_undo_remove3  rz   r   c                 z    | j                   |k(  r+| j                  |kD  r| xj                  dz  c_        |S |dz  }|S rt   ru   rv   s      r   ry   zAddOperation._on_undo_add;  rz   r   Nr{   r   r   r   r}   r}     s    6@r   r}   c                   "    e Zd ZdZd Zd Zd Zy)ReplaceOperationz?Replaces an object property or an array element by a new value.c                    	 | j                   d   }| j                  j	                  |      \  }}||S |dk(  rt        d      t        |t              r|t        |      k\  s|dk  rt        d      t        |t              r ||vrfdj                  |      }t        |      |#t        dj                  t        |                  t        d	j                  | j                  |            |||<   |S # t        $ r}t        d      d }~ww xY w)
Nr,   r   r   z7'path' with '-' can't be applied to 'replace' operationr   zcan't replace outside of listz)can't replace a non-existent object '{0}'r   r   )rH   rn   r   rF   rl   r2   r
   r   r   r	   rm   rG   r   rE   )rI   rN   r,   rJ   rp   rq   rr   s          r   r6   zReplaceOperation.applyG  s   	CNN7+E
 ||++C0<L3;"#\]]fo.s6{"dQh'(GHH/6!AHHN',,| ; B B4< PQQ'(\(c(cdhdqdqsw(xyyt
7  	C"AC C	Cs   C2 2	D;DDc                     |S rP   r   rv   s      r   rw   z ReplaceOperation._on_undo_removeg      
r   c                     |S rP   r   rv   s      r   ry   zReplaceOperation._on_undo_addj  r   r   Nr{   r   r   r   r   r   D  s    I@r   r   c                   f    e Zd ZdZd Zed        Zed        Zej                  d        Zd Z	d Z
y)	MoveOperationz?Moves an object property or an array element to a new location.c                    	 t        | j                  d   | j                        r| j                  d   }n| j                  | j                  d         }|j                  |      \  }}	 ||   }| j                  |k(  r|S t        |t              r&| j                  j                  |      rt        d      t        d| j                  d   d| j                        j                  |      }t        d| j                  |d| j                        j                  |      }|S # t        $ r}t	        d      d }~ww xY w# t        t        f$ r}t        t        |            d }~ww xY w)	Nfrom.The operation does not contain a 'from' memberz*Cannot move values into their own childrenremoveoprC   r0   addr   rC   r,   )r2   rH   r1   rn   r   rl   ro   r   rf   rF   r	   containsrj   r6   r}   rE   rI   rN   from_ptrrJ   rp   rq   r,   s          r   r6   zMoveOperation.applyq  sg   	B$..0$2B2BC>>&1++DNN6,BC
  '',	-4LE
 <<8#Jfn-%%h/#$PQQNN6*
 '') */s 	
 MM
 ''	) */s	 	 
;  	B"@B B	B *% 	-#CG,,	-s0   AD  (D<  	D9)D44D9<E$EE$c                 z    | j                  | j                  d         }dj                  |j                  d d       S )Nr   r^   r_   )r1   rH   r`   ra   rI   r   s     r   	from_pathzMoveOperation.from_path  s5    ##DNN6$:;xxs+,,r   c                     | j                  | j                  d         }	 t        |j                  d         S # t        $ r |j                  d   cY S w xY wNr   r_   )r1   rH   rc   ra   rG   r   s     r   from_keyzMoveOperation.from_key  sR    ##DNN6$:;	&x~~b)** 	&>>"%%	&s   8 AAc                     | j                  | j                  d         }t        |      |j                  d<   |j                  | j                  d<   y r   )r1   rH   rf   ra   rC   )rI   r,   r   s      r   r   zMoveOperation.from_key  s?    ##DNN6$:; Zr!)vr   c                     | j                   |k(  r*| j                  |k\  r| xj                  dz  c_        n|dz  }| j                  |k(  r+| j                  |kD  r| xj                  dz  c_        |S |dz  }|S rt   r   r   rC   r!   rv   s      r   rw   zMoveOperation._on_undo_remove  sl    >>T!}}#"q99xx#~A 
 q
r   c                     | j                   |k(  r*| j                  |kD  r| xj                  dz  c_        n|dz  }| j                  |k(  r+| j                  |kD  r| xj                  dz  c_        |S |dz  }|S rt   r   rv   s      r   ry   zMoveOperation._on_undo_add  sl    >>T!}}s""q99xx#~A 
 q
r   N)r   r   r   r   r6   rg   r   r   rh   rw   ry   r   r   r   r   r   n  sU    I#J - - & & __/ /
r   r   c                       e Zd ZdZd Zy)TestOperationz!Test value by specified location.c           
         	 | j                   j                  |      \  }}||}n| j                   j                  ||      }	 | j                  d   }||k7  r1d}t	        |j                  |t        |      |t        |                  |S # t        $ r}t	        t        |            d }~ww xY w# t        $ r}t        d      d }~ww xY w)Nr,   r   z0{0} ({1}) is not equal to tested value {2} ({3}))rF   rl   walkr   r   rf   rH   rn   r   rm   r   )rI   rN   rp   rq   valrJ   r,   rr   s           r   r6   zTestOperation.apply  s    	/<<//4LFD|ll''5	CNN7+E
 %<DC%cjjd3i16U'E F F 
 $ 	/%c"g..	/
  	C"AC C	Cs/   ?B	 B. 		B+B&&B+.	C7CCNr   r   r   r   r6   r   r   r   r   r     s
    +r   r   c                       e Zd ZdZd Zy)CopyOperationzA Copies an object property or an array element to a new location c                    	 | j                  | j                  d         }|j	                  |      \  }}	 t        j                  ||         }t        d| j                  |d| j                         j                  |      }|S # t        $ r}t        d      d }~ww xY w# t        t        f$ r}t        t        |            d }~ww xY w)Nr   r   r   r   r0   )r1   rH   rn   r   rl   copydeepcopyro   r   rf   r}   rE   r6   r   s          r   r6   zCopyOperation.apply  s    	B''v(>?H
  '',	-MM&,/E MM
 ''	) */s	 	 
!  	B"@B B	B *% 	-#CG,,	-s.   B B 	BBBC.CCNr   r   r   r   r   r     s
    Kr   r   c            	           e Zd Z eej
                        Z ee      Z e	e
eeeeed      Z	 efdZd Zd ZeZd Zd Zd Zd Zed	efd
       Zedd	efd       ZddZed        ZddZ d Z!y	)r4   )r   r   replacemovetestr   c                     || _         || _        | j                   D ].  }t        |t              rt	        d      | j                  |       0 y )NzMDocument is expected to be sequence of operations, got a sequence of strings.)r8   r1   r2   r3   r   _get_operation)rI   r8   r1   r   s       r   rK   zJsonPatch.__init__2  sW    
& ** 	$B "j)& (P Q Q #	$r   c                 "    | j                         S )zstr(self) -> self.to_string())	to_stringrS   s    r   __str__zJsonPatch.__str__J  s    ~~r   c                 ,    t        | j                        S rP   )boolr8   rS   s    r   __bool__zJsonPatch.__bool__N      DJJr   c                 ,    t        | j                        S rP   )iterr8   rS   s    r   __iter__zJsonPatch.__iter__S  r   r   c                 >    t        t        | j                              S rP   )rQ   tuple_opsrS   s    r   rT   zJsonPatch.__hash__V  s    E$))$%%r   c                 V    t        |t              sy| j                  |j                  k(  S rV   )r2   r4   r   rW   s     r   rY   zJsonPatch.__eq__Y  s"    %+yyEJJ&&r   c                     | |k(   S rP   r   rW   s     r   r[   zJsonPatch.__ne__^  r\   r   Nc                 F    |xs | j                   } ||      } | ||      S )a  Creates JsonPatch instance from string source.

        :param patch_str: JSON patch as raw string.
        :type patch_str: str

        :param loads: A function of one argument that loads a serialized
                      JSON string.
        :type loads: function

        :param pointer_cls: JSON pointer class to use.
        :type pointer_cls: Type[JsonPointer]

        :return: :class:`JsonPatch` instance.
        r0   )json_loader)cls	patch_strloadsr1   r   r8   s         r   r5   zJsonPatch.from_stringa  s)      .sI&5k22r   Tc                     |xs | j                   }t        ||||      }|j                  dd||       t        |j	                               } | ||      S )aC  Creates JsonPatch instance based on comparison of two document
        objects. Json patch would be created for `src` argument against `dst`
        one.

        :param src: Data source document object.
        :type src: dict

        :param dst: Data source document object.
        :type dst: dict

        :param dumps: A function of one argument that produces a serialized
                      JSON string.
        :type dumps: function

        :param pointer_cls: JSON pointer class to use.
        :type pointer_cls: Type[JsonPointer]

        :return: :class:`JsonPatch` instance.

        >>> src = {'foo': 'bar', 'numbers': [1, 3, 4, 8]}
        >>> dst = {'baz': 'qux', 'numbers': [1, 4, 7]}
        >>> patch = JsonPatch.from_diff(src, dst)
        >>> new = patch.apply(src)
        >>> new == dst
        True
        r0    N)json_dumperDiffBuilder_compare_valuesr&   execute)	r   r=   r>   optimizationdumpsr1   r   builderopss	            r   r<   zJsonPatch.from_diffu  sT    > .sc3MD#s37??$%3K00r   c                 F    |xs | j                   } || j                        S )z!Returns patch set as JSON string.)r   r8   )rI   r   r   s      r   r   zJsonPatch.to_string  s!    /t//4::&&r   c                 T    t        t        | j                  | j                              S rP   )r   mapr   r8   rS   s    r   r   zJsonPatch._ops  s    S,,djj9::r   c                 x    |st        j                  |      }| j                  D ]  }|j                  |      } |S )a5  Applies the patch to a given object.

        :param obj: Document object.
        :type obj: dict

        :param in_place: Tweaks the way how patch would be applied - directly to
                         specified `obj` or to its copy.
        :type in_place: bool

        :return: Modified `obj`.
        )r   r   r   r6   )rI   rN   r9   rH   s       r   r6   zJsonPatch.apply  s=     --$C 	'I//#&C	' 
r   c                     d|vrt        d      |d   }t        |t              st        d      || j                  vrt        dj	                  |            | j                  |   } ||| j
                        S )Nr   z&Operation does not contain 'op' memberzOperation's op must be a stringzUnknown operation {0!r}r0   )r   r2   r3   
operationsrm   r1   )rI   rH   r   r   s       r   r   zJsonPatch._get_operation  sy    y "#KLLt_"j)"#DEET__$"#<#C#CB#GHHoob!9$*:*:;;r   rP   )F)"r   r   r   staticmethodjsonr   r   
_jsonloadsr   r   rj   r}   r   r   r   r   r   r   rK   r   r   __nonzero__r   rT   rY   r[   classmethodr5   r<   r   rg   r   r6   r   r   r   r   r4   r4     s    tzz*Kz*K!!## J,Z +6 $0   K &'
" *.K 3 3& (,D#"1 "1H'
 ; ;*<r   r4   c                   z    e Zd Zej                  efdZd Zd Zd Z	d Z
d Zd Zd Zd	 Zd
 Zd Zd Zd Zd Zy)r   c                     || _         || _        i i g| _        g g g| _        g x| _        }|| _        || _        ||d g|d d  y rP   )r   r1   index_storageindex_storage2_DiffBuilder__rootsrc_docdst_doc)rI   r   r   r   r1   roots         r   rK   zDiffBuilder.__init__  sS    
& "X!2hdt$Qr   c                     |t        |      f}	 | j                  |   }|j                  |      }||g||<   y ||   j                  |       y # t        $ r# | j
                  |   j                  ||f       Y y w xY wrP   )r   r   getr'   rG   r   )rI   r,   indexst	typed_keystoragestoreds          r   store_indexzDiffBuilder.store_index  s    DK(			?((,G[[+F~&+W	"	"))%0 	?#**Iu+=>	?s   (A A )A98A9c                 >   |t        |      f}	 | j                  |   j                  |      }|r|j                         S y # t        $ rS | j
                  |   }t        t        |      dz
  dd      D ]%  }||   d   |k(  s|j                  |      d   c cY S  Y y w xY w)Nr   r_   r   )r   r   r   poprG   r   ranger   )rI   r,   r   r   r   r   is          r   
take_indexzDiffBuilder.take_index  s    DK(			-''+//	:Fzz|#   	-))"-G3w<>2r2 -1:a=I-";;q>!,,-	-s   /A   ?B BBBc                 H    | j                   }|d   }|||gx|d<   |d<   |d   S )Nr   r   r   )rI   r   r   lasts       r   r   zDiffBuilder.insert  s6    {{Aw!4,,Q$q'Awr   c                 .    |\  }}}||d<   ||d<   g |d d  y )Nr   r   r   )rI   r   	link_prev	link_next_s        r   r   zDiffBuilder.remove  s)    "'	9a 	! 	!ar   c              #   Z   K   | j                   }|d   }||ur|d    |d   }||ury y wNr      r   )rI   startr   currs       r   	iter_fromzDiffBuilder.iter_from  s<     {{Qx$q'M7D $   &++c              #   Z   K   | j                   }|d   }||ur|d    |d   }||ury y wr   r   )rI   r   r   s      r   r   zDiffBuilder.__iter__  s<     {{Aw$q'M7D $r   c              #     K   | j                   }|d   }||ur|d   |ur|d   |d   d   }}|j                  |j                  k(  rkt        |      t        k(  rYt        |      t        k(  rGt        d|j                  |j                  d   d| j                        j                   |d   d   }|d   j                   |d   }||ury y w)Nr   r   r   r,   r   r0   )r   rE   r   rj   r}   r   rH   r1   )rI   r   r   op_first	op_seconds        r   r   zDiffBuilder.execute  s     {{Aw$Awd"&*1gtAwqz)$$	(:(::X/9Y<7*' ) 2 2!*!4!4W!=, $(#3#3	5 6?Y	?
  71:Dq'###7D $s   CCCc                    | j                  |t              }||d   }t        |j                        t        k(  rSt        |      t        k(  rA| j                  |      D ]-  }|j                  |j                  |j                        |_        / | j                  |       |j                  t        ||      k7  rAt        d|j                  t        ||      d| j                        }| j                  |       y y t        dt        ||      |d| j                        }| j                  |      }| j                  ||t                y )Nr   r   r   r   rC   r0   r   r   )r   
_ST_REMOVEr   r!   rc   r   rw   rC   r   rE   
_path_joinr   r1   r   r}   r   _ST_ADD)	rI   rC   r!   itemr   r   vnew_op	new_indexs	            r   _item_addedzDiffBuilder._item_added  s"   j1qBBFF|s"tCyC'7. @A..rww?BF@ KK{{js33& KK&tS1(  $//	1
 F# 4 ""4-#  ++	-F
 F+IT9g6r   c                    t        dt        ||      d| j                        }| j                  |t              }| j                  |      }||d   }|j                  j                  | j                        d   }t        |      t        k(  rA| j                  |      D ]-  }	|	j                  |j                  |j                        |_        / | j                  |       |j                   |j                   k7  r5t#        d|j                   |j                   d| j                        }||d<   y | j                  |       y | j%                  ||t&               y )Nr   r   r0   r   r   r   r  )rj   r  r1   r   r	  r   rF   rl   r   r   r&   r   ry   rC   r!   r   rE   r   r   r  )
rI   rC   r!   r
  r  r   r  r   
added_itemr  s
             r   _item_removedzDiffBuilder._item_removed5  s,    tS)"
 '') g.KK'	qB
 ++DLL9!<JJ4'. =A^^BGGRVV<BF= KK"++-& "OOKK(  $//	1
  &	! I& T9j9r   c           	      l    | j                  t        dt        ||      |d| j                               y )Nr   r   r0   )r   r   r  r1   )rI   rC   r!   r
  s       r   _item_replacedzDiffBuilder._item_replacedV  s6    $tS)&
 ''	) 	*r   c                 \   t        |j                               }t        |j                               }||z
  }||z
  }|D ]!  }| j                  |t        |      ||          # |D ]!  }| j	                  |t        |      ||          # ||z  D ]  }| j                  ||||   ||           y rP   )setkeysr  rf   r  r   )	rI   rC   r=   r>   src_keysdst_keys
added_keysremoved_keysr!   s	            r   _compare_dictszDiffBuilder._compare_dicts]  s    sxxz?sxxz?(
(* 	9CtSXs3x8	9  	7CT3s8SX6	7 h& 	@C  sCHc#h?	@r   c                 T   t        |      t        |      }}t        ||      }t        ||      }t        |      D ]  }||k  r||   ||   }
}	|	|
k(  rt	        |	t
              r.t	        |
t
              r| j                  t        ||      |	|
       Vt	        |	t              r.t	        |
t              r| j                  t        ||      |	|
       | j                  |||	       | j                  |||
       ||kD  r| j                  ||||          | j                  ||||           y rP   )r   maxminr   r2   r	   r  r  r
   _compare_listsr  r  )rI   rC   r=   r>   len_srclen_dstmax_lenmin_lenr!   oldnews              r   r  zDiffBuilder._compare_listsl  s   s8SXgw'gw'> 	6CW}s8SXS#:^4sN3''
4(=sCH_5"38''
4(=sCH &&tS#6$$T347"""4#c(;   sCH5-	6r   c                 j   t        |t              r.t        |t              r| j                  t        ||      ||       y t        |t              r.t        |t              r| j                  t        ||      ||       y | j                  |      | j                  |      k(  ry | j                  |||       y rP   )r2   r	   r  r  r
   r  r   r  )rI   rC   r!   r=   r>   s        r   r   zDiffBuilder._compare_values  s    c>*3/
4 5sC@_-30
4 5sC@ ZZ_

3/ c3/r   N)r   r   r   r   r   r   rK   r   r   r   r   r   r   r   r  r  r  r  r  r   r   r   r   r   r     sS    /3zz{ %?-(72:B*@680r   r   c                 l    || S | dz   t        |      j                  dd      j                  dd      z   S )Nr^   ~z~0z~1)rf   r   ru   s     r   r  r    s9    
{#:C((d3;;CFFFr   )5r   
__future__r   r$   r   	functoolsr   syscollections.abcr   ImportErrortypesr   r(   jsonpointerr   r   r	  r  r	   r
   unicoderf   
__author____version____website____license__version_infobytesr3   	Exceptionr   r   r   AssertionErrorr   r-   partialr   r   r:   r?   objectrA   rj   r}   r   r   r   r   r4   r   r  r   r   r   <module>r;     s  B & '     
%(&
 : 
? 0
@$ vJ$ $7) 7* $,n $  YtzzYG
 &+ %&P &1 B03/V 3/ln D1> 1h'~ 'TSN SlN 6N 2M< M<`T0& T0nGe  %$$%
    ;
Cs3   D D- D; D*)D*-D87D8;EE