o
    pf	                     @   s   d Z ddlmZmZmZ ddlZddlZddlZddlZddl	m
Z
mZ ddlmZ ejr5ddlmZmZ G dd	 d	ed	g d
ZedejZdd ZdS )z9Function to parse FS URLs in to their constituent parts.
    )absolute_importprint_functionunicode_literalsN)parse_qsunquote   )
ParseError)OptionalTextc                   @   s   e Zd ZdZdS )ParseResulta+  A named tuple containing fields of a parsed FS URL.

    Attributes:
        protocol (str): The protocol part of the url, e.g. ``osfs``
            or ``ftp``.
        username (str, optional): A username, or `None`.
        password (str, optional): A password, or `None`.
        resource (str): A *resource*, typically a domain and path, e.g.
            ``ftp.example.org/dir``.
        params (dict): A dictionary of parameters extracted from the
            query string.
        path (str, optional): A path within the filesystem, or `None`.

    N)__name__
__module____qualname____doc__ r   r   H/home/ertert/spirit/venv/lib/python3.10/site-packages/fs/opener/parse.pyr      s    r   )protocolusernamepasswordresourceparamspathz>
^
(.*?)
:\/\/

(?:
(?:(.*?)@(.*?))
|(.*?)
)

(?:
!(.*?)$
)*$
c                 C   s   t | }|du rtd| | \}}}}}|s"d}d}|}	n|d\}}
}t|}t|}|}	|	d\}	}}t|	}|rSt|dd}dd t	|D }ni }t
||||||S )	a  Parse a Filesystem URL and return a `ParseResult`.

    Arguments:
        fs_url (str): A filesystem URL.

    Returns:
        ~fs.opener.parse.ParseResult: a parse result instance.

    Raises:
        ~fs.errors.ParseError: if the FS URL is not valid.

    Nz{!r} is not a fs2 url:?T)keep_blank_valuesc                 S   s   i | ]\}}|t |d  qS )r   )r   ).0kvr   r   r   
<dictcomp>\   s    z parse_fs_url.<locals>.<dictcomp>)
_RE_FS_URLmatchr   formatgroups	partitionr   r   six	iteritemsr   )fs_urlr    fs_namecredentialsurl1url2r   r   r   url_has_qsqsr   _paramsr   r   r   r   parse_fs_url<   s&   
r0   )r   
__future__r   r   r   typingcollectionsrer$   six.moves.urllib.parser   r   errorsr   TYPE_CHECKINGr	   r
   
namedtupler   compileVERBOSEr   r0   r   r   r   r   <module>   s*    
