wL i*(dZddlZddlZddlZddlZddlZddlZddlZddlm Z ejZ dZ ejdk(rdZndZdZd ed efd Zd Zdd ed efdZGddeZdd efdZdZdZdZdZdZdZdZdZddZy)z Utilities for path handling. N)systemctjj|xr$tj|tjS)zBWhether `path` is a directory, to which the user has write access.)ospathisdiraccessW_OKrs X/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/IPython/utils/path.py _writable_dirr s) 77==  ;299T277#;;win32c< ddl}|jjj}|j |j |j g|_|jd}|||d}|dk(s|dkDr|S|jS#t$r}td|d}~wwxYw)zGet a long path name (expand ~) on Windows using ctypes. Examples -------- >>> get_long_path_name('c:\\docume~1') 'c:\\Documents and Settings' rNz2you need to have ctypes installed for this to worki) ctypes ImportErrorwindllkernel32GetLongPathNameW c_wchar_pc_uintargtypescreate_unicode_buffervalue)rre_GetLongPathNamebufrvs r _get_long_path_namers [ "==11BB%+%5%5v7G7G MM%!**3/ dC - 7b3hK99  [RSYZ Z [sB B BBc|S)z Dummy no-op.r s r rr6s r ct|S)zExpand a path into its long form. On Windows this expands any ~ in the paths. On other platforms, it is a null operation. )rr s r get_long_path_namer"<s t $$r rreturnctjjd}|j|rd|t |dz}|S)z%Reverse of :func:`os.path.expanduser`~N)rr expanduser startswithlen)rhomes r compress_userr*Es< 77  c "D td3t9:&& Kr c tjj|}tjj|r|S|j ds&|dz}tjj|r|St d|z)zReturn a valid python filename in the current directory. If the given name is not a file, it adds '.py' and searches again. Raises IOError with an informative message if the file isn't found. z.pyzFile `%r` not found.)rrr&isfileendswithIOError)namepy_names r get_py_filenamer1Lsh 77  d #D ww~~d == , 77>>' "N (4/ 00r filenamec&|jdjd}tjj|r!tjj |r|S|d}nt |t r|f}|D]}|dk(rtj}ttjj||}tjj |setjj|cStd|d|)aFind 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 occurrence 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 ------- path : str returns absolute path to file. Raises ------ IOError "').zFile z, does not exist in any of the search paths: ) striprrisabsr, isinstancestrgetcwd expand_pathjoinabspathr.)r2 path_dirsrtestnames r filefindrB]sN~~c"((-H ww}}X277>>(#; Is #L - 3;ryy{rww||D(;< 77>>( #77??8, , - Y( **r c eZdZy) HomeDirErrorN)__name__ __module__ __qualname__r r r rDrDsr rDctjjd}tjj|}t |sRtj dk(r? ddl}|j|jd5}|j|dd}ddd|r t |rt|tsJd|Std|z#1swY=xYw#YDxYw) aVReturn the 'home' directory, as a unicode string. Uses os.path.expanduser('~'), and checks for writability. See stdlib docs for how this is determined. For Python <3.8, $HOME is first priority on *ALL* platforms. For Python >=3.8 on Windows, %HOME% is no longer considered. Parameters ---------- require_writable : bool [default: False] if True: guarantees the return value is a writable directory, otherwise raises HomeDirError if False: The path is resolved, but it is not guaranteed to exist or be writable. r%ntrNz@Software\Microsoft\Windows\CurrentVersion\Explorer\Shell FoldersPersonalz#Homedir should be unicode not byteszD%s is not a writable dir, set $HOME environment variable to override) rrr&realpathr r/winregOpenKeyHKEY_CURRENT_USER QueryValueExr:r;rD)require_writablehomedirwregkeys r get_home_dirrTs&gg  %Gggw'G  !bggo  !&&S ?++C ;A>  ? w!7'3'N)NN'=?FGH H ? ?   s$ C>CCCCC ctj}tjdk(r]|jddxs(tjj t d}|rt|rt|tsJ|Sy)zReturn the XDG_CONFIG_HOME, if it is defined and exists, else None. This is only for non-OS X posix (Linux,Unix,etc.) systems. posixXDG_CONFIG_HOMENz.config renvironr/getrr>rTr r:r;envxdgs r get_xdg_dirr^sd **C ww'gg'.Y"'',,|~y2Y =%c3' ''J r ctj}tjdk(r]|jddxs(tjj t d}|rt|rt|tsJ|Sy)zReturn the XDG_CACHE_HOME, if it is defined and exists, else None. This is only for non-OS X posix (Linux,Unix,etc.) systems. rVXDG_CACHE_HOMENz.cacherXr[s r get_xdg_cache_dirrasd **C ww'gg&-Wlnh1W =%c3' ''J r ctjdk(r|jdd}tjj tjj |}tjdk(r|jdd}|S)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' rIz$\ IPYTHON_TEMP)rr/replacer expandvarsr&)ss r r=r=sb ww} IIe^ , 277--a01A ww} IIne , Hr c\d}djt||jdS)z"Unescape glob pattern in `string`.cVdD]#}|jdj||}%|S)Nz*[]!?z\{0})rdformat)rfpatterns r unescapezunescape_glob..unescapes/ mapsplit)stringrks r unescape_globrps( 99S6<<#78 99r cg}tjdk7rtnd}|D]1}|jt j|xs ||g3|S)z Do glob expansion for each element in `args` and return a flattened list. Unmatched glob pattern will remain as-is in the returned list. rc|SNr )xs r zshellglob..sqr )sysplatformrpextendglob)argsexpandedrkas r shellglobr} sPH!$  7}[H 7 ! 5! 67 Or icttdstSd} tj|||S#t$r}|j }Yd}~|Sd}~wwxYw)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. linkrN)hasattrrENOLINKrOSErrorerrno)srcdst link_errnors r rrsT 2v J S  WW s2 A A  Actjj|r=tjj|tjj |}t ||}|t jk(rtj|jtj|jk(ry|dtjddfzz} t||tj||y|dk7rt!j"||yy# tj|#t$rYwxYwxYw)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-%04Xir)rrrr>basenamerrEEXISTstatst_inorandomrandint link_or_copyremoverrenameshutilcopy)rrrnew_dsts r rr/s ww}}Sggll3 0 0 56c3JU\\! 773<  "''#,"5"5 5  v~~a'?&BBB  g & '3 q  C    '"    s0 DED32E3 D?<E>D??Ec6tjj|s tj||ytjj|std|zy#t$r(}|j t j k7rYd}~yd}~wwxYw)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) rrexistsmakedirsrrrrr.)rrrs r ensure_dir_existsrSsy 77>>$   KK4 (WW]]4 84?@@! ww%,,&' sA'' B0BBrs)F)i) __doc__rrvrrrrywarningsIPython.utils.processrgetfilesystemencoding fs_encodingr rwrr"r;r*r1rB ExceptionrDrTr^rar=rpr}rrrrr r r rs ( (c'') <<<72 %1"8*s8*s8*v 9 )HC)HV&& .:  ""HAr