comparison babel/messages/checkers.py @ 488:07a27065102a stable-0.9.x

Merged revisions 458 via svnmerge from http://svn.edgewall.org/repos/babel/trunk ........ r458 | aronacher | 2008-10-31 17:13:59 +0100 (vr, 31 okt 2008) | 3 lines Removed `ValueError` raising for string formatting message checkers if the string does not contain any string formattings. The new behavior is undefined. This fixes at least one of the problems of the #150 ticket. ........
author jruigrok
date Sun, 11 Apr 2010 09:10:49 +0000
parents c2ae38340540
children b29ff192b610
comparison
equal deleted inserted replaced
487:2d1c17275e5b 488:07a27065102a
67 """Test format string `alternative` against `format`. `format` can be the 67 """Test format string `alternative` against `format`. `format` can be the
68 msgid of a message and `alternative` one of the `msgstr`\s. The two 68 msgid of a message and `alternative` one of the `msgstr`\s. The two
69 arguments are not interchangeable as `alternative` may contain less 69 arguments are not interchangeable as `alternative` may contain less
70 placeholders if `format` uses named placeholders. 70 placeholders if `format` uses named placeholders.
71 71
72 If `format` does not use string formatting a `ValueError` is raised. 72 The behavior of this function is undefined if the string does not use
73 string formattings.
73 74
74 If the string formatting of `alternative` is compatible to `format` the 75 If the string formatting of `alternative` is compatible to `format` the
75 function returns `None`, otherwise a `TranslationError` is raised. 76 function returns `None`, otherwise a `TranslationError` is raised.
76 77
77 Examples for compatible format strings: 78 Examples for compatible format strings:
123 'and named placeholders') 124 'and named placeholders')
124 return bool(positional) 125 return bool(positional)
125 126
126 a, b = map(_parse, (format, alternative)) 127 a, b = map(_parse, (format, alternative))
127 128
128 # if a does not use string formattings, we are dealing with invalid
129 # input data. This function only works if the first string provided
130 # does contain string format chars
131 if not a:
132 raise ValueError('original string provided does not use string '
133 'formatting.')
134
135 # now check if both strings are positional or named 129 # now check if both strings are positional or named
136 a_positional, b_positional = map(_check_positional, (a, b)) 130 a_positional, b_positional = map(_check_positional, (a, b))
137 if a_positional and not b_positional and not b: 131 if a_positional and not b_positional and not b:
138 raise TranslationError('placeholders are incompatible') 132 raise TranslationError('placeholders are incompatible')
139 elif a_positional != b_positional: 133 elif a_positional != b_positional:
Copyright (C) 2012-2017 Edgewall Software