o
    ”^©i}  ã                   @   sv   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d„ Z
dd	„ Zd
eeef deeef defdd„ZdS )é    N)ÚPath)ÚUnion)ÚunquoteÚurlparsez^file://([^/]+|/[A-Z]:)c                 C   s*   t | ƒ ¡  ¡  ¡ }t tdd„ |¡}|S )z¾Attempt 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                 S   s   d  |  d¡ ¡ ¡S )Nz	file://{}é   )ÚformatÚgroupÚlower)Úm© r   úL/home/ubuntu/hpml_nyu/venv/lib/python3.10/site-packages/jupyter_lsp/paths.pyÚ<lambda>   s    z normalized_uri.<locals>.<lambda>)r   Ú
expanduserÚresolveÚas_uriÚreÚsubÚRE_PATH_ANCHOR)Úroot_dirÚroot_urir   r   r   Únormalized_uri
   s
   
ÿr   c                 C   sB   t jdk}t| ƒ}t|jƒ}|r| d¡r|dd… }|S |}|S )z¨Return 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Úresultr   r   r   Úfile_uri_to_path   s   

ÿr"   Úrootr   Úreturnc                 C   s6   zt |ƒ ¡  t | ƒ ¡ ¡ W dS  ty   Y dS w )z"Return if path is relative to rootTF)r   r   Úrelative_toÚ
ValueError)r#   r   r   r   r   Úis_relative'   s   ÿr'   )r   r   Úpathlibr   Útypingr   Úurllib.parser   r   r   r   r"   ÚstrÚboolr'   r   r   r   r   Ú<module>   s    *