a
    ͝Gd                     @   sf   d Z ddlZddlZddlmZ ddlmZ edZej	ej
 ej
ej
dddZG d	d
 d
ZdS )z

uritemplate.template
====================

This module contains the essential inner workings of uritemplate.

What treasures await you:

- URITemplate class

You see a treasure chest of knowledge in front of you.
What do you do?
>

    N)
orderedset)variablez	{([^}]+)})var_dict	overridesreturnc                 C   s   | r|   }|| |S |S N)copyupdate)r   r   opts r   P/var/www/html/django/DPS/env/lib/python3.9/site-packages/uritemplate/template.py_merge   s
    
r   c                   @   s   e Zd ZdZedddZedddZeddd	Zee	d
ddZ
edddZeje	edddZdejej ejedddZdejej ejd dddZdS )URITemplatea	  This parses the template and will be used to expand it.

    This is the most important object as the center of the API.

    Example::

        from uritemplate import URITemplate
        import requests


        t = URITemplate(
            'https://api.github.com/users/sigmavirus24/gists{/gist_id}'
        )
        uri = t.expand(gist_id=123456)
        resp = requests.get(uri)
        for gist in resp.json():
            print(gist['html_url'])

    Please note::

        str(t)
        # 'https://api.github.com/users/sigmavirus24/gists{/gistid}'
        repr(t)  # is equivalent to
        # URITemplate(str(t))
        # Where str(t) is interpreted as the URI string.

    Also, ``URITemplates`` are hashable so they can be used as keys in
    dictionaries.

    uric                 C   sP   || _ dd t| j D | _t | _| jD ]}|jD ]}| j| q8q.d S )Nc                 S   s   g | ]}t | d  qS )r   )r   ZURIVariablegroups).0mr   r   r   
<listcomp>K   s   z(URITemplate.__init__.<locals>.<listcomp>)r   template_refinditer	variablesr   Z
OrderedSetZvariable_namesadd)selfr   varnamer   r   r   __init__F   s    



zURITemplate.__init__)r   c                 C   s   d|  S )NzURITemplate("%s")r   r   r   r   r   __repr__U   s    zURITemplate.__repr__c                 C   s   | j S r   r   r   r   r   r   __str__X   s    zURITemplate.__str__)otherr   c                 C   s   t |tstS | j|jkS r   )
isinstancer   NotImplementedr   )r   r    r   r   r   __eq__[   s    
zURITemplate.__eq__c                 C   s
   t | jS r   )hashr   r   r   r   r   __hash__`   s    zURITemplate.__hash__)r   replacer   c                    sr   | j s| jS |}i  | j D ]} || qdtd fdd}dtd fdd}|r`|n|}t|| jS )Nzre.Match[str])matchr   c                    s     |  d dS )Nr    )getr   )r'   expandedr   r   replace_alln   s    z(URITemplate._expand.<locals>.replace_allc                    s"   |   d }d| } |p |S )Nr   z{%s})r   r)   )r'   Zmatch_groupr   r*   r   r   replace_partialq   s    z,URITemplate._expand.<locals>.replace_partial)r   r   r	   expandstrr   sub)r   r   r&   Z	expansionvr,   r-   Zreplace_funcr   r*   r   _expandc   s    
zURITemplate._expandN)r   kwargsr   c                 K   s   |  t||dS )am  Expand the template with the given parameters.

        :param dict var_dict: Optional dictionary with variables and values
        :param kwargs: Alternative way to pass arguments
        :returns: str

        Example::

            t = URITemplate('https://api.github.com{/end}')
            t.expand({'end': 'users'})
            t.expand(end='gists')

        .. note:: Passing values by both parts, may override values in
                  ``var_dict``. For example::

                      expand('https://{var}', {'var': 'val1'}, var='val2')

                  ``val2`` will be used instead of ``val1``.

        F)r2   r   r   r   r3   r   r   r   r.   z   s    zURITemplate.expandc                 K   s   t | t||dS )a  Partially expand the template with the given parameters.

        If all of the parameters for the template are not given, return a
        partially expanded template.

        :param dict var_dict: Optional dictionary with variables and values
        :param kwargs: Alternative way to pass arguments
        :returns: :class:`URITemplate`

        Example::

            t = URITemplate('https://api.github.com{/end}')
            t.partial()  # => URITemplate('https://api.github.com{/end}')

        T)r   r2   r   r4   r   r   r   partial   s    zURITemplate.partial)N)N)__name__
__module____qualname____doc__r/   r   r   r   objectboolr#   intr%   r   VariableValueDictr2   tOptionalZVariableValuer.   r5   r   r   r   r   r   %   s*    
 
r   )r9   retypingr>   Zuritemplater   r   compiler   r?   r=   r   r   r   r   r   r   <module>   s   

