o
    Q `E	                     @   s   d Z ddlmZ ddlmZ ddl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r=dd	lmZmZ ed
g dZG dd
 d
e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TextParseResult)Zprotocolusernamepasswordresourceparamspathc                   @   s   e Zd ZdZdS )r   a+  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   1/usr/lib/python3/dist-packages/fs/opener/parse.pyr      s    z>
^
(.*?)
:\/\/

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

(?:
!(.*?)$
)*$
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)Z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   sixZ	iteritemsr   )Zfs_urlr   Zfs_nameZcredentialsZurl1Zurl2r   r   r   Zurl_Zhas_qsZqsr   Z_paramsr   r   r   r   parse_fs_url>   s&   
r$   )r   Z
__future__r   r   r   collectionsretypingr"   Zsix.moves.urllib.parser   r   errorsr   ZTYPE_CHECKINGr	   r
   
namedtupleZ_ParseResultr   compileVERBOSEr   r$   r   r   r   r   <module>   s*    