mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-40956: Convert _sqlite3 module level functions to Argument Clinic (GH-22484)
This commit is contained in:
parent
bcbf758476
commit
7d21027157
4 changed files with 313 additions and 88 deletions
|
@ -33,6 +33,12 @@
|
|||
#error "SQLite 3.7.3 or higher required"
|
||||
#endif
|
||||
|
||||
#include "clinic/module.c.h"
|
||||
/*[clinic input]
|
||||
module _sqlite3
|
||||
[clinic start generated code]*/
|
||||
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/
|
||||
|
||||
/* static objects at module-level */
|
||||
|
||||
PyObject *pysqlite_Error = NULL;
|
||||
|
@ -102,19 +108,20 @@ Opens a connection to the SQLite database file *database*. You can use\n\
|
|||
\":memory:\" to open a database connection to a database that resides in\n\
|
||||
RAM instead of on disk.");
|
||||
|
||||
static PyObject* module_complete(PyObject* self, PyObject* args, PyObject*
|
||||
kwargs)
|
||||
/*[clinic input]
|
||||
_sqlite3.complete_statement as pysqlite_complete_statement
|
||||
|
||||
statement: str
|
||||
|
||||
Checks if a string contains a complete SQL statement. Non-standard.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
pysqlite_complete_statement_impl(PyObject *module, const char *statement)
|
||||
/*[clinic end generated code: output=e55f1ff1952df558 input=f6b24996b31c5c33]*/
|
||||
{
|
||||
static char *kwlist[] = {"statement", NULL};
|
||||
char* statement;
|
||||
|
||||
PyObject* result;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "s", kwlist, &statement))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (sqlite3_complete(statement)) {
|
||||
result = Py_True;
|
||||
} else {
|
||||
|
@ -126,23 +133,22 @@ static PyObject* module_complete(PyObject* self, PyObject* args, PyObject*
|
|||
return result;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(module_complete_doc,
|
||||
"complete_statement(sql)\n\
|
||||
\n\
|
||||
Checks if a string contains a complete SQL statement. Non-standard.");
|
||||
/*[clinic input]
|
||||
_sqlite3.enable_shared_cache as pysqlite_enable_shared_cache
|
||||
|
||||
static PyObject* module_enable_shared_cache(PyObject* self, PyObject* args, PyObject*
|
||||
kwargs)
|
||||
do_enable: int
|
||||
|
||||
Enable or disable shared cache mode for the calling thread.
|
||||
|
||||
Experimental/Non-standard.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
pysqlite_enable_shared_cache_impl(PyObject *module, int do_enable)
|
||||
/*[clinic end generated code: output=259c74eedee1516b input=8400e41bc58b6b24]*/
|
||||
{
|
||||
static char *kwlist[] = {"do_enable", NULL};
|
||||
int do_enable;
|
||||
int rc;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwargs, "i", kwlist, &do_enable))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
rc = sqlite3_enable_shared_cache(do_enable);
|
||||
|
||||
if (rc != SQLITE_OK) {
|
||||
|
@ -153,22 +159,23 @@ static PyObject* module_enable_shared_cache(PyObject* self, PyObject* args, PyOb
|
|||
}
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(module_enable_shared_cache_doc,
|
||||
"enable_shared_cache(do_enable)\n\
|
||||
\n\
|
||||
Enable or disable shared cache mode for the calling thread.\n\
|
||||
Experimental/Non-standard.");
|
||||
/*[clinic input]
|
||||
_sqlite3.register_adapter as pysqlite_register_adapter
|
||||
|
||||
static PyObject* module_register_adapter(PyObject* self, PyObject* args)
|
||||
type: object(type='PyTypeObject *')
|
||||
caster: object
|
||||
/
|
||||
|
||||
Registers an adapter with pysqlite's adapter registry. Non-standard.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
pysqlite_register_adapter_impl(PyObject *module, PyTypeObject *type,
|
||||
PyObject *caster)
|
||||
/*[clinic end generated code: output=a287e8db18e8af23 input=839dad90e2492725]*/
|
||||
{
|
||||
PyTypeObject* type;
|
||||
PyObject* caster;
|
||||
int rc;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "OO", &type, &caster)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* a basic type is adapted; there's a performance optimization if that's not the case
|
||||
* (99 % of all usages) */
|
||||
if (type == &PyLong_Type || type == &PyFloat_Type
|
||||
|
@ -183,23 +190,25 @@ static PyObject* module_register_adapter(PyObject* self, PyObject* args)
|
|||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(module_register_adapter_doc,
|
||||
"register_adapter(type, callable)\n\
|
||||
\n\
|
||||
Registers an adapter with pysqlite's adapter registry. Non-standard.");
|
||||
/*[clinic input]
|
||||
_sqlite3.register_converter as pysqlite_register_converter
|
||||
|
||||
static PyObject* module_register_converter(PyObject* self, PyObject* args)
|
||||
name as orig_name: unicode
|
||||
converter as callable: object
|
||||
/
|
||||
|
||||
Registers a converter with pysqlite. Non-standard.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
pysqlite_register_converter_impl(PyObject *module, PyObject *orig_name,
|
||||
PyObject *callable)
|
||||
/*[clinic end generated code: output=a2f2bfeed7230062 input=e074cf7f4890544f]*/
|
||||
{
|
||||
PyObject* orig_name;
|
||||
PyObject* name = NULL;
|
||||
PyObject* callable;
|
||||
PyObject* retval = NULL;
|
||||
_Py_IDENTIFIER(upper);
|
||||
|
||||
if (!PyArg_ParseTuple(args, "UO", &orig_name, &callable)) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* convert the name to upper case */
|
||||
name = _PyObject_CallMethodIdNoArgs(orig_name, &PyId_upper);
|
||||
if (!name) {
|
||||
|
@ -217,24 +226,42 @@ error:
|
|||
return retval;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(module_register_converter_doc,
|
||||
"register_converter(typename, callable)\n\
|
||||
\n\
|
||||
Registers a converter with pysqlite. Non-standard.");
|
||||
/*[clinic input]
|
||||
_sqlite3.enable_callback_tracebacks as pysqlite_enable_callback_trace
|
||||
|
||||
static PyObject* enable_callback_tracebacks(PyObject* self, PyObject* args)
|
||||
enable: int
|
||||
/
|
||||
|
||||
Enable or disable callback functions throwing errors to stderr.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
pysqlite_enable_callback_trace_impl(PyObject *module, int enable)
|
||||
/*[clinic end generated code: output=4ff1d051c698f194 input=cb79d3581eb77c40]*/
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "i", &_pysqlite_enable_callback_tracebacks)) {
|
||||
return NULL;
|
||||
}
|
||||
_pysqlite_enable_callback_tracebacks = enable;
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PyDoc_STRVAR(enable_callback_tracebacks_doc,
|
||||
"enable_callback_tracebacks(flag)\n\
|
||||
\n\
|
||||
Enable or disable callback functions throwing errors to stderr.");
|
||||
/*[clinic input]
|
||||
_sqlite3.adapt as pysqlite_adapt
|
||||
|
||||
obj: object
|
||||
proto: object(c_default='(PyObject*)pysqlite_PrepareProtocolType') = PrepareProtocolType
|
||||
alt: object = NULL
|
||||
/
|
||||
|
||||
Adapt given object to given protocol. Non-standard.
|
||||
[clinic start generated code]*/
|
||||
|
||||
static PyObject *
|
||||
pysqlite_adapt_impl(PyObject *module, PyObject *obj, PyObject *proto,
|
||||
PyObject *alt)
|
||||
/*[clinic end generated code: output=0c3927c5fcd23dd9 input=a58ab77fb5ae22dd]*/
|
||||
{
|
||||
return pysqlite_microprotocols_adapt(obj, proto, alt);
|
||||
}
|
||||
|
||||
static void converters_init(PyObject* module)
|
||||
{
|
||||
|
@ -252,18 +279,12 @@ static void converters_init(PyObject* module)
|
|||
static PyMethodDef module_methods[] = {
|
||||
{"connect", (PyCFunction)(void(*)(void))module_connect,
|
||||
METH_VARARGS | METH_KEYWORDS, module_connect_doc},
|
||||
{"complete_statement", (PyCFunction)(void(*)(void))module_complete,
|
||||
METH_VARARGS | METH_KEYWORDS, module_complete_doc},
|
||||
{"enable_shared_cache", (PyCFunction)(void(*)(void))module_enable_shared_cache,
|
||||
METH_VARARGS | METH_KEYWORDS, module_enable_shared_cache_doc},
|
||||
{"register_adapter", (PyCFunction)module_register_adapter,
|
||||
METH_VARARGS, module_register_adapter_doc},
|
||||
{"register_converter", (PyCFunction)module_register_converter,
|
||||
METH_VARARGS, module_register_converter_doc},
|
||||
{"adapt", (PyCFunction)pysqlite_adapt, METH_VARARGS,
|
||||
pysqlite_adapt_doc},
|
||||
{"enable_callback_tracebacks", (PyCFunction)enable_callback_tracebacks,
|
||||
METH_VARARGS, enable_callback_tracebacks_doc},
|
||||
PYSQLITE_ADAPT_METHODDEF
|
||||
PYSQLITE_COMPLETE_STATEMENT_METHODDEF
|
||||
PYSQLITE_ENABLE_CALLBACK_TRACE_METHODDEF
|
||||
PYSQLITE_ENABLE_SHARED_CACHE_METHODDEF
|
||||
PYSQLITE_REGISTER_ADAPTER_METHODDEF
|
||||
PYSQLITE_REGISTER_CONVERTER_METHODDEF
|
||||
{NULL, NULL}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue