3 4\0X@svdZddlmZmZddlmZmZedddgeddged d d d ggZd dZ ddZ ddZ ddZ e Z dS)z babel.messages.checkers ~~~~~~~~~~~~~~~~~~~~~~~ Various routines that help with validation of translations. :since: version 0.9 :copyright: (c) 2013 by the Babel Team. :license: BSD, see LICENSE for more details. )TranslationError PYTHON_FORMAT) string_typesizipiduxXfFgGcCsd|jst|jtstddS|dkr*dS|j}t|ttfsD|f}t||jkr`td|jdS)z0Verify the number of plurals in the translation.z/Found plural forms for non-pluralizable messageNz*Wrong number of plural forms (expected %d)) Z pluralizable isinstancestringrrlisttuplelen num_plurals)catalogmessagemsgstrsr/usr/lib/python3.6/checkers.pyrs rcCsld|jkrdS|j}t|ttfs(|f}|j}t|ttfsB|f}x$t||D]\}}|rNt||qNWdS)z9Verify the format string placeholders in the translation.z python-formatN)flagsidrrrrr_validate_format)rrZmsgidsrZmsgidZmsgstrrrr python_format.s rcCs$dd}dd}dd}t|||f\}}t|||f\}}|rV| rV| rVtdn||krftd|rt|t|krtd xtt||D]4\} \\} } \} } || | std | d | | fqWnTt|} xJ|D]B\}}|| krtd |q||| |std ||| |fqWdS)aTest 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. The behavior of this function is undefined if the string does not use string formattings. 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 :raises TranslationError: on formatting errors cSsNg}xDtj|D]6}|j\}}}|dkr4|dkr4q|j|t|fqW|S)N%)rfinditergroupsappendstr)rresultmatchnameformattypecharrrr_parse^sz _validate_format.._parsecSs2||kr dSx tD]}||kr||krdSqWdS)NTF)_string_format_compatibilities)absetrrr _compatiblegs  z%_validate_format.._compatiblecSsDd}x6|D].\}}|dkr$|dk}q |dk|kr tdq Wt|S)Nz5format string mixes positional and named placeholders)rbool)resultsZ positionalr%charrrr_check_positionalos   z+_validate_format.._check_positionalzplaceholders are incompatiblez)the format strings are of different kindsz-positional format placeholders are unbalancedzDincompatible format for placeholder %d: %r and %r are not compatiblezunknown named placeholder %rzDincompatible format for placeholder %r: %r and %r are not compatibleN)maprr enumeraterdict)r& alternativer(r-r1r*r+Z a_positionalZ b_positionalidx_firstsecondZtype_mapr%r'rrrr>s.    $ rc Csdg}yddlm}Wntk r(Yn$Xx |jdD]}|j|jq6Wt|dkr`ttgS|S)Nr) working_setzbabel.checkers) Z pkg_resourcesr; ImportErrorZiter_entry_pointsr!loadrrr)checkersr;Z entry_pointrrr_find_checkerss r?N)__doc__Zbabel.messages.catalogrrZ babel._compatrrr,r)rrrr?r>rrrr s  _