diff options
author | Eugene Eeo <xe0jun@hotmail.com> | 2014-12-14 00:45:48 +0800 |
---|---|---|
committer | Eugene Eeo <xe0jun@hotmail.com> | 2014-12-14 00:45:48 +0800 |
commit | 940383d720d592e8428bbd641c1ba0052c367fb4 (patch) | |
tree | 3b2ce3dd23cf8177ff88b678650e48f05fa3eb7d /uritemplate/template.py | |
parent | 835e9b5d276cd7cf6fdc399a820ef210d805b0bd (diff) | |
download | uritemplates-940383d720d592e8428bbd641c1ba0052c367fb4.tar.gz |
add testcase and helper function
Diffstat (limited to 'uritemplate/template.py')
-rw-r--r-- | uritemplate/template.py | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/uritemplate/template.py b/uritemplate/template.py index 0d45214..363e8ea 100644 --- a/uritemplate/template.py +++ b/uritemplate/template.py @@ -21,6 +21,10 @@ 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) + + class URITemplate(object): """This parses the template and will be used to expand it. @@ -121,7 +125,8 @@ class URITemplate(object): ``val2`` will be used instead of ``val1``. """ - kwargs.update(var_dict or {}) + if var_dict: + _update(kwargs, var_dict) return self._expand(kwargs, False) @@ -141,6 +146,7 @@ class URITemplate(object): t.partial() # => URITemplate('https://api.github.com{/end}') """ - kwargs.update(var_dict or {}) + if var_dict: + _update(kwargs, var_dict) return URITemplate(self._expand(kwargs, True)) |