
    Dg                        d Z ddlm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	ddl
Z
ddlmZ ddlmZ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mZmZ ej        d	k    rd
 ZneZej        dk    Z e rddl!Z! G d de"          Z# G d dej$                  Z%d Z&d Z'e re%pej$        Z( G d de(          Z)d Z*d Z+d Z,d Z-dS )z
local path implementation.
    )with_statement)contextmanagerN)common)iswin32fspath)S_ISLNKS_ISDIRS_ISREG)abspathnormpathisabsexistsisdirisfileislinkdirname)   r   c                 <    t          t          | |                    S N)listmap)funciters     C/var/www/sysmax/venv/lib/python3.11/site-packages/py/_path/local.pymap_as_listr      s    CdOO$$$    )r      c                   X    e Zd Zd Zd Zed             Zed             Zd Zd Z	d Z
dS )	Statc                 2    t          | j        d|z             S )Nst_)getattr_osstatresult)selfnames     r   __getattr__zStat.__getattr__   s    t)54<888r   c                 "    || _         || _        d S r   )pathr#   )r$   r(   osstatresults      r   __init__zStat.__init__   s    	)r   c                     t           rt          d          dd l}t          j                            |j        | j                  }|d         S )N	XXX win32r   )r   NotImplementedErrorpwdpyerrorchecked_callgetpwuiduid)r$   r.   entrys      r   ownerz
Stat.owner"   sE     	3%k222


%%clDH==Qxr   c                     t           rt          d          ddl}t          j                            |j        | j                  }|d         S )z return group name of file. r,   r   N)r   r-   grpr/   r0   r1   getgrgidgid)r$   r7   r4   s      r   groupz
Stat.group*   sG      	3%k222


%%clDH==Qxr   c                 4    t          | j        j                  S r   )r	   r#   st_moder$   s    r   r   z
Stat.isdir3       t)1222r   c                 4    t          | j        j                  S r   )r
   r#   r<   r=   s    r   r   zStat.isfile6   r>   r   c                 f    | j                                         }t          | j        j                  S r   )r(   lstatr   r#   r<   r$   sts     r   r   zStat.islink9   s'    Y__t)1222r   N)__name__
__module____qualname__r&   r*   propertyr5   r:   r   r   r    r   r   r   r      s        9 9 9* * *   X   X3 3 33 3 33 3 3 3 3r   r   c                   *    e Zd ZddZd Zd Zd	dZdS )
	PosixPathr   c                    t          |          }t          |          }|ri|                     d           D ]Q}|                    d          r9t          j                            t          j        t          |          ||           Rt          j                            t          j        t          |           ||           dS )z change ownership to the given user and group.
            user and group may be specified by a number or
            by a name.  if rec is True change ownership
            recursively.
        c                 .    |                      d          S Nr   linkcheck)xs    r   <lambda>z!PosixPath.chown.<locals>.<lambda>G   s    agg1goo r   recr   rN   N)
	getuserid
getgroupidvisitrQ   r/   r0   r1   oschownstr)r$   userr:   rU   r3   r9   rR   s          r   rZ   zPosixPath.chown>   s     oo 	FZZ$=$=Z>> F F777?? FH))"(CFFCEEE
bhD		3<<<<<r   c                 `    t           j                            t          j        | j                  S )z" return value of a symbolic link. )r/   r0   r1   rY   readlinkstrpathr=   s    r   r^   zPosixPath.readlinkL   s    x$$R[$,???r   c                     t           j                            t          j        t          |          t          |                      dS )z( posix style hard link to another name. N)r/   r0   r1   rY   rO   r[   )r$   oldnames     r   mklinktozPosixPath.mklinktoP   s0    
bgs7||SYY?????r      c                    |r?t           j                            t          j        t          |          | j                   dS |                     |          }|                     |          	                    |          }| 	                    |          }|
                    | j                  }| j                            d|z  |fz             }t           j                            t          j        || j                   dS )zI create a symbolic link with the given value (pointing to another name). )z..N)r/   r0   r1   rY   symlinkr[   r_   r   	__class__reltocountsepjoin)r$   valueabsolutebase	relsourcereldestntargets           r   mksymlinktozPosixPath.mksymlinktoT   s     		DH!!"*c%jj$,GGGGG;;u%%Du--33D99Ijj&&Gdh''AX]]8A:#=>>FH!!"*fdlCCCCCr   Nr   rc   )rD   rE   rF   rZ   r^   rb   rr   rH   r   r   rJ   rJ   =   sf        = = = =@ @ @@ @ @D D D D D Dr   rJ   c                 n    dd l }t          | t                    s|                    |           d         } | S Nr      )r.   
isinstanceintgetpwnam)r\   r.   s     r   rV   rV   a   s8    JJJdC   %||D!!!$Kr   c                 n    dd l }t          | t                    s|                    |           d         } | S rv   )r7   rx   ry   getgrnam)r:   r7   s     r   rW   rW   g   s8    JJJeS!! 'U##A&Lr   c                   X    e Zd ZdZ G d de          Zej        Z G d dej	                  Z	dCdZ
d	 Zd
 Zd Zd Zd Zd ZdDdZdEdZd Zd Z fdZd ZdFdZd Zd Z fdZ edej        j        z             ZdGdZd Zd  Z dHd!Z!d" Z"dId#Z#d$ Z$dJd%Z%dJd&Z&dKd(Z'd) Z(d* Z)dLd,Z*d- Z+dMd.Z,d/ Z-e.d0             Z/d1 Z0d2 Z1d3 Z2d4 Z3dNd6Z4d7 Z5d8 Z6dOd9Z7d: Z8dGd;Z9 e:e9          Z9d< Z; e:e;          Z;e:d=             Z<e:dMd>            Z=	 	 dPdBZ> e:e>          Z> xZ?S )Q	LocalPathzb object oriented interface to os.path and other local filesystem
        related information.
    c                       e Zd ZdZdS )LocalPath.ImportMismatchErrorz: raised on pyimport() if there is a mismatch of __file__'sN)rD   rE   rF   __doc__rH   r   r   ImportMismatchErrorr   s   s        HHHHr   r   c                   ,    e Zd Zd Zd Zd Zd Zd ZdS )LocalPath.Checkersc                     	 | j         S # t          $ rb 	 | j                                        | _         n8# t          j        j        $ r! | j                                        | _         Y nw xY w| j         cY S w xY wr   )
_statcacheAttributeErrorr(   statr/   r0   ELOOPrA   r=   s    r   _statzLocalPath.Checkers._statx   s    '&! ' ' '8&*inn&6&6DOOx~ 8 8 8&*ioo&7&7DOOO8&&&'s/   	 
A53A52A(%A5'A((
A54A5c                 N    t          |                                 j                  S r   )r	   r   moder=   s    r   dirzLocalPath.Checkers.dir       4::<<,---r   c                 N    t          |                                 j                  S r   )r
   r   r   r=   s    r   filezLocalPath.Checkers.file   r   r   c                 *    |                                  S r   )r   r=   s    r   r   zLocalPath.Checkers.exists   s    ::<<r   c                 \    | j                                         }t          |j                  S r   )r(   rA   r   r   rB   s     r   rO   zLocalPath.Checkers.link   s#    ""B27###r   N)rD   rE   rF   r   r   r   r   rO   rH   r   r   Checkersr   w   s_        	' 	' 	'	. 	. 	.	. 	. 	.	  	  	 	$ 	$ 	$ 	$ 	$r   r   NFc                 0   |0t           j                            t          j                  | _        dS 	 t          |          }n# t          $ r t          d          w xY w|rt          j	        
                    |          }t          |          | _        dS )a   Initialize and return a local Path instance.

        Path can be relative to the current directory.
        If path is None it defaults to the current working directory.
        If expanduser is True, tilde-expansion is performed.
        Note that Path instances always carry an absolute path.
        Note also that passing in a local path object will simply return
        the exact same path object. Use new() to get a new copy.
        NzDcan only pass None, Path instances or non-empty strings to LocalPath)r/   r0   r1   rY   getcwdr_   r   	TypeError
ValueErrorr(   
expanduserr   )r$   r(   r   s      r   r*   zLocalPath.__init__   s     <800;;DLLLFd|| F F F  "E F F FF  0w))$//"4==DLLLs   A Ac                 d    | j         }t          r|                                }t          |          S r   )r_   r   lowerhash)r$   ss     r   __hash__zLocalPath.__hash__   s)    L 			AAwwr   c                     t          |           }	 t          |          }n# t          $ r Y dS w xY wt          r;|                                }	 |                                }n# t          $ r Y dS w xY w||k    S NF)r   r   r   r   r   )r$   others1s2s       r   __eq__zLocalPath.__eq__   s    D\\	BB 	 	 	55	 	BXXZZ!   uuRxs   ! 
//A# #
A10A1c                     | |k     S r   rH   r$   r   s     r   __ne__zLocalPath.__ne__   s    EM""r   c                 B    t          |           t          |          k     S r   r   r   s     r   __lt__zLocalPath.__lt__       d||fUmm++r   c                 B    t          |           t          |          k    S r   r   r   s     r   __gt__zLocalPath.__gt__   r   r   c                    t          |          }t          |          st          |          }| |k    rdS t          t          j        d          sdS t          j                            t          j        j	        | j
        |          S )zD return True if 'other' references the same file as 'self'.
        TsamefileF)r   r   r   hasattrrY   r(   r/   r0   r1   r   r_   r   s     r   r   zLocalPath.samefile   sw     uU|| 	#ENNE5==4rw
++ 	5x$$ $,7 7 	7r   rc   c                    |                      dd          r|rPt          r|                     dd           ddl}t          j                            |j        | j        |           dS t          j                            t          j
        | j                   dS t          r|                     d           t          j                            t          j        | j                   dS )z remove a file or directory (or a directory tree if rec=1).
        if ignore_errors is True, errors while removing directories will
        be ignored.
        rc   r   )r   rO   i  rT   N)ignore_errors)rQ   r   chmodshutilr/   r0   r1   rmtreer_   rY   rmdirremove)r$   rU   r   r   s       r   r   zLocalPath.remove   s    
 ::!!:$$ 	; 	> -JJu!J,,,%%M4<"/ & 1 1 1 1 1 %%bh===== "

5!!!H!!")T\:::::r   md5   c                    	 	 ddl }n'# t          $ r |dk    rd}t          |          }Y nw xY w t          ||                      }n(# t          t          f$ r t          d|d          w xY w|                     d          }	 	 |                    |          }|s(|                                |	                                 S |
                    |           U# |	                                 w xY w)z. return hexdigest of hashvalue for this file. r   Nsha1shazDon't know how to compute z hashrb)hashlibImportError
__import__r"   r   r   openread	hexdigestcloseupdate)r$   hashtype	chunksizemodr   fbufs          r   computehashzLocalPath.computehash   s,   		O+%%%%% + + +v%%$H **+ *73))++DD, 	O 	O 	O*888MNNN	OIIdOO	!ffY'' ,>>++ GGIIII C   	! GGIIIIs3    A !,A ,A %A-+C C C2c                 4   t                               | j                  }|s| j        |_        |S |                     d          \  }}}}}d|v rd|v sd|v rt          d|z            nT|                    d|          }	 |d         }|r|                    d          sd|z   }n# t          $ r Y nw xY w||z   |d<   d|v r|d         s||d<   n|                    d|           |                    d| j	                   t          d	|z            |_        |S )
a   create a modified version of this path.
            the following keyword arguments modify various path parts::

              a:/some/path/to/a/file.ext
              xx                           drive
              xxxxxxxxxxxxxxxxx            dirname
                                xxxxxxxx   basename
                                xxxx       purebasename
                                     xxx   ext
        z'drive,dirname,basename,purebasename,extbasenamepurebasenameextzinvalid specification %r.r   ri   z%(dirname)s%(sep)s%(basename)s)object__new__rf   r_   
_getbyspecr   
setdefault
startswithKeyErrorri   r   )	r$   kwobjdriver   r   r   r   pbs	            r   newzLocalPath.new   sd    nnT^,, 	,CKJ59__668 682w,s##u{{ !;b!@AAA (3 ~|<<B$i  $s~~c22 $)C	    
  #XBzNOOByMO!ByMMMM)W---
eTX&&&,r13 3
s   B& &
B32B3c                 @   g }| j                             | j                  }t          d|                    d                    }|j        }|D ]}|dk    r ||d                    |dk    r, || j                            |dd                              L|d         }|dk    r ||           f|                    d          }|dk    r|d	}
}	n|d|         ||d         }
}	|d
k    r ||	           |dk    r ||
           t          d|z            |S )z! see new for what 'spec' can be. N,r   r   r   r   r    r   r   zinvalid part specification %r)r_   splitri   filterappendrj   rfindr   )r$   specrespartsargsr   r%   r   ir   r   s              r   r   zLocalPath._getbyspec"  sW   ""48,,dDJJsOO-- 	Q 	QDwuQx    ""tx}}U3B3Z001111 9:%%F8$$$$ s++ABww,4bc,4RaRL(122,c~--|,,,,s()H4)OPPP
r   c                     |sFt                               | j                  }t          | j                  |_        |r
 |j        | }|S  t          t          |           j        |i |S )zB return the directory path joined with any given path arguments.  )	r   r   rf   r   r_   rj   superr~   dirpath)r$   r   kwargsr(   rf   s       r   r   zLocalPath.dirpath@  sl     	>>$.11D"4<00DL ( ty$'K-uY%%-t>v>>>r   c                 &   | j         }d |D             }| j        }|                    d          r?g }t          |          D ]-}t	          |          r|}|} n|                    d|           .|                    |          rdn|}|D ]S}|                    |          }t          r+|                    d          }|	                    d|          }||z   |z   }|}Tt                              | j                  }	t          |          |	_        |	S )z return a new path by appending all 'args' as path
        components.  if abs=1 is used restart from root if any
        of the args is an absolute path.
        c                 ,    g | ]}t          |          S rH   r   ).0args     r   
<listcomp>z"LocalPath.join.<locals>.<listcomp>P  s    ///36#;;///r   absr   r   /)ri   r_   getreversedr   insertendswithstripr   replacer   r   rf   r   )
r$   r   r   ri   strargsr_   newargsr   
actual_sepr   s
             r   rj   zLocalPath.joinJ  s*   
 h//$///,::e 	'G(( ' ':: !G%GEq#&&&&"++C009RRc
 	 	C))C..C ,iinnkk#s++
*S0GJJnnT^,,w''
r   rc                    |r(|                                                      d           |r2t          j                            t
          j        | j        ||          S t          j                            t          | j        |          S )zu return an opened file with the given mode.

        If ensure is True, create parent directories if needed.
        rc   r   encoding)r   ensurer/   r0   r1   ior   r_   )r$   r   r  r   s       r   r   zLocalPath.openh  ss    
  	)LLNN!!a!((( 	Y8(($,x(XXXx$$T4<>>>r   c                 r    t                               | j                  }| j        | j        z   |z   |_        |S r   )r   r   rf   r_   ri   )r$   r%   childs      r   	_fastjoinzLocalPath._fastjoins  s/    t~..tx/$6r   c                 *    t          | j                  S r   )r   r_   r=   s    r   r   zLocalPath.islinkx  s    dl###r   c                    |st          | j                  S t          |          dk    rDd|v r|d         t          | j                  z   S d|v r|d         t	          | j                  z   S  t          t          |           j        di |S )Nrc   r   r   rH   )r   r_   lenr   r   r   r~   rQ   )r$   r   rf   s     r   rQ   zLocalPath.check{  s     	($,'''r77a<<{{e9uT\':'::::||f:t|(<(<<<<+uY%%+11b111r   z*?[c                    |F|Dt           j                            t          j        | j                  }t          | j        |          S t          |t           j	        j
                  r\| j                            |          s.|                     |          }t          |j                  r|gS g S t          j        |          }t           j                            t          j        | j                  }g }|D ]9}|                     |          }| ||          r|                    |           :|                     ||           |S )zi list directory contents, possibly filter by the given fil func
            and possibly sorted.
        )r/   r0   r1   rY   listdirr_   r   r  rx   builtin_basestring_patterncharsintersectionr   r   	FNMatcherr   	_sortlist)r$   filsortnamesr  r   r%   s          r   r
  zLocalPath.listdir  s&    ;4<H))"*dlCCEt~u555c2:122 	(%22377 s++%-(( #!7N	"3''C%%bj$,?? 	" 	"DNN4((E{cc%jj{

5!!!sD!!!
r   c                 4    |                                  j        S )z+ return size of the underlying file object )r   sizer=   s    r   r  zLocalPath.size  s    yy{{r   c                 4    |                                  j        S )z, return last modification time of the path. )r   mtimer=   s    r   r  zLocalPath.mtime      yy{{  r   c                    |                      d          rz|                     d          r|                    | j                  }| |k    sJ t          | |           |rt	          | j        |j                   |rt          | |           dS dS d }|                     |          D ]}|                    |           }|                    |          }|	                                
                    d           |                     d          r(|                    |                                           |                     d          rt          ||           n,|                     d          r|
                    d           |rt	          |j        |j                   |rt          ||           dS )z copy path to target.

            If mode is True, will copy copy permission from path to target.
            If stat is True, copy permission, last modification
            time, last access time, and flags from path to target.
        rc   r   r   c                 .    |                      d          S rM   rP   )ps    r   rU   zLocalPath.copy.<locals>.rec  s    wwAw&r   rT   rN   N)rQ   rj   r   copychunkedcopymoder_   copystatrX   rg   r   r  rr   r^   )r$   rq   r   r   rU   rR   relpathnewxs           r   copyzLocalPath.copy  s    ::1: 	&|||"" 4T]33<<<<f%%% 7v~666 'v&&&&&' '' ' 'ZZCZ(( & &''$--{{7++%%!%,,,777?? '$$QZZ\\222WW!W__ '4((((WWW^^ 'KKAK&&& 6QY555 &Q%%%& &r   c                     t          |          }t          j                            t          j        | j        |          S )z rename this path to target. )r   r/   r0   r1   rY   renamer_   )r$   rq   s     r   r$  zLocalPath.rename  s+    x$$RYfEEEr   c                     |                      d          }ddl}	 t          j                            |j        |||           |                                 dS # |                                 w xY w)z! pickle object into path locationwbr   N)r   pickler/   r0   r1   dumpr   )r$   r   binr   r'  s        r   r(  zLocalPath.dump  s`    IIdOO	H!!&+sAs;;;GGIIIIIAGGIIIIs   'A A.c                      | j         | }t          j                            t          j        t          |                     |S )z1 create & return the directory joined with args. )rj   r/   r0   r1   rY   mkdirr   )r$   r   r  s      r   r+  zLocalPath.mkdir  s5    DIt
bhq		222r   c                     |r(|                                                      d           |                     d          5 }|                    |           ddd           dS # 1 swxY w Y   dS )ze write binary data into path.   If ensure is True create
        missing parent directories.
        rc   r   r&  Nr   r  r   write)r$   datar  r   s       r   write_binaryzLocalPath.write_binary  s      	)LLNN!!a!(((YYt__ 	GGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s    A##A'*A'c                     |r(|                                                      d           |                     d|          5 }|                    |           ddd           dS # 1 swxY w Y   dS )z~ write text data into path using the specified encoding.
        If ensure is True create missing parent directories.
        rc   r   wr   Nr-  )r$   r/  r   r  r   s        r   
write_textzLocalPath.write_text  s      	)LLNN!!a!(((YYsXY.. 	!GGDMMM	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	s   A%%A),A)r2  c                 n   |r(|                                                      d           d|v r/t          j                            |          st          d          nt          j                            |          s`t          j                            |          st          |          }n1t          j                            |t          j
                              }|                     |          }	 |                    |           |                                 dS # |                                 w xY w)z^ write data into path.   If ensure is True create
        missing parent directories.
        rc   r   bzcan only process bytesN)r   r  r/   r  _isbytesr   _istextr[   _totextsysgetdefaultencodingr   r.  r   )r$   r/  r   r  r   s        r   r.  zLocalPath.write  s     	)LLNN!!a!((($;;:&&t,, ; !9:::; :%%d++ Nz**400 Nt99DD:--dC4J4L4LMMDIIdOO	GGDMMMGGIIIIIAGGIIIIs   3D D4c                 L   |                                  }|| k    r| S |                    d          r|                                 |                     d          rG	 |                                  n1# t          j        j        $ r |                     d          r Y nw xY w| S )Nr   r   )r   rQ   _ensuredirsr+  r/   r0   EEXIST)r$   parents     r   r<  zLocalPath._ensuredirs  s    T>>K<<A< 	!   ::!: 	

8?    ::!:$$  
 s   A3 3+B! B!c                 4    | j         | }|                    dd          r|                                S |                                                                 |                    d          s'|                    d                                           |S )z ensure that an args-joined path exists (by default as
            a file). if you specify a keyword argument 'dir=True'
            then the path is forced to be a directory path.
        r   r   rc   r  r2  )rj   r   r<  r   rQ   r   r   )r$   r   r   r  s       r   r  zLocalPath.ensure  s    
 DIt::eQ 	==??"IIKK##%%%777?? $s!!###Hr   Tc                    |dk    r=t          | t          j                            t          j        | j                            S 	 t          | t	          j        | j                            S # t          $ r  t          $ r Y dS w xY w)z Return an os.stat() tuple. TN)	r   r/   r0   r1   rY   r   r_   KeyboardInterrupt	Exception)r$   raisings     r   r   zLocalPath.stat!  s    d??bh33BGT\JJKKK	bgdl33444  	 	 	 	 	 	44	s   &A, ,BBc                 |    t          | t          j                            t          j        | j                            S )z Return an os.lstat() tuple. )r   r/   r0   r1   rY   rA   r_   r=   s    r   rA   zLocalPath.lstat,  s(    D"(//$,GGHHHr   c                    |0t           j                            t          j        | j        |          S 	 t           j                            t          j        | j        d|f          S # t           j        j        $ rG t           j                            t          j        | j        |                                 |f          cY S w xY w)z set modification time for the given path.  if 'mtime' is None
        (the default) then the file's mtime is set to current time.

        Note that the resolution for 'mtime' is platform dependent.
        Nr   )r/   r0   r1   rY   utimer_   EINVALatime)r$   r  s     r   setmtimezLocalPath.setmtime0  s     =8((4<GGG	X8((4<"eMMMx 	X 	X 	X8((4<$**,,PUAVWWWWW	Xs   1A& &AC Cc                     	 |                                  }n# t          j        j        $ r d}Y nw xY wt          j                            t
          j        | j                   |S )z; change directory to self and return old current directory N)rf   r/   r0   ENOENTr1   rY   chdirr_   r$   olds     r   rL  zLocalPath.chdir=  sa    	..""CCx 	 	 	CCC	
bh555
s    00c              #      K   |                                  }	 |V  ||                                  dS dS # ||                                  w w xY w)z
        Return a context manager, which changes to the path's dir during the
        managed "with" context.
        On __enter__ it returns the old dir, which might be ``None``.
        N)rL  rM  s     r   as_cwdzLocalPath.as_cwdG  s\       jjll	III		 s		 s	   6 Ac                 p    |                      t          j                            | j                            S )z4 return a new path which contains no symbolic links.)rf   rY   r(   realpathr_   r=   s    r   rR  zLocalPath.realpathU  s&    ~~bg..t|<<===r   c                 4    |                                  j        S )z& return last access time of the path. )r   rH  r=   s    r   rH  zLocalPath.atimeY  r  r   c                     d| j         z  S )Nz	local(%r)r_   r=   s    r   __repr__zLocalPath.__repr__]  s    T\))r   c                     | j         S )z+ return string representation of the Path. rU  r=   s    r   __str__zLocalPath.__str__`  s
    |r   r   c                 \   t          |t                    st          d|d          |rQ|                     |          D ]:}t          j                            t          j        t          |          |           ;t          j                            t          j        | j
        |           dS )z change permissions to the given mode. If mode is an
            integer it directly encodes the os-specific modes.
            if rec is True perform recursively.
        zmode z must be an integerrT   N)rx   ry   r   rX   r/   r0   r1   rY   r   r[   r_   )r$   r   rU   rR   s       r   r   zLocalPath.chmodd  s    
 $$$ 	D)DDDBCCC 	>ZZCZ(( > >%%bhA====
bhd;;;;;r   c                     d}|                      d          D ]W}|                                rA|                    d                                          s nt	          |j                  s n|}X|S )z return the Python package path by looking for the last
        directory upwards which still contains an __init__.py.
        Return None if a pkgpath can not be determined.
        NT)reverse__init__.py)r   r   rj   r   isimportabler   )r$   pkgpathr>  s      r   	pypkgpathzLocalPath.pypkgpathp  s}    
 jjj.. 	! 	!F||~~ !{{=1188:: E#FO44 E r   c                 
   |r~t          |          }|dk    r1|t          j        vr!t          j                            |           d S d S |t          j        d         k    r$t          j                            d|           d S d S d S )Nr   r   )r[   r9  r(   r   r   )r$   
ensuremoder(   r   s       r   _ensuresyspathzLocalPath._ensuresyspath  s     	*D		AX%%CH$$HOOA&&&&& %$ ##HOOAq)))))	* 	* $#r   c                    |                                  st          j                            |           |dk    r|| j        }t
          st          d          t          j        	                    |t          |                     }|"t          d|dt          |                     t          j                            |          }|j                            |           |S d}||                                 }||                                }|                     d                              |                              | j                  }|d         d	k    r|                                 d
                    |          }n|                                 }| j        }|                     ||           t/          |           t0          j        |         }| j        dk    r|S |j        }|dd         dv r|dd         }n"|                    d          r|dd         dz   }|                    t:          j        j        dz             r| j        dk    r
|dd         }	 |                     |          }	n# t          j        j        $ r d}	Y nw xY w|	s1t;          j         d          }
|
dk    r| !                    |||           |S 	 t0          j        |         S # tD          $ r ddl#}|$                    |          }t          |           |_        |t0          j        |<   	 t          j%        &                    t          |           |j'                   n#  t0          j        |=  xY w|cY S w xY w)a   return path as an imported python module.

        If modname is None, look for the containing package
        and construct an according module name.
        The module will be put/looked up in sys.modules.
        if ensuresyspath is True then the root dir for importing
        the file (taking __init__.py files into account) will
        be prepended to sys.path if it isn't there already.
        If ensuresyspath=="append" the root dir will be appended
        if it isn't already contained in sys.path.
        if ensuresyspath is False no modification of syspath happens.

        Special value of ensuresyspath=="importlib" is intended
        purely for using in pytest, it is capable only of importing
        separate .py files outside packages, e.g. for test suite
        without any __init__.py file. It effectively allows having
        same-named test modules in different places and offers
        mild opt-in via this option. Note that it works only in
        recent versions of python.
        	importlibNz0Can't use importlib due to old version of PythonzCan't find module z at location r   )r   r   r*   r   r\  )z.pycz.pyoz	$py.classiz.pyiFPY_IGNORE_IMPORTMISMATCH1r   )(rQ   r/   r0   rK  r   ALLOW_IMPORTLIB_MODEr   rd  utilspec_from_file_locationr[   module_from_specloaderexec_moduler_  r   r   rg   r   ri   poprj   rb  r   r9  modulesr   __file__r   rY   r(   r   getenvr   r   types
ModuleTyper  execfile__dict__)r$   modnameensuresyspathr   r   r^  pkgrootr  modfileissameignorerr  s               r   pyimportzLocalPath.pyimport  sz   * zz|| 	((//$'''K''+' H!FH H H>99T$ $D|!kWWc$iii)   .11$77CK##C(((J?nn&&G"!//++R((..w77==dhGG9
**IIKKK((5//,,..+w777w+g&C}--
lGrss|///!#2#,!!+.. /!#2#,.m ;<< ,=M11%dsdmGw//8?    K#=>>S==227GTJJJJ{7++   &&w//"4yy'*G$J''D		3<@@@@G,


s=   'I= =JJK! !AM3(2MM3M++M32M3c                    ddl m}m} t          t          |          }|x|d<   |d<    |t	          |           g|z   fi |}|                                \  }}|                                }t          j        	                    |          r1t          j        
                    |t          j                              }|dk    rt          j        	                    |          r1t          j        
                    |t          j                              }t          j        j                            ||t	          |           ||          |S )z return stdout text from executing a system child process,
            where the 'self' path points to executable.
            The process is directly invoked and not through a system shell.
        r   )PopenPIPEstdoutstderr)
subprocessr~  r  r   r[   communicatewaitr/   r  r6  r8  r9  r:  processcmdexecError)	r$   argv
popen_optsr~  r  procr  r  rets	            r   sysexeczLocalPath.sysexec  s3   
 	+*******3%%6::
8z(3uc$ii[4'66:66))++iikk:v&& 	JZ''0F0H0HIIF!88z""6** N++FC4J4L4LMM*$**3SYY+16< < <r   c                    t          |          r9t          j                            |          }|                    d          r|S nx|t
          rtt          j        d                             d          }d|vrd|vr|	                    d           	 t          j        d         fd	|D             }n5# t          $ r Y n)w xY wt          j        d
                             d          }g }t
          r2|t          j        d                             t          j                  z  }|	                    d           |D ]}|D ]~}t          j                            |                              |d          |z   }	 |                    d          r|r ||          s^|c c S e# t          j        j        $ r Y {w xY wdS )ab   return a path object found by looking at the systems
            underlying PATH specification. If the checker is not None
            it will be invoked to filter matching paths.  If a binary
            cannot be found, None is returned
            Note: This is probably not working on plain win32 systems
            but may work on cygwin.
        rc   r  NPath;r   r   
SYSTEMROOTc                 <    g | ]}|                     d           S )z%SystemRoot%)r   )r   r(   
systemroots     r   r   z%LocalPath.sysfind.<locals>.<listcomp>  s7     !4 !4 !4%) "&nj!I!I !4 !4 !4r   PATH:PATHEXTT)r   )r   r/   r(   localrQ   r   rY   environr   r   r   pathseprj   r0   EACCES)	clsr%   checkerpathsr  tryaddrR   addextr  s	           @r   sysfindzLocalPath.sysfind  s    ;; "	d##AwwAw  } :Jv.44S99E3e+;+;S)))4%'Z%=
!4 !4 !4 !4-2!4 !4 !4 $    Jv.44S99EF B"*Y/55bjAAAMM" 
 
$ 	 	Fa((--d-==FA777?? %& -'.wqzz !-$,#$HHHHH	%
 8?   	 ts*   B7 7
CC<#F' F''F>=F>c                     	 t           j        d         }nI# t          $ r< 	 t           j        d         t           j        d         z   }n# t          $ r Y Y d S w xY wY nw xY w | |          S )NHOME	HOMEDRIVEHOMEPATH)rY   r  r   )r  rR   s     r   _gethomedirzLocalPath._gethomedir(  s    	
6"AA 	 	 	J{+bj.DD   ttt 	
 s1vvs2    
A%AA
AAAAAc                 l    ddl }t          j                            |                                          S )zf return the system's temporary directory
            (where tempfiles are usually created in)
        r   N)tempfiler/   r(   r  
gettempdir)r  r  s     r   get_temprootzLocalPath.get_temproot6  s-    
 	w}}X0022333r   c                     ddl }||                                 } | t          j                            |j        t          |                              S )zr return a Path object pointing to a fresh new temporary directory
            (which we created ourself).
        r   Nr   )r  r  r/   r0   r1   mkdtempr[   )r  rootdirr  s      r   r  zLocalPath.mkdtemp>  sQ    
 	?&&((Gs28(()9s7||(LLMMMr   session-r     c                 p   ||                                  }|                                fd}d }d }d}	 d}	|                                D ]}
 ||
          }|t          |	|          }	 	 |                    |t          |	dz             z             }|r ||          } ||           nD# t          j        j        t          j        j	        t          j        j
        f$ r ||	k    r |	}Y w xY w	 d }|d	z   fd
} ||          }|rM|rJ|                                D ]4}
 ||
          }|||	|z
  k    r	 |r ||
           nb# t          j        j        t          j        j	        t          j        j
        f$ r*  ||
          }|sY lt          ||z
            |k     rY Y nw xY w|                    t          t          j                              z             }	 |
                    |           |                    d           n# t"          $ r   Y nxY w ||
          r+	 |
                    d           "# t"          $ r   Y 1xY w6	 t$          j        d         }n6# t(          $ r) 	 t$          j        d         }n# t(          $ r d}Y nw xY wY nw xY wt          |          }|d|                    d                   dz   |z   }	 t%          j        |           n# t.          $ r Y nw xY w	 t%          j        ||           n# t.          t2          t4          f$ r Y nw xY w|S )aa   return unique directory with a number greater than the current
            maximum one.  The number is assumed to start directly after prefix.
            if keep is true directories with a number less than (maxnum-keep)
            will be removed. If .lock files are used (lock_timeout non-zero),
            algorithm is multi-process safe.
        Nc                     | j                                         }|                              r6	 t          |t	                    d                   S # t
          $ r Y dS w xY wdS )z; parse the number out of a path (if it matches the prefix) N)r   r   r   ry   r  r   )r(   	nbasenamenprefixs     r   	parse_numz.LocalPath.make_numbered_dir.<locals>.parse_numT  sz    ++--I##G,, yW7888!   DD s   #A 
A#"A#c                    t          j                    }|                     d          }t          |d          r#|                    t          |                     nt          j                            t           j	        t          |          t           j
        t           j        z  t           j        z  d          }t          j        |d          5 }|                    t          |                     ddd           n# 1 swxY w Y   |S )z1 exclusively create lockfile. Throws when failed z.lockrr   i  r2  N)rY   getpidrj   r   rr   r[   r/   r0   r1   r   O_WRONLYO_CREATO_EXCLfdopenr.  )r(   mypidlockfilefdr   s        r   create_lockfilez4LocalPath.make_numbered_dir.<locals>.create_lockfile]  s   IKKEyy))Hx// ($$SZZ0000X**27CMM2;QSQ[C[^`^gCginooYr3'' (1GGCJJ'''( ( ( ( ( ( ( ( ( ( ( ( ( ( (Os   #C==DDc                 d     t          j                     fd}t          j        |           dS )z, ensure lockfile is removed at process exit c                      t          j                    k    rd S 	                                   d S # t          j        j        $ r Y d S w xY wr   )rY   r  r   r/   r0   r  )r  r  s   r   try_remove_lockfilezXLocalPath.make_numbered_dir.<locals>.atexit_remove_lockfile.<locals>.try_remove_lockfilel  s\     9;;%''FOO%%%%%x~   DDs   2 A
	A
N)rY   r  atexitregister)r  r  r  s   ` @r   atexit_remove_lockfilez;LocalPath.make_numbered_dir.<locals>.atexit_remove_lockfilei  sF    IKKE      O/00000r   Tr   rc   c                 l    	 |                                  j        S # t          j        j        $ r Y dS w xY w)z read file modification time N)rA   r  r/   r0   r  )r(   s    r   	get_mtimez.LocalPath.make_numbered_dir.<locals>.get_mtime  s>    zz||))8>   s    33zgarbage-c                 <    | j         }|                              S )z7 check if path denotes directory scheduled for removal )r   r   )r(   bngarbage_prefixs     r   
is_garbagez/LocalPath.make_numbered_dir.<locals>.is_garbage  s    B==000r   rT   USERUSERNAMEcurrent-)r  r   r
  maxr+  r[   r/   r0   r=  rK  EBUSYr   rj   uuiduuid4r$  r   rA  rY   r  r   r   unlinkOSErrorre   r   r-   )r  prefixr  keeplock_timeoutr  r  r  lastmaxmaxnumr(   numudirr  r  r  	udir_time	path_timegarbage_pathusernamesrcdestr  r  s                         @@r   make_numbered_dirzLocalPath.make_numbered_dirH  sC    ?&&((G,,..	 	 	 	 	
	 
	 
		1 	1 	1$ 	F)) . .ioo? --F}}Vc&(mm%;<< 5.t44H**8444HORX_bhnE    f$$  	 	 	  *,	1 	1 	1 	1 	1 IdOO	 #	I #	)) " "ioo?sv}'='=%' 2+OD111HORX_bhnM % % %$-IdOO	( %$Hy9455DD %H ED% $+<<TZ\\ARAR0R#S#SLL111$+++2222,   :d## ****,   	%z&)HH 	% 	% 	%%:j1 % % %$%	% 4yy?CIIcNN?#c)H4	IdOOOO 	 	 	D		JsD!!!!)<= 	 	 	D	 s   2A B3 3>C43C4EAF1F10F1++HH%4II!I4 4
J'?JJ'J!J' J!!J'&J'K2 2
K?>K?L L32L3r   )rc   F)r   r   )r   FN)NN)FFrt   )F)r2  F)Tr   rs   )NT)r  Nr   r  )@rD   rE   rF   r   r   r   rY   ri   r   r   r*   r   r   r   r   r   r   r   r   r   r   r   rj   r   r  r   rQ   setr(   r  r
  r  r  r"  r$  r(  r+  r0  r3  r.  r<  r  r   rA   rI  rL  r   rP  rR  rH  rV  rX  r   r_  rb  r|  r  r  classmethodr  r  r  r  __classcell__)rf   s   @r   r~   r~   o   sY        I I I I Ik I I I &C$ $ $ $ $6? $ $ $0) ) ) ),    # # #, , ,, , ,7 7 7; ; ; ;*   ,& & &P  <? ? ? ? ?  <	? 	? 	? 	?  
$ $ $2 2 2 2 2 C+,,M   .     ! ! !!& !& !& !&FF F F
              *     	 	 	 	I I IX X X X     ^> > >! ! !* * *  
< 
< 
< 
<  * * *[ [ [ [z  (+ + + +X k'""G   +k**K
 4 4 [4 N N N [N FG'-Y Y Y Yt $$566r   r~   c                 :    ddl }|                    | |           dS )z" copy permission from src to dst. r   N)r   r  r  r  r   s      r   r  r    s%    MMM
OOCr   c                 n    ddl }|                    t          |           t          |                     dS )z[ copy permission,  last modification time,
    last access time, and flags from src to dst.r   N)r   r  r[   r  s      r   r  r    s3     MMM
OOCHHc$ii(((((r   c                 z   d}|                      d          }	 |                     d          }	 	 |                    |          }|sn|                    |           .	 |                                 n# |                                 w xY w	 |                                 d S # |                                 w xY w)Nr   r   r&  )r   r   r.  r   )r  r  r   fsrcfdestr   s         r   r  r    s    I88D>>D		$	!ii	** C   	!  KKMMMMEKKMMMMM



s"   B$ /A4 B$ 4B

B$ $B:c                     | rS| d                                          s| d         dk    r/|                     dd          } |  p|                                 S d S d S )Nr   _r   )isalphar   isalnum)r%   s    r   r]  r]    sa     *a"" *d1gnn||C$$x)4<<>>)* *nnr   ).r   
__future__r   
contextlibr   r9  rY   r  r  r  r/   py._pathr   py._path.commonr   r   r   r   r	   r
   os.pathr   r   r   r   r   r   r   r   version_infor   r   rh  rd  r   r   PathBaserJ   rV   rW   FSBaser~   r  r  r  r]  rH   r   r   <module>r     sU    & % % % % % % % % % % %                                         				       + + + + + + + + * * * * * * * * * * T T T T T T T T T T T T T T T T T T T Te% % % % K'%/  !3 !3 !3 !3 !36 !3 !3 !3F"D "D "D "D "D "D "D "DH     	"	5fos7 s7 s7 s7 s7 s7 s7 s7l  ) ) )  "* * * * *r   