diff options
Diffstat (limited to 'compat.py')
-rw-r--r-- | compat.py | 12 |
1 files changed, 12 insertions, 0 deletions
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<named>[A-Za-z0-9_]+)\}') +else: + def str_format(string, *args, **kwargs): + return string.format(*args, **kwargs) |