
    "                     h    S r SSKrSSKJr  SSKJr  \R                  " S5      rS r " S S\	5      r
g)	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                 Z    U (       a#  U R                  5       nUR                  U5        U$ U$ N)copyupdate)var_dict	overridesoptss      /platform/bq/third_party/uritemplate/template.py_merger      s'    }}I    c                   P    \ rS rSrSrS rS rS rS rS r	S r
SS
 jrSS jrSrg	)URITemplate"   a  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                 X   Xl         [        R                  U R                   5       Vs/ s H  n[        UR	                  5       S   5      PM!     snU l        [        5       U l        U R
                   H1  nUR                   H  nU R                  R                  U5        M      M3     g s  snf )Nr   )	uritemplate_refinditerr   groups	variablesr   variable_namesadd)selfr   mvariablenames        r   __init__URITemplate.__init__C   s     1<0D0DTXX0N
0N1K
1&0N
 )lH //##''- 0 '
s   &B'c                     SU -  $ )NzURITemplate("%s") r   s    r   __repr__URITemplate.__repr__Q   s    "T))r   c                     U R                   $ r   r   r"   s    r   __str__URITemplate.__str__T   s    xxr   c                 4    U R                   UR                   :H  $ r   r&   )r   others     r   __eq__URITemplate.__eq__W   s    xx599$$r   c                 ,    [        U R                  5      $ r   )hashr   r"   s    r   __hash__URITemplate.__hash__Z   s    DHH~r   c                   ^ U R                   (       d  U R                  $ Un0 mU R                    H#  nTR                  UR                  U5      5        M%     U4S jnU4S jnU(       a  UOUn[        R                  X R                  5      $ )Nc                 J   > TR                  U R                  5       S   S5      $ )Nr    )getr   )matchexpandeds    r   replace_all(URITemplate._expand.<locals>.replace_allf   s    <<q 1266r   c                 h   > U R                  5       S   n SU -  nTR                  U 5      =(       d    U$ )Nr   z{%s})r   r4   )r5   varr6   s     r   replace_partial,URITemplate._expand.<locals>.replace_partiali   s0    LLN1%E5.C<<&-#-r   )r   r   r   expandr   sub)r   r	   replace	expansionvr7   r;   r6   s          @r   _expandURITemplate._expand]   sh    ~~88O	AOOAHHY/0  	7	.
 &-/+w11r   Nc                 8    U R                  [        X5      S5      $ )a  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)rB   r   r   r	   kwargss      r   r=   URITemplate.expandr   s    * ||F84e<<r   c                 J    [        U R                  [        X5      S5      5      $ )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   rB   r   rE   s      r   partialURITemplate.partial   s      4<<x(@$GHHr   )r   r   r   r   )__name__
__module____qualname____firstlineno____doc__r   r#   r'   r+   r/   rB   r=   rI   __static_attributes__r!   r   r   r   r   "   s0    >.*%2*=.Ir   r   )rO   reuritemplate.orderedsetr   uritemplate.variabler   compiler   r   objectr   r!   r   r   <module>rV      s8   " 
 - ,jj%wI& wIr   