
    PiA                        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-2026 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         d          dS )z0Verify the number of plurals in the translation.z/Found plural forms for non-pluralizable messageNz'Wrong number of plural forms (expected ))	pluralizable
isinstancestringstrr   listtuplelennum_plurals)r   r   msgstrss      k/home/jaya/work/projects/VOICE-AGENT/VIET/agent-env/lib/python3.11/site-packages/babel/messages/checkers.pyr    r       s     '.#.. 	V"#TUUU 
nGge}-- *
7||w***Lg6ILLL
 
 	
 +*    c                X   d|j         vrdS |j        }t          |t          t          f          s|f}|j        }t          |t          t          f          s|f}|d         rt          |d         |d                    |j        r%|dd         D ]}|rt          |d         |           dS dS )z9Verify the format string placeholders in the translation.zpython-formatNr      )flagsidr   r   r   r   _validate_formatr   )r   r   msgidsr!   msgstrs        r"   python_formatr+   /   s    gm++ZFftUm,, nGge}-- *qz 0GAJ/// 4abbk 	4 	4F 4 F3334 4	4 	4r#   formatr   alternativec           
        dd}dd	}dd} ||           } ||          }|sdS  ||          } ||          }|r|s|st          d          ||k    rt          d          |rt          |          t          |          k    rt          d          t          t          ||                    D ]7\  }	\  \  }
}\  }
} |||          st          d|	dz   dd|d|d          8d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>._compatibleh   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_positionalp   sd    
" 	 	KD%!!T\

DLZ//*O   0 Jr#   Nzplaceholders are incompatiblez)the format strings are of different kindsz-positional format placeholders are unbalancedz$incompatible format for placeholder r%   r	   z: z and z are not compatiblezunknown named placeholder )r   r   r   r/   )r:   r   r;   r   r   r<   )rA   r/   r   r<   )r   r   	enumeratezipdict)r,   r-   r9   r@   rE   r:   r;   a_positionalb_positionalidx_firstsecondtype_mapr7   r8   s                   r"   r(   r(   B   sY   :      
  
  
  
  	vA{A  %$Q''L$$Q''L LL L L>???		%	%JKKK  q66SVV"#RSSS.7Aq		.B.B 	 	*C**1ekq&;uf-- &C37H C CC C%+C C C  	 	 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._compatrR   extendr   r    r+   )rR   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#   rZ   N)r   r   r   r   r   r   )r,   r   r-   r   r   r   )r   rP   )__doc__
__future__r   collections.abcr   babel.messages.catalogr   r   r   r   r>   r    r+   r(   r[   rZ   __annotations__rT   r#   r"   <module>ra      s   
 
 
 # " " " " " $ $ $ $ $ $ T T T T T T T T T T T T OO#J" 
 
 
 
(4 4 4 4&_ _ _ _D	 	 	 	 ?Mn>N>N N N N N N Nr#   