
    "                     h    d Z ddlZddlmZ ddlmZ  ej                  d      Zd Z G d de	      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)URIVariablez	{([^}]+)}c                 P    | r#| j                         }|j                  |       |S |S N)copyupdate)var_dict	overridesoptss      /platform/bq/third_party/uritemplate/template.py_merger      s'    }}I    c                   D    e Zd ZdZd Zd Zd Zd Zd Zd Z	dd	Z
d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.

    c                 L   || _         t        j                  | j                         D cg c]  }t        |j	                         d           c}| _        t               | _        | j
                  D ].  }|j                  D ]  }| j                  j                  |        0 y c c}w )Nr   )	uritemplate_refinditerr   groups	variablesr   variable_namesadd)selfr   mvariablenames        r   __init__zURITemplate.__init__C   s     1<0D0DTXX0N
0N1K
1&0N
 )lH //##''- 0 '
s   #B!c                     d| z  S )NzURITemplate("%s") r   s    r   __repr__zURITemplate.__repr__Q   s    "T))r   c                     | j                   S r   r   r    s    r   __str__zURITemplate.__str__T   s    xxr   c                 4    | j                   |j                   k(  S r   r#   )r   others     r   __eq__zURITemplate.__eq__W   s    xx599$$r   c                 ,    t        | j                        S r   )hashr   r    s    r   __hash__zURITemplate.__hash__Z   s    DHH~r   c                     | j                   s| j                  S |}i | j                   D ]"  }j                  |j                  |             $ fd}fd}|r|n|}t        j                  || j                        S )Nc                 J    j                  | j                         d   d      S )Nr    )getr   )matchexpandeds    r   replace_allz(URITemplate._expand.<locals>.replace_allf   s    <<q 1266r   c                 ^    | j                         d   } d| z  }j                  |       xs |S )Nr   z{%s})r   r.   )r/   varr0   s     r   replace_partialz,URITemplate._expand.<locals>.replace_partiali   s0    LLN1%E5.C<<&-#-r   )r   r   r   expandr   sub)r   r	   replace	expansionvr1   r4   r0   s          @r   _expandzURITemplate._expand]   sj    ~~88O	AOOAHHY/0  	7	.
 &-/+w11r   Nc                 :    | 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	   kwargss      r   r5   zURITemplate.expandr   s    * ||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   r<   s      r   partialzURITemplate.partial   s!      4<<x(@$GHHr   r   )__name__
__module____qualname____doc__r   r!   r$   r'   r*   r:   r5   r?   r   r   r   r   r   "   s0    >.*%2*=.Ir   r   )rC   reuritemplate.orderedsetr   uritemplate.variabler   compiler   r   objectr   r   r   r   <module>rI      s:   " 
 - ,bjj%wI& wIr   