
    Nf                     t    d Z ddlZddlmZ ddlmZ  ej                  d      Zd Zd Z	d Z
d	 Z	 dd
Zd Zy)zA collection of URI utilities with logic built on the VSCode URI library.

https://github.com/Microsoft/vscode-uri/blob/e59cab84f5df6265aed18ae5f43552d3eef13bb9/lib/index.ts
    N)parse)IS_WINz^\/[a-zA-Z]:c                 .   t        j                  |       \  }}}}}}t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      t        j                  |      fS )z$Parse and decode the parts of a URI.)r   urlparseunquote)urischemenetlocpathparamsqueryfragments          *lib/python3.12/site-packages/pylsp/uris.pyr   r      so    49NN34G1FFD&%ffdfeh     c           
         | \  }}}}}}t         j                  |      r|dd t        j                  |dd       z   }nt        j                  |      }t        j                  t        j                  |      t        j                  |      |t        j                  |      t        j                  |      t        j                  |      f      S )z"Unparse and encode parts of a URI.N   )RE_DRIVE_LETTER_PATHmatchr   quote
urlunparse)partsr	   r
   r   r   r   r   quoted_paths           r   r   r      s    491FFD&% !!$'2AhT!"X!66kk$'KKKKKKKKKK!	
	 	r   c                     t        |       \  }}}}}}|r|r|dk(  rdj                  ||      }n1t        j                  |      r|d   j	                         |dd z   }n|}t
        r|j                  dd      }|S )a&  Returns the filesystem path of the given URI.

    Will handle UNC paths and normalize windows drive letters to lower-case. Also
    uses the platform specific path separator. Will *not* validate the path for
    invalid characters and semantics. Will *not* look at the scheme of this URI.
    filez//{}{}      N/\)r   formatr   r   lowerr   replace)r   r	   r
   r   _params_query	_fragmentvalues           r   
to_fs_pathr&   4   s~     8@}4FFD'69$6V+-		#	#D	)Q$qr(* c4(Lr   c                 P    d}d\  }}}t        |       \  } }t        ||| |||f      S )z,Returns a URI for the given filesystem path.r   ) r(   r(   )_normalize_win_pathr   )r   r	   r   r   r   r
   s         r   from_fs_pathr*   P   s9    F(FE8&t,LD&vvtVUHEFFr   c           	          t        |       \  }}}	}
}}t        |      \  }}t        |xs ||xs ||xs |	|xs |
|xs ||xs |f      S )zTReturn a URI with the given part(s) replaced.

    Parts are decoded / encoded.
    )r   r)   r   )r   r	   r
   r   r   r   r   
old_scheme
old_netlocold_path
old_params	old_queryold_fragment_netlocs                 r   uri_withr3   X   ss     MUMIJ
Hj)\ (-MD' j jH jY$	
	 	r   c                 0   d}t         r| j                  dd      } | d d dk(  r'| j                  dd      }|dk(  r| dd  }n
| d| }| |d  } | j                  d      sd| z   } t        j                  |       r| d   | d   j                         z   | dd  z   } | |fS )	Nr(   r   r   r   z//r   r   )r   r!   index
startswithr   r   r    )r   r
   idxs      r   r)   r)   o   s    F
 ||D#& BQx4jja "9!"XF!C[F:D ??3Tz !!$'Awa(483<r   )NNNNNN)__doc__reurllibr   pylspr   compiler   r   r   r&   r*   r3   r)    r   r   <module>r?      sL   
 
  !rzz/2 
,8G QU.r   