From 940383d720d592e8428bbd641c1ba0052c367fb4 Mon Sep 17 00:00:00 2001 From: Eugene Eeo Date: Sun, 14 Dec 2014 00:45:48 +0800 Subject: add testcase and helper function --- uritemplate/template.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'uritemplate/template.py') 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)) -- cgit v1.2.3