o
    «ïg  ã                   @   s6   d dl mZ d dlmZ d dlmZ G dd„ dƒZdS )é    )Úi18n)ÚWebobInputWrapper©Ú	clean_keyc                   @   s`   e Zd ZdZdd„ Zdd„ Zdd„ ZdZd	Zd
Z	d
Z
d
Zdd„ ZdZdZi Zdd„ Zdd„ Zd
S )ÚDefaultMetaz‹
    This is the default Meta class which defines all the default values and
    therefore also the 'API' of the class Meta interface.
    c                 C   s   |j dd|i|¤ŽS )aŽ  
        bind_field allows potential customization of how fields are bound.

        The default implementation simply passes the options to
        :meth:`UnboundField.bind`.

        :param form: The form.
        :param unbound_field: The unbound field.
        :param options:
            A dictionary of options which are typically passed to the field.

        :return: A bound field
        ÚformN© )Úbind)Úselfr   Úunbound_fieldÚoptionsr   r   úY/var/www/html/portale_awareness/portale-venv/lib/python3.10/site-packages/wtforms/meta.pyÚ
bind_field   s   zDefaultMeta.bind_fieldc                 C   s0   |durt |dƒst |dƒrt|ƒS tdƒ‚|S )aZ  
        wrap_formdata allows doing custom wrappers of WTForms formdata.

        The default implementation detects webob-style multidicts and wraps
        them, otherwise passes formdata back un-changed.

        :param form: The form.
        :param formdata: Form data.
        :return: A form-input wrapper compatible with WTForms.
        NÚgetlistÚgetallzNformdata should be a multidict-type wrapper that supports the 'getlist' method)Úhasattrr   Ú	TypeError)r
   r   Úformdatar   r   r   Úwrap_formdata   s   
ÿzDefaultMeta.wrap_formdatac                 C   sZ   dd„ |  ¡ D ƒ}t|ddƒ}|dur$dd„ |  ¡ D ƒ}t|fi |¤Ž}|j|fi |¤ŽS )z£
        render_field allows customization of how widget rendering is done.

        The default implementation calls ``field.widget(field, **render_kw)``
        c                 S   ó   i | ]	\}}t |ƒ|“qS r   r   ©Ú.0ÚkÚvr   r   r   Ú
<dictcomp>:   ó    z,DefaultMeta.render_field.<locals>.<dictcomp>Ú	render_kwNc                 S   r   r   r   r   r   r   r   r   >   r   )ÚitemsÚgetattrÚdictÚwidget)r
   Úfieldr   Úother_kwr   r   r   Úrender_field3   s   zDefaultMeta.render_fieldFÚ
csrf_tokenNc                 C   s$   | j dur	|   ¡ S ddlm} |ƒ S )a—  
        Build a CSRF implementation. This is called once per form instance.

        The default implementation builds the class referenced to by
        :attr:`csrf_class` with zero arguments. If `csrf_class` is ``None``,
        will instead use the default implementation
        :class:`wtforms.csrf.session.SessionCSRF`.

        :param form: The form.
        :return: A CSRF implementation.
        Nr   )ÚSessionCSRF)Ú
csrf_classÚwtforms.csrf.sessionr%   )r
   r   r%   r   r   r   Ú
build_csrfJ   s   
zDefaultMeta.build_csrfTc                 C   s^   | j }|du r	dS | jr*|rt|ƒnd}| j |¡}|du r(t |¡ }| j|< |S t |¡S )zë
        Override in subclasses to provide alternate translations factory.
        See the i18n documentation for more.

        :param form: The form.
        :return: An object that provides gettext() and ngettext() methods.
        FN)ÚlocalesÚcache_translationsÚtupleÚtranslations_cacheÚgetr   Úget_translations)r
   r   r)   Útranslationsr   r   r   r.   c   s   ÿ
zDefaultMeta.get_translationsc                 C   s"   |  ¡ D ]
\}}t| ||ƒ qdS )zV
        Given a dictionary of values, update values on this `Meta` instance.
        N)r   Úsetattr)r
   ÚvaluesÚkeyÚvaluer   r   r   Úupdate_values   s   ÿzDefaultMeta.update_values)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r#   ÚcsrfÚcsrf_field_nameÚcsrf_secretÚcsrf_contextr&   r(   r)   r*   r,   r.   r4   r   r   r   r   r      s     r   N)Úwtformsr   Úwtforms.utilsr   Úwtforms.widgets.corer   r   r   r   r   r   Ú<module>   s    