Paul Franklin <pf.rhli...@gmail.com> writes: > To trigger this bug, make an xx.po file (with a correct > header) with this stanza in it: > > #: ../gramps/gen/datehandler/_datedisplay.py:168 > #, python-brace-format > msgid "{long_month} {year}" > msgstr "{long_month.f[D]} {year}" > > and when you run run "msgfmt -c -v xx.po" on it, it is > flagged as having an error: > > xx.po:21: 'msgstr' is not a valid Python brace format string, unlike > 'msgid'. Reason: In the directive number 0, there is an unterminated > format directive. > msgfmt: found 1 fatal error
Thanks for the report. I didn't realize that PEP3101 allows such "chained" invocations of '.' and '[..]'. I have pushed the attached patch to fix this. Regards, -- Daiki Ueno
>From b4220c509a90186931a69575981c1b0e80ffc1f6 Mon Sep 17 00:00:00 2001 From: Daiki Ueno <u...@gnu.org> Date: Wed, 23 Mar 2016 15:17:21 +0900 Subject: [PATCH] format-python-brace: Support chained expression * gettext-tools/src/format-python-brace.c (parse_directive): Recognize chained getattr/getitem expressions. * gettext-tools/tests/format-python-brace-1: Add test for the case where both getattr and getitem are used. Reported by Paul Franklin in: https://lists.gnu.org/archive/html/bug-gettext/2016-03/msg00017.html --- gettext-tools/src/format-python-brace.c | 11 +++++++++-- gettext-tools/tests/format-python-brace-1 | 2 ++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/gettext-tools/src/format-python-brace.c b/gettext-tools/src/format-python-brace.c index a212707..c76088c 100644 --- a/gettext-tools/src/format-python-brace.c +++ b/gettext-tools/src/format-python-brace.c @@ -140,7 +140,13 @@ parse_directive (struct spec *spec, return false; } + /* Parse '.' (getattr) or '[..]' (getitem) operators followed by a + name. If must not recurse, but can be specifed in a chain, such + as "foo.bar.baz[0]". */ + for (;;) + { c = *format; + if (c == '.') { format++; @@ -152,7 +158,6 @@ parse_directive (struct spec *spec, FDI_SET (format, FMTDIR_ERROR); return false; } - c = *format; } else if (c == '[') { @@ -175,7 +180,9 @@ parse_directive (struct spec *spec, FDI_SET (format, FMTDIR_ERROR); return false; } - c = *format; + } + else + break; } if (c == ':') diff --git a/gettext-tools/tests/format-python-brace-1 b/gettext-tools/tests/format-python-brace-1 index 601b023..3a1f9ea 100755 --- a/gettext-tools/tests/format-python-brace-1 +++ b/gettext-tools/tests/format-python-brace-1 @@ -30,6 +30,8 @@ cat <<\EOF > f-pyb-1.data "abc{value[0}" # Invalid: unknown character in getitem operator "abc{value[!]}" +# Valid: use of both getattr and getitem operators +"abc{value.v[name]}" # Valid: format specifier "abc{value:0}" # Valid: standard format specifier -- 2.5.0