
    1jd3                        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 d dlmZ d dlmZmZmZ d dlmZmZmZmZmZmZ deeeef      fdZd	 Zd
 Zd'dZdefdZd Zd Z d Z!d Z"dedefdZ# G d de$      Z% e%       Z&dedefdZ'd(dede(fdZ)	 d'de	eef   dee   de(deeee*f      fd Z+e+dfd!edee   d"e
e   dedef
d#Z,d$ Z-d% Z.d!edefd&Z/y))    )deepcopy)fnmatchcase)SequenceTupleIteratorAnyUnionOptionalMutableMappingMutableSequence)options)InvalidGlobInvalidKeyNamePathNotFound)PathSegmentCreatorHintsGlobPathSymmetricIntreturnc                      	 t         j                               S # t        $ rO 	 t        t	                     }t         fd|      }t        |       cY S # t        $ r t        g       cY cY S w xY ww xY w)a  
    Returns an iterator which yields tuple pairs of (node index, node value), regardless of node type.

    * For dict nodes `node.items()` will be returned.
    * For sequence nodes (lists/tuples/etc.) a zip between index number and index value will be returned.
    * Edge cases will result in an empty iterator being returned.

    make_walkable(node) -> (generator -> (key, value))
    c                 .    t        | t                    S N)r   len)inodes    .lib/python3.12/site-packages/dpath/segments.py<lambda>zmake_walkable.<locals>.<lambda>   s    LCI$>     )	iteritemsAttributeErrorranger   mapzip	TypeError	enumerate)r   indicess   ` r   make_walkabler*   
   sp    !DJJL!! 
!		!CI&G>HGw%% 	! R= 		!
!s,    	A4.AA4A0+A4/A00A4c                 d    t         t        t        t        t        t        d      f}t        | |      S )z:
    Return True if thing is a leaf, otherwise False.
    N)bytesstrintfloatbooltype
isinstance)thingleavess     r   leafr5   #   s'     S#udDJ7FeV$$r    c                 X    	 t        |       xs t        |       dk(  S # t        $ r Y yw xY w)z\
    Same as leaf(thing), but also treats empty sequences and
    dictionaries as True.
    r   F)r5   r   r'   )r3   s    r   leafyr7   ,   s0    E{-c%jAo- s    	)) c              #   B  K   t        |       st        |       D ]F  \  }}d}	 t        |      }|'|dk(  r"t        j
                  st        d||fz          ||fz   |f H t        |       D ]  \  }}t        |||fz         D ]  }|    yy# t        $ r Y nw xY ww)z
    Yield all valid (segments, value) pairs (from a breadth-first
    search, right-to-left on sequences).

    walk(obj) -> (generator -> (segments, value))
    Nr   zREmpty string keys not allowed without dpath.options.ALLOW_EMPTY_STRING_KEYS=True: )r5   r*   r   r'   r   ALLOW_EMPTY_STRING_KEYSr   walk)objlocationkvlengthfounds         r   r;   r;   9   s      9!#& 	'DAqFQ !fk':Y:Y$ &T(0A4'8&: ; ; qd?Q&&	' "#& 	DAqaQD1 	   s(   BBA#B	BBBBsegmentsc                     | }t        |      D ]b  \  }}t        |      rt        d| d| d      t        |t              r+t        |t
              r|j                         rt        |      }||   }d |S )z^
    Return the value at the path indicated by segments.

    get(obj, segments) -> value
    Path: [])r(   r5   r   r2   r   r-   	isdecimalr.   )r<   rB   currentr   segments        r   getrJ   T   sz     G) #
7=z1#Q788gx(Z-E'J[J[J]'lG'"# Nr    c                 ,    	 t        | |       y#  Y yxY w)zl
    Return True if the path exists in the obj. Otherwise return False.

    has(obj, segments) -> bool
    TF)rJ   )r<   rB   s     r   hasrL   f   s    Cs    c              #   6   K   d}| D ]  }|dz  }| d|   yw)z
    Yield a tuple of segments for each possible length of segments.
    Starting from the shortest length of segments and increasing by 1.

    expand(keys) -> (..., keys[:-2], keys[:-1])
    r      Nr8   )rB   index_s      r   expandrQ   s   s2      E 
vs   c           
          g }t        |      D ]+  }|j                  |d   t        t        | |            f       - t	        |      S )z
    For each segment produce a tuple of (segment, type(value)).

    types(obj, segments) -> ((segment[0], type0), (segment[1], type1), ...)
    )rQ   appendr1   rJ   tuple)r<   rB   resultdepths       r   typesrX      sG     F! :uRy$s3"789:=r    c                 .    t        d t        |             S )zi
    Yield all leaves as (segment, value) pairs.

    leaves(obj) -> (generator -> (segment, value))
    c                     t        | d         S )NrN   )r7   )ps    r   r   zleaves.<locals>.<lambda>   s    E!A$K r    )filterr;   )r<   s    r   r4   r4      s     'c33r    rI   c                 <    t        | t              rt        |       S | S )z
    If the segment is an integer, return the string conversion.
    Otherwise return the segment unchanged. The conversion uses 'str'.

    int_str(segment) -> str
    )r2   r.   r-   )rI   s    r   int_strr^      s     '37|Nr    c                       e Zd ZdZy)Starzj
    Used to create a global STAR symbol for tracking stars added when
    expanding star-star globs.
    N)__name__
__module____qualname____doc__r8   r    r   r`   r`      s     	r    r`   globc                 J   t        |       } t        |      }t        |       }t        |      }|}d|v rf|j                  d      }d||dz   d v rt        d|       ||k\  r"t        f||z
  dz   z  }|d| |z   ||dz   d z   }n||dz
  k(  r|d| ||dz   d z   }|t        |      k(  rct        | |      }|D ]Q  \  }}	|	t        u rt        |t              rd}	nd}		 t        |t              r|t        |	      k(  rC	 t        ||	      s yS yy#  t        |      }Y "xY w#  Y  yxY w)	a  
    Return True if the segments match the given glob, otherwise False.

    For the purposes of matching, integers are converted to their string
    equivalent (via str(segment)). This conversion happens on both the
    segments and the glob. This implies you cannot (with this function)
    differentiate a list index 0 from a dictionary key '0'.

    Star-star segments are a special case in that they will expand to 0
    or more star segments and the type will be coerced to match that of
    the segment.

    A segment is considered to match a glob if the function
    fnmatch.fnmatchcase returns True. If fnmatchcase returns False or
    throws an exception the result will be False.

    match(segments, glob) -> bool
    z**rN   Nz3Invalid glob. Only one '**' is permitted per glob:    **FT)rU   r   rO   r   STARr&   r2   r,   r.   r-   r   )
rB   re   path_lenglob_lenss_globss
more_starsr   sgs
             r   matchrq      sz   & XH;D8}H4yH Gt|ZZ4Q=  STXSYZ[[
 x Hx$7!$;<J3Bi*,tBFG}<GA% 3Bi$rAvw-/G 3w<'" 	DAq Dya'AA a%!s1v+ #1a(  )/	:  ' Fs   D9DDD"Nr3   rO   c                     	  t        |              }|dz   t        |       z
  }t        |      D ]  }||gz  }
 | j                  |       | S # t        $ r Y | S w xY w)z
    Extend a sequence like thing such that it contains at least index +
    1 many elements. The extension values will be None (default).

    extend(thing, int) -> [thing..., None, ...]
    rN   )r1   r   r$   extendr'   )r3   rO   value	expansionextrar   s         r   rs   rs     su    DKM	 c%j(u 	!A% I	!Y L   	Ls   AA 	AArH   r   hintsc                 l   ||   }t        |      }t        | t              rt        |      }t        | t              rt        | |       |t        |      k  r ||   d          | |<   y|dz   |k  r	||dz      }nd}t        |t              s t        |t              r|j                         rg | |<   yi | |<   y)z
    Create missing path components. If the segment is an int, then it will
    create a list. Otherwise a dictionary is created.

    set(obj, segments, value) -> obj
    rN   N)r   r2   r   r.   r   rs   r-   rG   )rH   rB   r   rw   rI   r@   segment_nexts          r   _default_creatorrz     s     qkG]F'8$g,'?+w  	3u:~&58A;= q56>#AE?LLlC(Zc-J|OeOeOg!GG!GGr    r<   creatorc                    | }t        |      }t        |dd       D ]q  \  }}t        |t              r+t        |t              r|j                         rt        |      }	 ||    ||   }||dz
  k7  sUt        |      sat        d| d| d       |d   }	t        |	t              r+t        |t              r|	j                         rt        |	      }	t        |	t              rt        ||	       |||	<   | S #  | |||||       n Y xY w)z
    Set the value in obj at the place indicated by segments. If creator is not
    None (default _default_creator), then call the creator function to
    create any missing path components.

    set(obj, segments, value) -> obj
    NrS   rN   rD   rE   rF   )
r   r(   r2   r-   r   rG   r.   r5   r   rs   )
r<   rB   rt   r{   rw   rH   r@   r   rI   last_segments
             r   setr~   C  s    G]F "(3B-0 9G gs#
7H(E'J[J[J]'lG
	
 G '"
?tG}z1#Q788)9, B<L ,$GX)F<KaKaKc<(,$w%!GLJ+	"1e4 5s   C33Dc                 D    t        |       D ]  } || ||      du s |S  |S )a  
    Walk obj applying f to each path and returning accumulator acc.

    The function f will be called, for each result in walk(obj):

        f(obj, (segments, value), acc)

    If the function f returns False (exactly False), then processing
    will stop. Otherwise processing will continue with the next value
    retrieved from the walk.

    fold(obj, f(obj, (segments, value), acc) -> bool, acc) -> acc
    F)r;   )r<   faccpairs       r   foldr   z  s7     S	 S$%J Jr    c                 Z    t        t        |             }|D ]  } || ||      du s |S  |S )z
    Same as fold(), but permits mutating obj.

    This requires all paths in walk(obj) to be loaded into memory
    (whereas fold does not).

    foldm(obj, f(obj, (segments, value), acc) -> bool, acc) -> acc
    F)rU   r;   )r<   r   r   pairsr   s        r   foldmr     sA     $s)E S$%J Jr    c                 D    fd}t        | | t        |                    S )z
    Return a view of the object where the glob matches. A view retains
    the same form as the obj, but is limited to only the paths that
    matched. Views are new objects (a deepcopy of the matching values).

    view(obj, glob) -> obj'
    c           	          |\  }}t        |      r0t        ||      s#t        ||t        |      t	        | |             y y y )N)rw   )rq   rL   r~   r   rX   )r<   r   rV   rB   rt   re   s        r   r   zview.<locals>.f  sD     54 vx(FHhuoU3=QR ) !r    )r   r1   )r<   re   r   s    ` r   viewr     s"    S Q	S	$$r    )r8   r   )0copyr   fnmatchr   typingr   r   r   r   r	   r
   r   r   dpathr   dpath.exceptionsr   r   r   dpath.typesr   r   r   r   r   r   r*   r5   r7   r;   rJ   rL   rQ   rX   r4   r^   objectr`   ri   rq   r.   rs   r1   rz   r~   r   r   r   r8   r    r   <module>r      so     c c c  F F M M!8E+s*:$;< !2%
6t $

	4	[ 	[ 		6 	 vUD U Up/ # : 57	#"~x/0#";'#" #" k4/01	#"T &644;'4 '"	4
 4 4n( %n %D %r    