
    ^h
                         S r SSKrSSKrSSKrSSKrSSKrSSKJr  \R                  " 5       r	SS jr
S r \R                  rS rS	 rSS
 jrg! \ a    Sr Nf = f)z
Utilities for path handling.
    N   )	py3compatc                 n   U R                  S5      R                  S5      n [        R                  R                  U 5      (       a&  [        R                  R	                  U 5      (       a  U $ Uc  SnO"[        U[        R                  5      (       a  U4nU H  nUS:X  a  [        R                  " 5       n[        [        R                  R                  X 5      5      n[        R                  R	                  U5      (       d  Ml  [        R                  R                  U5      s  $    [        SU < SU< 35      e)ac  Find a file by looking through a sequence of paths.

This iterates through a sequence of paths looking for a file and returns
the full, absolute path of the first occurence of the file.  If no set of
path dirs is given, the filename is tested as is, after running through
:func:`expandvars` and :func:`expanduser`.  Thus a simple call::

    filefind('myfile.txt')

will find the file in the current working dir, but::

    filefind('~/myfile.txt')

Will find the file in the users home directory.  This function does not
automatically try any paths, such as the cwd or the user's home directory.

Parameters
----------
filename : str
    The filename to look for.
path_dirs : str, None or sequence of str
    The sequence of paths to look for the file in.  If None, the filename
    need to be absolute or be in the cwd.  If a string, the string is
    put into a sequence and the searched.  If a sequence, walk through
    each element and join with ``filename``, calling :func:`expandvars`
    and :func:`expanduser` before testing for existence.

Returns
-------
Raises :exc:`IOError` or returns absolute path to file.
"') .zFile z, does not exist in any of the search paths: )stripospathisabsisfile
isinstancer   string_typesgetcwdexpand_pathjoinabspathIOError)filename	path_dirsr   testnames       O/home/james-whalen/.local/lib/python3.13/site-packages/ipython_genutils/path.pyfilefindr      s    D ~~c"((-H	ww}}X277>>(#;#;		Iy55	6	6L	3;y//1rww||D;<77>>(##77??8,,	  Y( * *    c                    [         R                  S:X  a  U R                  SS5      n [         R                  R	                  [         R                  R                  U 5      5      n [         R                  S:X  a  U R                  SS5      n U $ )zExpand $VARS and ~names in a string, like a shell

:Examples:

   In [2]: os.environ['FOO']='test'

   In [3]: expand_path('variable FOO is $FOO')
   Out[3]: 'variable FOO is test'
ntz$\IPYTHON_TEMP)r   namereplacer   
expandvars
expanduser)ss    r   r   r   K   sb     
ww}IIe^,
277--a01A	ww}IIne,Hr   i  c                     [        [        S5      (       d  [        $ Sn [        R                  " X5        U$ ! [         a  nUR
                  n SnAU$ SnAff = f)zHard links ``src`` to ``dst``, returning 0 or errno.

Note that the special errno ``ENOLINK`` will be returned if ``os.link`` isn't
supported by the operating system.
linkr   N)hasattrr   ENOLINKr%   OSErrorerrno)srcdst
link_errnoes       r   r%   r%   g   sU     2vJ
   WW
s   7 
AAAc                    [         R                  R                  U5      (       a=  [         R                  R                  U[         R                  R	                  U 5      5      n[        X5      nU[        R                  :X  a  [         R                  " U 5      R                  [         R                  " U5      R                  :X  a  gUS[        R                  " SS5      4-  -   n [        X5        [         R                  " X15        gUS:w  a  [         R"                  " X5        gg!    [         R                  " U5        e ! [         a     e f = f= f)a  Attempts to hardlink ``src`` to ``dst``, copying if the link fails.

Attempts to maintain the semantics of ``shutil.copy``.

Because ``os.link`` does not overwrite files, a unique temporary file
will be used if the target already exists, then that file will be moved
into place.
Nz
-temp-%04Xr   i   r   )r   r   isdirr   basenamer%   r)   EEXISTstatst_inorandomrandintlink_or_copyremover(   renameshutilcopy)r*   r+   r,   new_dsts       r   r6   r6   x   s     
ww}}Sggll3 0 0 56cJU\\!773<"''#,"5"55 v~~a'?&BBB	& 			'	q 	C 
			'"   s0   #D# #E&D=<E=
E
E	E

Ec                 H   [         R                  R                  U 5      (       d   [         R                  " XS9  g[         R                  R                  U 5      (       d  [        SU -  5      eg! [         a)  nUR
                  [
        R                  :w  a  e  SnAgSnAff = f)zensure that a directory exists

If it doesn't exist, try to create it and protect against a race condition
if another process is doing the same.

The default permissions are 755, which differ from os.makedirs default of 777.
)modeNz %r exists but is not a directory)	r   r   existsmakedirsr(   r)   r1   r/   r   )r   r=   r-   s      r   ensure_dir_existsr@      s}     77>>$	KK( WW]]4  84?@@ !  	ww%,,& '	s   A. .
B!8BB!)N)i  )__doc__r   sysr)   r9   r4   r   r   getfilesystemencodingfs_encodingr   r   r'   AttributeErrorr%   r6   r@    r   r   <module>rG      so    
 
     '')3*l.mmG""JAs  Gs   A AA