a
    “˜ëjRt  ã                   @   s  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zddlm	Z	 W n e
yf   ddlm	Z	 Y n0 zddlmZ W n e
yŽ   eZY n0 ddlmZmZ dZdZzddlmZmZ W n& e
yâ   ddlmZmZ eZY n0 d	Zd
ZdZdZejdk�reefZG dd„ deƒZG dd„ deƒZ G dd„ deƒZ!G dd„ dee"ƒZ#dd„ Z$ej%ej&e$d�Z'defdd„Z(efdd„Z)G dd„ de*ƒZ+G d d!„ d!e+ƒZ,G d"d#„ d#e+ƒZ-G d$d%„ d%e+ƒZ.G d&d'„ d'e+ƒZ/G d(d)„ d)e+ƒZ0G d*d+„ d+e+ƒZ1G d,d-„ d-e*ƒZ2G d.d/„ d/e*ƒZ3d0d1„ Z4dS )2z 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                   @   s   e Zd ZdZdS )ÚJsonPatchExceptionzBase Json Patch exceptionN©Ú__name__Ú
__module__Ú__qualname__Ú__doc__© r   r   úH/mnt/bigstor/www/usecases/.venv/lib/python3.9/site-packages/jsonpatch.pyr   P   s   r   c                   @   s   e Zd ZdZdS )ÚInvalidJsonPatchz, Raised if an invalid JSON Patch is created Nr   r   r   r   r   r   T   s   r   c                   @   s   e Zd ZdZdS )Ú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   c                   @   s   e Zd ZdZdS )ÚJsonPatchTestFailedz A Test operation failed Nr   r   r   r   r   r   a   s   r   c                 C   s<   t  t¡}| D ]\}}||  |¡ qtdd„ | ¡ D ƒƒS )z'Convert duplicate keys values to lists.c                 s   s.   | ]&\}}|t |ƒd kr |d n|fV  qdS )r   r   N)Úlen)Ú.0ÚkeyÚvaluesr   r   r   Ú	<genexpr>l   s   ÿzmultidict.<locals>.<genexpr>)ÚcollectionsÚdefaultdictÚlistÚappendÚdictÚitems)Zordered_pairsZmdictr   Úvaluer   r   r   Ú	multidicte   s    
ýr"   )Úobject_pairs_hookFc                 C   s2   t |tƒrtj||d�}nt||d�}| | |¡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_placer%   r   r   r   Úapply_patchx   s    !
r.   c                 C   s   t j| ||d�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
    r$   )r(   Ú	from_diff)ÚsrcÚdstr%   r   r   r   Ú
make_patch    s    r2   c                   @   sb   e Zd ZdZefdd„Zdd„ Zdd„ Zdd	„ Zd
d„ Z	e
dd„ ƒZe
dd„ ƒZejdd„ ƒZdS )ÚPatchOperationz'A single operation inside a JSON Patch.c              
   C   s”   || _ | d¡stdƒ‚t|d | j ƒr@|d j| _|d | _nJ|d | _z|   | j¡| _W n, tyˆ } ztdƒ‚W Y d }~n
d }~0 0 || _d S )NÚpathz#Operation must have a 'path' memberzInvalid 'path')	r%   Ú__contains__r   r&   r4   ÚlocationÚpointerÚ	TypeErrorÚ	operation)Úselfr9   r%   Úexr   r   r   Ú__init__»   s    

zPatchOperation.__init__c                 C   s   t dƒ‚dS )zGAbstract method that applies a patch operation to the specified object.z%should implement the patch operation.N)ÚNotImplementedError)r:   Úobjr   r   r   r*   Í   s    zPatchOperation.applyc                 C   s   t t| j ¡ ƒƒS ©N)ÚhashÚ	frozensetr9   r    ©r:   r   r   r   Ú__hash__Ñ   s    zPatchOperation.__hash__c                 C   s   t |tƒsdS | j|jkS ©NF)r&   r3   r9   ©r:   Úotherr   r   r   Ú__eq__Ô   s    
zPatchOperation.__eq__c                 C   s
   | |k S r?   r   rE   r   r   r   Ú__ne__Ù   s    zPatchOperation.__ne__c                 C   s   d  | jjd d… ¡S )Nú/éÿÿÿÿ)Újoinr7   ÚpartsrB   r   r   r   r4   Ü   s    zPatchOperation.pathc                 C   s6   zt | jjd ƒW S  ty0   | jjd  Y S 0 d S )NrJ   )Úintr7   rL   Ú
ValueErrorrB   r   r   r   r   à   s    zPatchOperation.keyc                 C   s*   t |ƒ| jjd< | jj| _| j| jd< d S )NrJ   r4   )Ústrr7   rL   r4   r6   r9   )r:   r!   r   r   r   r   ç   s    
N)r   r   r   r   r   r<   r*   rC   rG   rH   Úpropertyr4   r   Úsetterr   r   r   r   r3   ¸   s   

r3   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚRemoveOperationz/Removes an object property or an array element.c              
   C   s|   | j  |¡\}}t|tƒr2t|tƒs2td |¡ƒ‚z
||= W n: ttfyv } zd |¡}t	|ƒ‚W Y d }~n
d }~0 0 |S )Nzinvalid array index '{0}'z(can't remove a non-existent object '{0}')
r7   Úto_lastr&   r   rM   r   ÚformatÚKeyErrorÚ
IndexErrorr   )r:   r>   ÚsubobjÚpartr;   Úmsgr   r   r   r*   ñ   s    

zRemoveOperation.applyc                 C   s0   | j |kr,| j|kr$|  jd7  _n|d8 }|S ©Nr   ©r4   r   ©r:   r4   r   r   r   r   Ú_on_undo_removeÿ   s
    

zRemoveOperation._on_undo_removec                 C   s0   | j |kr,| j|kr$|  jd8  _n|d8 }|S rZ   r[   r\   r   r   r   Ú_on_undo_add  s
    

zRemoveOperation._on_undo_addN©r   r   r   r   r*   r]   r^   r   r   r   r   rR   î   s   rR   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚAddOperationz,Adds an object property or an array element.c              
   C   sê   z| j d }W n, ty: } ztdƒ‚W Y d }~n
d }~0 0 | j |¡\}}t|tƒr–|dkrj| |¡ qæ|t|ƒks~|dk rˆt	dƒ‚qæ| 
||¡ nPt|tƒr¸|d u r®|}qæ|||< n.|d u rÔtd t|ƒ¡ƒ‚nt	d | j|¡ƒ‚|S )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})r9   rU   r   r7   rS   r&   r	   r   r   r   Úinsertr   r8   rT   Útyper6   )r:   r>   r!   r;   rW   rX   r   r   r   r*     s*    ÿ



zAddOperation.applyc                 C   s0   | j |kr,| j|kr$|  jd7  _n|d7 }|S rZ   r[   r\   r   r   r   r]   3  s
    

zAddOperation._on_undo_removec                 C   s0   | j |kr,| j|kr$|  jd8  _n|d7 }|S rZ   r[   r\   r   r   r   r^   ;  s
    

zAddOperation._on_undo_addNr_   r   r   r   r   r`     s    r`   c                   @   s(   e Zd ZdZdd„ Zdd„ Zdd„ ZdS )	ÚReplaceOperationz?Replaces an object property or an array element by a new value.c              
   C   sð   z| j d }W n, ty: } ztdƒ‚W Y d }~n
d }~0 0 | j |¡\}}|d u rX|S |dkrhtdƒ‚t|tƒr�|t|ƒks†|dk rätdƒ‚nTt|t	ƒr¶||vräd 
|¡}t|ƒ‚n.|d u rÒtd 
t|ƒ¡ƒ‚ntd	 
| j|¡ƒ‚|||< |S )
Nr!   ra   rb   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}'rc   rd   )r9   rU   r   r7   rS   r&   r	   r   r   r   rT   r8   rf   r6   )r:   r>   r!   r;   rW   rX   rY   r   r   r   r*   G  s.    ÿ




zReplaceOperation.applyc                 C   s   |S r?   r   r\   r   r   r   r]   g  s    z ReplaceOperation._on_undo_removec                 C   s   |S r?   r   r\   r   r   r   r^   j  s    zReplaceOperation._on_undo_addNr_   r   r   r   r   rg   D  s    rg   c                   @   sN   e Zd ZdZdd„ Zedd„ ƒZedd„ ƒZejdd„ ƒZd	d
„ Z	dd„ Z
dS )ÚMoveOperationz?Moves an object property or an array element to a new location.c              
   C   s  z2t | jd | jƒr | jd }n|  | jd ¡}W n, ty^ } ztdƒ‚W Y d }~n
d }~0 0 | |¡\}}z|| }W n4 ttfy® } ztt|ƒƒ‚W Y d }~n
d }~0 0 | j	|kr¾|S t |t
ƒrÜ| j	 |¡rÜtdƒ‚td| jd dœ| jd� |¡}td| j|dœ| jd� |¡}|S )	NÚfromú.The operation does not contain a 'from' memberz*Cannot move values into their own childrenÚremove©Úopr4   r$   Úadd©rm   r4   r!   )r&   r9   r%   rU   r   rS   rV   r   rO   r7   r   ÚcontainsrR   r*   r`   r6   ©r:   r>   Úfrom_ptrr;   rW   rX   r!   r   r   r   r*   q  sJ    ÿ"


ÿþýýýüüzMoveOperation.applyc                 C   s$   |   | jd ¡}d |jd d… ¡S )Nri   rI   rJ   )r%   r9   rK   rL   ©r:   rr   r   r   r   Ú	from_path–  s    zMoveOperation.from_pathc                 C   sB   |   | jd ¡}zt|jd ƒW S  ty<   |jd  Y S 0 d S ©Nri   rJ   )r%   r9   rM   rL   r8   rs   r   r   r   Úfrom_key›  s
    zMoveOperation.from_keyc                 C   s.   |   | jd ¡}t|ƒ|jd< |j| jd< d S ru   )r%   r9   rO   rL   r4   )r:   r!   rr   r   r   r   rv   £  s    c                 C   s\   | j |kr,| j|kr$|  jd7  _n|d8 }| j|krX| j|krP|  jd7  _n|d7 }|S rZ   ©rt   rv   r4   r   r\   r   r   r   r]   ©  s    



zMoveOperation._on_undo_removec                 C   s\   | j |kr,| j|kr$|  jd8  _n|d8 }| j|krX| j|krP|  jd8  _n|d7 }|S rZ   rw   r\   r   r   r   r^   ¶  s    



zMoveOperation._on_undo_addN)r   r   r   r   r*   rP   rt   rv   rQ   r]   r^   r   r   r   r   rh   n  s   %


rh   c                   @   s   e Zd ZdZdd„ ZdS )ÚTestOperationz!Test value by specified location.c              
   C   sÊ   z0| j  |¡\}}|d u r |}n| j  ||¡}W n0 ty` } ztt|ƒƒ‚W Y d }~n
d }~0 0 z| jd }W n, tyœ } ztdƒ‚W Y d }~n
d }~0 0 ||krÆd}t| 	|t
|ƒ|t
|ƒ¡ƒ‚|S )Nr!   ra   z0{0} ({1}) is not equal to tested value {2} ({3}))r7   rS   Úwalkr   r   rO   r9   rU   r   rT   rf   )r:   r>   rW   rX   Úvalr;   r!   rY   r   r   r   r*   Ç  s&    "ÿÿzTestOperation.applyN©r   r   r   r   r*   r   r   r   r   rx   Ä  s   rx   c                   @   s   e Zd ZdZdd„ ZdS )ÚCopyOperationzA Copies an object property or an array element to a new location c              
   C   sº   z|   | jd ¡}W n, ty@ } ztdƒ‚W Y d }~n
d }~0 0 | |¡\}}zt || ¡}W n4 ttfy– } ztt	|ƒƒ‚W Y d }~n
d }~0 0 t
d| j|dœ| j d� |¡}|S )Nri   rj   rn   ro   r$   )r%   r9   rU   r   rS   ÚcopyÚdeepcopyrV   r   rO   r`   r6   r*   rq   r   r   r   r*   â  s*    ÿ"ýüüzCopyOperation.applyNr{   r   r   r   r   r|   ß  s   r|   c                   @   sÂ   e Zd ZeejƒZeeƒZe	e
eeeeedœƒZefdd„Zdd„ Zdd„ ZeZdd	„ Zd
d„ Zdd„ Zdd„ Zedefdd„ƒZeddefdd„ƒZddd„Zedd„ ƒZd dd„Z dd„ Z!dS )!r(   )rk   rn   ÚreplaceÚmoveÚtestr}   c                 C   s8   || _ || _| j D ] }t|tƒr(tdƒ‚|  |¡ qd S )NzMDocument is expected to be sequence of operations, got a sequence of strings.)r,   r%   r&   r'   r   Ú_get_operation)r:   r,   r%   rm   r   r   r   r<   2  s    


zJsonPatch.__init__c                 C   s   |   ¡ S )zstr(self) -> self.to_string())Ú	to_stringrB   r   r   r   Ú__str__J  s    zJsonPatch.__str__c                 C   s
   t | jƒS r?   )Úboolr,   rB   r   r   r   Ú__bool__N  s    zJsonPatch.__bool__c                 C   s
   t | jƒS r?   )Úiterr,   rB   r   r   r   Ú__iter__S  s    zJsonPatch.__iter__c                 C   s   t t| jƒƒS r?   )r@   ÚtupleÚ_opsrB   r   r   r   rC   V  s    zJsonPatch.__hash__c                 C   s   t |tƒsdS | j|jkS rD   )r&   r(   rŠ   rE   r   r   r   rG   Y  s    
zJsonPatch.__eq__c                 C   s
   | |k S r?   r   rE   r   r   r   rH   ^  s    zJsonPatch.__ne__Nc                 C   s   |p| j }||ƒ}| ||d�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.
        r$   )Újson_loader)ÚclsZ	patch_strÚloadsr%   r‹   r,   r   r   r   r)   a  s    
zJsonPatch.from_stringTc           	      C   sB   |p| j }t||||d�}| dd||¡ t| ¡ ƒ}| ||d�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
        r$   Ú N)Újson_dumperÚDiffBuilderÚ_compare_valuesr   Úexecute)	rŒ   r0   r1   ÚoptimizationÚdumpsr%   r�   ZbuilderÚopsr   r   r   r/   u  s
    
zJsonPatch.from_diffc                 C   s   |p| j }|| jƒS )z!Returns patch set as JSON string.)r�   r,   )r:   r”   r�   r   r   r   rƒ   š  s    
zJsonPatch.to_stringc                 C   s   t t| j| jƒƒS r?   )r‰   Úmapr‚   r,   rB   r   r   r   rŠ   Ÿ  s    zJsonPatch._opsFc                 C   s(   |st  |¡}| jD ]}| |¡}q|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Š   r*   )r:   r>   r-   r9   r   r   r   r*   £  s
    

zJsonPatch.applyc                 C   sZ   d|vrt dƒ‚|d }t|tƒs*t dƒ‚|| jvrBt d |¡ƒ‚| j| }||| jd�S )Nrm   z&Operation does not contain 'op' memberzOperation's op must be a stringzUnknown operation {0!r}r$   )r   r&   r'   Ú
operationsrT   r%   )r:   r9   rm   rŒ   r   r   r   r‚   ¸  s    


zJsonPatch._get_operation)N)F)"r   r   r   ÚstaticmethodÚjsonr”   r�   Ú
_jsonloadsr‹   r   rR   r`   rg   rh   rx   r|   r—   r   r<   r„   r†   Ú__nonzero__rˆ   rC   rG   rH   Úclassmethodr)   r/   rƒ   rP   rŠ   r*   r‚   r   r   r   r   r(   ø  s:   
ú6þ$


r(   c                   @   s„   e Zd Zejefdd„Zdd„ Zdd„ Zdd„ Z	d	d
„ Z
dd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ Zdd„ ZdS )r�   c                 C   sL   || _ || _i i g| _g g g| _g  | _}|| _|| _||d g|d d …< d S r?   )r”   r%   Úindex_storageÚindex_storage2Ú_DiffBuilder__rootÚsrc_docÚdst_doc)r:   r    r¡   r”   r%   Úrootr   r   r   r<   Ê  s    


zDiffBuilder.__init__c                 C   sr   |t |ƒf}z:| j| }| |¡}|d u r6|g||< n||  |¡ W n& tyl   | j|  ||f¡ Y n0 d S r?   )rf   r�   Úgetr   r8   rž   )r:   r!   ÚindexÚstÚ	typed_keyÚstorageÚstoredr   r   r   Ústore_indexÔ  s    

zDiffBuilder.store_indexc                 C   s�   |t |ƒf}z"| j|  |¡}|r,| ¡ W S W n\ tyŠ   | j| }tt|ƒd ddƒD ]*}|| d |krZ| |¡d    Y S qZY n0 d S )Nr   rJ   r   )rf   r�   r£   Úpopr8   rž   Úranger   )r:   r!   r¥   r¦   r¨   r§   Úir   r   r   Ú
take_indexá  s    
zDiffBuilder.take_indexc                 C   s,   | j }|d }|||g |d< |d< |d S )Nr   r   ©rŸ   )r:   rm   r¢   Úlastr   r   r   re   î  s    zDiffBuilder.insertc                 C   s*   |\}}}||d< ||d< g |d d …< d S )Nr   r   r   )r:   r¤   Z	link_prevZ	link_nextÚ_r   r   r   rk   ô  s    
zDiffBuilder.removec                 c   s.   | j }|d }||ur*|d V  |d }qd S ©Nr   é   r®   )r:   Ústartr¢   Úcurrr   r   r   Ú	iter_fromú  s
    
zDiffBuilder.iter_fromc                 c   s.   | j }|d }||ur*|d V  |d }qd S r±   r®   )r:   r¢   r´   r   r   r   rˆ     s
    
zDiffBuilder.__iter__c                 c   s¦   | j }|d }||ur¢|d |urŒ|d |d d  }}|j|jkrŒt|ƒtkrŒt|ƒtkrŒtd|j|jd dœ| jd�jV  |d d }q|d jV  |d }qd S )Nr   r²   r   r!   ro   r$   )rŸ   r6   rf   rR   r`   rg   r9   r%   )r:   r¢   r´   Zop_firstZ	op_secondr   r   r   r’     s*    
ÿ
þýü
zDiffBuilder.executec           	      C   sÔ   |   |t¡}|d urœ|d }t|jƒtkrXt|ƒtkrX|  |¡D ]}| |j|j¡|_q@|  |¡ |j	t
||ƒkrÐtd|j	t
||ƒdœ| jd�}|  |¡ n4tdt
||ƒ|dœ| jd�}|  |¡}|  ||t¡ d S )Nr²   r€   ©rm   ri   r4   r$   rn   ro   )r­   Ú
_ST_REMOVErf   r   rM   rµ   r]   r4   rk   r6   Ú
_path_joinrh   r%   re   r`   r©   Ú_ST_ADD)	r:   r4   r   Úitemr¤   rm   ÚvÚnew_opÚ	new_indexr   r   r   Ú_item_added  s2    
ýüýü
zDiffBuilder._item_addedc           
      C   sØ   t dt||ƒdœ| jd�}|  |t¡}|  |¡}|d urÆ|d }|j | j¡d }t	|ƒt
kr€|  |¡D ]}	|	 |j|j¡|_qh|  |¡ |j|jkrºtd|j|jdœ| jd�}||d< qÔ|  |¡ n|  ||t¡ d S )Nrk   rl   r$   r²   r   r€   r¶   )rR   r¸   r%   r­   r¹   re   r7   rS   r¡   rf   r   rµ   r^   r4   r   rk   r6   rh   r©   r·   )
r:   r4   r   rº   r¼   r¤   r½   rm   Z
added_itemr»   r   r   r   Ú_item_removed5  s4    þý

ýü
zDiffBuilder._item_removedc                 C   s&   |   tdt||ƒ|dœ| jd�¡ d S )Nr   ro   r$   )re   rg   r¸   r%   )r:   r4   r   rº   r   r   r   Ú_item_replacedV  s    ýüzDiffBuilder._item_replacedc           	      C   s’   t | ¡ ƒ}t | ¡ ƒ}|| }|| }|D ]}|  |t|ƒ|| ¡ q,|D ]}|  |t|ƒ|| ¡ qL||@ D ]}|  |||| || ¡ qpd S r?   )ÚsetÚkeysr¿   rO   r¾   r‘   )	r:   r4   r0   r1   Zsrc_keysZdst_keysZ
added_keysZremoved_keysr   r   r   r   Ú_compare_dicts]  s    zDiffBuilder._compare_dictsc                 C   sþ   t |ƒt |ƒ }}t||ƒ}t||ƒ}t|ƒD ]Ê}||k rÊ|| ||  }	}
|	|
krXq.qøt|	tƒr‚t|
tƒr‚|  t||ƒ|	|
¡ qøt|	tƒr¬t|
tƒr¬|  	t||ƒ|	|
¡ qø|  
|||	¡ |  |||
¡ q.||kræ|  
|||| ¡ q.|  |||| ¡ q.d S r?   )r   ÚmaxÚminr«   r&   r   rÃ   r¸   r	   Ú_compare_listsr¿   r¾   )r:   r4   r0   r1   Zlen_srcZlen_dstÚmax_lenZmin_lenr   ÚoldÚnewr   r   r   rÆ   l  s*    


ÿ
ÿzDiffBuilder._compare_listsc                 C   s~   t |tƒr*t |tƒr*|  t||ƒ||¡ nPt |tƒrTt |tƒrT|  t||ƒ||¡ n&|  |¡|  |¡krld S |  |||¡ d S r?   )r&   r   rÃ   r¸   r	   rÆ   r”   rÀ   )r:   r4   r   r0   r1   r   r   r   r‘   ˆ  s    
ÿ
ÿ	zDiffBuilder._compare_valuesN)r   r   r   r™   r”   r   r<   r©   r­   re   rk   rµ   rˆ   r’   r¾   r¿   rÀ   rÃ   rÆ   r‘   r   r   r   r   r�   È  s   
!r�   c                 C   s,   |d u r| S | d t |ƒ dd¡ dd¡ S )NrI   ú~z~0z~1)rO   r   r[   r   r   r   r¸   Ÿ  s    r¸   )5r   Ú
__future__r   r   r}   Ú	functoolsr™   ÚsysÚcollections.abcr   ÚImportErrorÚtypesr   r   Zjsonpointerr   r   r¹   r·   r   r	   ÚunicoderO   Ú
__author__Ú__version__Z__website__Ú__license__Úversion_infoÚbytesr'   Ú	Exceptionr   r   r   ÚAssertionErrorr   r"   Úpartialr�   rš   r.   r2   Úobjectr3   rR   r`   rg   rh   rx   r|   r(   r�   r¸   r   r   r   r   Ú<module>!   s`   

	(6"4*V Q X