mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-10 19:16:34 +03:00
Make Column picklable on Python >= 3.3
Also expose the type from the extensions module, not from the main module.
This commit is contained in:
parent
9f7cd6b374
commit
a2a5461c28
|
@ -55,7 +55,6 @@ from psycopg2._psycopg import DateFromTicks, TimeFromTicks, TimestampFromTicks
|
|||
from psycopg2._psycopg import Error, Warning, DataError, DatabaseError, ProgrammingError
|
||||
from psycopg2._psycopg import IntegrityError, InterfaceError, InternalError
|
||||
from psycopg2._psycopg import NotSupportedError, OperationalError
|
||||
from psycopg2._psycopg import Column
|
||||
|
||||
from psycopg2._psycopg import _connect, apilevel, threadsafety, paramstyle
|
||||
from psycopg2._psycopg import __version__
|
||||
|
|
|
@ -58,7 +58,7 @@ except ImportError:
|
|||
|
||||
from psycopg2._psycopg import adapt, adapters, encodings, connection, cursor, lobject, Xid
|
||||
from psycopg2._psycopg import string_types, binary_types, new_type, new_array_type, register_type
|
||||
from psycopg2._psycopg import ISQLQuote, Notify, Diagnostics
|
||||
from psycopg2._psycopg import ISQLQuote, Notify, Diagnostics, Column
|
||||
|
||||
from psycopg2._psycopg import QueryCanceledError, TransactionRollbackError
|
||||
|
||||
|
|
|
@ -625,8 +625,10 @@ psyco_GetDecimalType(void)
|
|||
static PyObject *
|
||||
psyco_make_description_type(void)
|
||||
{
|
||||
PyObject *nt = NULL;
|
||||
PyObject *coll = NULL;
|
||||
PyObject *nt = NULL;
|
||||
PyTypeObject *t = NULL;
|
||||
PyObject *s = NULL;
|
||||
PyObject *rv = NULL;
|
||||
|
||||
/* Try to import collections.namedtuple */
|
||||
|
@ -640,12 +642,26 @@ psyco_make_description_type(void)
|
|||
}
|
||||
|
||||
/* Build the namedtuple */
|
||||
rv = PyObject_CallFunction(nt, "ss", "Column",
|
||||
"name type_code display_size internal_size precision scale null_ok");
|
||||
if(!(t = (PyTypeObject *)PyObject_CallFunction(nt, "ss", "Column",
|
||||
"name type_code display_size internal_size precision scale null_ok"))) {
|
||||
goto exit;
|
||||
}
|
||||
|
||||
/* Export the tuple on the extensions module
|
||||
* Required to guarantee picklability on Py > 3.3 (see Python issue 21374)
|
||||
* for previous Py version the module is psycopg2 anyway but for consistency
|
||||
* we'd rather expose it from the extensions module. */
|
||||
if (!(s = Text_FromUTF8("psycopg2.extensions"))) { goto exit; }
|
||||
if (0 > PyDict_SetItemString(t->tp_dict, "__module__", s)) { goto exit; }
|
||||
|
||||
rv = (PyObject *)t;
|
||||
t = NULL;
|
||||
|
||||
exit:
|
||||
Py_XDECREF(coll);
|
||||
Py_XDECREF(nt);
|
||||
Py_XDECREF((PyObject *)t);
|
||||
Py_XDECREF(s);
|
||||
|
||||
return rv;
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user