
    iKjV              	          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!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initeqc            
          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	 d5dee   dee
   de	dz  d
efd       Ze	 d5d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e
df   fd*Z,ed
e-fd+       Z.d
e-fd,Z/ded-e
d
efd.Z0ded-ed
efd/Z1d!e2d
e'fd0Z3d!e
d
e'fd1Z4d!e
d
e'fd2Z5d!e
d
e'fd3Z6d!e
d
e'fd4Z7y)6r   u  Base path.

    Identity is the *address*: two paths are equal if their ``parts`` are
    equal. The separator is presentation only — two paths that name the
    same address but render differently are still equal. Subclasses that
    introduce a resource binding (``AccessorPath``) extend the identity
    to include the binding and override ``__eq__`` accordingly; the
    BasePath/AccessorPath boundary is the only place class participates
    in equality.
    .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       _/Users/ahmed/devFolder/Ultron/claude-voice/.venv/lib/python3.12/site-packages/pathable/paths.py__init__zBasePath.__init__3   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%   r6   r7   argparts           r0   r.   zBasePath._parse_args8   s     !#CD$$tzz"$&t{{7+,$,yydE*4;;w/0$c
+t$)t:  3 : [,--r2   rC   c                      | |d|iS )Nr&    )rC   r(   r&   s      r0   _from_partszBasePath._from_partsg   s     D.I..r2   r   c                     | j                  |       }t        j                  |d|       t        j                  |d|xs |j                         |S )Nr%   r&   )__new__r,   r-   r&   )rC   r%   r&   instances       r0   _from_parsed_partszBasePath._from_parsed_partso   sK     ;;s#8We4k9#B0B0B	
 r2   c                 :    t        d | j                  D              S )Nc              3   2   K   | ]  }t        |        y wNr>   .0ps     r0   	<genexpr>z#BasePath._cparts.<locals>.<genexpr>   s     0ZSVZ   )rB   r%   r/   s    r0   _cpartszBasePath._cparts|   s     0TZZ000r2   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)rA   
__module____qualname__)rR   rS   cs      r0   rT   z&BasePath._cmp_parts.<locals>.<genexpr>   sB      
B1 Q""#1T!W%9%9$:;Q?Bs   <>T)strict)rB   zipr%   rW   rV   s    r0   
_cmp_partszBasePath._cmp_parts   s/      
DJJTB
 
 	
r2   r/   c                 |    | j                  || j                        }| j                  |z   }| j                  |      S )Nr*   )r.   r&   r%   _clone_with_parts)r/   r(   r%   parts_joineds       r0   _make_childzBasePath._make_child   s:      4>> :zzE)%%l33r2   rE   c                 D    | j                   |fz   }| j                  |      S rO   r%   rb   )r/   rE   r%   s      r0   _make_child_relpathzBasePath._make_child_relpath   s%     

dW$%%e,,r2   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'   )rL   r&   r/   r%   s     r0   rb   zBasePath._clone_with_parts   s     &&u&GGr2   c                     t        |       S rO   rP   rV   s    r0   
__fspath__zBasePath.__fspath__   s    4yr2   c                 F    dj                  d | j                  D              S )z2Return the path as a POSIX path (always uses '/')./c              3   2   K   | ]  }t        |        y wrO   rP   rQ   s     r0   rT   z$BasePath.as_posix.<locals>.<genexpr>   s     3
1A
rU   )joinr%   rV   s    r0   as_posixzBasePath.as_posix   s    xx3

333r2   c                 L    | j                   syt        | j                   d         S )zFinal path component. )r%   r>   rV   s    r0   namezBasePath.name   s!     zz4::b>""r2   rt   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rr   rZ   z..rr   rZ   r      )rfind)rt   dots     r0   _split_stem_suffixzBasePath._split_stem_suffix   sf     ?"8Ojjo!8axCtABx/Rx8ODSz4:%%r2   c                 B    | j                  | j                        \  }}|S )z9Final component's last suffix, including the leading dot.rz   rt   )r/   stemsuffixs      r0   r~   zBasePath.suffix   s!     ..tyy9fr2   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.rv   rZ   rw   N)rt   
startswithsplitlen)r/   rt   restr%   rS   s        r0   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      r0   r}   zBasePath.stem   s!     ))$))4ar2   c                 Z    | j                   s| S | j                  | j                   dd       S )zLogical parent path.Nrs   rf   rV   s    r0   parentzBasePath.parent   s+     zzK%%djj"o66r2   c           	            j                   syt         fdt        dt         j                         dz         D              S )z.Logical ancestors (like pathlib's `.parents`).rG   c              3   \   K   | ]#  }j                  j                  d |         % y wrO   )rb   r%   )rR   ir/   s     r0   rT   z#BasePath.parents.<locals>.<genexpr>   s0      
2 ""4::cr?32s   ),rw   )r%   rB   ranger   rV   s   `r0   parentszBasePath.parents   s=     zz 
1c$**o12
 
 	
r2   otherc                 6    | j                  t        |            S )z,Combine this path with one or more segments.)rd   listr/   r   s     r0   joinpathzBasePath.joinpath   s    U,,r2   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 separatorNrs   )r%   
ValueErrorr8   r>   r@   r&   rb   )r/   rt   	new_partss      r0   	with_namezBasePath.with_name   sy    zzDEE$$011566>>T!CDDJJsOtg-	%%i00r2   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 strrZ   z#Invalid suffix; must start with '.'rv   zInvalid name for with_suffix())	r%   r   r8   r>   r@   r   rt   r}   r   )r/   r~   rt   new_names       r0   with_suffixzBasePath.with_suffix   s    zzFGG&#&233&++C0BCCyy?"=>>99v%~~h''r2   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      r0   is_relative_tozBasePath.is_relative_to
  sO    &&u$..&A{c$**o-zz,C,-<<r2   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   rL   rb   r%   r   r   s      r0   relative_tozBasePath.relative_to  s    
 &&u$..&A"t""K0(4X5P5PQ\hlhvhv5P5w4z{  %%djj[1A1C&DEEr2   c                 L    | j                   j                  | j                        S rO   )r&   ro   rW   rV   s    r0   __str__zBasePath.__str__  s    ~~""4<<00r2   c                 L    | j                   j                   dt        |       dS )N())	__class____name__r>   rV   s    r0   __repr__zBasePath.__repr__   s$    ..))*!CI=::r2   c                     | j                   fS rO   )r%   rV   s    r0   _identity_keyzBasePath._identity_key#  s     

}r2   c                 4    t        | j                               S rO   )hashr   rV   s    r0   _hashzBasePath._hash)  s    D&&())r2   c                     | j                   S rO   )r   rV   s    r0   __hash__zBasePath.__hash__-  s    zzr2   keyc                 R    	 | j                  |g      S # t        $ r	 t        cY S w xY wrO   )rd   r@   NotImplementedr/   r   s     r0   __truediv__zBasePath.__truediv__0  s9    	"## 
  	"!!	"s    &&c                     	 | j                  |f| j                  z   | j                        S # t        $ r	 t        cY S w xY w)Nr'   )rH   r%   r&   r@   r   r   s     r0   __rtruediv__zBasePath.__rtruediv__:  sJ    	"###t~~ $    	"!!	"s   *- ??c                 `    t        |t              st        S | j                  |j                  k(  S rO   )r8   r   r   r%   r   s     r0   __eq__zBasePath.__eq__B  s'    %*!! zzU[[((r2   c                 `    t        |t              st        S | j                  |j                  k  S rO   r8   r   r   r`   r   s     r0   __lt__zBasePath.__lt__O  s)    %*!! !1!111r2   c                 `    t        |t              st        S | j                  |j                  k  S rO   r   r   s     r0   __le__zBasePath.__le__V  '    %*!!%"2"222r2   c                 `    t        |t              st        S | j                  |j                  kD  S rO   r   r   s     r0   __gt__zBasePath.__gt__[  s'    %*!!!1!111r2   c                 `    t        |t              st        S | j                  |j                  k\  S rO   r   r   s     r0   __ge__zBasePath.__ge__`  r   r2   rO   )8r   r[   r\   __doc__rB   r   __annotations__r   r&   r>   r	   r1   classmethodr   r.   rA   r   rH   rL   r   rW   r`   r   rd   rg   rb   rk   rp   rt   staticmethodrz   r~   r   r}   r   r   r   r   r   boolr   r   r   r   r   r?   r   r   r   r   r,   r   r   r   r   r   rG   r2   r0   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;# ;uS#X  *s * *# ") "# ") ""9 "8 "	 ")F )t )2C 2D 23C 3D 3
2C 2D 2
3C 3D 3r2   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e
df   fdZdedefdZej4                  Z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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&       Z0 xZ1S ))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-   superr1   )r/   r   r&   r(   r   s       r0   r1   zAccessorPath.__init__l  s)     	4X6$4)4r2   rC   r3   c                 4    |t        d       | |g|d|iS )Naccessor must be providedr&   )r   )rC   r(   r&   r   s       r0   rH   zAccessorPath._from_partsu  s+     89988d8i88r2   c                     |t        d      | j                  |       }t        j                  |d|       t        j                  |d|xs |j                         t        j                  |d|       |S )Nr   r%   r&   r   )r   rJ   r,   r-   r&   )rC   r%   r&   r   rK   s        r0   rL   zAccessorPath._from_parsed_parts  so     899;;s#8We4k9#B0B0B	
 	8Z:r2   r/   c                 R    | j                  || j                  | j                        S )z=Create a new instance of the same class with the given parts.r&   r   )rL   r&   r   ri   s     r0   rb   zAccessorPath._clone_with_parts  s-     &&nn]] ' 
 	
r2   c                 2    | j                   | j                  fS rO   )r%   r   rV   s    r0   r   zAccessorPath._identity_key  s     

DMM**r2   r   c                     t        |t              st        S t        |t              sy| j                  |j                  k(  xr | j
                  |j
                  k(  S )NF)r8   r   r   r   r%   r   r   s     r0   r   zAccessorPath.__eq__  sF    %*!!
 %.zzU[[(LT]]enn-LLr2   c                     t        |t              sy| j                  |j                  k(  xr | j                  |j                  u S )u  Return True if ``other`` is an equal address bound to the
        same accessor *instance* (object identity on the accessor).

        Stricter than ``==``, which only requires that the accessors
        compare equal under their own ``__eq__`` semantics. Use this
        when you need to assert that two paths are not just naming the
        same resource but are literally backed by the same accessor
        object — for example, to verify cache attribution.
        F)r8   r   r%   r   r   s     r0   is_same_bindingzAccessorPath.is_same_binding  s6     %.zzU[[(LT]]enn-LLr2   r   c                     	 | j                  |f| j                  z   | j                  | j                        S # t        $ r	 t
        cY S w xY w)Nr   )rH   r%   r&   r   r@   r   r   s     r0   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%   rg   r   s     r0   __floordiv__zAccessorPath.__floordiv__  s+    ##DJJ4'',,r2   c                 Z    || z  }|j                   j                  |j                         |S )z2Return a new existing path with the key prepended.)r   validater%   )r/   r   news      r0   __rfloordiv__zAccessorPath.__rfloordiv__  s(    Dj 	cii(
r2   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%   rg   r   s     r0   __iter__zAccessorPath.__iter__  s6     
 ==%%djj1C**3// 2s   ?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_noderg   
_read_node)r/   r   pathr   childs        r0   __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     r0   __contains__zAccessorPath.__contains__  s     }}%%djj#66r2   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%   rV   s    r0   __len__zAccessorPath.__len__  s    
 }}  ,,r2   c                 P    | j                   j                  | j                        duS )zCheck if the path exists.Nr   statr%   rV   s    r0   existszAccessorPath.exists  s     }}!!$**-T99r2   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%   rV   s    r0   r   zAccessorPath.is_traversable  s    
 }}++DJJ77r2   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%   rV   s    r0   r   zAccessorPath.keys   s    
 }}!!$**--r2   c              #      K   | j                   j                  | j                        D ]  }|| j                  |      f  yw)zReturn path's items.Nr   r   s     r0   itemszAccessorPath.items'  s9     ==%%djj1Ct//444 2s   AAc                      y rO   rG   r   s     r0   getzAccessorPath.get,  s    '*r2   defaultc                      y rO   rG   r/   r   r   s      r0   r   zAccessorPath.get/  s    >Ar2   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      r0   r   zAccessorPath.get2  s%    	9 	N	s    c                 L    | j                   j                  | j                        S )zReturn the path's value.)r   readr%   rV   s    r0   r   zAccessorPath.read_value9      }}!!$**--r2   c                 L    | j                   j                  | j                        S )z:Return metadata for the path, or None if it doesn't exist.r   rV   s    r0   r   zAccessorPath.stat=  r  r2   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   rV   s    r0   openzAccessorPath.openA  s      oos   )NNrO   )2r   r[   r\   r   rB   r   r   r   r   r   r	   r>   r1   r   rA   r   r   rH   r   rL   rb   r   r,   r   r   r   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   @r0   r   r   f  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
	
+uS#X +	MF 	Mt 	M   HMV M M"= "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    r2   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.rC   r   r3   c                 (    t        |      } | |      S )z*Public constructor for a Path-backed path.r   )rC   r   r   s      r0   	from_pathzFilesystemPath.from_pathM  s      %8}r2   N)r   r[   r\   r   r   rA   r   r
  rG   r2   r0   r  r  J  s7    &"# 
 r2   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.rC   lookupr(   kwargsr3   c                 .     | j                   |g|i |S )z,Public constructor for a lookup-backed path.)_from_lookup)rC   r  r(   r  s       r0   from_lookupzLookupPath.from_lookupZ  s!      s8888r2   c                 0    t        |      } | |g|i |S rO   r   )rC   r  r(   r  r   s        r0   r  zLookupPath._from_lookupd  s#     "&)8-d-f--r2   N)
r   r[   r\   r   r   rA   r   r	   r  r  rG   r2   r0   r  r  W  s    <9,99 9 	9
 
9 9 .,.. . 	.
 
. .r2   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>   r9   r  r  rG   r2   r0   <module>r     s     	 $ $ % ! %          -   + +   & ( $ % & Kz2	/LM: $Uu-3 3 .3D
a 8WQ1W- a H
\$U"23 
.j)[@A .r2   