a
    ÇZEg�  ã                   @  s¢   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
ddœdd„Zd	d
ddœdd„Zddddœdd„Zddœ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-2024 by the Babel Team.
    :license: BSD, see LICENSE for more details.
é    )Úannotations)ÚCallable)ÚPYTHON_FORMATÚCatalogÚMessageÚTranslationError>   ÚiÚuÚdÚxÚX>   ÚGÚFÚfÚgzCatalog | Noner   ÚNone)ÚcatalogÚmessageÚreturnc                 C  sd   |j st|jtƒstdƒ‚dS | du r*dS |j}t|ttfƒsD|f}t|ƒ| jkr`td| j ƒ‚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))	ZpluralizableÚ
isinstanceÚstringÚstrr   ÚlistÚtupleÚlenÚnum_plurals)r   r   Úmsgstrs© r   úP/var/www/sistema_ama/venv/lib/python3.9/site-packages/babel/messages/checkers.pyr      s    ÿr   c                 C  sh   d|j vrdS |j}t|ttfƒs(|f}|j}t|ttfƒsB|f}t||ƒD ]\}}|rLt||ƒ qLdS )z9Verify the format string placeholders in the translation.zpython-formatN)ÚflagsÚidr   r   r   r   ÚzipÚ_validate_format)r   r   Zmsgidsr   ÚmsgidZmsgstrr   r   r   Úpython_format.   s    
r$   r   )ÚformatÚalternativer   c              	   C  s@  dddœdd„}ddddœdd	„}ddd
œdd„}t || |fƒ\}}t |||fƒ\}}|rl|sl|sltdƒ‚n||kr|tdƒ‚|rÞt|ƒt|ƒkr˜tdƒ‚tt||ƒƒD ]4\}	\\}
}\}
}|||ƒs¦td|	d ||f ƒ‚q¦n^t|ƒ}|D ]P\}}||v�rtd|›�ƒ‚qê|||| ƒsêtd|›d|›d|| ›d�ƒ‚qêd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.

    The behavior of this function is undefined if the string does not use
    string formatting.

    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   zlist[tuple[str, str]])r   r   c                 S  sJ   g }t  | ¡D ]6}| ¡ \}}}|dkr2|d u r2q| |t|ƒf¡ q|S )Nú%)r   ÚfinditerÚgroupsÚappendr   )r   ÚresultÚmatchÚnamer%   Útypecharr   r   r   Ú_parse^   s    z _validate_format.<locals>._parseÚbool)ÚaÚbr   c                 S  s0   | |krdS t D ]}| |v r||v r dS qdS )NTF)Ú_string_format_compatibilities)r1   r2   Úsetr   r   r   Ú_compatibleg   s    z%_validate_format.<locals>._compatible)Úresultsr   c                 S  s@   d }| D ].\}}|d u r"|d u }q|d u |krt dƒ‚qt|ƒS )Nz5format string mixes positional and named placeholders)r   r0   )r6   Ú
positionalr-   Z_charr   r   r   Ú_check_positionalo   s    

z+_validate_format.<locals>._check_positionalz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 compatibleN)Úmapr   r   Ú	enumerater!   Údict)r%   r&   r/   r5   r8   r1   r2   Za_positionalZb_positionalÚidxÚ_ÚfirstÚsecondZtype_mapr-   r.   r   r   r   r"   >   s:     	
"
þ

ÿÿÿr"   z1list[Callable[[Catalog | None, Message], object]])r   c                  C  s@   ddl m}  g }| dd„ | dƒD ƒ¡ t|ƒdkr<ttgS |S )Nr   )Úfind_entrypointsc                 s  s   | ]\}}|ƒ V  qd S )Nr   )Ú.0r-   Úloadr   r   r   Ú	<genexpr>    ó    z!_find_checkers.<locals>.<genexpr>zbabel.checkers)Zbabel.messages._compatrA   Úextendr   r   r$   )rA   Úcheckersr   r   r   Ú_find_checkers�   s    rH   rG   N)Ú__doc__Ú
__future__r   Úcollections.abcr   Zbabel.messages.catalogr   r   r   r   r3   r   r$   r"   rH   rG   Ú__annotations__r   r   r   r   Ú<module>   s   ý_