
    ?wg~                     P    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      Z	y)z Tablib - DBF Support.
    N   )dbfdbfnew)recordc                   H    e Zd ZdZdZdZed        Zed        Zed        Z	y)	DBFFormatr   )csvzutf-8c                    t        j                         }t        j                         \  }}|d   }t	        |j
                  |      D ]D  \  }}t        |      t        t        fv r|j                  |ddd       2|j                  |dd       F |j                  |       t        j                  |d      }|D ]J  }	t        j                  |      }
t	        |j
                  |	      D ]
  \  }}||
|<    |
j                          L |j!                          t#        |d      }t%        j&                  |j)                               }|j!                          t+        j                   |       t+        j,                  |       |j/                         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streams                J/var/www/horilla/myenv/lib/python3.12/site-packages/tablib/formats/_dbf.py
export_setzDBFFormat.export_set   sQ    .."&..0	8 AJ	&)'//9&E 	6"I{K S%L0!!)S"a8!!)S"5		6 	h778a0 	C((2F*-goos*C 0&	;$/y!0LLN		 	(D)
JOO-.

		(      c                    |j                          t        j                  |      }|j                  |_        t        |j                        D ]2  }|j                  D cg c]
  }||   |    }}|j                  |       4 yc c}w )z$Returns a dataset from a DBF stream.N)wiper   r   
fieldNamesr   rangerecordCountappend)r)   dset	in_stream_dbfr   fr2   s          r5   
import_setzDBFFormat.import_set0   sn     			wwy!D,,- 	F,0OO<q4<?<C<KK	<s   Bc                 R    	 t        j                  |d       y# t        $ r Y yw xY w)z-Returns True if the given stream is valid DBFTr   F)r   r   	Exception)r)   r4   s     r5   detectzDBFFormat.detect;   s*    	GGFT* 		s    	&&N)
__name__
__module____qualname__title
extensionsDEFAULT_ENCODINGclassmethodr6   rB   rE    r7   r5   r   r      sL    EJ! !<    r7   r   )
__doc__r#   r&   r   _vendor.dbfpyr   r   r   r   r   rM   r7   r5   <module>rP      s#    	 	  ' /7 7r7   