mirror of
https://github.com/psycopg/psycopg2.git
synced 2024-11-29 20:23:45 +03:00
Zope DA fixes and preparing 2.0.
This commit is contained in:
parent
bfb00b86fd
commit
429fd4f1d7
|
@ -18,11 +18,12 @@
|
||||||
# See the LICENSE file for details.
|
# 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 sys
|
||||||
import time
|
import time
|
||||||
import db
|
import db
|
||||||
|
import re
|
||||||
|
|
||||||
import Acquisition
|
import Acquisition
|
||||||
import Shared.DC.ZRDB.Connection
|
import Shared.DC.ZRDB.Connection
|
||||||
|
@ -62,10 +63,10 @@ class Connection(Shared.DC.ZRDB.Connection.Connection):
|
||||||
"""ZPsycopg Connection."""
|
"""ZPsycopg 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_/conn'
|
||||||
|
|
||||||
def __init__(self, id, title, connection_string,
|
def __init__(self, id, title, connection_string,
|
||||||
zdatetime, check=None, tilevel=2, encoding=''):
|
zdatetime, check=None, tilevel=2, encoding=''):
|
||||||
|
@ -185,7 +186,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 = {
|
||||||
|
@ -208,35 +209,37 @@ for icon in ('table', 'view', 'stable', 'what', 'field', 'text', 'bin',
|
||||||
## zope-specific psycopg typecasters ##
|
## zope-specific psycopg typecasters ##
|
||||||
|
|
||||||
# convert an ISO timestamp string from postgres to a Zope DateTime object
|
# convert an ISO timestamp string from postgres to a Zope DateTime object
|
||||||
def _cast_DateTime(str, curs):
|
def _cast_DateTime(iso, curs):
|
||||||
if str:
|
if iso:
|
||||||
|
return DateTime(re.split("GMT\+?|GMT-?", iso)[0])
|
||||||
|
|
||||||
# this will split us into [date, time, GMT/AM/PM(if there)]
|
# this will split us into [date, time, GMT/AM/PM(if there)]
|
||||||
dt = str.split(' ')
|
# dt = str.split(' ')
|
||||||
if len(dt) > 1:
|
# if len(dt) > 1:
|
||||||
# we now should split out any timezone info
|
# # we now should split out any timezone info
|
||||||
dt[1] = dt[1].split('-')[0]
|
# dt[1] = dt[1].split('-')[0]
|
||||||
dt[1] = dt[1].split('+')[0]
|
# dt[1] = dt[1].split('+')[0]
|
||||||
return DateTime(' '.join(dt[:2]))
|
# return DateTime(' '.join(dt[:2]))
|
||||||
else:
|
# else:
|
||||||
return DateTime(dt[0])
|
# return DateTime(dt[0])
|
||||||
|
|
||||||
# convert an ISO date string from postgres to a Zope DateTime object
|
# convert an ISO date string from postgres to a Zope DateTime object
|
||||||
def _cast_Date(str, curs):
|
def _cast_Date(iso, curs):
|
||||||
if str:
|
if iso:
|
||||||
return DateTime(str)
|
return DateTime(iso)
|
||||||
|
|
||||||
# Convert a time string from postgres to a Zope DateTime object.
|
# Convert a time string from postgres to a Zope DateTime object.
|
||||||
# NOTE: we set the day as today before feeding to DateTime so
|
# NOTE: we set the day as today before feeding to DateTime so
|
||||||
# that it has the same DST settings.
|
# that it has the same DST settings.
|
||||||
def _cast_Time(str, curs):
|
def _cast_Time(iso, curs):
|
||||||
if str:
|
if iso:
|
||||||
return DateTime(time.strftime('%Y-%m-%d %H:%M:%S',
|
return DateTime(time.strftime('%Y-%m-%d %H:%M:%S',
|
||||||
time.localtime(time.time())[:3]+
|
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?
|
# TODO: DateTime does not support intervals: what's the best we can do?
|
||||||
def _cast_Interval(str, curs):
|
def _cast_Interval(iso, curs):
|
||||||
return str
|
return iso
|
||||||
|
|
||||||
ZDATETIME = new_type((1184, 1114), "ZDATETIME", _cast_DateTime)
|
ZDATETIME = new_type((1184, 1114), "ZDATETIME", _cast_DateTime)
|
||||||
ZINTERVAL = new_type((1186,), "ZINTERVAL", _cast_Interval)
|
ZINTERVAL = new_type((1186,), "ZINTERVAL", _cast_Interval)
|
||||||
|
|
|
@ -22,20 +22,10 @@ __version__ = '2.0'
|
||||||
|
|
||||||
import DA
|
import DA
|
||||||
|
|
||||||
methods = DA.folder_methods
|
def initialize(context):
|
||||||
classes = DA.classes
|
context.registerClass(
|
||||||
meta_types = DA.meta_types
|
DA.Connection,
|
||||||
misc_ = DA.misc_
|
permission = 'Add Z Psycopg 2 Database Connections',
|
||||||
|
constructors = (DA.manage_addZPsycopgConnectionForm,
|
||||||
__ac_permissions__ = DA.__ac_permissions__
|
DA.manage_addZPsycopgConnection),
|
||||||
|
icon = SOFTWARE_HOME + '/Shared/DC/ZRDB/www/DBAdapterFolder_icon.gif')
|
||||||
# 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')
|
|
||||||
|
|
|
@ -1,13 +1,13 @@
|
||||||
<dtml-var manage_page_header>
|
<dtml-var manage_page_header>
|
||||||
|
|
||||||
<dtml-var "manage_form_title(this(), _,
|
<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_product='ZPsycopgDA',
|
||||||
help_topic='ZPsycopgDA-Method-Add.stx'
|
help_topic='ZPsycopgDA-Method-Add.stx'
|
||||||
)">
|
)">
|
||||||
|
|
||||||
<p class="form-help">
|
<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.
|
queries on a PostgreSQL database.
|
||||||
</p>
|
</p>
|
||||||
|
|
||||||
|
@ -26,7 +26,7 @@ or DSN for short) is a string... (TODO: finish docs)
|
||||||
</td>
|
</td>
|
||||||
<td align="left" valign="top">
|
<td align="left" valign="top">
|
||||||
<input type="text" name="id" size="40"
|
<input type="text" name="id" size="40"
|
||||||
value="Psycopg_database_connection" />
|
value="Psycopg2_database_connection" />
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
@ -37,7 +37,7 @@ or DSN for short) is a string... (TODO: finish docs)
|
||||||
</td>
|
</td>
|
||||||
<td align="left" valign="top">
|
<td align="left" valign="top">
|
||||||
<input type="text" name="title" size="40"
|
<input type="text" name="title" size="40"
|
||||||
value="Z Psycopg Database Connection"/>
|
value="Z Psycopg 2 Database Connection"/>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[build_ext]
|
[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_EXTENSIONS enables extensions to PEP-249 (you really want this)
|
||||||
# PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower)
|
# PSYCOPG_DISPLAY_SIZE enable display size calculation (a little slower)
|
||||||
# HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.3
|
# HAVE_PQFREEMEM should be defined on PostgreSQL >= 7.3
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -52,7 +52,7 @@ from distutils.command.build_ext import build_ext
|
||||||
from distutils.sysconfig import get_python_inc
|
from distutils.sysconfig import get_python_inc
|
||||||
from distutils.ccompiler import get_default_compiler
|
from distutils.ccompiler import get_default_compiler
|
||||||
|
|
||||||
PSYCOPG_VERSION = '2.0b8'
|
PSYCOPG_VERSION = '2.0'
|
||||||
version_flags = []
|
version_flags = []
|
||||||
|
|
||||||
# to work around older distutil limitations
|
# to work around older distutil limitations
|
||||||
|
|
Loading…
Reference in New Issue
Block a user