aboutsummaryrefslogtreecommitdiff
path: root/uritemplate/template.py
diff options
context:
space:
mode:
authorEugene Eeo <xe0jun@hotmail.com>2014-12-14 00:48:45 +0800
committerEugene Eeo <xe0jun@hotmail.com>2014-12-14 00:48:45 +0800
commit765d3ba096741672577c85af5f5455fd17b02b3a (patch)
tree199449a66c956d42ac298ca02f2c385b2edeeef9 /uritemplate/template.py
parent940383d720d592e8428bbd641c1ba0052c367fb4 (diff)
downloaduritemplates-765d3ba096741672577c85af5f5455fd17b02b3a.tar.gz
stick closer to suggestion
Diffstat (limited to 'uritemplate/template.py')
-rw-r--r--uritemplate/template.py19
1 files changed, 9 insertions, 10 deletions
diff --git a/uritemplate/template.py b/uritemplate/template.py
index 363e8ea..ee1fab5 100644
--- a/uritemplate/template.py
+++ b/uritemplate/template.py
@@ -21,8 +21,13 @@ from uritemplate.variable import URIVariable
template_re = re.compile('{([^\}]+)}')
-def _update(kwargs, var_dict):
- kwargs.update((k, v) for k, v in var_dict.items() if k not in kwargs)
+def _merge(var_dict, overrides):
+ if var_dict:
+ for k, v in var_dict.items():
+ if k in overrides:
+ continue
+ overrides[k] = v
+ return overrides
class URITemplate(object):
@@ -125,10 +130,7 @@ class URITemplate(object):
``val2`` will be used instead of ``val1``.
"""
- if var_dict:
- _update(kwargs, var_dict)
-
- return self._expand(kwargs, False)
+ return self._expand(_merge(var_dict, kwargs), False)
def partial(self, var_dict=None, **kwargs):
"""Partially expand the template with the given parameters.
@@ -146,7 +148,4 @@ class URITemplate(object):
t.partial() # => URITemplate('https://api.github.com{/end}')
"""
- if var_dict:
- _update(kwargs, var_dict)
-
- return URITemplate(self._expand(kwargs, True))
+ return URITemplate(self._expand(_merge(var_dict, kwargs), True))