[CalendarServer-changes] [15350] CalendarServer/trunk/txdav/base/datastore
source_changes at macosforge.org
source_changes at macosforge.org
Tue Dec 1 08:53:48 PST 2015
Revision: 15350
http://trac.calendarserver.org//changeset/15350
Author: cdaboo at apple.com
Date: 2015-12-01 08:53:48 -0800 (Tue, 01 Dec 2015)
Log Message:
-----------
Make sure pg8000 type conversions are in place when using an externally launched DB.
Modified Paths:
--------------
CalendarServer/trunk/txdav/base/datastore/dbapiclient.py
CalendarServer/trunk/txdav/base/datastore/suboracle.py
CalendarServer/trunk/txdav/base/datastore/subpostgres.py
Modified: CalendarServer/trunk/txdav/base/datastore/dbapiclient.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/dbapiclient.py 2015-11-30 22:52:34 UTC (rev 15349)
+++ CalendarServer/trunk/txdav/base/datastore/dbapiclient.py 2015-12-01 16:53:48 UTC (rev 15350)
@@ -322,7 +322,7 @@
dbkwargs["host"] = params.host
if params.port:
dbkwargs["port"] = int(params.port)
- return DBAPIConnector(dbmodule, postgresPreflight, **dbkwargs)
+ return DBAPIConnector(dbmodule, pg8000Preflight, **dbkwargs)
@staticmethod
@@ -406,3 +406,33 @@
# connection can safely be pooled without executing anything on it.
connection.commit()
c.close()
+
+
+
+def pg8000Preflight(connection):
+ """
+ Pre-flight function for pg8000/PostgreSQL connections: setup type mappings
+ in addition to the normal postgres preflight.
+ """
+
+ # Do the base PostgreSQL preflight
+ postgresPreflight(connection)
+
+ # Patch pg8000 behavior to match what we need wrt text processing
+ def my_text_out(v):
+ return v.encode("utf-8") if isinstance(v, unicode) else str(v)
+
+ connection.realConnection.py_types[str] = (705, postgres.core.FC_TEXT, my_text_out)
+ connection.realConnection.py_types[postgres.six.text_type] = (705, postgres.core.FC_TEXT, my_text_out)
+
+ def my_text_recv(data, offset, length):
+ return str(data[offset: offset + length])
+
+ connection.realConnection.default_factory = lambda: (postgres.core.FC_TEXT, my_text_recv)
+ connection.realConnection.pg_types[19] = (postgres.core.FC_BINARY, my_text_recv)
+ connection.realConnection.pg_types[25] = (postgres.core.FC_BINARY, my_text_recv)
+ connection.realConnection.pg_types[705] = (postgres.core.FC_BINARY, my_text_recv)
+ connection.realConnection.pg_types[829] = (postgres.core.FC_TEXT, my_text_recv)
+ connection.realConnection.pg_types[1042] = (postgres.core.FC_BINARY, my_text_recv)
+ connection.realConnection.pg_types[1043] = (postgres.core.FC_BINARY, my_text_recv)
+ connection.realConnection.pg_types[2275] = (postgres.core.FC_BINARY, my_text_recv)
Modified: CalendarServer/trunk/txdav/base/datastore/suboracle.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/suboracle.py 2015-11-30 22:52:34 UTC (rev 15349)
+++ CalendarServer/trunk/txdav/base/datastore/suboracle.py 2015-12-01 16:53:48 UTC (rev 15350)
@@ -31,6 +31,10 @@
class OracleService(MultiService):
+ """
+ A service for connecting to a locally running Oracle DB VM. This is only used
+ during unit tests.
+ """
def __init__(
self, dataStoreDirectory, subServiceFactory,
Modified: CalendarServer/trunk/txdav/base/datastore/subpostgres.py
===================================================================
--- CalendarServer/trunk/txdav/base/datastore/subpostgres.py 2015-11-30 22:52:34 UTC (rev 15349)
+++ CalendarServer/trunk/txdav/base/datastore/subpostgres.py 2015-12-01 16:53:48 UTC (rev 15350)
@@ -350,30 +350,9 @@
"""
Produce a DB-API 2.0 connection pointed at this database.
"""
- connection = self._connectorFor(databaseName).connect(label)
+ return self._connectorFor(databaseName).connect(label)
- if postgres.__name__ == "pg8000":
- # Patch pg8000 behavior to match what we need wrt text processing
- def my_text_out(v):
- return v.encode("utf-8") if isinstance(v, unicode) else str(v)
- connection.realConnection.py_types[str] = (705, postgres.core.FC_TEXT, my_text_out)
- connection.realConnection.py_types[postgres.six.text_type] = (705, postgres.core.FC_TEXT, my_text_out)
-
- def my_text_recv(data, offset, length):
- return str(data[offset: offset + length])
- connection.realConnection.default_factory = lambda: (postgres.core.FC_TEXT, my_text_recv)
- connection.realConnection.pg_types[19] = (postgres.core.FC_BINARY, my_text_recv)
- connection.realConnection.pg_types[25] = (postgres.core.FC_BINARY, my_text_recv)
- connection.realConnection.pg_types[705] = (postgres.core.FC_BINARY, my_text_recv)
- connection.realConnection.pg_types[829] = (postgres.core.FC_TEXT, my_text_recv)
- connection.realConnection.pg_types[1042] = (postgres.core.FC_BINARY, my_text_recv)
- connection.realConnection.pg_types[1043] = (postgres.core.FC_BINARY, my_text_recv)
- connection.realConnection.pg_types[2275] = (postgres.core.FC_BINARY, my_text_recv)
-
- return connection
-
-
def ready(self, createDatabaseConn, createDatabaseCursor):
"""
Subprocess is ready. Time to initialize the subservice.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.macosforge.org/pipermail/calendarserver-changes/attachments/20151201/188f72c5/attachment-0001.html>
More information about the calendarserver-changes
mailing list