
    Xh}                     t    d dl Z d dlZd dlmZ d dlmZ d dlmZmZ dZ	d Z
d Zdeeef   d	eeef   d
efdZy)    N)Path)Union)unquoteurlparsez^file://([^/]+|/[A-Z]:)c                     t        |       j                         j                         j                         }t	        j
                  t        d |      }|S )zAttempt to make an LSP rootUri from a ContentsManager root_dir

    Special care must be taken around windows paths: the canonical form of
    windows drives and UNC paths is lower case
    c                 ^    dj                  | j                  d      j                               S )Nz	file://{}   )formatgrouplower)ms    E/var/www/html/myenv/lib/python3.12/site-packages/jupyter_lsp/paths.py<lambda>z normalized_uri.<locals>.<lambda>   s"    +"4"4QWWQZ5E5E5G"H     )r   
expanduserresolveas_uriresubRE_PATH_ANCHOR)root_dirroot_uris     r   normalized_urir   
   sE     H~((*224;;=HvvH(H Or   c                     t         j                  dk(  }t        |       }t        |j                        }|r|j                  d      r|dd }|S |}|S )zReturn a path string for give file:/// URI.

    Respect the different path convention on Windows.
    Based on https://stackoverflow.com/a/57463161/6646912, BSD 0
    nt/r	   N)osnamer   r   path
startswith)file_uriwindows_pathfile_uri_parsedfile_uri_path_unquotedresults        r   file_uri_to_pathr&      s\     77d?Lx(O$_%9%9:.99#>'+ M (Mr   rootr   returnc                     	 t        |      j                         j                  t        |       j                                y# t        $ r Y yw xY w)z"Return if path is relative to rootTF)r   r   relative_to
ValueError)r'   r   s     r   is_relativer,   '   sD    T
((d););)=> s   ?A 	AA)r   r   pathlibr   typingr   urllib.parser   r   r   r   r&   strboolr,    r   r   <module>r3      sO    	 	   *+
 eCI& eCI.> 4 r   