Ñò ž²Hc @s™dZddklZddklZlZedddgƒeddgƒed d d d gƒgZd „Zd„Z d„Z d„Z e ƒZ dS(sQVarious routines that help with validation of translations. :since: version 0.9 iÿÿÿÿ(tizip(tTranslationErrort PYTHON_FORMATtitdtutxtXtftFtgtGcCs¡|ip(t|itƒptdƒ‚ndS|djodS|i}t|ttfƒp |f}nt|ƒ|i jotd|i ƒ‚ndS(s0Verify the number of plurals in the translation.s/Found plural forms for non-pluralizable messageNs*Wrong number of plural forms (expected %d)( t pluralizablet isinstancetstringt basestringRtNonetlistttupletlent num_plurals(tcatalogtmessagetmsgstrs((s;/usr/lib/python2.6/site-packages/babel/messages/checkers.pyRs    cCs©d|ijodS|i}t|ttfƒp |f}n|i}t|ttfƒp |f}nx5t||ƒD]$\}}|ot||ƒq}q}WdS(s9Verify the format string placeholders in the translation.s python-formatN(tflagstidR RRRRt_validate_format(RRtmsgidsRtmsgidtmsgstr((s;/usr/lib/python2.6/site-packages/babel/messages/checkers.pyt python_format2s     cCsÆd„}d„}d„}t|||fƒ\}}|ptdƒ‚nt|||fƒ\}}|o | o| otdƒ‚n||jotdƒ‚n|o–t|ƒt|ƒjotdƒ‚nxãtt||ƒƒD]O\} \\} } \} } || | ƒp!td| d | | fƒ‚qòqòWnzt|ƒ} xj|D]b\}}|| jotd |ƒ‚q\||| |ƒp!td ||| |fƒ‚q\q\Wd S( sTest format string `alternative` against `format`. `format` can be the msgid of a message and `alternative` one of the `msgstr`\s. The two arguments are not interchangeable as `alternative` may contain less placeholders if `format` uses named placeholders. If `format` does not use string formatting a `ValueError` is raised. If the string formatting of `alternative` is compatible to `format` the function returns `None`, otherwise a `TranslationError` is raised. Examples for compatible format strings: >>> _validate_format('Hello %s!', 'Hallo %s!') >>> _validate_format('Hello %i!', 'Hallo %d!') Example for an incompatible format strings: >>> _validate_format('Hello %(name)s!', 'Hallo %s!') Traceback (most recent call last): ... TranslationError: the format strings are of different kinds This function is used by the `python_format` checker. :param format: The original format string :param alternative: The alternative format string that should be checked against format :return: None on success :raises TranslationError: on formatting errors cSssg}xfti|ƒD]U}|iƒ\}}}|djo|djoqn|i|t|ƒfƒqW|S(Nt%(RtfinditertgroupsRtappendtstr(Rtresulttmatchtnametformatttypechar((s;/usr/lib/python2.6/site-packages/babel/messages/checkers.pyt_parsebscSsF||jotSx-tD]%}||jo||jotSqWtS(N(tTruet_string_format_compatibilitiestFalse(tatbtset((s;/usr/lib/python2.6/site-packages/babel/messages/checkers.pyt _compatibleks  cSsgd}xT|D]L\}}|djo|dj}q |dj|jotdƒ‚q q Wt|ƒS(Ns5format string mixes positional and named placeholders(RRtbool(tresultst positionalR&tchar((s;/usr/lib/python2.6/site-packages/babel/messages/checkers.pyt_check_positionalss  s8original string provided does not use string formatting.splaceholders are incompatibles)the format strings are of different kindss-positional format placeholders are unbalancedsDincompatible format for placeholder %d: %r and %r are not compatibleisunknown named placeholder %rsDincompatible format for placeholder %r: %r and %r are not compatibleN(tmapt ValueErrorRRt enumerateRtdict(R't alternativeR)R0R5R-R.t a_positionalt b_positionaltidxt_tfirsttsecondttype_mapR&R(((s;/usr/lib/python2.6/site-packages/babel/messages/checkers.pyRBs6   #   cCshyddkl}Wntj ottgSXg}x*|idƒD]}|i|iƒƒqGW|S(Niÿÿÿÿ(t working_setsbabel.checkers(t pkg_resourcesRBt ImportErrorRRtiter_entry_pointsR"tload(RBtcheckerst entry_point((s;/usr/lib/python2.6/site-packages/babel/messages/checkers.pyt_find_checkers¨s N( t__doc__t itertoolsRtbabel.messages.catalogRRR/R+RRRRIRG(((s;/usr/lib/python2.6/site-packages/babel/messages/checkers.pyts   f