
    FEf                        d dd Z ddd ZdgZddlmZ ddlmZmZmZm	Z	m
Z
 dd	lmZ dd
lmZ 	 	  G d d      Z G d d      Zedk(  r' e       Zej'                  ddd       ej'                  dddd       ej'                  ddd       ej)                  d        ed        edd      Z e ee              ee      Zded<   ded<   ded<   ej3                           ee      Zd ed<   d!ed<   d"ed<   ej3                           ed#        e ee              e ee            D ]/  Zee   Zej:                  D ]  Z ee d$ee             e        1 ej?                          y%y%)&z$Revision: 1.4 $   z$Date: 2006/07/04 08:18:18 $   dbf_new   )Dbf)DbfCharacterFieldDefDbfDateFieldDefDbfDateTimeFieldDefDbfLogicalFieldDefDbfNumericFieldDef)	DbfHeader)	DbfRecordc                   L    e Zd ZdZdZedfedfedfedfe	dfdZ
ddZd	 Zd
 Zy)_FieldDefinitionak  Field definition.

    This is a simple structure, which contains ``name``, ``type``,
    ``len``, ``dec`` and ``cls`` fields.

    Objects also implement get/setitem magic functions, so fields
    could be accessed via sequence interface, where 'name' has
    index 0, 'type' index 1, 'len' index 2, 'dec' index 3 and
    'cls' could be located at index 4.

    )nametypelendecclsNr         )CNLDTc                     | j                   |   \  }}||t        d      |}|| _        || _        || _        || _        || _        y )NzField length must be defined)	FLD_TYPES
ValueErrorr   r   r   r   r   )selfr   r   r   r   _cls_lens          U/var/www/VTS_Report/venv/lib/python3.12/site-packages/tablib/packages/dbfpy/dbfnew.py__init__z_FieldDefinition.__init__F   sR    ^^D)
d<{ !?@@D		    c                 d    | j                  | j                  | j                  | j                        S )z:Return `DbfFieldDef` instance from the current definition.)r   r   r   r   r    s    r#   getDbfFieldz_FieldDefinition.getDbfFieldR   s!    xx		488TXX66r%   c                 F    | j                         }|j                  |       y)zCreate a `DbfFieldDef` instance and append it to the dbf header.

        Arguments:
            dbfh: `DbfHeader` instance.

        N)r(   addField)r    dbfh_dbffs      r#   appendToHeaderz_FieldDefinition.appendToHeaderV   s       "er%   )N    )__name__
__module____qualname____doc__	__slots__r   r   r   r	   r
   r   r$   r(   r-    r%   r#   r   r   (   sR    
 4I
 #D) $' !$ q! "2&I
7r%   r   c                   ,    e Zd ZdZdZeZd ZddZd Z	y)r   a3  New .DBF creation helper.

    Example Usage:

        dbfn = dbf_new()
        dbfn.add_field("name",'C',80)
        dbfn.add_field("price",'N',10,2)
        dbfn.add_field("date",'D',8)
        dbfn.write("tst.dbf")

    Note:
        This module cannot handle Memo-fields,
        they are special.

    fieldsc                     g | _         y )Nr6   r'   s    r#   r$   zdbf_new.__init__v   s	    r%   c                 ^    | j                   j                  | j                  ||||             y)a  Add field definition.

        Arguments:
            name:
                field name (str object). field name must not
                contain ASCII NULs and it's length shouldn't
                exceed 10 characters.
            typ:
                type of the field. this must be a single character
                from the "CNLMDT" set meaning character, numeric,
                logical, memo, date and date/time respectively.
            len:
                length of the field. this argument is used only for
                the character and numeric fields. all other fields
                have fixed length.
                FIXME: use None as a default for this argument?
            dec:
                decimal precision. used only for the numric fields.

        N)r7   appendFieldDefinitionClass)r    r   typr   r   s        r#   	add_fieldzdbf_new.add_fieldy   s'    * 	444T3SIJr%   c                     t               }|j                          | j                  D ]  }|j                  |        t	        |d      }|j                  |       |j                          y)z/Create empty .DBF file using current structure.wbN)r   setCurrentDater7   r-   openwriteclose)r    filename_dbfh_fldDef
_dbfStreams        r#   rB   zdbf_new.write   s\    {{ 	*G""5)	* (D)
Jr%   N)r.   )
r/   r0   r1   r2   r3   r   r;   r$   r=   rB   r4   r%   r#   r   r   a   s$      I+K.	r%   __main__r   r   P   pricer   
      dater   r   ztst.dbfz*** created tst.dbf: ***r.   )readOnly	somethingg      %@)i  r      zfoo and bari/  )i  r      z(*** inserted 2 records into tst.dbf: ***z:	 N) __version____date____all__dbfr   r7   r   r	   r
   r   r   headerr   recordr   r   r   r/   dbfnr=   rB   printdbftreprrecstoreranger   i1
fieldNamesfldNamerC   r4   r%   r#   <module>rb      s   !B')!B/+    
6 6r8 8v z9DNN63#NN7CQ'NN63"JJy	
$%y1%D	$t*
D/CCKCLCKIIK
D/CCKCLCKIIK 

45	$t*CI 2h 	2GWIT#g,01	2	
 	JJLA r%   