File: //usr/local/CyberCP/lib/python3.10/site-packages/uritemplate/__pycache__/template.cpython-310.pyc
o
�h� � @ sj d Z ddlZddlZddlmZ ddlmZ e�d�Zdej ej
dej
dej
fd d
�ZG dd� d�ZdS )
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 �G/usr/local/CyberCP/lib/python3.10/site-packages/uritemplate/template.py�_merge s
r
c @ s� e Zd ZdZdefdd�Zdefdd�Zdefdd �Zd
ede fdd�Z
defd
d�Zde
jde defdd�Z ddeje
j de
jdefdd�Z ddeje
j de
jdd fdd�ZdS )�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 || _ dd� t�| j �D �| _t�� | _| jD ]}|jD ]}| j�|� qqd S )Nc S s g | ]}t �|�� d ��qS )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
�
��zURITemplate.__init__r c C s d| S )NzURITemplate("%s")r �r r r r �__repr__U s zURITemplate.__repr__c C s | j S r )r r r r r �__str__X s zURITemplate.__str__�otherc C s t |t�stS | j|jkS r )�
isinstancer �NotImplementedr )r r"