
    O&iu                     \    d Z ddlmZmZ h dddhh dgZd Zd Zd	 Zd
 Z e            Z	dS )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>   diuxX>   FGfgc                    |j         s+t          |j        t                    st	          d          dS | dS |j        }t          |t
          t          f          s|f}t          |          | j        k    rt	          d| j        z            dS )z0Verify the number of plurals in the translation.z/Found plural forms for non-pluralizable messageNz*Wrong number of plural forms (expected %d))	pluralizable
isinstancestringstrr   listtuplelennum_plurals)catalogmessagemsgstrss      d/home/geonatureadmin/si_en_reseau/tutos/venv/lib/python3.11/site-packages/babel/messages/checkers.pyr   r      s     '.#.. 	." $- . . . 
nGge}-- *
7||w***K&2 3 4 4 	4 +*    c                    d|j         vrdS |j        }t          |t          t          f          s|f}|j        }t          |t          t          f          s|f}t          ||          D ]\  }}|rt          ||           dS )z9Verify the format string placeholders in the translation.zpython-formatN)flagsidr   r   r   r   zip_validate_format)r   r   msgidsr   msgidmsgstrs         r   python_formatr$   ,   s    gm++ZFftUm,, nGge}-- *VW-- , ,v 	,UF+++, ,r   c           
         d }d }d }t          || |f          \  }}t          |||f          \  }}|r|s|st          d          ||k    rt          d          |rt          |          t          |          k    rt          d          t          t	          ||                    D ]2\  }	\  \  }
}\  }
} |||          st          d|	dz   ||fz            3dS t          |          }|D ]L\  }}||vrt          d	|z             ||||                   st          d
|d|d||         d          MdS )a  Test 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
    c                     g }t          j        |           D ]G}|                                \  }}}|dk    r|#|                    |t	          |          f           H|S )N%)r   finditergroupsappendr   )r   resultmatchnameformattypechars         r   _parsez _validate_format.<locals>._parse\   sj    "+F33 	1 	1E%*\\^^"D&(34<MM4X/0000r   c                 @    | |k    rdS t           D ]}| |v r||v r dS dS )NTF)_string_format_compatibilities)absets      r   _compatiblez%_validate_format.<locals>._compatiblee   s=    6641 	 	CCxxAHHttur   c                 p    d }| D ]#\  }}||d u }|d u |k    rt          d          $t          |          S )Nz5format string mixes positional and named placeholders)r   bool)results
positionalr-   chars       r   _check_positionalz+_validate_format.<locals>._check_positionalm   sl    
! 	E 	EJD$!!T\

DLZ//* ,D E E E 0 Jr   zplaceholders are incompatiblez)the format strings are of different kindsz-positional format placeholders are unbalancedzDincompatible format for placeholder %d: %r and %r are not compatible   zunknown named placeholder %rz$incompatible format for placeholder z: z and z are not compatibleN)mapr   r   	enumerater   dict)r.   alternativer0   r6   r<   r3   r4   a_positionalb_positionalidx_firstsecondtype_mapr-   r/   s                   r   r    r    <   s   @    	  	  	  v,--DAq "%%6A!?!?L, LL L L>???		%	%JKKK  Iq66SVV" $0 1 1 1.7Aq		.B.B 	A 	A*C**1ekq&;uf-- A& (J(+a'?(@ A A AA	A 	A 77 	I 	IND(8##&'E'LMMM [8D>:: I&& )-hhh(H I I II	I 	Ir   c                      g } 	 ddl m} |                    d          D ])}|                     |                                           *n# t
          $ r Y nw xY wt          |           dk    rt          t          gS | S )Nr   )working_setzbabel.checkers)	pkg_resourcesrJ   iter_entry_pointsr*   loadImportErrorr   r   r$   )checkersrJ   entry_points      r   _find_checkersrQ      s    H0------ '889IJJ 	0 	0KOOK,,..////	0    
 8}} ]++Os   A
 

AAN)
__doc__babel.messages.catalogr   r   r2   r   r$   r    rQ   rO    r   r   <module>rU      s   
 
 C B B B B B B B
 OO#J" 4 4 4(, , , \I \I \I~    >r   