Zope DA fixes and preparing 2.0.

This commit is contained in:
Federico Di Gregorio 2006-06-07 23:33:47 +00:00
parent bfb00b86fd
commit 429fd4f1d7
5 changed files with 41 additions and 48 deletions

View File

@ -18,11 +18,12 @@
# See the LICENSE file for details.
ALLOWED_PSYCOPG_VERSIONS = ('2.0b4', '2.0b5', '2.0b6', '2.0b7', '2.0b8')
ALLOWED_PSYCOPG_VERSIONS = ('2.0',)
import sys
import time
import db
import re
import Acquisition
import Shared.DC.ZRDB.Connection
@ -62,10 +63,10 @@ class Connection(Shared.DC.ZRDB.Connection.Connection):
"""ZPsycopg Connection."""
_isAnSQLConnection = 1
id = 'Psycopg_database_connection'
database_type = 'Psycopg'
meta_type = title = 'Z Psycopg Database Connection'
icon = 'misc_/ZPsycopgDA/conn'
id = 'Psycopg2_database_connection'
database_type = 'Psycopg2'
meta_type = title = 'Z Psycopg 2 Database Connection'
icon = 'misc_/conn'
def __init__(self, id, title, connection_string,
zdatetime, check=None, tilevel=2, encoding=''):
@ -185,7 +186,7 @@ class Connection(Shared.DC.ZRDB.Connection.Connection):
classes = (Connection,)
meta_types = ({'name':'Z Psycopg Database Connection',
meta_types = ({'name':'Z Psycopg 2 Database Connection',
'action':'manage_addZPsycopgConnectionForm'},)
folder_methods = {
@ -208,35 +209,37 @@ for icon in ('table', 'view', 'stable', 'what', 'field', 'text', 'bin',
## zope-specific psycopg typecasters ##
# convert an ISO timestamp string from postgres to a Zope DateTime object
def _cast_DateTime(str, curs):
if str:
# this will split us into [date, time, GMT/AM/PM(if there)]
dt = str.split(' ')
if len(dt) > 1:
# we now should split out any timezone info
dt[1] = dt[1].split('-')[0]
dt[1] = dt[1].split('+')[0]
return DateTime(' '.join(dt[:2]))
else:
return DateTime(dt[0])
def _cast_DateTime(iso, curs):
if iso:
return DateTime(re.split("GMT\+?|GMT-?", iso)[0])
# this will split us into [date, time, GMT/AM/PM(if there)]
# dt = str.split(' ')
# if len(dt) > 1:
# # we now should split out any timezone info
# dt[1] = dt[1].split('-')[0]
# dt[1] = dt[1].split('+')[0]
# return DateTime(' '.join(dt[:2]))
# else:
# return DateTime(dt[0])
# convert an ISO date string from postgres to a Zope DateTime object
def _cast_Date(str, curs):
if str:
return DateTime(str)
def _cast_Date(iso, curs):
if iso:
return DateTime(iso)
# Convert a time string from postgres to a Zope DateTime object.
# NOTE: we set the day as today before feeding to DateTime so
# that it has the same DST settings.
def _cast_Time(str, curs):
if str:
def _cast_Time(iso, curs):
if iso:
return DateTime(time.strftime('%Y-%m-%d %H:%M:%S',
time.localtime(time.time())[:3]+
time.strptime(str[:8], "%H:%M:%S")[3:]))
time.strptime(iso[:8], "%H:%M:%S")[3:]))
# TODO: DateTime does not support intervals: what's the best we can do?
def _cast_Interval(str, curs):
return str
def _cast_Interval(iso, curs):
return iso
ZDATETIME = new_type((1184, 1114), "ZDATETIME", _cast_DateTime)
ZINTERVAL = new_type((1186,), "ZINTERVAL", _cast_Interval)

View File

@ -22,20 +22,10 @@ __version__ = '2.0'
import DA
methods = DA.folder_methods
classes = DA.classes
meta_types = DA.meta_types
misc_ = DA.misc_
__ac_permissions__ = DA.__ac_permissions__
# FIXME: isn't this crazy? Apparently the variables above are enough
# to have the ZPsycopgDA product installed and working. :/
#
#def initialize(context):
# context.registerClass(
# DA.Connection,
# permission = 'Add Z Psycopg 2 Database Connections',
# constructors = (DA.manage_addZPsycopgConnectionForm,
# DA.manage_addZPsycopgConnection),
# icon = SOFTWARE_HOME + '/Shared/DC/ZRDB/www/DBAdapterFolder_icon.gif')
def initialize(context):
context.registerClass(
DA.Connection,
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

@ -1,13 +1,13 @@
<dtml-var manage_page_header>
<dtml-var "manage_form_title(this(), _,
form_title='Add Z Psycopg Database Connection',
form_title='Add Z Psycopg 2 Database Connection',
help_product='ZPsycopgDA',
help_topic='ZPsycopgDA-Method-Add.stx'
)">
<p class="form-help">
A Zope Psycopg Database Connection is used to connect and execute
A Zope Psycopg 2 Database Connection is used to connect and execute
queries on a PostgreSQL database.
</p>
@ -26,7 +26,7 @@ or DSN for short) is a string... (TODO: finish docs)
</td>
<td align="left" valign="top">
<input type="text" name="id" size="40"
value="Psycopg_database_connection" />
value="Psycopg2_database_connection" />
</td>
</tr>
<tr>
@ -37,7 +37,7 @@ or DSN for short) is a string... (TODO: finish docs)
</td>
<td align="left" valign="top">
<input type="text" name="title" size="40"
value="Z Psycopg Database Connection"/>
value="Z Psycopg 2 Database Connection"/>
</td>
</tr>
<tr>

View File

@ -1,5 +1,5 @@
[build_ext]
define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3
define=PSYCOPG_EXTENSIONS,PSYCOPG_DISPLAY_SIZE,PSYCOPG_NEW_BOOLEAN,HAVE_PQFREEMEM,HAVE_PQPROTOCOL3,PSYCOPG_DEBUG
# PSYCOPG_EXTENSIONS enables extensions to PEP-249 (you really want this)
# PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower)
# HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.3

View File

@ -52,7 +52,7 @@ from distutils.command.build_ext import build_ext
from distutils.sysconfig import get_python_inc
from distutils.ccompiler import get_default_compiler
PSYCOPG_VERSION = '2.0b8'
PSYCOPG_VERSION = '2.0'
version_flags = []
# to work around older distutil limitations