/usr/lib/python2.6/site-packages/babel/messages
Edit: /usr/lib/python2.6/site-packages/babel/messages/checkers.pyc (5691B)
Ñò
zDVc @ sŸ d Z d d k l Z l Z d d k l Z l Z e d d d g ƒ e d d g ƒ e d d
d d g ƒ g Z d
„ Z d „ Z
d „ Z d „ Z e ƒ Z
d S( sñ
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.
iÿÿÿÿ( t TranslationErrort
PYTHON_FORMAT( t string_typest izipt it dt ut xt Xt ft Ft gt Gc C s¡ | i p( t | i t ƒ p t d ƒ ‚ n d S| d j o d S| i } t | t t f ƒ p
| f } n t | ƒ | i j o t d | i ƒ ‚ n d S( s0 Verify the number of plurals in the translation.s/ Found plural forms for non-pluralizable messageNs* Wrong number of plural forms (expected %d)(
t pluralizablet
isinstancet stringR R t Nonet listt tuplet lent num_plurals( t catalogt messaget msgstrs( ( s6 /tmp/pip-build-lt8jXN/Babel/babel/messages/checkers.pyR s
c C s© d | i j o d S| i } t | t t f ƒ p
| f } n | i } t | t t f ƒ p
| f } n x5 t | | ƒ D]$ \ } } | o t | | ƒ q} q} Wd S( s9 Verify the format string placeholders in the translation.s
python-formatN( t flagst idR R R R R t _validate_format( R R t msgidsR t msgidt msgstr( ( s6 /tmp/pip-build-lt8jXN/Babel/babel/messages/checkers.pyt
python_format. s
c C s¯ d „ } d „ } d „ } t | | | f ƒ \ } } t | | | f ƒ \ } } | o | o | o t d ƒ ‚ n | | j o t d ƒ ‚ n | o– t | ƒ t | ƒ j o t d ƒ ‚ n xã t t | | ƒ ƒ D]O \ } \ \ }
} \ }
} | | | ƒ p! t d | d | | f ƒ ‚ qÛ qÛ Wnz t | ƒ }
xj | D]b \ } } | |
j o t d | ƒ ‚ qE| | |
| ƒ p! t d
| | |
| f ƒ ‚ qEqEWd S( s‹ 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 ss g } xf t i | ƒ D]U } | i ƒ \ } } } | d j o | d j o q n | i | t | ƒ f ƒ q W| S( Nt %( R t finditert groupsR t appendt str( R t resultt matcht namet formatt typechar( ( s6 /tmp/pip-build-lt8jXN/Babel/babel/messages/checkers.pyt _parse^ s c S sF | | j o t Sx- t D]% } | | j o | | j o t Sq Wt S( N( t Truet _string_format_compatibilitiest False( t at bt set( ( s6 /tmp/pip-build-lt8jXN/Babel/babel/messages/checkers.pyt _compatibleg s
c S sg d } xT | D]L \ } } | d j o | d j } q
| d j | j o t d ƒ ‚ q
q
Wt | ƒ S( Ns5 format string mixes positional and named placeholders( R R t bool( t resultst
positionalR&