o
    ;Di                     @   s   d dl mZmZmZ d dlmZ d dlmZ d dlm	Z	m
Z
 er-d dlmZmZmZmZ nd dlmZmZmZmZ ddd	Zdd
dZdddZee_		dddZee_		dddZee_		dddZee_dddZee_dddZee_dS )    )absolute_importprint_functiondivision)PY2)Table)read_source_from_argwrite_source_from_arg)fromcsv_impl
tocsv_implappendcsv_implteecsv_implNstrictc                 K   s,   t | } |dd td| |||d|S )a  
    Extract a table from a delimited file. E.g.::

        >>> import petl as etl
        >>> import csv
        >>> # set up a CSV file to demonstrate with
        ... table1 = [['foo', 'bar'],
        ...           ['a', 1],
        ...           ['b', 2],
        ...           ['c', 2]]
        >>> with open('example.csv', 'w') as f:
        ...     writer = csv.writer(f)
        ...     writer.writerows(table1)
        ...
        >>> # now demonstrate the use of fromcsv()
        ... table2 = etl.fromcsv('example.csv')
        >>> table2
        +-----+-----+
        | foo | bar |
        +=====+=====+
        | 'a' | '1' |
        +-----+-----+
        | 'b' | '2' |
        +-----+-----+
        | 'c' | '2' |
        +-----+-----+

    The `source` argument is the path of the delimited file, all other keyword
    arguments are passed to :func:`csv.reader`. So, e.g., to override the
    delimiter from the default CSV dialect, provide the `delimiter` keyword
    argument.

    Note that all data values are strings, and any intended numeric values will
    need to be converted, see also :func:`petl.transform.conversions.convert`.

    dialectexcel)sourceencodingerrorsheaderN )r   
setdefaultr	   r   r   r   r   csvargsr   r   D/var/www/Datamplify/venv/lib/python3.10/site-packages/petl/io/csv.pyfromcsv   s   '
r   c                 K   s$   | dd t| f|||d|S )zw
    Convenience function, as :func:`petl.io.csv.fromcsv` but with different
    default dialect (tab delimited).

    r   	excel-tab)r   r   r   )r   r   r   r   r   r   fromtsvA   s   r   Tc                 K   s2   t |}|dd t| f||||d| dS )aE  
    Write the table to a CSV file. E.g.::

        >>> import petl as etl
        >>> table1 = [['foo', 'bar'],
        ...           ['a', 1],
        ...           ['b', 2],
        ...           ['c', 2]]
        >>> etl.tocsv(table1, 'example.csv')
        >>> # look what it did
        ... print(open('example.csv').read())
        foo,bar
        a,1
        b,2
        c,2

    The `source` argument is the path of the delimited file, and the optional
    `write_header` argument specifies whether to include the field names in the
    delimited file.  All other keyword arguments are passed to
    :func:`csv.writer`. So, e.g., to override the delimiter from the default
    CSV dialect, provide the `delimiter` keyword argument.

    Note that if a file already exists at the given location, it will be
    overwritten.

    r   r   r   r   r   write_headerN)r   r   r
   tabler   r   r   r   r   r   r   r   tocsvM   s   
r    Fc                 K   s6   t |dd}|dd t| f||||d| dS )af  
    Append data rows to an existing CSV file. As :func:`petl.io.csv.tocsv`
    but the file is opened in append mode and the table header is not written by
    default.

    Note that no attempt is made to check that the fields or row lengths are
    consistent with the existing data, the data rows from the table are simply
    appended to the file.

    ab)moder   r   r   N)r   r   r   r   r   r   r   	appendcsvs   s   
r#   c                 K   &   | dd t| f||||d|S )zu
    Convenience function, as :func:`petl.io.csv.tocsv` but with different
    default dialect (tab delimited).

    r   r   r   )r   r    r   r   r   r   totsv      r%   c                 K   r$   )zy
    Convenience function, as :func:`petl.io.csv.appendcsv` but with different
    default dialect (tab delimited).

    r   r   r   )r   r#   r   r   r   r   	appendtsv   r&   r'   c                 K   s.   t |}|dd t| f||||d|S )zT
    Returns a table that writes rows to a CSV file as they are iterated over.

    r   r   r   )r   r   r   r   r   r   r   teecsv   s   
r(   c                 K   r$   )zv
    Convenience function, as :func:`petl.io.csv.teecsv` but with different
    default dialect (tab delimited).

    r   r   r   )r   r(   r   r   r   r   teetsv   r&   r)   )NNr   N)NNr   T)NNr   F)
__future__r   r   r   petl.compatr   petl.util.baser   petl.io.sourcesr   r   petl.io.csv_py2r	   r
   r   r   petl.io.csv_py3r   r   r    r#   r%   r'   r(   r)   r   r   r   r   <module>   s6   

-
#





