@@ -14,6 +14,12 @@ module instead.
14
14
#include "structmember.h" // PyMemberDef
15
15
#include <stdbool.h>
16
16
17
+ /*[clinic input]
18
+ module _csv
19
+ [clinic start generated code]*/
20
+ /*[clinic end generated code: output=da39a3ee5e6b4b0d input=385118b71aa43706]*/
21
+
22
+ #include "clinic/_csv.c.h"
17
23
#define NOT_SET ((Py_UCS4)-1)
18
24
#define EOL ((Py_UCS4)-2)
19
25
@@ -1473,8 +1479,18 @@ csv_writer(PyObject *module, PyObject *args, PyObject *keyword_args)
1473
1479
/*
1474
1480
* DIALECT REGISTRY
1475
1481
*/
1482
+
1483
+ /*[clinic input]
1484
+ _csv.list_dialects
1485
+
1486
+ Return a list of all known dialect names.
1487
+
1488
+ names = csv.list_dialects()
1489
+ [clinic start generated code]*/
1490
+
1476
1491
static PyObject *
1477
- csv_list_dialects (PyObject * module , PyObject * args )
1492
+ _csv_list_dialects_impl (PyObject * module )
1493
+ /*[clinic end generated code: output=a5b92b215b006a6d input=8953943eb17d98ab]*/
1478
1494
{
1479
1495
return PyDict_Keys (get_csv_state (module )-> dialects );
1480
1496
}
@@ -1506,11 +1522,23 @@ csv_register_dialect(PyObject *module, PyObject *args, PyObject *kwargs)
1506
1522
Py_RETURN_NONE ;
1507
1523
}
1508
1524
1525
+
1526
+ /*[clinic input]
1527
+ _csv.unregister_dialect
1528
+
1529
+ name: object
1530
+
1531
+ Delete the name/dialect mapping associated with a string name.
1532
+
1533
+ csv.unregister_dialect(name)
1534
+ [clinic start generated code]*/
1535
+
1509
1536
static PyObject *
1510
- csv_unregister_dialect (PyObject * module , PyObject * name_obj )
1537
+ _csv_unregister_dialect_impl (PyObject * module , PyObject * name )
1538
+ /*[clinic end generated code: output=0813ebca6c058df4 input=6b5c1557bf60c7e7]*/
1511
1539
{
1512
1540
_csvstate * module_state = get_csv_state (module );
1513
- if (PyDict_DelItem (module_state -> dialects , name_obj ) < 0 ) {
1541
+ if (PyDict_DelItem (module_state -> dialects , name ) < 0 ) {
1514
1542
if (PyErr_ExceptionMatches (PyExc_KeyError )) {
1515
1543
PyErr_Format (module_state -> error_obj , "unknown dialect" );
1516
1544
}
@@ -1519,21 +1547,42 @@ csv_unregister_dialect(PyObject *module, PyObject *name_obj)
1519
1547
Py_RETURN_NONE ;
1520
1548
}
1521
1549
1550
+ /*[clinic input]
1551
+ _csv.get_dialect
1552
+
1553
+ name: object
1554
+
1555
+ Return the dialect instance associated with name.
1556
+
1557
+ dialect = csv.get_dialect(name)
1558
+ [clinic start generated code]*/
1559
+
1522
1560
static PyObject *
1523
- csv_get_dialect (PyObject * module , PyObject * name_obj )
1561
+ _csv_get_dialect_impl (PyObject * module , PyObject * name )
1562
+ /*[clinic end generated code: output=aa988cd573bebebb input=edf9ddab32e448fb]*/
1524
1563
{
1525
- return get_dialect_from_registry (name_obj , get_csv_state (module ));
1564
+ return get_dialect_from_registry (name , get_csv_state (module ));
1526
1565
}
1527
1566
1567
+ /*[clinic input]
1568
+ _csv.field_size_limit
1569
+
1570
+ new_limit: object = NULL
1571
+
1572
+ Sets an upper limit on parsed fields.
1573
+
1574
+ csv.field_size_limit([limit])
1575
+
1576
+ Returns old limit. If limit is not given, no new limit is set and
1577
+ the old limit is returned
1578
+ [clinic start generated code]*/
1579
+
1528
1580
static PyObject *
1529
- csv_field_size_limit (PyObject * module , PyObject * args )
1581
+ _csv_field_size_limit_impl (PyObject * module , PyObject * new_limit )
1582
+ /*[clinic end generated code: output=f2799ecd908e250b input=cec70e9226406435]*/
1530
1583
{
1531
- PyObject * new_limit = NULL ;
1532
1584
_csvstate * module_state = get_csv_state (module );
1533
1585
long old_limit = module_state -> field_limit ;
1534
-
1535
- if (!PyArg_UnpackTuple (args , "field_size_limit" , 0 , 1 , & new_limit ))
1536
- return NULL ;
1537
1586
if (new_limit != NULL ) {
1538
1587
if (!PyLong_CheckExact (new_limit )) {
1539
1588
PyErr_Format (PyExc_TypeError ,
@@ -1650,44 +1699,21 @@ PyDoc_STRVAR(csv_writer_doc,
1650
1699
"\n"
1651
1700
"The \"fileobj\" argument can be any object that supports the file API.\n" );
1652
1701
1653
- PyDoc_STRVAR (csv_list_dialects_doc ,
1654
- "Return a list of all know dialect names.\n"
1655
- " names = csv.list_dialects()" );
1656
-
1657
- PyDoc_STRVAR (csv_get_dialect_doc ,
1658
- "Return the dialect instance associated with name.\n"
1659
- " dialect = csv.get_dialect(name)" );
1660
-
1661
1702
PyDoc_STRVAR (csv_register_dialect_doc ,
1662
1703
"Create a mapping from a string name to a dialect class.\n"
1663
1704
" dialect = csv.register_dialect(name[, dialect[, **fmtparams]])" );
1664
1705
1665
- PyDoc_STRVAR (csv_unregister_dialect_doc ,
1666
- "Delete the name/dialect mapping associated with a string name.\n"
1667
- " csv.unregister_dialect(name)" );
1668
-
1669
- PyDoc_STRVAR (csv_field_size_limit_doc ,
1670
- "Sets an upper limit on parsed fields.\n"
1671
- " csv.field_size_limit([limit])\n"
1672
- "\n"
1673
- "Returns old limit. If limit is not given, no new limit is set and\n"
1674
- "the old limit is returned" );
1675
-
1676
1706
static struct PyMethodDef csv_methods [] = {
1677
1707
{ "reader" , (PyCFunction )(void (* )(void ))csv_reader ,
1678
1708
METH_VARARGS | METH_KEYWORDS , csv_reader_doc },
1679
1709
{ "writer" , (PyCFunction )(void (* )(void ))csv_writer ,
1680
1710
METH_VARARGS | METH_KEYWORDS , csv_writer_doc },
1681
- { "list_dialects" , (PyCFunction )csv_list_dialects ,
1682
- METH_NOARGS , csv_list_dialects_doc },
1683
1711
{ "register_dialect" , (PyCFunction )(void (* )(void ))csv_register_dialect ,
1684
1712
METH_VARARGS | METH_KEYWORDS , csv_register_dialect_doc },
1685
- { "unregister_dialect" , (PyCFunction )csv_unregister_dialect ,
1686
- METH_O , csv_unregister_dialect_doc },
1687
- { "get_dialect" , (PyCFunction )csv_get_dialect ,
1688
- METH_O , csv_get_dialect_doc },
1689
- { "field_size_limit" , (PyCFunction )csv_field_size_limit ,
1690
- METH_VARARGS , csv_field_size_limit_doc },
1713
+ _CSV_LIST_DIALECTS_METHODDEF
1714
+ _CSV_UNREGISTER_DIALECT_METHODDEF
1715
+ _CSV_GET_DIALECT_METHODDEF
1716
+ _CSV_FIELD_SIZE_LIMIT_METHODDEF
1691
1717
{ NULL , NULL }
1692
1718
};
1693
1719
0 commit comments