cpython/Modules/_csv.c

/* csv module */

/*

This module provides the low-level underpinnings of a CSV reading/writing
module.  Users should not use this module directly, but import the csv.py
module instead.

*/

// clinic/_csv.c.h uses internal pycore_modsupport.h API
#ifndef Py_BUILD_CORE_BUILTIN
#define Py_BUILD_CORE_MODULE
#endif

#include "Python.h"
#include "pycore_pyatomic_ft_wrappers.h"

#include <stddef.h>               // offsetof()
#include <stdbool.h>

/*[clinic input]
module _csv
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=385118b71aa43706]*/

#include "clinic/_csv.c.h"
#define NOT_SET
#define EOL


_csvstate;

static struct PyModuleDef _csvmodule;

static inline _csvstate*
get_csv_state(PyObject *module)
{}

static int
_csv_clear(PyObject *module)
{}

static int
_csv_traverse(PyObject *module, visitproc visit, void *arg)
{}

static void
_csv_free(void *module)
{}

ParserState;

QuoteStyle;

StyleDesc;

static const StyleDesc quote_styles[] =;

DialectObj;

ReaderObj;

WriterObj;

/*
 * DIALECT class
 */

static PyObject *
get_dialect_from_registry(PyObject *name_obj, _csvstate *module_state)
{}

static PyObject *
get_char_or_None(Py_UCS4 c)
{}

static PyObject *
Dialect_get_lineterminator(DialectObj *self, void *Py_UNUSED(ignored))
{}

static PyObject *
Dialect_get_delimiter(DialectObj *self, void *Py_UNUSED(ignored))
{}

static PyObject *
Dialect_get_escapechar(DialectObj *self, void *Py_UNUSED(ignored))
{}

static PyObject *
Dialect_get_quotechar(DialectObj *self, void *Py_UNUSED(ignored))
{}

static PyObject *
Dialect_get_quoting(DialectObj *self, void *Py_UNUSED(ignored))
{}

static int
_set_bool(const char *name, char *target, PyObject *src, bool dflt)
{}

static int
_set_int(const char *name, int *target, PyObject *src, int dflt)
{}

static int
_set_char_or_none(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
{}

static int
_set_char(const char *name, Py_UCS4 *target, PyObject *src, Py_UCS4 dflt)
{}

static int
_set_str(const char *name, PyObject **target, PyObject *src, const char *dflt)
{}

static int
dialect_check_quoting(int quoting)
{}

static int
dialect_check_char(const char *name, Py_UCS4 c, DialectObj *dialect, bool allowspace)
{}

 static int
dialect_check_chars(const char *name1, const char *name2, Py_UCS4 c1, Py_UCS4 c2)
{}

#define D_OFF

static struct PyMemberDef Dialect_memberlist[] =;

#undef D_OFF

static PyGetSetDef Dialect_getsetlist[] =;

static void
Dialect_dealloc(DialectObj *self)
{}

static char *dialect_kws[] =;

static _csvstate *
_csv_state_from_type(PyTypeObject *type, const char *name)
{}

static PyObject *
dialect_new(PyTypeObject *type, PyObject *args, PyObject *kwargs)
{}

/* Since dialect is now a heap type, it inherits pickling method for
 * protocol 0 and 1 from object, therefore it needs to be overridden */

PyDoc_STRVAR(dialect_reduce_doc, "raises an exception to avoid pickling");

static PyObject *
Dialect_reduce(PyObject *self, PyObject *args) {}

static struct PyMethodDef dialect_methods[] =;

PyDoc_STRVAR(Dialect_Type_doc,
"CSV dialect\n"
"\n"
"The Dialect type records CSV parsing and generation options.\n");

static int
Dialect_clear(DialectObj *self)
{}

static int
Dialect_traverse(DialectObj *self, visitproc visit, void *arg)
{}

static PyType_Slot Dialect_Type_slots[] =;

PyType_Spec Dialect_Type_spec =;


/*
 * Return an instance of the dialect type, given a Python instance or kwarg
 * description of the dialect
 */
static PyObject *
_call_dialect(_csvstate *module_state, PyObject *dialect_inst, PyObject *kwargs)
{}

/*
 * READER
 */
static int
parse_save_field(ReaderObj *self)
{}

static int
parse_grow_buff(ReaderObj *self)
{}

static int
parse_add_char(ReaderObj *self, _csvstate *module_state, Py_UCS4 c)
{}

static int
parse_process_char(ReaderObj *self, _csvstate *module_state, Py_UCS4 c)
{}

static int
parse_reset(ReaderObj *self)
{}

static PyObject *
Reader_iternext(ReaderObj *self)
{}

static void
Reader_dealloc(ReaderObj *self)
{}

static int
Reader_traverse(ReaderObj *self, visitproc visit, void *arg)
{}

static int
Reader_clear(ReaderObj *self)
{}

PyDoc_STRVAR(Reader_Type_doc,
"CSV reader\n"
"\n"
"Reader objects are responsible for reading and parsing tabular data\n"
"in CSV format.\n"
);

static struct PyMethodDef Reader_methods[] =;
#define R_OFF

static struct PyMemberDef Reader_memberlist[] =;

#undef R_OFF


static PyType_Slot Reader_Type_slots[] =;

PyType_Spec Reader_Type_spec =;


static PyObject *
csv_reader(PyObject *module, PyObject *args, PyObject *keyword_args)
{}

/*
 * WRITER
 */
/* ---------------------------------------------------------------- */
static void
join_reset(WriterObj *self)
{}

#define MEM_INCR

/* Calculate new record length or append field to record.  Return new
 * record length.
 */
static Py_ssize_t
join_append_data(WriterObj *self, int field_kind, const void *field_data,
                 Py_ssize_t field_len, int *quoted,
                 int copy_phase)
{}

static int
join_check_rec_size(WriterObj *self, Py_ssize_t rec_len)
{}

static int
join_append(WriterObj *self, PyObject *field, int quoted)
{}

static int
join_append_lineterminator(WriterObj *self)
{}

PyDoc_STRVAR(csv_writerow_doc,
"writerow(iterable)\n"
"\n"
"Construct and write a CSV record from an iterable of fields.  Non-string\n"
"elements will be converted to string.");

static PyObject *
csv_writerow(WriterObj *self, PyObject *seq)
{}

PyDoc_STRVAR(csv_writerows_doc,
"writerows(iterable of iterables)\n"
"\n"
"Construct and write a series of iterables to a csv file.  Non-string\n"
"elements will be converted to string.");

static PyObject *
csv_writerows(WriterObj *self, PyObject *seqseq)
{}

static struct PyMethodDef Writer_methods[] =;

#define W_OFF

static struct PyMemberDef Writer_memberlist[] =;

#undef W_OFF

static int
Writer_traverse(WriterObj *self, visitproc visit, void *arg)
{}

static int
Writer_clear(WriterObj *self)
{}

static void
Writer_dealloc(WriterObj *self)
{}

PyDoc_STRVAR(Writer_Type_doc,
"CSV writer\n"
"\n"
"Writer objects are responsible for generating tabular data\n"
"in CSV format from sequence input.\n"
);

static PyType_Slot Writer_Type_slots[] =;

PyType_Spec Writer_Type_spec =;


static PyObject *
csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
{}

/*
 * DIALECT REGISTRY
 */

/*[clinic input]
_csv.list_dialects

Return a list of all known dialect names.

    names = csv.list_dialects()
[clinic start generated code]*/

static PyObject *
_csv_list_dialects_impl(PyObject *module)
/*[clinic end generated code: output=a5b92b215b006a6d input=8953943eb17d98ab]*/
{}

static PyObject *
csv_register_dialect(PyObject *module, PyObject *args, PyObject *kwargs)
{}


/*[clinic input]
_csv.unregister_dialect

    name: object

Delete the name/dialect mapping associated with a string name.

    csv.unregister_dialect(name)
[clinic start generated code]*/

static PyObject *
_csv_unregister_dialect_impl(PyObject *module, PyObject *name)
/*[clinic end generated code: output=0813ebca6c058df4 input=6b5c1557bf60c7e7]*/
{}

/*[clinic input]
_csv.get_dialect

    name: object

Return the dialect instance associated with name.

    dialect = csv.get_dialect(name)
[clinic start generated code]*/

static PyObject *
_csv_get_dialect_impl(PyObject *module, PyObject *name)
/*[clinic end generated code: output=aa988cd573bebebb input=edf9ddab32e448fb]*/
{}

/*[clinic input]
_csv.field_size_limit

    new_limit: object = NULL

Sets an upper limit on parsed fields.

    csv.field_size_limit([limit])

Returns old limit. If limit is not given, no new limit is set and
the old limit is returned
[clinic start generated code]*/

static PyObject *
_csv_field_size_limit_impl(PyObject *module, PyObject *new_limit)
/*[clinic end generated code: output=f2799ecd908e250b input=cec70e9226406435]*/
{}

static PyType_Slot error_slots[] =;

PyType_Spec error_spec =;

/*
 * MODULE
 */

PyDoc_STRVAR(csv_module_doc, "CSV parsing and writing.\n");

PyDoc_STRVAR(csv_reader_doc,
"    csv_reader = reader(iterable [, dialect='excel']\n"
"                        [optional keyword args])\n"
"    for row in csv_reader:\n"
"        process(row)\n"
"\n"
"The \"iterable\" argument can be any object that returns a line\n"
"of input for each iteration, such as a file object or a list.  The\n"
"optional \"dialect\" parameter is discussed below.  The function\n"
"also accepts optional keyword arguments which override settings\n"
"provided by the dialect.\n"
"\n"
"The returned object is an iterator.  Each iteration returns a row\n"
"of the CSV file (which can span multiple input lines).\n");

PyDoc_STRVAR(csv_writer_doc,
"    csv_writer = csv.writer(fileobj [, dialect='excel']\n"
"                            [optional keyword args])\n"
"    for row in sequence:\n"
"        csv_writer.writerow(row)\n"
"\n"
"    [or]\n"
"\n"
"    csv_writer = csv.writer(fileobj [, dialect='excel']\n"
"                            [optional keyword args])\n"
"    csv_writer.writerows(rows)\n"
"\n"
"The \"fileobj\" argument can be any object that supports the file API.\n");

PyDoc_STRVAR(csv_register_dialect_doc,
"Create a mapping from a string name to a dialect class.\n"
"    dialect = csv.register_dialect(name[, dialect[, **fmtparams]])");

static struct PyMethodDef csv_methods[] =;

static int
csv_exec(PyObject *module) {}

static PyModuleDef_Slot csv_slots[] =;

static struct PyModuleDef _csvmodule =;

PyMODINIT_FUNC
PyInit__csv(void)
{}