
    KiVJ              	          d Z ddlZddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ ddlm Z  ddlm!Z!  edd      Z" edd      Z# ed      Z$ ed d!"       G d# d             Z% G d$ d%e%eeeef         Z& G d& d'e&ee'e(f         Z) G d( d)e&e ee!f         Z*y)*zPathable paths module    N)Hashable)Iterator)contextmanager)	dataclass)cached_property)Path)Any)Generic)Sequence)TypeVar)cast)overload)KLookupAccessor)N)NodeAccessorPathAccessor)V)	SEPARATOR)parse_parts)	LookupKey)
LookupNode)LookupValue	TBasePathBasePath)boundTAccessorPathzAccessorPath[Any, Any, Any]TDefaultTF)frozeninitc            
       `   e Zd ZU dZeedf   ed<   eZe	ed<   ddde
de	dz  fdZeefdee
   d	e	d
eedf   fd       Ze	 d3dee   dee
   de	dz  d
efd       Ze	 d3dee   deedf   de	dz  d
dfd       Zed
ee	df   fd       Zed
eee	e	f   df   fd       Zdedee
   d
efdZdeded
efdZdedeedf   d
efdZd
e	fdZd
e	fdZed
e	fd       Zede	d
ee	e	f   fd       Zed
e	fd       Zed
ee	   fd       Z ed
e	fd       Z!eded
efd       Z"eded
eedf   fd        Z#ded!e
d
efd"Z$dede	d
efd#Z%ded$e	d
efd%Z&d!e
d
e'fd&Z(ded!e
d
efd'Z)d
e	fd(Z*d
e	fd)Z+d
e,fd*Z-ded+e
d
efd,Z.ded+ed
efd-Z/d!e
d
e'fd.Z0d!e
d
e'fd/Z1d!e
d
e'fd0Z2d!e
d
e'fd1Z3d!e
d
e'fd2Z4y)4r   z
Base path..parts	separatorNr%   argsc                    t         j                  | d|xs | j                         | j                  || j                        }t         j                  | d|       y )Nr%   sepr$   )object__setattr__r%   _parse_args)selfr%   r'   r$   s       Z/home/jay/workspace/scripts/.codegraph-venv/lib/python3.12/site-packages/pathable/paths.py__init__zBasePath.__init__*   sH    4i.I4>>J  4>> :4%0    r*   returnc                 J   g }|j                   }|j                  }|D ]  }|}t        ||       r ||j                         $t        |t              r ||j                  d             Lt        |t        j                        r=t        j                  |      }t        |t              r ||j                  d             t        |t        t        f      r	 ||       t        |t              r	 ||       t        dt        |             t        t        ||            S )zParse constructor arguments into canonical parts.

        Subclasses may override this class method to customize parsing rules
        (e.g. accepted part types) while preserving the public constructor
        behavior.
        asciiz@argument must be Hashable, bytes, os.PathLike, or BasePath; got )appendextend
isinstancer$   bytesdecodeosPathLikefspathstrintr   	TypeErrortypetupler   )clsr'   r*   r$   r5   r6   argparts           r/   r-   zBasePath._parse_args/   s     !# 	CD$$tzz"$&t{{7+,$,yydE*4;;w/0$c
+t$)t:  3	: [,--r1   rB   c                      | |d|iS )Nr%    )rB   r'   r%   s      r/   _from_partszBasePath._from_parts^   s     D.I..r1   r   c                     | j                  |       }t        j                  |d|       t        j                  |d|xs |j                         |S )Nr$   r%   )__new__r+   r,   r%   )rB   r$   r%   instances       r/   _from_parsed_partszBasePath._from_parsed_partsf   sK     ;;s#8We4k9#B0B0B	
 r1   c                 :    t        d | j                  D              S )Nc              3   2   K   | ]  }t        |        y wNr=   .0ps     r/   	<genexpr>z#BasePath._cparts.<locals>.<genexpr>v   s     0SV0   )rA   r$   r.   s    r/   _cpartszBasePath._cpartss   s     0TZZ000r1   c                 f    t        d t        | j                  | j                  d      D              S )a  Stable, type-aware comparison key for ordering.

        We include a fully-qualified type identifier so that e.g. `0` and "0"
        compare deterministically without being considered equal, and so that
        similarly-named types from different modules do not collide.
        c              3      K   | ]6  \  }}t        |      j                   d t        |      j                   |f 8 yw).N)r@   
__module____qualname__)rQ   rR   cs      r/   rS   z&BasePath._cmp_parts.<locals>.<genexpr>   sB      
1 Q""#1T!W%9%9$:;Q?
s   <>T)strict)rA   zipr$   rV   rU   s    r/   
_cmp_partszBasePath._cmp_partsx   s/      
DJJTB
 
 	
r1   r.   c                 |    | j                  || j                        }| j                  |z   }| j                  |      S )Nr)   )r-   r%   r$   _clone_with_parts)r.   r'   r$   parts_joineds       r/   _make_childzBasePath._make_child   s:      4>> :zzE)%%l33r1   rD   c                 D    | j                   |fz   }| j                  |      S rN   r$   ra   )r.   rD   r$   s      r/   _make_child_relpathzBasePath._make_child_relpath   s%     

dW$%%e,,r1   c                 <    | j                  || j                        S )zCreate a new instance of the same class with the given parts.

        Subclasses like `AccessorPath` require extra constructor state (e.g. accessor).
        This helper attempts to preserve that state.
        r&   )rK   r%   r.   r$   s     r/   ra   zBasePath._clone_with_parts   s     &&u&GGr1   c                     t        |       S rN   rO   rU   s    r/   
__fspath__zBasePath.__fspath__   s    4yr1   c                 F    dj                  d | j                  D              S )z2Return the path as a POSIX path (always uses '/')./c              3   2   K   | ]  }t        |        y wrN   rO   rP   s     r/   rS   z$BasePath.as_posix.<locals>.<genexpr>   s     31A3rT   )joinr$   rU   s    r/   as_posixzBasePath.as_posix   s    xx3

333r1   c                 L    | j                   syt        | j                   d         S )zFinal path component. )r$   r=   rU   s    r/   namezBasePath.name   s!     zz4::b>""r1   rs   c                 z    | dv r| dfS | j                  d      }|dk  r|dk(  rd| dd  vr| dfS | dfS | d | | |d  fS )Nrq   rY   z..rq   rY   r      )rfind)rs   dots     r/   _split_stem_suffixzBasePath._split_stem_suffix   sf     ?"8Ojjo!8axCtABx/Rx8ODSz4:%%r1   c                 B    | j                  | j                        \  }}|S )z9Final component's last suffix, including the leading dot.ry   rs   )r.   stemsuffixs      r/   r}   zBasePath.suffix   s!     ..tyy9fr1   c                     | j                   }|dv rg S |j                  d      r|dd }d|vrg S |}|j                  d      }t        |      dk  rg S |dd D cg c]  }d|z   	 c}S c c}w )z;Final component's suffixes, each including the leading dot.ru   rY   rv   N)rs   
startswithsplitlen)r.   rs   restr$   rR   s        r/   suffixeszBasePath.suffixes   s}     yy?"I??38D$	D

3u:?I!&qr+Aa+++s   A(c                 B    | j                  | j                        \  }}|S )z(Final component without its last suffix.r{   )r.   r|   _s      r/   r|   zBasePath.stem   s!     ))$))4ar1   c                 Z    | j                   s| S | j                  | j                   dd       S )zLogical parent path.Nrr   re   rU   s    r/   parentzBasePath.parent   s+     zzK%%djj"o66r1   c           	            j                   syt         fdt        dt         j                         dz         D              S )z.Logical ancestors (like pathlib's `.parents`).rF   c              3   \   K   | ]#  }j                  j                  d |         % y wrN   )ra   r$   )rQ   ir.   s     r/   rS   z#BasePath.parents.<locals>.<genexpr>   s0      
 ""4::cr?3
s   ),rv   )r$   rA   ranger   rU   s   `r/   parentszBasePath.parents   s=     zz 
1c$**o12
 
 	
r1   otherc                 6    | j                  t        |            S )z,Combine this path with one or more segments.)rc   listr.   r   s     r/   joinpathzBasePath.joinpath   s    U,,r1   c                     | j                   st        d      t        |t              st	        d      |st        d      | j
                  |v rt        d      | j                   dd |fz   }| j                  |      S )z4Return a new path with the final component replaced.z%with_name() requires a non-empty pathzname must be a strzname must be non-emptyz$name must not contain path separatorNrr   )r$   
ValueErrorr7   r=   r?   r%   ra   )r.   rs   	new_partss      r/   	with_namezBasePath.with_name   sy    zzDEE$$011566>>T!CDDJJsOtg-	%%i00r1   r}   c                    | j                   st        d      t        |t              st	        d      |r|j                  d      st        d      | j                  }|dv rt        d      | j                  |z   }| j                  |      S )z<Return a new path with the final component's suffix changed.z'with_suffix() requires a non-empty pathzsuffix must be a strrY   z#Invalid suffix; must start with '.'ru   zInvalid name for with_suffix())	r$   r   r7   r=   r?   r   rs   r|   r   )r.   r}   rs   new_names       r/   with_suffixzBasePath.with_suffix   s    zzFGG&#&233&++C0BCCyy?"=>>99v%~~h''r1   c                     | j                  || j                        }t        |      t        | j                        kD  ry| j                  dt        |       |k(  S )z/Return True if the path is relative to `other`.r)   FN)r-   r%   r   r$   r.   r   other_partss      r/   is_relative_tozBasePath.is_relative_to  sO    &&u$..&A{c$**o-zz,C,-<<r1   c                    | j                  || j                        } | j                  | s/t        | dt        j                  || j                              | j                  | j                  t        |      d       S )znReturn the relative path from `other` to self.

        Raises ValueError if self is not under other.
        r)   z is not in the subpath of r&   N)	r-   r%   r   r   r   rK   ra   r$   r   r   s      r/   relative_tozBasePath.relative_to  s    
 &&u$..&A"t""K0(4X5P5PQ\hlhvhv5P5w4z{  %%djj[1A1C&DEEr1   c                 L    | j                   j                  | j                        S rN   )r%   rn   rV   rU   s    r/   __str__zBasePath.__str__  s    ~~""4<<00r1   c                 L    | j                   j                   dt        |       dS )N())	__class____name__r=   rU   s    r/   __repr__zBasePath.__repr__  s$    ..))*!CI=::r1   c                 D    t        | j                  | j                  f      S rN   )hashr%   r$   rU   s    r/   __hash__zBasePath.__hash__  s    T^^TZZ011r1   keyc                 R    	 | j                  |g      S # t        $ r	 t        cY S w xY wrN   )rc   r?   NotImplementedr.   r   s     r/   __truediv__zBasePath.__truediv__  s9    	"## 
  	"!!	"s    &&c                     	 | j                  |f| j                  z   | j                        S # t        $ r	 t        cY S w xY w)Nr&   )rG   r$   r%   r?   r   r   s     r/   __rtruediv__zBasePath.__rtruediv__'  sJ    	"###t~~ $    	"!!	"s   *- ??c                     t        |t              st        S | j                  | j                  f|j                  |j                  fk(  S rN   )r7   r   r   r%   r$   r   s     r/   __eq__zBasePath.__eq__/  s7    %*!!

+/MMMr1   c                     t        |t              st        S | j                  | j                  f|j                  |j                  fk  S rN   r7   r   r   r%   r_   r   s     r/   __lt__zBasePath.__lt__4  A    %*!!0OO4
 
 	
r1   c                     t        |t              st        S | j                  | j                  f|j                  |j                  fk  S rN   r   r   s     r/   __le__zBasePath.__le__<  A    %*!!0OO5
 
 	
r1   c                     t        |t              st        S | j                  | j                  f|j                  |j                  fkD  S rN   r   r   s     r/   __gt__zBasePath.__gt__D  r   r1   c                     t        |t              st        S | j                  | j                  f|j                  |j                  fk\  S rN   r   r   s     r/   __ge__zBasePath.__ge__L  r   r1   rN   )5r   rZ   r[   __doc__rA   r   __annotations__r   r%   r=   r	   r0   classmethodr   r-   r@   r   rG   rK   r   rV   r_   r   rc   rf   ra   rj   ro   rs   staticmethodry   r}   r   r|   r   r   r   r   r   boolr   r   r   r   r>   r   r   r   r   r   r   r   r   rF   r1   r/   r   r   #   s   3Is;? 1c 1cDj 1
  ,.sm,. ,. 
x}		,. ,.\  !%/)_/sm/ :/ 
	/ /  !%
)_
Xs]#
 :
 
	
 
 1sCx 1 1 

E%S/3"67 

 

4) 449 4 4
-) -8 -	 -HH %hm 4H	HC 4# 4 #c # # 
& 
&sCx 
& 
&   
 ,$s) , , c  
 7Y 79 7 7 
i 
E)S.$9 
 
-y -# -) -1	 1 1 1() (S (Y (=S =T =
F) 
FS 
FY 
F1 1;# ;2# 2") "# ") ""9 "8 "	 "NC ND N

C 
D 

C 
D 

C 
D 

C 
D 
r1   c                       e Zd ZU dZeedf   ed<   eeee	f   ed<   dddeeee	f   de
dedz  f fd	Ze	 	 d#d
ee   dee
   dedz  deeee	f   dz  def
d       Ze	 	 d#d
ee   deedf   dedz  deeee	f   dz  def
d       Zdedeedf   defdZdededefdZdededefdZdededefdZdedee   fdZdedede	ez  fdZdedefdZdefdZdefdZdefdZ dee   fdZ!dedeeeef      fdZ"e#dede	dz  fd       Z$e#dede%de	e%z  fd       Z$d$dede&de&fdZ$de	fd Z'de(ee
f   dz  fd!Z)e*dee	   fd"       Z+ xZ,S )%AccessorPathz-Path for object that can be read by accessor..r$   accessorNr&   r'   r%   c                R    t         j                  | d|       t        |   |d|i y )Nr   r%   )r+   r,   superr0   )r.   r   r%   r'   r   s       r/   r0   zAccessorPath.__init__[  s)     	4X6$4)4r1   rB   r2   c                 4    |t        d       | |g|d|iS )Naccessor must be providedr%   )r   )rB   r'   r%   r   s       r/   rG   zAccessorPath._from_partsd  s+     89988d8i88r1   c                     |t        d      | j                  |       }t        j                  |d|       t        j                  |d|xs |j                         t        j                  |d|       |S )Nr   r$   r%   r   )r   rI   r+   r,   r%   )rB   r$   r%   r   rJ   s        r/   rK   zAccessorPath._from_parsed_partso  so     899;;s#8We4k9#B0B0B	
 	8Z:r1   r.   c                 R    | j                  || j                  | j                        S )z=Create a new instance of the same class with the given parts.r%   r   )rK   r%   r   rh   s     r/   ra   zAccessorPath._clone_with_parts  s-     &&nn]] ' 
 	
r1   r   c                     	 | j                  |f| j                  z   | j                  | j                        S # t        $ r	 t
        cY S w xY w)Nr   )rG   r$   r%   r   r?   r   r   s     r/   r   zAccessorPath.__rtruediv__  sR    	"###.. $  
  	"!!	"s   58 A
	A
c                 p    | j                   j                  | j                  |       | j                  |      S )z1Return a new existing path with the key appended.)r   require_childr$   rf   r   s     r/   __floordiv__zAccessorPath.__floordiv__  s+    ##DJJ4'',,r1   c                 Z    || z  }|j                   j                  |j                         |S )z2Return a new existing path with the key prepended.)r   validater$   )r.   r   news      r/   __rfloordiv__zAccessorPath.__rfloordiv__  s(    Dj 	cii(
r1   c              #      K   | j                   j                  | j                        D ]  }| j                  |        yw)zjIterate over all child paths.

        Raises KeyError if the path is missing or non-traversable.
        Nr   keysr$   rf   r   s     r/   __iter__zAccessorPath.__iter__  s;     
 ==%%djj1 	0C**3//	0s   ?Ac                 n   d}	 | j                   | j                     }| j                   j                  ||      }	 | j                   j                  |      r| j                  |      }|S 	 	 t        t        | j                   j                  |            S # t        $ r: | |z  }|j	                         r|cY S t        t        |j                               cY S w xY w# t        $ r || |z  }|j	                         r|cY S Y w xY w# t        $ r( || |z  }t        t        |j                               cY S w xY w)zAccess a child path's value.N)r   r$   _get_subnodeNotImplementedErroris_traversabler   r   
read_value_is_traversable_noderf   
_read_node)r.   r   pathr   childs        r/   __getitem__zAccessorPath.__getitem__  s+   %)	.]]4::.FMM..vs;E	}}11%8//4 9	.4==33E:;;% # 	.3;D""$4??,--	. # 	|s{""$ %	 # 	.|s{4??,--	.s:   5B -C *(D  C5CC"D ?D .D43D4c                 N    | j                   j                  | j                  |      S )zCheck if a key exists in the path.

        This mirrors typical container semantics: membership checks return a
        boolean and do not raise for missing/non-traversable intermediate
        nodes.
        )r   containsr$   r   s     r/   __contains__zAccessorPath.__contains__  s     }}%%djj#66r1   c                 L    | j                   j                  | j                        S )znReturn the number of child paths.

        Raises KeyError if the path is missing or non-traversable.
        )r   r   r$   rU   s    r/   __len__zAccessorPath.__len__  s    
 }}  ,,r1   c                 P    | j                   j                  | j                        duS )zCheck if the path exists.Nr   statr$   rU   s    r/   existszAccessorPath.exists  s     }}!!$**-T99r1   c                 L    | j                   j                  | j                        S )zReturn True if the path can enumerate child keys.

        This is a convenience wrapper around `accessor.is_traversable(...)`.
        )r   r   r$   rU   s    r/   r   zAccessorPath.is_traversable  s    
 }}++DJJ77r1   c                 L    | j                   j                  | j                        S )zqReturn all keys at the current path.

        Raises KeyError if the path is missing or non-traversable.
        )r   r   r$   rU   s    r/   r   zAccessorPath.keys  s    
 }}!!$**--r1   c              #      K   | j                   j                  | j                        D ]  }|| j                  |      f  yw)zReturn path's items.Nr   r   s     r/   itemszAccessorPath.items  s>     ==%%djj1 	5Ct//444	5s   AAc                      y rN   rF   r   s     r/   getzAccessorPath.get  s    '*r1   defaultc                      y rN   rF   r.   r   r   s      r/   r   zAccessorPath.get  s    >Ar1   c                 0    	 | |   S # t         $ r |cY S w xY w)z=Return the value for key if key is in the path, else default.)KeyErrorr   s      r/   r   zAccessorPath.get  s%    	9 	N	s    c                 L    | j                   j                  | j                        S )zReturn the path's value.)r   readr$   rU   s    r/   r   zAccessorPath.read_value      }}!!$**--r1   c                 L    | j                   j                  | j                        S )z:Return metadata for the path, or None if it doesn't exist.r   rU   s    r/   r   zAccessorPath.stat  r   r1   c              #   0   K   | j                          yw)zContext manager that yields the current path's value.

        This mirrors a file-like "open" API but works for any accessor.
        N)r   rU   s    r/   openzAccessorPath.open  s      oos   )NNrN   )-r   rZ   r[   r   rA   r   r   r   r   r   r	   r=   r0   r   r@   r   r   rG   r   rK   ra   r   r   r   r   r   r   r   r   r>   r   r   r   r   r   r   r   r    r+   r   dictr   r   r   __classcell__)r   s   @r/   r   r   U  s   7C=1a7## !%	5q!Qw'5 5 :	5  !%15	9- 9sm9 :9 q!Qw'$.	9
 
9 9  !%15	- Xs]# : q!Qw'$.	
 
  

$)(C-$8
	
"= "x "M "-= -q -] -
M  m 0} 0-)@ 0.- .a .A4E .B7 7d 7- -: :8 8.hqk .5M 5huQ5E/F&G 5
 *q*QX* *AqA8AHA Aq 6 V .A ..d38nt+ .  hqk    r1   r   c                   4    e Zd ZdZeded    dedd fd       Zy)FilesystemPathzPath for filesystem objects.rB   r   r2   c                 (    t        |      } | |      S )z*Public constructor for a Path-backed path.r   )rB   r   r   s      r/   	from_pathzFilesystemPath.from_path  s      %8}r1   N)r   rZ   r[   r   r   r@   r   r  rF   r1   r/   r   r     s7    &"# 
 r1   r   c                   h    e Zd ZdZeded    dedededd f
d       Zeded    dedededd f
d       Z	y	)

LookupPathz2Path for object that supports __getitem__ lookups.rB   lookupr'   kwargsr2   c                 .     | j                   |g|i |S )z,Public constructor for a lookup-backed path.)_from_lookup)rB   r  r'   r  s       r/   from_lookupzLookupPath.from_lookup$  s!      s8888r1   c                 0    t        |      } | |g|i |S rN   r   )rB   r  r'   r  r   s        r/   r  zLookupPath._from_lookup.  s#     "&)8-d-f--r1   N)
r   rZ   r[   r   r   r@   r   r	   r	  r  rF   r1   r/   r  r  !  s    <9,99 9 	9
 
9 9 .,.. . 	.
 
. .r1   r  )+r   r:   collections.abcr   r   
contextlibr   dataclassesr   	functoolsr   pathlibr   typingr	   r
   r   r   r   r   pathable.accessorsr   r   r   r   r   r   pathable.parsersr   r   pathable.typesr   r   r   r   r   r    r   r   r=   r8   r   r  rF   r1   r/   <module>r     s     	 $ $ % ! %          -   + +   & ( $ % & Kz2	/LM: $U#n
 n
 $n
b	| 8WQ1W- | ~
\$U"23 
.j)[@A .r1   