
    ?wg                         d Z ddlZddlZddlmZ ddlmZ  ej                  d      Zdej                  ej                     dej                  dej                  fd	Z G d
 d      Zy)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                 P    | r#| j                         }|j                  |       |S |S N)copyupdate)r   r   optss      K/var/www/horilla/myenv/lib/python3.12/site-packages/uritemplate/template.py_merger      s)     }}I    c                   ,   e Zd ZdZdefdZdefdZdefdZdede	fdZ
defd	Zd
ej                  de	defdZ	 dd
ej"                  ej                     dej$                  defdZ	 dd
ej"                  ej                     dej$                  dd fdZy)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                 t   || _         t        j                  | j                         D cg c](  }t        j                  |j                         d         * c}| _        t        j                         | _	        | j                  D ].  }|j                  D ]  }| j                  j                  |        0 y c c}w )Nr   )r   template_refinditerr   URIVariablegroups	variablesr   
OrderedSetvariable_namesadd)selfr   mvarnames        r   __init__zURITemplate.__init__F   s    
 !))$((38
   A/8

 )335>> 	.C** .##''-.	.8
s   -B5r   c                     d| z  S )NzURITemplate("%s") r   s    r   __repr__zURITemplate.__repr__U   s    "T))r   c                     | j                   S r	   )r   r#   s    r   __str__zURITemplate.__str__X   s    xxr   otherc                 `    t        |t              st        S | j                  |j                  k(  S r	   )
isinstancer   NotImplementedr   )r   r'   s     r   __eq__zURITemplate.__eq__[   s%    %-!!xx599$$r   c                 ,    t        | j                        S r	   )hashr   r#   s    r   __hash__zURITemplate.__hash__`   s    DHH~r   r   replacec                 "   | j                   s| j                  S |}i | j                   D ]"  }j                  |j                  |             $ dddt        ffd}dddt        ffd}|r|n|}t
        j                  || j                        S )Nmatchzre.Match[str]r   c                 J    j                  | j                         d   d      S )Nr    )getr   )r1   expandeds    r   replace_allz(URITemplate._expand.<locals>.replace_alln   s    <<q 1266r   c                 ^    | j                         d   }d|z  }j                  |      xs |S )Nr   z{%s})r   r4   )r1   match_groupr   r5   s      r   replace_partialz,URITemplate._expand.<locals>.replace_partialq   s1    ,,.+K;&C<<,33r   )r   r   r   expandstrr   sub)	r   r   r/   	expansionvr6   r9   replace_funcr5   s	           @r   _expandzURITemplate._expandc   s     ~~88O	%' 	1AOOAHHY/0	1	7 	73 	7	4? 	4s 	4
 +2{|TXX66r   Nkwargsc                 :    | j                  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)r@   r   r   r   rA   s      r   r:   zURITemplate.expandz   s    2 ||F8V4e<<r   c                 L    t        | j                  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   r@   r   rC   s      r   partialzURITemplate.partial   s!    ( 4<<x(@$GHHr   r	   )__name__
__module____qualname____doc__r;   r    r$   r&   objectboolr+   intr.   r   VariableValueDictr@   tOptionalVariableValuer:   rE   r"   r   r   r   r   %   s    >.C .*# * %F %t %
# 7 227=A7	72 <@=**X778= ((= 
	=: <@I**X778I ((I 
	Ir   r   )rI   retypingrN   uritemplater   r   compiler   rO   rM   r   r   r"   r   r   <module>rU      sp     
  "  bjj%jj334)) DI DIr   