
    MhK                        U d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 h dddhh dgZ
ddZddZddZddZ e            Zded<   dS )z
    babel.messages.checkers
    ~~~~~~~~~~~~~~~~~~~~~~~

    Various routines that help with validation of translations.

    :since: version 0.9

    :copyright: (c) 2013-2025 by the Babel Team.
    :license: BSD, see LICENSE for more details.
    )annotations)Callable)PYTHON_FORMATCatalogMessageTranslationError>   diuxX>   FGfgcatalogCatalog | Nonemessager   returnNonec                   |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)r   r   msgstrss      W/var/www/html/test/jupyter/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"   formatr   alternativec           
        dd}dd	}dd}t          || |f          \  }}|sdS 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|           ||||                   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.

    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
    r   r   r   list[tuple[str, str]]c                    g }t          j        |           D ]G}|                                \  }}}|dk    r|#|                    |t	          |          f           H|S )N%)r   finditergroupsappendr   )r   resultmatchnamer,   typechars         r!   _parsez _validate_format.<locals>._parse[   sj    (*"+F33 	1 	1E%*\\^^"D&(34<MM4X/0000r"   abboolc                @    | |k    rdS t           D ]}| |v r||v r dS dS )NTF)_string_format_compatibilities)r:   r;   sets      r!   _compatiblez%_validate_format.<locals>._compatibled   s=    6641 	 	CCxxAHHttur"   resultsc                p    d }| D ]#\  }}||d u }|d u |k    rt          d          $t          |          S )Nz5format string mixes positional and named placeholders)r   r<   )rA   
positionalr7   _chars       r!   _check_positionalz+_validate_format.<locals>._check_positionall   sl    
" 	E 	EKD%!!T\

DLZ//* ,D E E E 0 Jr"   Nz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 z$incompatible format for placeholder z: z and z are not compatible)r   r   r   r/   )r:   r   r;   r   r   r<   )rA   r/   r   r<   )mapr   r   	enumerater&   dict)r,   r-   r9   r@   rE   r:   r;   a_positionalb_positionalidx_firstsecondtype_mapr7   r8   s                   r!   r'   r'   >   s:   :      	  	  	  	  v,--DAq  "%%6A!?!?L, LL L L>???		%	%JKKK  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 	 	ND(8##&'LD'L'LMMM [8D>:: &N4 N NN N(0N N N  	 	r"   1list[Callable[[Catalog | None, Message], object]]c                     ddl m}  g }|                    d  | d          D                        t          |          dk    rt          t
          gS |S )Nr   )find_entrypointsc              3  0   K   | ]\  }} |            V  d S )N ).0r7   loads      r!   	<genexpr>z!_find_checkers.<locals>.<genexpr>   s,      RR|dDDFFRRRRRRr"   zbabel.checkers)babel.messages._compatrS   extendr   r   r+   )rS   checkerss     r!   _find_checkersr\      sj    777777BDHOORR/?/?@P/Q/QRRRRRR
8}} ]++Or"   r[   N)r   r   r   r   r   r   )r,   r   r-   r   r   r   )r   rQ   )__doc__
__future__r   collections.abcr   babel.messages.catalogr   r   r   r   r>   r   r+   r'   r\   r[   __annotations__rU   r"   r!   <module>rb      s   
 
 
 # " " " " " $ $ $ $ $ $ T T T T T T T T T T T T OO#J" 4 4 4 4(, , , , \ \ \ \~    ?Mn>N>N N N N N N Nr"   