o
    e                     @   sJ   d Z ddlZddlZddlZddlmZmZ ddlmZ G dd dZ	dS )z Tablib - DBF Support.
    N)dbfdbfnew)recordc                   @   s>   e Zd ZdZdZdZedd ZedddZed	d
 Z	dS )	DBFFormatr   )csvzutf-8c                 C   s   t  }t \}}|d }t|j|D ]\}}t|ttfv r)|	|ddd q|	|dd q|
| tj|dd}|D ]}	t|}
t|j|	D ]\}}||
|< qL|
  q?|  t|d}t| }|  t| t| | S )	z'Returns DBF representation of a Datasetr   N
      CP   readOnlyrb)r   dbf_newtempfilemkstempzipheaderstypeintfloat	add_fieldwriter   Dbf	dbfrecord	DbfRecordstorecloseopenioBytesIOreadosremovegetvalue)clsdatasetnew_dbf	temp_filetemp_uri	first_row	fieldnamefield_valuedbf_filerowr   
dbf_streamstream r1   F/var/www/html/venv/lib/python3.10/site-packages/tablib/formats/_dbf.py
export_set   s*   






zDBFFormat.export_setTc                    sN   |   t|  j|_t jD ] fdd jD }|| qdS )z$Returns a dataset from a DBF stream.c                    s   g | ]}  | qS r1   r1   ).0f_dbfr   r1   r2   
<listcomp>8   s    z(DBFFormat.import_set.<locals>.<listcomp>N)wiper   r   
fieldNamesr   rangerecordCountappend)r%   dset	in_streamr   r.   r1   r6   r2   
import_set0   s   
zDBFFormat.import_setc                 C   s*   z
t j|dd W dS  ty   Y dS w )z-Returns True if the given stream is valid DBFTr   F)r   r   	Exception)r%   r0   r1   r1   r2   detect;   s   zDBFFormat.detectN)T)
__name__
__module____qualname__title
extensionsDEFAULT_ENCODINGclassmethodr3   r@   rB   r1   r1   r1   r2   r      s    

r   )
__doc__r   r"   r   tablib.packages.dbfpyr   r   r   r   r   r1   r1   r1   r2   <module>   s    