File: //usr/lib/python3.6/site-packages/babel/messages/__pycache__/checkers.cpython-36.pyc
3
4\0X� � @ sv d Z ddlmZmZ ddlmZmZ edddg�eddg�ed d
ddg�gZd
d� Z dd� Z
dd� Zdd� Ze� 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_types�izip�i�d�u�x�X�f�F�g�Gc C sd |j st|jt�std��dS | dkr*dS |j}t|ttf�sD|f}t|�| jkr`td| j ��dS )z0Verify the number of plurals in the translation.z/Found plural forms for non-pluralizable messageNz*Wrong number of plural forms (expected %d)) Zpluralizable�
isinstance�stringr r �list�tuple�len�num_plurals)�catalog�message�msgstrs� r �/usr/lib/python3.6/checkers.pyr s r c C sl d|j krdS |j}t|ttf�s(|f}|j}t|ttf�sB|f}x$t||�D ]\}}|rNt||� qNW dS )z9Verify the format string placeholders in the translation.z
python-formatN)�flags�idr r r r r �_validate_format)r r Zmsgidsr ZmsgidZmsgstrr r r �
python_format. s
r c C s$ dd� }dd� }dd� }t || |f�\}}t |||f�\}}|rV| rV| rVtd��n||krftd��|r�t|�t|�kr�td ��x�tt||��D ]4\} \\}
}\}
}|||�s�td
| d ||f ��q�W nTt|�}
xJ|D ]B\}}||
kr�td| ��q�|||
| �s�td
|||
| f ��q�W dS )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 S sN g }xDt j| �D ]6}|j� \}}}|dkr4|d kr4q|j|t|�f� qW |S )N�%)r �finditer�groups�append�str)r �result�match�name�format�typecharr r r �_parse^ s z _validate_format.<locals>._parsec S s2 | |krdS x t D ]}| |kr||krdS qW dS )NTF)�_string_format_compatibilities)�a�b�setr r r �_compatibleg s
z%_validate_format.<locals>._compatiblec S sD d }x6| D ].\}}|d kr$|d k}q
|d k|kr
t d��q
W t|�S )Nz5format string mixes positional and named placeholders)r �bool)�resultsZ
positionalr% �charr r r �_check_positionalo s
z+_validate_format.<locals>._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 compatible� zunknown named placeholder %rzDincompatible format for placeholder %r: %r and %r are not compatibleN)�mapr r � enumerater �dict)r&