o
    bi%                     @   s<   d Z ddlmZ ddlmZ ddlmZ G dd deZdS )z6Module containing the logic for the URIBuilder object.   )compat)normalizers)uric                   @   sn   e Zd ZdZ		dddZdd Zdd Zd	d
 Zdd Zdd Z	dd Z
dd Zdd Zdd Zdd ZdS )
URIBuildera  Object to aid in building up a URI Reference from parts.

    .. note::

        This object should be instantiated by the user, but it's recommended
        that it is not provided with arguments. Instead, use the available
        method to populate the fields.

    Nc                 C   s.   || _ || _|| _|| _|| _|| _|| _dS )a  Initialize our URI builder.

        :param str scheme:
            (optional)
        :param str userinfo:
            (optional)
        :param str host:
            (optional)
        :param int port:
            (optional)
        :param str path:
            (optional)
        :param str query:
            (optional)
        :param str fragment:
            (optional)
        Nschemeuserinfohostportpathqueryfragment)selfr   r   r	   r
   r   r   r    r   _/var/www/secure340b-portal/env/lib/python3.10/site-packages/urllib3/packages/rfc3986/builder.py__init__    s   
zURIBuilder.__init__c                 C   s   d}|j | dS )z0Provide a convenient view of our builder object.zURIBuilder(scheme={b.scheme}, userinfo={b.userinfo}, host={b.host}, port={b.port}, path={b.path}, query={b.query}, fragment={b.fragment}))b)format)r   Z	formatstrr   r   r   __repr__;   s   zURIBuilder.__repr__c              	   C   s,   t |}t|| j| j| j| j| j| jdS )a  Add a scheme to our builder object.

        After normalizing, this will generate a new URIBuilder instance with
        the specified scheme and all other attributes the same.

        .. code-block:: python

            >>> URIBuilder().add_scheme('HTTPS')
            URIBuilder(scheme='https', userinfo=None, host=None, port=None,
                    path=None, query=None, fragment=None)

        r   )	r   Znormalize_schemer   r   r	   r
   r   r   r   )r   r   r   r   r   
add_schemeB   s   
zURIBuilder.add_schemec              	   C   sV   |du rt dt|}|durd|t|}t| j|| j| j| j	| j
| jdS )a  Add credentials as the userinfo portion of the URI.

        .. code-block:: python

            >>> URIBuilder().add_credentials('root', 's3crete')
            URIBuilder(scheme=None, userinfo='root:s3crete', host=None,
                    port=None, path=None, query=None, fragment=None)

            >>> URIBuilder().add_credentials('root', None)
            URIBuilder(scheme=None, userinfo='root', host=None,
                    port=None, path=None, query=None, fragment=None)
        NzUsername cannot be Nonez{}:{}r   )
ValueErrorr   Znormalize_usernamer   Znormalize_passwordr   r   r	   r
   r   r   r   )r   usernamepasswordr   r   r   r   add_credentialsZ   s"   
zURIBuilder.add_credentialsc              	   C   s(   t | j| jt|| j| j| j| jdS )a  Add hostname to the URI.

        .. code-block:: python

            >>> URIBuilder().add_host('google.com')
            URIBuilder(scheme=None, userinfo=None, host='google.com',
                    port=None, path=None, query=None, fragment=None)

        r   )	r   r   r   r   normalize_hostr
   r   r   r   )r   r	   r   r   r   add_host{   s   
zURIBuilder.add_hostc              	   C   s\   t |}|dk rtd||dkrtd|t| j| j| jd|| j| j| j	dS )a  Add port to the URI.

        .. code-block:: python

            >>> URIBuilder().add_port(80)
            URIBuilder(scheme=None, userinfo=None, host=None, port='80',
                    path=None, query=None, fragment=None)

            >>> URIBuilder().add_port(443)
            URIBuilder(scheme=None, userinfo=None, host=None, port='443',
                    path=None, query=None, fragment=None)

            z5ports are not allowed to be negative. You provided {}i  z>ports are not allowed to be larger than 65535. You provided {}z{}r   )
intr   r   r   r   r   r	   r   r   r   )r   r
   Zport_intr   r   r   add_port   s.   zURIBuilder.add_portc              	   C   s<   | ds
d|}t| j| j| j| jt|| j	| j
dS )a  Add a path to the URI.

        .. code-block:: python

            >>> URIBuilder().add_path('sigmavirus24/rfc3985')
            URIBuilder(scheme=None, userinfo=None, host=None, port=None,
                    path='/sigmavirus24/rfc3986', query=None, fragment=None)

            >>> URIBuilder().add_path('/checkout.php')
            URIBuilder(scheme=None, userinfo=None, host=None, port=None,
                    path='/checkout.php', query=None, fragment=None)

        /z/{}r   )
startswithr   r   r   r   r	   r
   r   normalize_pathr   r   )r   r   r   r   r   add_path   s   

zURIBuilder.add_pathc              	   C   s2   t t|}t| j| j| j| j| j	|| j
dS )a  Generate and add a query a dictionary or list of tuples.

        .. code-block:: python

            >>> URIBuilder().add_query_from({'a': 'b c'})
            URIBuilder(scheme=None, userinfo=None, host=None, port=None,
                    path=None, query='a=b+c', fragment=None)

            >>> URIBuilder().add_query_from([('a', 'b c')])
            URIBuilder(scheme=None, userinfo=None, host=None, port=None,
                    path=None, query='a=b+c', fragment=None)

        r   )r   normalize_queryr   	urlencoder   r   r   r	   r
   r   r   )r   Zquery_itemsr   r   r   r   add_query_from   s   zURIBuilder.add_query_fromc              	   C   s(   t | j| j| j| j| jt|| jdS )a  Add a pre-formated query string to the URI.

        .. code-block:: python

            >>> URIBuilder().add_query('a=b&c=d')
            URIBuilder(scheme=None, userinfo=None, host=None, port=None,
                    path=None, query='a=b&c=d', fragment=None)

        r   )	r   r   r   r	   r
   r   r   r#   r   )r   r   r   r   r   	add_query   s   
zURIBuilder.add_queryc              
   C   s(   t | j| j| j| j| j| jt|dS )a  Add a fragment to the URI.

        .. code-block:: python

            >>> URIBuilder().add_fragment('section-2.6.1')
            URIBuilder(scheme=None, userinfo=None, host=None, port=None,
                    path=None, query=None, fragment='section-2.6.1')

        r   )	r   r   r   r	   r
   r   r   r   Znormalize_fragment)r   r   r   r   r   add_fragment   s   
zURIBuilder.add_fragmentc                 C   s,   t | jt| j| j| jf| j| j	| j
S )a>  Create a URIReference from our builder.

        .. code-block:: python

            >>> URIBuilder().add_scheme('https').add_host('github.com'
            ...     ).add_path('sigmavirus24/rfc3986').finalize().unsplit()
            'https://github.com/sigmavirus24/rfc3986'

            >>> URIBuilder().add_scheme('https').add_host('github.com'
            ...     ).add_path('sigmavirus24/rfc3986').add_credentials(
            ...     'sigmavirus24', 'not-re@l').finalize().unsplit()
            'https://sigmavirus24:not-re%40l@github.com/sigmavirus24/rfc3986'

        )r   ZURIReferencer   r   Znormalize_authorityr   r	   r
   r   r   r   )r   r   r   r   finalize  s   zURIBuilder.finalize)NNNNNNN)__name__
__module____qualname____doc__r   r   r   r   r   r   r"   r%   r&   r'   r(   r   r   r   r   r      s    

!'r   N)r,    r   r   r   objectr   r   r   r   r   <module>   s
   