o
    @j8                     @   s   d dl Z d dlZ d dlZ d dlmZmZmZmZmZm	Z	m
Z
mZ d dlmZ d dlmZ ddlmZ ddlmZ ddlmZmZmZmZ dd	lmZ erTdd
lmZmZ ed ZG dd dZ dS )    N)AnyCallableDictListTYPE_CHECKINGTupleUnioncast)Literal)ast   )BUILTINS)Compiler)CurrentEnvironmentMessagePatternResolverEnvironmentnative_to_fluent)
FluentNone
FluentType)zeroonetwofewmanyotherc                
   @   s   e Zd ZdZ		d dee deeeee	gdf f df de
fdd	Zd!dejde
ddfddZdede
fddZdedefddZd!dede
defddZ	d"dedeeee	f df deeedf ee f fddZdejfddZdS )#FluentBundlea  
    Bundles are single-language stores of translations.  They are
    aggregate parsed Fluent resources in the Fluent syntax and can
    format translation units (entities) to strings.

    Always use `FluentBundle.get_message` to retrieve translation units from
    a bundle. Generate the localized string by using `format_pattern` on
    `message.value` or `message.attributes['attr']`.
    Translations can contain references to other entities or
    external arguments, conditional logic in form of select expressions, traits
    which describe their grammatical features, and can use Fluent builtins.
    See the documentation of the Fluent syntax for more information.
    NTlocales	functionsr   use_isolatingc                 C   s   || _ i t|p	i | _|| _i | _i | _i | _ttt	t
jt
jf gtf t | _|  | _tttgtt	ttf gtf f tjj| jj| _d S N)r   r   
_functionsr    	_messages_terms	_compiledr	   r   r   FTLr   Termr   	_compiler_get_babel_locale_babel_localer   intfloatPluralCategorybabelplural	to_pythonplural_form_plural_form)selfr   r   r     r4   d/var/www/www-root/data/www/ai-bot.pdev.uz/venv/lib/python3.10/site-packages/fluent/runtime/bundle.py__init__#   s   $
 
zFluentBundle.__init__Fresourceallow_overridesreturnc                 C   sX   |j D ]&}t|tjtjfsqt|tjr| jn| j}|jj}||vs%|r)|||< qd S r!   )	body
isinstancer&   r   r'   r#   r$   idname)r3   r7   r8   itemmap_full_idr4   r4   r5   add_resource3   s   
zFluentBundle.add_resource
message_idc                 C   s
   || j v S r!   )r#   r3   rB   r4   r4   r5   has_message=      
zFluentBundle.has_messagec                 C   s
   |  |S r!   )_lookuprC   r4   r4   r5   get_message@   rE   zFluentBundle.get_messageentry_idtermc                 C   sd   |rd| }n|}z| j | W S  ty   Y nw |r | j| n| j| }| || j |< | j | S )N-)r%   LookupErrorr$   r#   r(   )r3   rH   rI   compiled_identryr4   r4   r5   rF   C   s   

zFluentBundle._lookuppatternargsr   c              
   C   s   |d urdd |  D }ni }g }t| t|d|d}z	||}W ||fS  tyA } z|| d}W Y d }~||fS d }~ww )Nc                 S   s   i | ]	\}}|t |qS r4   r   ).0argnameargvaluer4   r4   r5   
<dictcomp>U   s    z/FluentBundle.format_pattern.<locals>.<dictcomp>)rO   )contextcurrenterrorsz{???})itemsr   r   
ValueErrorappend)r3   rN   rO   fluent_argsrV   envresulter4   r4   r5   format_patternP   s&   

zFluentBundle.format_patternc              	   C   sD   | j D ]}ztj|ddW   S  tjy   Y qw tj S )NrJ   _)r   r.   LocaleparsereplaceUnknownLocaleErrordefault)r3   lcr4   r4   r5   r)   g   s   

zFluentBundle._get_babel_locale)NT)Fr!   )__name__
__module____qualname____doc__r   strr   r   r   r   boolr6   r&   ResourcerA   rD   r   rG   rF   r   r   	Exceptionr^   r.   r`   r)   r4   r4   r4   r5   r      s0    


r   )!r.   babel.numbersbabel.pluraltypingr   r   r   r   r   r   r   r	   typing_extensionsr
   fluent.syntaxr   r&   builtinsr   preparer   resolverr   r   r   r   utilsr   typesr   r   r-   r   r4   r4   r4   r5   <module>   s    (