From 003592d52cd1b7fd868b6ffe41136b25ebac309d Mon Sep 17 00:00:00 2001 From: yvesf Date: Wed, 24 Nov 2010 21:43:54 +0100 Subject: +compat.py --- compat.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 compat.py (limited to 'compat.py') diff --git a/compat.py b/compat.py new file mode 100644 index 0000000..ba14fb2 --- /dev/null +++ b/compat.py @@ -0,0 +1,12 @@ + +if not hasattr('', 'format'): + from string import Template + import re + def str_format(string, *args, **kwargs): + tpl = Template(string) + tpl.pattern = str_format.re + return tpl.substitute(*args, **kwargs) + str_format.re = re.compile(r'\{(?P[A-Za-z0-9_]+)\}') +else: + def str_format(string, *args, **kwargs): + return string.format(*args, **kwargs) -- cgit v1.2.1