diff options
author | Étienne Loks <etienne.loks@proxience.com> | 2015-03-03 01:32:09 +0100 |
---|---|---|
committer | Étienne Loks <etienne.loks@proxience.com> | 2015-03-03 01:32:09 +0100 |
commit | 2de676cf9c16f4aff6579908e6609b3074e96a99 (patch) | |
tree | a07a79874d47da3c2f89cd0470e1b23c9ea9a106 /ishtar_common/ooo_replace.py | |
parent | 4eea13b55a671eeef3078c8d589b628614296419 (diff) | |
download | Ishtar-2de676cf9c16f4aff6579908e6609b3074e96a99.tar.bz2 Ishtar-2de676cf9c16f4aff6579908e6609b3074e96a99.zip |
Fix ooo_replace pretag (just before the first ###)
Diffstat (limited to 'ishtar_common/ooo_replace.py')
-rw-r--r-- | ishtar_common/ooo_replace.py | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/ishtar_common/ooo_replace.py b/ishtar_common/ooo_replace.py index 5d75dce21..4c487dd17 100644 --- a/ishtar_common/ooo_replace.py +++ b/ishtar_common/ooo_replace.py @@ -80,12 +80,12 @@ def _format_value(value, default_value): value = unicode(value) if value else default_value return value -VAR_EXPR = u"###VAR %s###" +VAR_EXPR = u"###%sVAR %s###" WHOLE_KEY_FILTER = u"((?:(?: )*(?:<[^#>]*>)*(?: )*(?:[-a-zA-Z0-9_])*(?: )*)*)" WHOLE_KEY_FILTER = u"([^#]*)" -RE_VAR = re.compile(VAR_EXPR % WHOLE_KEY_FILTER) -IF_EXPR = u"###IF %s###(.*)###ENDIF###" -RE_IF = re.compile(IF_EXPR % WHOLE_KEY_FILTER) +RE_VAR = re.compile(VAR_EXPR % (WHOLE_KEY_FILTER, WHOLE_KEY_FILTER)) +IF_EXPR = u"###%sIF %s###(.*)###ENDIF###" +RE_IF = re.compile(IF_EXPR % (WHOLE_KEY_FILTER, WHOLE_KEY_FILTER)) TAG_FILTER = re.compile(u"(<[^<^>]*>)") KEY_FILTER = re.compile(u"([-a-zA-Z0-9_]*)") @@ -106,7 +106,7 @@ def _filter_key(base_key): full_key += k return full_key, tags -def _ishtar_parsing(context, value, default_value=''): +def _custom_parsing(context, value, default_value=''): """ ###VAR nom_var### for displaying a variable name ###IF nom_var### ###ENDIF### for conditionnal display @@ -117,17 +117,22 @@ def _ishtar_parsing(context, value, default_value=''): for base_key in regexp.findall(value[:]): v, val = "", None if if_cond: # the value inside the if is parsed - base_key, val = base_key + pre_tag, base_key, val = base_key + else: + pre_tag, base_key = base_key key, extra_markers = _filter_key(base_key) + v = '' + if pre_tag: + v = pre_tag if key in context and context[key]: if if_cond: - v = _ishtar_parsing(context, val, default_value) + v += _custom_parsing(context, val, default_value) else: - v = _format_value(context[key], default_value) + v += _format_value(context[key], default_value) # to preserve a consistent OOO file put extra_markers if extra_markers: v += extra_markers - value = re.sub(sub_exp % base_key, v, value) + value = re.sub(sub_exp % (pre_tag, base_key), v, value) return value def ooo_replace(infile, outfile, context, default_value=''): @@ -161,7 +166,7 @@ def ooo_replace(infile, outfile, context, default_value=''): str_io = StringIO() content.write(str_io) value = str_io.getvalue() - value = _ishtar_parsing(context, value, default_value).encode('utf-8') + value = _custom_parsing(context, value, default_value).encode('utf-8') for f in inzip.infolist(): if f.filename == 'content.xml': |