diff options
author | yvesf <yvesf@pinky.(none)> | 2010-11-24 21:43:54 +0100 |
---|---|---|
committer | yvesf <yvesf@pinky.(none)> | 2010-11-24 21:43:54 +0100 |
commit | 003592d52cd1b7fd868b6ffe41136b25ebac309d (patch) | |
tree | bbd16d0bf96c244c7983e519f48c390b51b1edf9 /compat.py | |
parent | 708137185642f408427372300144412a4102ec38 (diff) | |
download | booksearch-003592d52cd1b7fd868b6ffe41136b25ebac309d.tar.gz booksearch-003592d52cd1b7fd868b6ffe41136b25ebac309d.zip |
+compat.py
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) |