U
    fgP                     @   s<   d dl mZ ddlmZ ddlmZ dZG dd deZd	S )
   )widgets   )Field    )unset_value)	FormFieldc                       sz   e Zd ZdZe Zd fdd	ZedfddZ	dd	d
Z
dd Zdd Zdd Zdd Zedd Zedd Z  ZS )r   a-  
    Encapsulate a form as a field in another form.

    :param form_class:
        A subclass of Form that will be encapsulated.
    :param separator:
        A string which will be suffixed to this field's name to create the
        prefix to enclosed fields. The default is fine for most uses.
    N-c                    sB   t  j||f| || _|| _d | _| jr2td|r>tdd S )NzGFormField cannot take filters, as the encapsulated data is not mutable.zTFormField does not accept any validators. Instead, define them on the enclosed form.)super__init__
form_class	separator_objfilters	TypeError)selfr   labelZ
validatorsr   kwargs	__class__ 7/tmp/pip-unpacked-wheel-p06mjha7/wtforms/fields/form.pyr
      s    zFormField.__init__c                 C   s   |rt d|tkrBz|  }W n t k
r:   | j}Y nX || _|| _| j| j }t|trx| j	f ||d|| _
n| j	|||d| _
d S )NzFFormField cannot take filters, as the encapsulateddata is not mutable.)formdataprefix)r   objr   )r   r   defaultr   Zobject_datanamer   
isinstancedictr   form)r   r   dataZextra_filtersr   r   r   r   process'   s    
zFormField.processr   c                 C   s   |rt d| j S )NzWFormField does not accept in-line validators, as it gets errors from the enclosed form.)r   r   validate)r   r   Zextra_validatorsr   r   r   r!   =   s
    zFormField.validatec                 C   sH   t ||d }|d kr,| jd kr&td| j}| j| t||| d S )NzZpopulate_obj: cannot find a value to populate from the provided obj or input data/defaults)getattrr   r   r   populate_objsetattr)r   r   r   	candidater   r   r   r#   E   s    
zFormField.populate_objc                 C   s
   t | jS N)iterr   r   r   r   r   __iter__R   s    zFormField.__iter__c                 C   s
   | j | S r&   )r   r   r   r   r   r   __getitem__U   s    zFormField.__getitem__c                 C   s   t | j|S r&   )r"   r   r*   r   r   r   __getattr__X   s    zFormField.__getattr__c                 C   s   | j jS r&   )r   r   r(   r   r   r   r   [   s    zFormField.datac                 C   s   | j jS r&   )r   errorsr(   r   r   r   r-   _   s    zFormField.errors)NNr   )r   )__name__
__module____qualname____doc__r   ZTableWidgetZwidgetr
   r   r    r!   r#   r)   r+   r,   propertyr   r-   __classcell__r   r   r   r   r      s    
     

r   N) r   corer   Zwtforms.utilsr   __all__r   r   r   r   r   <module>   s   