Ñò ž²Hc @ s™ d Z d d k 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( sQ Various routines that help with validation of translations. :since: version 0.9 iÿÿÿÿ( t izip( t TranslationErrort PYTHON_FORMATt 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 stringt basestringR t Nonet listt tuplet lent num_plurals( t catalogt messaget msgstrs( ( s; /usr/lib/python2.6/site-packages/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( ( s; /usr/lib/python2.6/site-packages/babel/messages/checkers.pyt python_format2 s c C sÆ d „ } d „ } d „ } t | | | f ƒ \ } } | p t d ƒ ‚ n 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 | ƒ ‚ q\| | | | ƒ p! t d | | | | f ƒ ‚ q\q\Wd 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. If `format` does not use string formatting a `ValueError` is raised. 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 :return: None on success :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( ( s; /usr/lib/python2.6/site-packages/babel/messages/checkers.pyt _parseb 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( ( s; /usr/lib/python2.6/site-packages/babel/messages/checkers.pyt _compatiblek 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&