Does not crash on importing needed modules. (Closes: #32)

This commit is contained in:
Federico Di Gregorio 2005-11-15 11:51:05 +00:00
parent 164eb32817
commit 65fe7db04d
4 changed files with 33 additions and 18 deletions

View File

@ -1,3 +1,8 @@
2005-11-15 Federico Di Gregorio <fog@initd.org>
* psycopg/psycopgmodule.c: now bails out with correct exception when one
of the needed modules can't be imported (should fix #32.)
2005-11-14 Federico Di Gregorio <fog@initd.org> 2005-11-14 Federico Di Gregorio <fog@initd.org>
* psycopg/typecast.c: added typecast_parse_date and typecast_parse_time * psycopg/typecast.c: added typecast_parse_date and typecast_parse_time

View File

@ -42,7 +42,6 @@ from psycopg2.extensions import INTEGER, LONGINTEGER, FLOAT, BOOLEAN, DATE
from psycopg2.extensions import TIME, INTERVAL from psycopg2.extensions import TIME, INTERVAL
from psycopg2.extensions import new_type, register_type from psycopg2.extensions import new_type, register_type
# add a new connection to a folder # add a new connection to a folder
@ -56,17 +55,16 @@ def manage_addZPsycopgConnection(self, id, title, connection_string,
zdatetime, check, tilevel)) zdatetime, check, tilevel))
if REQUEST is not None: return self.manage_main(self, REQUEST) if REQUEST is not None: return self.manage_main(self, REQUEST)
# the connection object # the connection object
class Connection(Shared.DC.ZRDB.Connection.Connection): class Connection(Shared.DC.ZRDB.Connection.Connection):
"""ZPsycopg Connection.""" """ZPsycopg 2 Connection."""
_isAnSQLConnection = 1 _isAnSQLConnection = 1
id = 'Psycopg_database_connection' id = 'Psycopg2_database_connection'
database_type = 'Psycopg' database_type = 'Psycopg2'
meta_type = title = 'Z Psycopg Database Connection' meta_type = title = 'Z Psycopg 2 Database Connection'
icon = 'misc_/ZPsycopgDA/conn' icon = 'misc_/ZPsycopgDA/conn'
def __init__(self, id, title, connection_string, def __init__(self, id, title, connection_string,
@ -187,7 +185,7 @@ class Connection(Shared.DC.ZRDB.Connection.Connection):
classes = (Connection,) classes = (Connection,)
meta_types = ({'name':'Z Psycopg Database Connection', meta_types = ({'name':'Z Psycopg 2 Database Connection',
'action':'manage_addZPsycopgConnectionForm'},) 'action':'manage_addZPsycopgConnectionForm'},)
folder_methods = { folder_methods = {
@ -195,7 +193,7 @@ folder_methods = {
'manage_addZPsycopgConnectionForm': manage_addZPsycopgConnectionForm} 'manage_addZPsycopgConnectionForm': manage_addZPsycopgConnectionForm}
__ac_permissions__ = ( __ac_permissions__ = (
('Add Z Psycopg Database Connections', ('Add Z Psycopg 2 Database Connections',
('manage_addZPsycopgConnectionForm', 'manage_addZPsycopgConnection')),) ('manage_addZPsycopgConnectionForm', 'manage_addZPsycopgConnection')),)
# add icons # add icons

View File

@ -17,7 +17,7 @@
# #
# See the LICENSE file for details. # See the LICENSE file for details.
__doc__ = "ZPsycopg Database Adalper Registration." __doc__ = "ZPsycopg 2 Database Adapter Registration."
__version__ = '2.0' __version__ = '2.0'
import DA import DA
@ -27,12 +27,15 @@ classes = DA.classes
meta_types = DA.meta_types meta_types = DA.meta_types
misc_ = DA.misc_ misc_ = DA.misc_
__ac_permissions__=DA.__ac_permissions__ __ac_permissions__ = DA.__ac_permissions__
def initialize(context): # FIXME: isn't this crazy? Apparently the variables above are enough
context.registerClass( # to have the ZPsycopgDA product installed and working. :/
DA.Connection, #
permission = 'Add Z Psycopg Database Connections', #def initialize(context):
constructors = (DA.manage_addZPsycopgConnectionForm, # context.registerClass(
DA.manage_addZPsycopgConnection), # DA.Connection,
icon = SOFTWARE_HOME + '/Shared/DC/ZRDB/www/DBAdapterFolder_icon.gif') # permission = 'Add Z Psycopg 2 Database Connections',
# constructors = (DA.manage_addZPsycopgConnectionForm,
# DA.manage_addZPsycopgConnection),
# icon = SOFTWARE_HOME + '/Shared/DC/ZRDB/www/DBAdapterFolder_icon.gif')

View File

@ -484,7 +484,11 @@ init_psycopg(void)
/* import python builtin datetime module, if available */ /* import python builtin datetime module, if available */
#ifdef HAVE_PYDATETIME #ifdef HAVE_PYDATETIME
pyDateTimeModuleP = PyImport_ImportModule("datetime"); pyDateTimeModuleP = PyImport_ImportModule("datetime");
if (pyDateTimeModuleP == NULL) {
Dprintf("initpsycopg: can't import datetime module");
PyErr_SetString(PyExc_ImportError, "can't import datetime module");
return;
}
pydatetimeType.ob_type = &PyType_Type; pydatetimeType.ob_type = &PyType_Type;
if (PyType_Ready(&pydatetimeType) == -1) return; if (PyType_Ready(&pydatetimeType) == -1) return;
@ -498,6 +502,11 @@ init_psycopg(void)
/* import psycopg2.tz anyway (TODO: replace with C-level module?) */ /* import psycopg2.tz anyway (TODO: replace with C-level module?) */
pyPsycopgTzModule = PyImport_ImportModule("psycopg2.tz"); pyPsycopgTzModule = PyImport_ImportModule("psycopg2.tz");
if (pyPsycopgTzModule == NULL) {
Dprintf("initpsycopg: can't import psycopg2.tz module");
PyErr_SetString(PyExc_ImportError, "can't import psycopg2.tz module");
return;
}
pyPsycopgTzLOCAL = pyPsycopgTzLOCAL =
PyObject_GetAttrString(pyPsycopgTzModule, "LOCAL"); PyObject_GetAttrString(pyPsycopgTzModule, "LOCAL");
pyPsycopgTzFixedOffsetTimezone = pyPsycopgTzFixedOffsetTimezone =