o
    {j6h¦  ã                   @   sj   d Z ddlZddlZddlmZ ddlmZ e d¡Zdej	ej
 dej
dej
f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   úc/var/www/html/chefvision.cloud.itp360.com/venv/lib/python3.10/site-packages/uritemplate/template.pyÚ_merge   s
   
r   c                   @   sº   e Zd ZdZdefdd„Zdefdd„Zdefdd	„Zd
ede	fdd„Z
defdd„Zdejde	defdd„Z	ddejej dejdefdd„Z	ddejej dejdd f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 |¡ qqd S )Nc                 S   s   g | ]}t  | ¡ d  ¡‘qS )r   )r   ÚURIVariableÚgroups)Ú.0Úmr   r   r   Ú
<listcomp>K   s    ÿÿz(URITemplate.__init__.<locals>.<listcomp>)r   Útemplate_reÚfinditerÚ	variablesr   Ú
OrderedSetÚ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__Úotherc                 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   Úreplacec                    sv   | j s| jS |}i ‰ | j D ]
}ˆ  | |¡¡ qdddtf‡ fdd„}dddtf‡ fdd„}|r2|n|}t || j¡S )NÚmatchzre.Match[str]r   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)   Úmatch_groupr   r,   r   r   Úreplace_partialq   s   z,URITemplate._expand.<locals>.replace_partial)r   r   r	   ÚexpandÚstrr   Úsub)r   r   r(   Ú	expansionÚvr.   r0   Úreplace_funcr   r,   r   Ú_expandc   s   
zURITemplate._expandNÚkwargsc                 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)r7   r   ©r   r   r8   r   r   r   r1   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   r7   r   r9   r   r   r   Úpartial•   s   zURITemplate.partialr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__r2   r   r    r!   ÚobjectÚboolr%   Úintr'   r   ÚVariableValueDictr7   ÚtÚOptionalÚVariableValuer1   r:   r   r   r   r   r   %   s<    ÿÿ
þþ
þý
üþ
þýür   )r>   ÚreÚtypingrC   Úuritemplater   r   Úcompiler   rD   rB   r   r   r   r   r   r   Ú<module>   s    

ÿþ
ý