Ë
    ¬Œj7)  ã                   ó¸   — d Z dZdZdZdZddlZddlZddlmZm	Z	 ddl
mZmZ  e«       Zdd	„Zefd
„Zd„ Z G d„ de«      Z G d„ d«      Z G d„ d«      Zd„ Zd„ Zy)z7 Identify specific nodes in a JSON document (RFC 6901) u    Stefan KÃ¶gl <stefan@skoegl.net>z3.1.1z2https://github.com/stefankoegl/python-json-pointerzModified BSD Licenseé    N)ÚMappingÚSequence)ÚteeÚchainc                 ó>   — t        |«      }|j                  | ||«      S )a¾  Resolves a pointer against doc and sets the value of the target within doc.

    With inplace set to true, doc is modified as long as pointer is not the
    root.

    >>> obj = {'foo': {'anArray': [ {'prop': 44}], 'another prop': {'baz': 'A string' }}}

    >>> set_pointer(obj, '/foo/anArray/0/prop', 55) ==     {'foo': {'another prop': {'baz': 'A string'}, 'anArray': [{'prop': 55}]}}
    True

    >>> set_pointer(obj, '/foo/yet another prop', 'added prop') ==     {'foo': {'another prop': {'baz': 'A string'}, 'yet another prop': 'added prop', 'anArray': [{'prop': 55}]}}
    True

    >>> obj = {'foo': {}}
    >>> set_pointer(obj, '/foo/a%20b', 'x') ==     {'foo': {'a%20b': 'x' }}
    True
    )ÚJsonPointerÚset)ÚdocÚpointerÚvalueÚinplaces       úU/var/www/html/Fitness-lenito-AI-main/venv/lib/python3.12/site-packages/jsonpointer.pyÚset_pointerr   /   s!   € ô, ˜'Ó"€GØ�;‰;�s˜E 7Ó+Ð+ó    c                 ó<   — t        |«      }|j                  | |«      S )aa   Resolves pointer against doc and returns the referenced object

    >>> obj = {'foo': {'anArray': [ {'prop': 44}], 'another prop': {'baz': 'A string' }}, 'a%20b': 1, 'c d': 2}

    >>> resolve_pointer(obj, '') == obj
    True

    >>> resolve_pointer(obj, '/foo') == obj['foo']
    True

    >>> resolve_pointer(obj, '/foo/another prop') == obj['foo']['another prop']
    True

    >>> resolve_pointer(obj, '/foo/another prop/baz') == obj['foo']['another prop']['baz']
    True

    >>> resolve_pointer(obj, '/foo/anArray/0') == obj['foo']['anArray'][0]
    True

    >>> resolve_pointer(obj, '/some/path', None) == None
    True

    >>> resolve_pointer(obj, '/a b', None) == None
    True

    >>> resolve_pointer(obj, '/a%20b') == 1
    True

    >>> resolve_pointer(obj, '/c d') == 2
    True

    >>> resolve_pointer(obj, '/c%20d', None) == None
    True
    )r   Úresolve)r
   r   Údefaults      r   Úresolve_pointerr   I   s    € ôH ˜'Ó"€GØ�?‰?˜3 Ó(Ð(r   c                 óF   — t        | «      \  }}|D ]  } n t        ||«      S )zñ Transforms a list to a list of tuples of adjacent items

    s -> (s0,s1), (s1,s2), (s2, s3), ...

    >>> list(pairwise([]))
    []

    >>> list(pairwise([1]))
    []

    >>> list(pairwise([1, 2, 3, 4]))
    [(1, 2), (2, 3), (3, 4)]
    )r   Úzip)ÚiterableÚaÚbÚ_s       r   Úpairwiser   q   s*   € ô ˆx‹=�D€A€qÛˆÙð äˆq�!‹9Ðr   c                   ó   — e Zd Zy)ÚJsonPointerExceptionN)Ú__name__Ú
__module__Ú__qualname__© r   r   r   r   …   s   „ Ør   r   c                   ó   — e Zd ZdZd„ Zd„ Zy)Ú	EndOfListz)Result of accessing element "-" of a listc                 ó   — || _         y ©N)Úlist_)Úselfr&   s     r   Ú__init__zEndOfList.__init__Œ   s	   € Øˆ�
r   c                 óv   — dj                  | j                  j                  t        | j                  «      ¬«      S )Nz{cls}({lst}))ÚclsÚlst)ÚformatÚ	__class__r   Úreprr&   ©r'   s    r   Ú__repr__zEndOfList.__repr__�   s2   € Ø×$Ñ$¨¯©×)@Ñ)@Ü)-¨d¯j©jÓ)9ð %ó ;ð 	;r   N)r   r   r    Ú__doc__r(   r0   r!   r   r   r#   r#   ‰   s   „ Ù3òó;r   r#   c                   óæ   — e Zd ZdZ ej
                  d«      Z ej
                  d«      Zd„ Zd„ Z	e
fd„ZeZdd„Zed„ «       Zd	„ Zd
„ Zd„ Zd„ Zd„ Zd„ Zed„ «       Zd„ Zd„ Zd„ Zd„ Zed„ «       Zy)r   z:A JSON Pointer that can reference parts of a JSON documentz0|[1-9][0-9]*$z(~[^01]|~$)c                 ó6  — | j                   j                  |«      }|r(t        dj                  |j	                  «       «      «      ‚|j                  d«      }|j                  d«      dk7  rt        d«      ‚|D �cg c]  }t        |«      ‘Œ }}|| _        y c c}w )NzFound invalid escape {}Ú/r   Ú zLocation must start with /)	Ú_RE_INVALID_ESCAPEÚsearchr   r,   ÚgroupÚsplitÚpopÚunescapeÚparts)r'   r   Úinvalid_escaper<   Úparts        r   r(   zJsonPointer.__init__œ   s”   € ð ×0Ñ0×7Ñ7¸Ó@ˆÙÜ&Ð'@×'GÑ'GØ×$Ñ$Ó&ó((ó )ð )ð —‘˜cÓ"ˆØ�9‰9�Q‹<˜2ÒÜ&Ð'CÓDÐDá,1Ó2©E D”˜$•¨EˆÐ2Øˆ�
ùò 3s   Á:Bc                 ó¸   — | j                   s|dfS | j                   dd D ]  }| j                  ||«      }Œ |t        j                  || j                   d   «      fS )z>Resolves ptr until the last step, returns (sub-doc, last-step)Néÿÿÿÿ)r<   Úwalkr   Úget_part©r'   r
   r>   s      r   Úto_lastzJsonPointer.to_last«   s[   € ð �zŠzØ˜�9Ðà—J‘J˜s “OˆDØ—)‘)˜C Ó&‰Cð $ð ”K×(Ñ(¨¨d¯j©j¸©nÓ=Ð=Ð=r   c                 ó†   — | j                   D ]  }	 | j                  ||«      }Œ |S # t        $ r |t        u r‚ |cY c S w xY w)zBResolves the pointer against doc and returns the referenced object)r<   rA   r   Ú_nothing)r'   r
   r   r>   s       r   r   zJsonPointer.resolve¶   sO   € ð —J”JˆDð#Ø—i‘i  TÓ*‘ð ð ˆ
øô (ò #ØœhÑ&Øà"”Nð	#ús   ‘'§A ¿A c                 ó  — t        | j                  «      dk(  r|rt        d«      ‚|S |st        j                  |«      }| j                  |«      \  }}t        |t        «      r|dk(  r|j                  |«       |S |||<   |S )zFResolve the pointer against the doc and replace the target with value.r   zCannot set root in placeÚ-)	Úlenr<   r   ÚcopyÚdeepcopyrD   Ú
isinstancer   Úappend)r'   r
   r   r   Úparentr>   s         r   r	   zJsonPointer.setÇ   s~   € ô ˆt�z‰z‹?˜aÒÙÜ*Ð+EÓFÐFØˆLáÜ—-‘- Ó$ˆCàŸ™ cÓ*‰ˆ�ä�fœhÔ'¨D°CªKØ�M‰M˜%Ô ð ˆ
ð !ˆF�4‰Làˆ
r   c                 ó   — t        |t        «      r|S t        |t        «      rH|dk(  r|S t        j                  j                  t        |«      «      st        d|z  «      ‚t        |«      S t        |d«      r|S t        dt        |«      z  «      ‚)z)Returns the next step in the correct typerH   z"'%s' is not a valid sequence indexÚ__getitem__zXDocument '%s' does not support indexing, must be mapping/sequence or support __getitem__)rL   r   r   r   Ú_RE_ARRAY_INDEXÚ	fullmatchÚstrr   ÚintÚhasattrÚtype)r*   r
   r>   s      r   rB   zJsonPointer.get_partÛ   s”   € ô �cœ7Ô#ØˆKä˜œXÔ&à�sŠ{Ø�ä×.Ñ.×8Ñ8¼¸T»ÔCÜ*Ð+OÐRVÑ+VÓWÐWä�t“9Ðä�S˜-Ô(ð ˆKô 'ð (YÜ[_Ð`cÓ[dñ(eó fð fr   c                 ó   — | j                   S )zYReturns the list of the parts. For example, JsonPointer('/a/b').get_parts() == ['a', 'b'])r<   r/   s    r   Ú	get_partszJsonPointer.get_partsõ   s   € ð �z‰zÐr   c                 ó8  — t         j                  ||«      }t        |d«      sJ dt        |«      ›�«       ‚t	        |t
        «      r|dk(  rt        |«      S 	 ||   S 	 ||   S # t        $ r t        d|›d�«      ‚w xY w# t        $ r t        d|›d|›�«      ‚w xY w)z7 Walks one step in doc and returns the referenced part rP   zinvalid document type rH   zindex 'z' is out of boundszmember 'z' not found in )
r   rB   rU   rV   rL   r   r#   Ú
IndexErrorr   ÚKeyErrorrC   s      r   rA   zJsonPointer.walkú   s°   € ô ×#Ñ# C¨Ó.ˆä�s˜MÔ*ÑUÌ$ÈsÌ)Ð,UÓUÐ*ä�cœ8Ô$Ø�sŠ{Ü  “~Ð%ðTØ˜4‘yÐ ð	TØ�t‘9Ðøô ò TÝ*ÊDÐ+RÓSÐSðTûô ò 	TÝ&ÊÉcÐ'RÓSÐSð	Tús   ÁA" ÁA> Á"A;Á>Bc                 ó`   — | j                   dt        |j                   «       |j                   k(  S )ú- Returns True if self contains the given ptr N)r<   rI   )r'   Úptrs     r   ÚcontainszJsonPointer.contains  s$   € à�z‰z˜/œ3˜sŸy™y›>Ð*¨c¯i©iÑ7Ð7r   c                 ó$   — | j                  |«      S )r]   )r_   )r'   Úitems     r   Ú__contains__zJsonPointer.__contains__  s   € à�}‰}˜TÓ"Ð"r   c                 ó   — t        |t        «      r|j                  }n(t        |t        «      rt        |«      j                  }n|}	 t        j	                  t        | j                  |«      «      S #  t        d«      ‚xY w)zD Returns a new JsonPointer with the given suffix append to this ptr zInvalid suffix)rL   r   r<   rS   Ú
from_partsr   r   )r'   ÚsuffixÚsuffix_partss      r   ÚjoinzJsonPointer.join  sh   € ä�fœkÔ*Ø!Ÿ<™<‰LÜ˜¤Ô$Ü& vÓ.×4Ñ4‰Là!ˆLð	9Ü×)Ñ)¬%°·
±
¸LÓ*IÓJÐJøð	9Ü&Ð'7Ó8Ð8ús   Á(A0 Á0A=c                 ó$   — | j                  |«      S r%   )rg   )r'   re   s     r   Ú__truediv__zJsonPointer.__truediv__'  s   € Ø�y‰y˜Ó Ð r   c                 ó€   — | j                   D �cg c]  }t        |«      ‘Œ }}dj                  d„ |D «       «      S c c}w )zwReturns the string representation of the pointer

        >>> ptr = JsonPointer('/~0/0/~1').path == '/~0/0/~1'
        r5   c              3   ó&   K  — | ]	  }d |z   –— Œ y­w©r4   Nr!   ©Ú.0r>   s     r   Ú	<genexpr>z#JsonPointer.path.<locals>.<genexpr>1  s   è ø€ Ð4©e d�s˜T•z©eùó   ‚)r<   Úescaperg   )r'   r>   r<   s      r   ÚpathzJsonPointer.path*  s:   € ð +/¯*ª*Ó5©* $”˜•¨*ˆÐ5Ø�w‰wÑ4©eÓ4Ó4Ð4ùò 6s   �;c                 óV   — t        |t        «      sy| j                  |j                  k(  S )a  Compares a pointer to another object

        Pointers can be compared by comparing their strings (or splitted
        strings), because no two different parts can point to the same
        structure in an object (eg no different number representations)
        F)rL   r   r<   )r'   Úothers     r   Ú__eq__zJsonPointer.__eq__3  s$   € ô ˜%¤Ô-Øà�z‰z˜UŸ[™[Ñ(Ð(r   c                 ó>   — t        t        | j                  «      «      S r%   )ÚhashÚtupler<   r/   s    r   Ú__hash__zJsonPointer.__hash__@  s   € Ü”E˜$Ÿ*™*Ó%Ó&Ð&r   c                 ó   — | j                   S r%   )rr   r/   s    r   Ú__str__zJsonPointer.__str__C  s   € Ø�y‰yÐr   c                 ód   — t        | «      j                  dz   t        | j                  «      z   dz   S )NÚ(Ú))rV   r   r.   rr   r/   s    r   r0   zJsonPointer.__repr__F  s)   € Ü�D‹z×"Ñ" SÑ(¬4°·	±	«?Ñ:¸SÑ@Ð@r   c                 óŽ   — |D �cg c]  }t        t        |«      «      ‘Œ }} | dj                  d„ |D «       «      «      }|S c c}w )zœConstructs a JsonPointer from a list of (unescaped) paths

        >>> JsonPointer.from_parts(['a', '~', '/', 0]).path == '/a/~0/~1/0'
        True
        r5   c              3   ó&   K  — | ]	  }d |z   –— Œ y­wrl   r!   rm   s     r   ro   z)JsonPointer.from_parts.<locals>.<genexpr>Q  s   è ø€ Ð7±¨˜# �*±ùrp   )rq   rS   rg   )r*   r<   r>   r^   s       r   rd   zJsonPointer.from_partsI  sD   € ñ 05Ó5©u t”œ˜D›	Õ"¨uˆÐ5Ù�"—'‘'Ñ7±Ó7Ó7Ó8ˆØˆ
ùò 6s   …AN©T)r   r   r    r1   ÚreÚcompilerQ   r6   r(   rD   rF   r   Úgetr	   ÚclassmethodrB   rX   rA   r_   rb   rg   ri   Úpropertyrr   ru   ry   r{   r0   rd   r!   r   r   r   r   ”   s»   „ ÙDð !�b—j‘jÐ!1Ó2€OØ#˜Ÿ™ MÓ2Ðòò	>ð $,ó ð €Cóð( ñfó ðfò2ò
Tò08ò#ò9ò!ð ñ5ó ð5ò)ò'òòAð ñó ñr   r   c                 óF   — | j                  dd«      j                  dd«      S )NÚ~ú~0r4   ú~1©Úreplace©Úss    r   rq   rq   U  s    € Ø�9‰9�S˜$Ó×'Ñ'¨¨TÓ2Ð2r   c                 óF   — | j                  dd«      j                  dd«      S )NrŠ   r4   r‰   rˆ   r‹   r�   s    r   r;   r;   Y  s    € Ø�9‰9�T˜3Ó×'Ñ'¨¨cÓ2Ð2r   r�   )r1   Ú
__author__Ú__version__Ú__website__Ú__license__rJ   r‚   Úcollections.abcr   r   Ú	itertoolsr   r   ÚobjectrF   r   r   r   Ú	Exceptionr   r#   r   rq   r;   r!   r   r   Ú<module>r˜      su   ðñ> >ð 0€
Ø€ØB€Ø$€ã Û 	ß -ß  á‹8€ó,ð4 +3ó %)òPô(	˜9ô 	÷;ñ ;÷~ñ ~òB3ó3r   