U
    -¿áfG  ã                   @   s   d Z dd„ Zdd„ ZdS )z˜Convert a NT pathname to a file URL and vice versa.

This module only exists to provide OS-specific code
for urllib.requests, thus do not use directly.
c                 C   sü   ddl }ddl}|  dd¡} d| kr\| dd… dkr@| dd… } |  d¡}|j d	 |¡¡S |  d¡}t|ƒdks„|d d
 |jkr”d|  }t	|ƒ‚|d d
  
¡ }|d  d¡}|d }|D ]}|r¾|d	 |j |¡ }q¾| d¡rø|  d¡rø|d	7 }|S )z{OS-specific conversion from a relative URL of the 'file' scheme
    to a file system path; not recommended for general use.é    Nú:ú|é   z////é   ú/ú\éÿÿÿÿz	Bad URL: é   )ÚstringÚurllib.parseÚreplaceÚsplitÚparseZunquoteÚjoinÚlenZascii_lettersÚOSErrorÚupperÚendswith)Zurlr
   ÚurllibÚ
componentsÚcompÚerrorÚdriveÚpath© r   ú /usr/lib/python3.8/nturl2path.pyÚurl2pathname   s(    	

r   c                 C   s4  ddl }| dd… dkrf| dd… } | dd…  ¡ dkrJd| dd…  } n| dd… d	krftd
|  ƒ‚d	| kr¢| dd… dkr†d|  } |  d¡}|j d |¡¡S | jd	dd}t|ƒdksÌt|d ƒdkrÜd
|  }t|ƒ‚|j |d  ¡ ¡}|d  d¡}d| d	 }|D ] }|r|d |j |¡ }q|S )z{OS-specific conversion from a file system path to a relative URL
    of the 'file' scheme; not recommended for general use.r   Nr   z\\?\zUNC\r   r	   r   r   z
Bad path: z\\r   )Úmaxsplitz///)r   r   r   r   r   Zquoter   r   )Úpr   r   r   r   r   r   r   r   r   Úpathname2url-   s.    
r   N)Ú__doc__r   r   r   r   r   r   Ú<module>   s   %