;idZddlZddlZddlmZddlmZejdZdej ej dej dej fd Z Gd d Z dS) 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 overridesreturnc`|r+|}|||S|SN)copyupdate)rroptss HC:\PYTHON\MyICR_Workspace\venv\Lib\site-packages\uritemplate/template.py_mergers6}} I ceZdZdZdefdZdefdZdefdZdede fdZ de fd Z d e jd e defd Z dd eje jde jdefdZ dd eje jde jddfdZd S) 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||_dt|jD|_t j|_|jD]&}|jD]}|j|'dS)Ncfg|].}tj|d/S)r)r URIVariablegroups).0ms r z(URITemplate.__init__..Ks?8 8 8   A / /8 8 8 r)r template_refinditer variablesr OrderedSetvariable_namesadd)selfrvarnames r __init__zURITemplate.__init__Fs8 8  ))$(338 8 8  )355> . .C* . .#''---- . . .rrc d|zS)NzURITemplate("%s")r s r __repr__zURITemplate.__repr__Us "T))rc|jSr )rr&s r __str__zURITemplate.__str__Xs xrothercZt|tstS|j|jkSr ) isinstancerNotImplementedr)r r*s r __eq__zURITemplate.__eq__[s)%-- "! !x59$$rc*t|jSr )hashrr&s r __hash__zURITemplate.__hash__`sDH~~rrreplacec|js|jS|}i|jD]*}||+dddtffd }dddtffd }|r|n|}t ||jS)Nmatchz re.Match[str]rc`|ddS)Nr)getr)r4expandeds r replace_allz(URITemplate._expand..replace_allns$<< q 1266 6rcp|d}d|z}|p|S)Nrz{%s})rr7)r4 match_groupr!r8s r replace_partialz,URITemplate._expand..replace_partialqs6,,..+K;&C<< ,,3 3r)rrr expandstrrsub) r rr2 expansionvr9r< replace_funcr8s @r _expandzURITemplate._expandcs~ 8O %' 1 1A OOAHHY// 0 0 0 0 7 73 7 7 7 7 7 7 4? 4s 4 4 4 4 4 4 +2B{ |TX666rNkwargsc J|t||dS)amExpand 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)rCrr rrDs r r=zURITemplate.expandzs"2||F8V44e<< URITemplate('https://api.github.com{/end}') T)rrCrrFs r partialzURITemplate.partials*(4<<x(@(@$GGHHHrr )__name__ __module__ __qualname____doc__r>r#r'r)objectboolr.intr1rVariableValueDictrCtOptional VariableValuer=rHr%rr rr&su> .C . . . .*#****%F%t%%%% #7 27=A7 77772<@==*X78=(= ====:<@II*X78I(I  IIIIIIrr) rLretypingrQ uritemplaterrcompilerrRrPrrr%rr rXs" """""" bj%% j34)CICICICICICICICICICIr