@@ -42,47 +42,44 @@ module _sqlite3
42
42
[clinic start generated code]*/
43
43
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=81e330492d57488e]*/
44
44
45
- // NOTE: This must equal sqlite3.Connection.__init__ argument spec!
46
- /*[clinic input]
47
- _sqlite3.connect as pysqlite_connect
48
-
49
- database: object
50
- timeout: double = 5.0
51
- detect_types: int = 0
52
- isolation_level: object = NULL
53
- check_same_thread: bool(accept={int}) = True
54
- factory: object(c_default='(PyObject*)clinic_state()->ConnectionType') = ConnectionType
55
- cached_statements: int = 128
56
- uri: bool = False
57
-
58
- Opens a connection to the SQLite database file database.
59
-
60
- You can use ":memory:" to open a database connection to a database that resides
61
- in RAM instead of on disk.
62
- [clinic start generated code]*/
45
+ // NB: This needs to be in sync with the Connection.__init__ docstring.
46
+ PyDoc_STRVAR (module_connect_doc ,
47
+ "connect($module, /, database, timeout=5.0, detect_types=0,\n"
48
+ " isolation_level='', check_same_thread=True,\n"
49
+ " factory=ConnectionType, cached_statements=128, uri=False)\n"
50
+ "--\n"
51
+ "\n"
52
+ "Opens a connection to the SQLite database file database.\n"
53
+ "\n"
54
+ "You can use \":memory:\" to open a database connection to a database that resides\n"
55
+ "in RAM instead of on disk." );
56
+
57
+ #define PYSQLITE_CONNECT_METHODDEF \
58
+ {"connect", _PyCFunction_CAST(module_connect), METH_FASTCALL|METH_KEYWORDS, module_connect_doc},
63
59
64
60
static PyObject *
65
- pysqlite_connect_impl (PyObject * module , PyObject * database , double timeout ,
66
- int detect_types , PyObject * isolation_level ,
67
- int check_same_thread , PyObject * factory ,
68
- int cached_statements , int uri )
69
- /*[clinic end generated code: output=450ac9078b4868bb input=e16914663ddf93ce]*/
61
+ module_connect (PyObject * module , PyObject * const * args , Py_ssize_t nargsf ,
62
+ PyObject * kwnames )
70
63
{
71
- if (isolation_level == NULL ) {
72
- isolation_level = PyUnicode_FromString ("" );
73
- if (isolation_level == NULL ) {
74
- return NULL ;
75
- }
64
+ pysqlite_state * state = pysqlite_get_state (module );
65
+ PyObject * factory = (PyObject * )state -> ConnectionType ;
66
+
67
+ static const int FACTORY_POS = 5 ;
68
+ Py_ssize_t nargs = PyVectorcall_NARGS (nargsf );
69
+ if (nargs > FACTORY_POS ) {
70
+ factory = args [FACTORY_POS ];
76
71
}
77
- else {
78
- Py_INCREF (isolation_level );
72
+ else if (kwnames != NULL ) {
73
+ for (Py_ssize_t i = 0 ; i < PyTuple_GET_SIZE (kwnames ); i ++ ) {
74
+ PyObject * item = PyTuple_GET_ITEM (kwnames , i ); // borrowed ref.
75
+ if (PyUnicode_CompareWithASCIIString (item , "factory" ) == 0 ) {
76
+ factory = args [nargs + i ];
77
+ break ;
78
+ }
79
+ }
79
80
}
80
- PyObject * res = PyObject_CallFunction (factory , "OdiOiOii" , database ,
81
- timeout , detect_types ,
82
- isolation_level , check_same_thread ,
83
- factory , cached_statements , uri );
84
- Py_DECREF (isolation_level );
85
- return res ;
81
+
82
+ return PyObject_Vectorcall (factory , args , nargsf , kwnames );
86
83
}
87
84
88
85
/*[clinic input]
0 commit comments