ƪbuTdZddlmZmZhdddhhdgZdZdZd Zd ZeZ y ) z babel.messages.checkers ~~~~~~~~~~~~~~~~~~~~~~~ Various routines that help with validation of translations. :since: version 0.9 :copyright: (c) 2013-2022 by the Babel Team. :license: BSD, see LICENSE for more details. )TranslationError PYTHON_FORMAT>diuxX>FGfgc|js&t|jts t dy|y|j}t|t t fs|f}t||jk7rt d|jzy)z0Verify the number of plurals in the translation.z/Found plural forms for non-pluralizable messageNz*Wrong number of plural forms (expected %d)) pluralizable isinstancestringstrrlisttuplelen num_plurals)catalogmessagemsgstrss 9/usr/lib/python3/dist-packages/babel/messages/checkers.pyrrs   '..#."$-. . nnG ge} -* 7|w***K&22 34 4+cd|jvry|j}t|ttfs|f}|j }t|ttfs|f}t ||D]\}}|s t||y)z9Verify the format string placeholders in the translation.z python-formatN)flagsidrrrrzip_validate_format)rrmsgidsrmsgidmsgstrs r python_formatr$,stgmm+ ZZF ftUm ,nnG ge} -*VW-, v  UF +,rc d}d}d}t|||f\}}t|||f\}}|r|s |s td||k7r td|rft|t|k7r tdtt ||D]+\} \\} } \} } || | rtd| dz| | fzyt |} |D];\}}|| vrtd |z||| |r%td |d |d | |d y)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 cg}tj|D]:}|j\}}}|dk(r||j|t |f<|S)N%)rfinditergroupsappendr)rresultmatchnameformattypechars r_parsez _validate_format.._parse\s]"++F3 1E%*\\^ "D&(34< MM4X/ 0  1  rc<||k(rytD] }||vs||vs yy)NTF)_string_format_compatibilities)absets r _compatiblez%_validate_format.._compatiblees0 61 CCxAH rcbd}|D]\}}||du} |du|k7stdt|S)Nz5format string mixes positional and named placeholders)rbool)results positionalr-chars r_check_positionalz+_validate_format.._check_positionalmsY ! EJD$!!T\ DLZ/*,DEE  EJrzplaceholders 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 %rz$incompatible format for placeholder z: z and z are not compatibleN)maprr enumeraterdict)r. alternativer0r6r<r3r4 a_positional b_positionalidx_firstsecondtype_mapr-r/s rr r <sY@   v , -DAq"%%6A!?L,L>??  %JKK q6SV "$01 1.7Aq .B A *C**1ekq&uf-&(J(+a'?(@AA A7 IND(8#&'E'LMM 8D>:&)-h(HII  Ircg} ddlm}|jdD]!}|j|j # t |dk(r ttgS|S#t $rY'wxYw)Nr) working_setzbabel.checkers) pkg_resourcesrJiter_entry_pointsr*load ImportErrorrrr$)checkersrJ entry_points r_find_checkersrQssH0-'889IJ 0K OOK,,. / 0 8}]++ O    sA A('A(N) __doc__babel.messages.catalogrrr2rr$r rQrOrrrUsH C #J"4( , \I~   r