�
ƪbu � �T � d Z ddlmZmZ h d�ddhh d�gZd� Zd� Zd � Zd
� Z e� Z 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> �d�i�u�x�X> �F�G�f�gc � � |j s&t |j t � st d� �y| �y|j }t |t
t f� s|f}t |� | j k7 rt d| j z � �y)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 �9/usr/lib/python3/dist-packages/babel/messages/checkers.pyr r s� � �����'�.�.�#�.�"� $-� .�
.��
����n�n�G��g��e�}�-��*��
�7�|�w�*�*�*��K�&�2�2� 3� 4� 4� +� c � � d|j vry|j }t |t t f� s|f}|j
}t |t t f� s|f}t
||� D ] \ }}|s� t ||� � y)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$ , st � ��g�m�m�+��
�Z�Z�F��f�t�U�m�,�����n�n�G��g��e�}�-��*���V�W�-� ,�
��v���U�F�+�,r c
� � d� }d� }d� }t || |f� \ }}t |||f� \ }}|r|s
|st d� �||k7 rt d� �|rft |� t |� k7 rt d� �t t ||� � D ]+ \ } \ \ }
}\ }
} |||� r�t d| dz ||fz � � yt |� }
|D ]; \ }}||
vrt d |z � � |||
| � r�%t d
|�d|�d|
| �d
�� � y)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 ]: }|j � \ }}}|dk( r|��|j |t |� f� �< |S )N�%)r �finditer�groups�appendr )r �result�match�name�format�typechars r �_parsez _validate_format.<locals>._parse\ s] � ���"�+�+�F�3� 1�E�%*�\�\�^�"�D�&�(��3��4�<���M�M�4��X��/�0� 1�
�
r c �< |