From 7412f8725187670d0cdd4d427dcf53c0032446bd Mon Sep 17 00:00:00 2001 From: Ian Cordasco Date: Sun, 28 Jul 2013 20:40:31 -0500 Subject: Convert non-string-ish types to strings --- uritemplate/template.py | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'uritemplate/template.py') diff --git a/uritemplate/template.py b/uritemplate/template.py index ddfb12a..491464d 100644 --- a/uritemplate/template.py +++ b/uritemplate/template.py @@ -16,10 +16,14 @@ What do you do? """ import re +import sys from uritemplate.variable import URIVariable template_re = re.compile('{([^\}]+)}') +if sys.version_info[0] == 3: + basestring = (str, bytes) + class URITemplate(object): @@ -105,6 +109,10 @@ class URITemplate(object): expansion = var_dict or {} expansion.update(kwargs) + for (k, v) in expansion.items(): + if not isinstance(v, basestring): + expansion[k] = str(v) + expanded = {} for v in self.variables: expanded.update(v.expand(expansion)) -- cgit v1.2.3