o
    „s¢Y�  ã                   @   s|  d Z 	 ddd… Zddd… ZdgZddlT ddlT ddlT ddlT G d	d
„ d
eƒZ	G dd„ deƒZ
edkr¼e
ƒ Ze ddd¡ e dddd¡ e ddd¡ e d¡ edƒ eddd�Zeeeƒƒ eeƒZded< ded< ded< e ¡  eeƒZded< ded< d ed< e ¡  ed!ƒ eeeƒƒ eeeƒƒD ]Zee ZejD ]Zed"eee f ƒ q¥eƒ  qœe ¡  d#S d#S )$a!  .DBF creation helpers.

Note: this is a legacy interface.  New code should use Dbf class
    for table creation (see examples in dbf.py)

TODO:
  - handle Memo fields.
  - check length of the fields accoring to the
    `http://www.clicketyclick.dk/databases/xbase/format/data_types.html`

z$Revision: 1.4 $é   éþÿÿÿz$Date: 2006/07/04 08:18:18 $é   Údbf_newé   )Ú*c                   @   sR   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	d
„Zdd„ Zdd„ ZdS )Ú_FieldDefinitionaj  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 iterface, 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ÚTé    c                 C   sL   | j | \}}|d u r|d u rtdƒ‚|}|| _|| _|| _|| _|| _d S )NzField length must be defined)Ú	FLD_TYPESÚ
ValueErrorr   r	   r
   r   r   )Úselfr   r	   r
   r   Ú_clsÚ_len© r   úO/var/www/html/env/lib/python3.10/site-packages/tablib/packages/dbfpy3/dbfnew.pyÚ__init__?   s   
z_FieldDefinition.__init__c                 C   s   |   | j| j| j¡S )z:Return `DbfFieldDef` instance from the current definition.)r   r   r
   r   ©r   r   r   r   ÚgetDbfFieldK   s   z_FieldDefinition.getDbfFieldc                 C   s   |   ¡ }| |¡ dS )z†Create a `DbfFieldDef` instance and append it to the dbf header.

        Arguments:
            dbfh: `DbfHeader` instance.

        N)r   ÚaddField)r   ÚdbfhÚ_dbffr   r   r   ÚappendToHeaderO   s   z_FieldDefinition.appendToHeader)Nr   )Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú	__slots__ÚDbfCharacterFieldDefÚDbfNumericFieldDefÚDbfLogicalFieldDefÚDbfDateFieldDefÚDbfDateTimeFieldDefr   r   r   r"   r   r   r   r   r   !   s    õ
r   c                   @   s2   e Zd ZdZdZeZdd„ Zddd„Zdd	„ Z	d
S )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                 C   s
   g | _ d S )Nr-   r   r   r   r   r   o   s   
zdbf_new.__init__r   c                 C   s   | j  |  ||||¡¡ dS )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)r.   ÚappendÚFieldDefinitionClass)r   r   Útypr
   r   r   r   r   Ú	add_fieldr   s   zdbf_new.add_fieldc                 C   sD   t ƒ }| ¡  | jD ]}| |¡ q
t|dƒ}| |¡ | ¡  dS )z/Create empty .DBF file using current structure.ÚwbN)Ú	DbfHeaderÚsetCurrentDater.   r"   ÚopenÚwriteÚclose)r   ÚfilenameÚ_dbfhÚ_fldDefÚ
_dbfStreamr   r   r   r7   ‰   s   


zdbf_new.writeN)r   )
r#   r$   r%   r&   r'   r   r0   r   r2   r7   r   r   r   r   r   Z   s    
Ú__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%s:	 %sN)r&   Ú__version__Ú__date__Ú__all__Údbfr.   ÚheaderÚrecordÚobjectr   r   r#   Údbfnr2   r7   ÚprintÚDbfÚdbftÚreprÚ	DbfRecordÚrecÚstoreÚranger
   Úi1Ú
fieldNamesÚfldNamer8   r   r   r   r   Ú<module>   sN   	9;

à