U
    Cdi                     @   s^   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddlmZ G dd	 d	ed	ej	eZ
d
S )z?Module containing the implementation of the URIReference class.    )
namedtuple   )compat)misc)normalizers)URIMixinc                       sJ   e Zd ZdZdZd fdd	ZejZdd Zdd	 Z	e
dd
dZ  ZS )URIReferencea  Immutable object representing a parsed URI Reference.

    .. note::

        This class is not intended to be directly instantiated by the user.

    This object exposes attributes for the following components of a
    URI:

    - scheme
    - authority
    - path
    - query
    - fragment

    .. attribute:: scheme

        The scheme that was parsed for the URI Reference. For example,
        ``http``, ``https``, ``smtp``, ``imap``, etc.

    .. attribute:: authority

        Component of the URI that contains the user information, host,
        and port sub-components. For example,
        ``google.com``, ``127.0.0.1:5000``, ``username@[::1]``,
        ``username:password@example.com:443``, etc.

    .. attribute:: path

        The path that was parsed for the given URI Reference. For example,
        ``/``, ``/index.php``, etc.

    .. attribute:: query

        The query component for a given URI Reference. For example, ``a=b``,
        ``a=b%20c``, ``a=b+c``, ``a=b,c=d,e=%20f``, etc.

    .. attribute:: fragment

        The fragment component of a URI. For example, ``section-3.1``.

    This class also provides extra attributes for easier access to information
    like the subcomponents of the authority component.

    .. attribute:: userinfo

        The user information parsed from the authority.

    .. attribute:: host

        The hostname, IPv4, or IPv6 address parsed from the authority.

    .. attribute:: port

        The port parsed from the authority.
     utf-8c                    s0   t t| | |pd|pd|pd||}||_|S )zCreate a new URIReference.N)superr   __new__encoding)clsscheme	authoritypathqueryfragmentr   ref	__class__r	   //tmp/pip-unpacked-wheel-79v45wuf/rfc3986/uri.pyr   U   s    
zURIReference.__new__c                 C   sx   |}t |trt| }nBt |tsZzt|}W n( tk
rX   tdt|jY nX t| t|k}|pv| |S )z"Compare this reference to another.z)Unable to compare URIReference() to {0}())	
isinstancetupler   from_string	TypeErrorformattype__name__Znormalized_equality)selfotherZ	other_refZnaive_equalityr	   r	   r   __eq__f   s    



zURIReference.__eq__c                 C   sN   t t| jpdt| j| j| jft| j	p0dt
| jt| j| jS )a  Normalize this reference as described in Section 6.2.2.

        This is not an in-place normalization. Instead this creates a new
        URIReference.

        :returns: A new reference object with normalized components.
        :rtype: URIReference
         )r   r   Znormalize_schemer   Znormalize_authorityuserinfohostportnormalize_pathr   Znormalize_queryr   Znormalize_fragmentr   r   )r   r	   r	   r   	normalizey   s    

zURIReference.normalizec              	   C   sZ   t ||}tj| }| |d |d t|d |t|d |t|d ||S )a	  Parse a URI reference from the given unicode URI string.

        :param str uri_string: Unicode URI to be parsed into a reference.
        :param str encoding: The encoding of the string provided
        :returns: :class:`URIReference` or subclass thereof
        r   r   r   r   r   )r   Zto_strr   ZURI_MATCHERmatch	groupdictr   Zencode_component)r   Z
uri_stringr   Z	split_urir	   r	   r   r      s    zURIReference.from_string)r
   )r
   )r   
__module____qualname____doc__slotsr   r   __hash__r!   r'   classmethodr   __classcell__r	   r	   r   r   r      s   9 r   N)r,   collectionsr   r"   r   r   r   Z_mixinr   ZURI_COMPONENTSr   r	   r	   r	   r   <module>   s   