
    8@d                     p    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dS )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.11/site-packages/pylsp/uris.pyr   r      sv    49N34G4G1FFD&%ffdfeh     c           
         | \  }}}}}}t                               |          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&% !!$'' (2A2hT!""X!6!66k$''FFFEH   r   c                 2   t          |           \  }}}}}}|r|r|dk    rd                    ||          }nBt                              |          r&|d                                         |dd         z   }n|}t
          r|                    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&   0   s     8@}}4FFD'69 
$ 
6V++--		#	#D	)	) Q$qrr(*  )c4((Lr   c                 `    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*   L   s?    F(FE8&t,,LD&vvtVUHEFFFr   c                     t          |           \  }}}	}
}}t          |          \  }}t          |p||p||p|	|p|
|p||p|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   T   sw    
 MUUXMMIJ
Hj)\'--MD'*** L   r   c                    d}t           r|                     dd          } | d d         dk    r;|                     dd          }|dk    r| dd          }n| d|         }| |d          } |                     d          sd| z   } t                              |           r.| d         | d                                         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)   e   s    F
  '||D#&& BQBx4jja  "99!""XFF!C%[F:D ??3 Tz !!$'' 4Awa(483<r   )NNNNNN)__doc__reurllibr   pylspr   compiler   r   r   r&   r*   r3   r)    r   r   <module>r?      s     
			            !rz/22 
 
 
  (  8G G G   "    r   