ó
k4Vdc           @   sT   d  Z  d d l Z d d l m Z e j d ƒ Z d „  Z d e f d „  ƒ  YZ d S(   sê   

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?
>

iÿÿÿÿN(   t   URIVariables
   {([^\}]+)}c         C   s'   |  r# |  j  ƒ  } | j | ƒ | S| S(   N(   t   copyt   update(   t   var_dictt	   overridest   opts(    (    sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyt   _merge   s
    t   URITemplatec           B   s\   e  Z d  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 d „ Z
 d	 d „ Z RS(
   s	  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         C   sx   | |  _  g  t j |  j  ƒ D] } t | j ƒ  d ƒ ^ q |  _ t ƒ  |  _ x$ |  j D] } |  j j | j ƒ qW Wd  S(   Ni    (	   t   urit   template_ret   finditerR    t   groupst	   variablest   sett   variable_namesR   (   t   selfR   t   mt   variable(    (    sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyt   __init__A   s
    	8c         C   s   d |  S(   Ns   URITemplate("%s")(    (   R   (    (    sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyt   __repr__N   s    c         C   s   |  j  S(   N(   R   (   R   (    (    sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyt   __str__Q   s    c         C   s   |  j  | j  k S(   N(   R   (   R   t   other(    (    sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyt   __eq__T   s    c         C   s   t  |  j ƒ S(   N(   t   hashR   (   R   (    (    sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyt   __hash__W   s    c            s‰   |  j  s |  j S| } i  ‰  x' |  j  D] } ˆ  j | j | ƒ ƒ q& W‡  f d †  } ‡  f d †  } | rp | n | } t j | |  j ƒ S(   Nc            s   ˆ  j  |  j ƒ  d d ƒ S(   Ni    t    (   t   getR   (   t   match(   t   expanded(    sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyt   replace_allc   s    c            s-   |  j  ƒ  d }  d |  } ˆ  j |  ƒ p, | S(   Ni    s   {%s}(   R   R   (   R   t   var(   R   (    sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyt   replace_partialf   s    
(   R   R   R   t   expandR	   t   sub(   R   R   t   replacet	   expansiont   vR   R   (    (   R   sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyt   _expandZ   s    	c         K   s   |  j  t | | ƒ t ƒ S(   sm  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``.

        (   R%   R   t   False(   R   R   t   kwargs(    (    sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyR    o   s    c         K   s   t  |  j t | | ƒ t ƒ ƒ S(   sù  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}')

        (   R   R%   R   t   True(   R   R   R'   (    (    sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyt   partial†   s    N(   t   __name__t
   __module__t   __doc__R   R   R   R   R   R%   t   NoneR    R)   (    (    (    sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyR       s   						(	   R,   t   ret   uritemplate.variableR    t   compileR	   R   t   objectR   (    (    (    sb   /var/www/html/phendo-backend/phendo_python/env/lib/python2.7/site-packages/uritemplate/template.pyt   <module>   s
   	