<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[14663] CalendarServer/trunk</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta">
<dt>Revision</dt> <dd><a href="http://trac.calendarserver.org//changeset/14663">14663</a></dd>
<dt>Author</dt> <dd>cdaboo@apple.com</dd>
<dt>Date</dt> <dd>2015-04-06 14:13:15 -0700 (Mon, 06 Apr 2015)</dd>
</dl>

<h3>Log Message</h3>
<pre>Replace config.DSN with a set of attributes for the various fields needed to connect to a DB.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#CalendarServertrunkproject">CalendarServer/trunk/.project</a></li>
<li><a href="#CalendarServertrunkcalendarservertapcaldavpy">CalendarServer/trunk/calendarserver/tap/caldav.py</a></li>
<li><a href="#CalendarServertrunkcalendarservertaputilpy">CalendarServer/trunk/calendarserver/tap/util.py</a></li>
<li><a href="#CalendarServertrunkconfcaldavdappleplist">CalendarServer/trunk/conf/caldavd-apple.plist</a></li>
<li><a href="#CalendarServertrunkconfcaldavdtestplist">CalendarServer/trunk/conf/caldavd-test.plist</a></li>
<li><a href="#CalendarServertrunkconfcaldavdplist">CalendarServer/trunk/conf/caldavd.plist</a></li>
<li><a href="#CalendarServertrunktwistedcaldavstdconfigpy">CalendarServer/trunk/twistedcaldav/stdconfig.py</a></li>
<li><a href="#CalendarServertrunktxdavbasedatastoredbapiclientpy">CalendarServer/trunk/txdav/base/datastore/dbapiclient.py</a></li>
<li><a href="#CalendarServertrunktxdavbasedatastoresuboraclepy">CalendarServer/trunk/txdav/base/datastore/suboracle.py</a></li>
<li><a href="#CalendarServertrunktxdavbasedatastoresubpostgrespy">CalendarServer/trunk/txdav/base/datastore/subpostgres.py</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="CalendarServertrunkproject"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/.project (14662 => 14663)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/.project        2015-04-06 16:44:14 UTC (rev 14662)
+++ CalendarServer/trunk/.project        2015-04-06 21:13:15 UTC (rev 14663)
</span><span class="lines">@@ -5,6 +5,7 @@
</span><span class="cx">         &lt;projects&gt;
</span><span class="cx">                 &lt;project&gt;CalDAVClientLibrary&lt;/project&gt;
</span><span class="cx">                 &lt;project&gt;cffi&lt;/project&gt;
</span><ins>+                &lt;project&gt;cx_Oracle&lt;/project&gt;
</ins><span class="cx">                 &lt;project&gt;kerberos&lt;/project&gt;
</span><span class="cx">                 &lt;project&gt;pg8000&lt;/project&gt;
</span><span class="cx">                 &lt;project&gt;psutil&lt;/project&gt;
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertapcaldavpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tap/caldav.py (14662 => 14663)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tap/caldav.py        2015-04-06 16:44:14 UTC (rev 14662)
+++ CalendarServer/trunk/calendarserver/tap/caldav.py        2015-04-06 21:13:15 UTC (rev 14663)
</span><span class="lines">@@ -80,6 +80,7 @@
</span><span class="cx"> from txweb2.metafd import ConnectionLimiter, ReportingHTTPService
</span><span class="cx"> from txweb2.server import Site
</span><span class="cx"> 
</span><ins>+from txdav.base.datastore.dbapiclient import DBAPIConnector
</ins><span class="cx"> from txdav.caldav.datastore.scheduling.imip.inbound import MailRetriever
</span><span class="cx"> from txdav.caldav.datastore.scheduling.imip.inbound import scheduleNextMailPoll
</span><span class="cx"> from txdav.common.datastore.upgrade.migrate import UpgradeToDatabaseStep
</span><span class="lines">@@ -114,7 +115,6 @@
</span><span class="cx"> from calendarserver.tap.util import (
</span><span class="cx">     ConnectionDispenser, Stepper,
</span><span class="cx">     checkDirectories, getRootResource,
</span><del>-    oracleConnectorFromConfig, pgConnectorFromConfig,
</del><span class="cx">     pgServiceFromConfig, getDBPool, MemoryLimitService,
</span><span class="cx">     storeFromConfig, getSSLPassphrase, preFlightChecks,
</span><span class="cx">     storeFromConfigWithDPSClient, storeFromConfigWithoutDPS,
</span><span class="lines">@@ -1500,9 +1500,17 @@
</span><span class="cx">         @rtype: L{IService}
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx"> 
</span><del>-        def createSubServiceFactory(
-            dialect=POSTGRES_DIALECT, paramstyle='pyformat'
-        ):
</del><ins>+        def createSubServiceFactory(dbtype):
+            if dbtype == &quot;&quot;:
+                dialect = POSTGRES_DIALECT
+                paramstyle = &quot;pyformat&quot;
+            elif dbtype == &quot;postgres&quot;:
+                dialect = POSTGRES_DIALECT
+                paramstyle = &quot;pyformat&quot;
+            elif dbtype == &quot;oracle&quot;:
+                dialect = ORACLE_DIALECT
+                paramstyle = &quot;numeric&quot;
+
</ins><span class="cx">             def subServiceFactory(connectionFactory, storageService):
</span><span class="cx">                 ms = MultiService()
</span><span class="cx">                 cp = ConnectionPool(
</span><span class="lines">@@ -1606,26 +1614,14 @@
</span><span class="cx">                 # to it.
</span><span class="cx">                 pgserv = pgServiceFromConfig(
</span><span class="cx">                     config,
</span><del>-                    createSubServiceFactory(),
</del><ins>+                    createSubServiceFactory(&quot;&quot;),
</ins><span class="cx">                     uid=overrideUID, gid=overrideGID
</span><span class="cx">                 )
</span><span class="cx">                 return pgserv
</span><del>-            elif config.DBType == &quot;postgres&quot;:
-                # Connect to a postgres database that is already running.
-                return createSubServiceFactory()(
-                    pgConnectorFromConfig(config), None
-                )
-            elif config.DBType == &quot;oracle&quot;:
-                # Connect to an Oracle database that is already running.
-                return createSubServiceFactory(
-                    dialect=ORACLE_DIALECT,
-                    paramstyle=&quot;numeric&quot;
-                )(
-                    oracleConnectorFromConfig(config), None
-                )
</del><span class="cx">             else:
</span><del>-                raise UsageError(
-                    &quot;Unknown database type {}&quot;.format(config.DBType)
</del><ins>+                # Connect to a database that is already running.
+                return createSubServiceFactory(config.DBType)(
+                    DBAPIConnector.connectorFor(config.DBType, **config.DatabaseConnection).connect, None
</ins><span class="cx">                 )
</span><span class="cx">         else:
</span><span class="cx">             store = storeFromConfig(config, None, None)
</span></span></pre></div>
<a id="CalendarServertrunkcalendarservertaputilpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/calendarserver/tap/util.py (14662 => 14663)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/calendarserver/tap/util.py        2015-04-06 16:44:14 UTC (rev 14662)
+++ CalendarServer/trunk/calendarserver/tap/util.py        2015-04-06 21:13:15 UTC (rev 14663)
</span><span class="lines">@@ -75,8 +75,7 @@
</span><span class="cx"> from twistedcaldav.timezoneservice import TimezoneServiceResource
</span><span class="cx"> from twistedcaldav.timezonestdservice import TimezoneStdServiceResource
</span><span class="cx"> 
</span><del>-from txdav.base.datastore.dbapiclient import DBAPIConnector, OracleConnector
-from txdav.base.datastore.dbapiclient import postgresPreflight
</del><ins>+from txdav.base.datastore.dbapiclient import DBAPIConnector
</ins><span class="cx"> from txdav.base.datastore.subpostgres import PostgresService
</span><span class="cx"> from txdav.caldav.datastore.scheduling.ischedule.dkim import DKIMUtils, DomainKeyResource
</span><span class="cx"> from txdav.caldav.datastore.scheduling.ischedule.localservers import buildServersDB
</span><span class="lines">@@ -157,23 +156,6 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><del>-def pgConnectorFromConfig(config):
-    &quot;&quot;&quot;
-    Create a postgres DB-API connector from the given configuration.
-    &quot;&quot;&quot;
-    from txdav.base.datastore.subpostgres import postgres
-    return DBAPIConnector(postgres, postgresPreflight, config.DSN).connect
-
-
-
-def oracleConnectorFromConfig(config):
-    &quot;&quot;&quot;
-    Create a postgres DB-API connector from the given configuration.
-    &quot;&quot;&quot;
-    return OracleConnector(config.DSN).connect
-
-
-
</del><span class="cx"> class ConnectionWithPeer(Connection):
</span><span class="cx"> 
</span><span class="cx">     connected = True
</span><span class="lines">@@ -828,14 +810,10 @@
</span><span class="cx">             # get a PostgresService to tell us what the local connection
</span><span class="cx">             # info is, but *don't* start it (that would start one postgres
</span><span class="cx">             # master per slave, resulting in all kinds of mayhem...)
</span><del>-            connectionFactory = pgServiceFromConfig(
-                config, None).produceConnection
-        elif config.DBType == 'postgres':
-            connectionFactory = pgConnectorFromConfig(config)
-        elif config.DBType == 'oracle':
-            connectionFactory = oracleConnectorFromConfig(config)
</del><ins>+            connectionFactory = pgServiceFromConfig(config, None).produceConnection
</ins><span class="cx">         else:
</span><del>-            raise UsageError(&quot;unknown DB type: %r&quot; % (config.DBType,))
</del><ins>+            connectionFactory = DBAPIConnector.connectorFor(config.DBType, **config.DatabaseConnection).connect
+
</ins><span class="cx">         pool = ConnectionPool(connectionFactory, dialect=dialect,
</span><span class="cx">                               paramstyle=paramstyle,
</span><span class="cx">                               maxConnections=config.MaxDBConnectionsPerPool)
</span></span></pre></div>
<a id="CalendarServertrunkconfcaldavdappleplist"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/conf/caldavd-apple.plist (14662 => 14663)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/conf/caldavd-apple.plist        2015-04-06 16:44:14 UTC (rev 14662)
+++ CalendarServer/trunk/conf/caldavd-apple.plist        2015-04-06 21:13:15 UTC (rev 14663)
</span><span class="lines">@@ -97,8 +97,7 @@
</span><span class="cx">     &lt;!-- Database connection --&gt;
</span><span class="cx">     &lt;key&gt;DBType&lt;/key&gt;
</span><span class="cx">     &lt;string&gt;&lt;/string&gt;
</span><del>-    &lt;key&gt;DSN&lt;/key&gt;
-    &lt;string&gt;&lt;/string&gt;
</del><ins>+
</ins><span class="cx">     &lt;key&gt;Postgres&lt;/key&gt;
</span><span class="cx">     &lt;dict&gt;
</span><span class="cx">         &lt;key&gt;Ctl&lt;/key&gt;
</span></span></pre></div>
<a id="CalendarServertrunkconfcaldavdtestplist"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/conf/caldavd-test.plist (14662 => 14663)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/conf/caldavd-test.plist        2015-04-06 16:44:14 UTC (rev 14662)
+++ CalendarServer/trunk/conf/caldavd-test.plist        2015-04-06 21:13:15 UTC (rev 14663)
</span><span class="lines">@@ -98,8 +98,17 @@
</span><span class="cx">     &lt;!--
</span><span class="cx">     &lt;key&gt;DBType&lt;/key&gt;
</span><span class="cx">     &lt;string&gt;postgres&lt;/string&gt;
</span><del>-    &lt;key&gt;DSN&lt;/key&gt;
-    &lt;string&gt;:caldav:caldav:::&lt;/string&gt;
</del><ins>+    &lt;key&gt;DatabaseConnection&lt;/key&gt;
+    &lt;dict&gt;
+            &lt;key&gt;endpoint&lt;/key&gt;
+            &lt;string&gt;tcp:localhost&lt;/string&gt;
+            &lt;key&gt;database&lt;/key&gt;
+            &lt;string&gt;caldav&lt;/string&gt;
+            &lt;key&gt;user&lt;/key&gt;
+            &lt;string&gt;caldav&lt;/string&gt;
+            &lt;key&gt;password&lt;/key&gt;
+            &lt;string&gt;&lt;/string&gt;
+    &lt;/dict&gt;
</ins><span class="cx">      --&gt;
</span><span class="cx"> 
</span><span class="cx">     &lt;!-- Data root --&gt;
</span></span></pre></div>
<a id="CalendarServertrunkconfcaldavdplist"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/conf/caldavd.plist (14662 => 14663)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/conf/caldavd.plist        2015-04-06 16:44:14 UTC (rev 14662)
+++ CalendarServer/trunk/conf/caldavd.plist        2015-04-06 21:13:15 UTC (rev 14663)
</span><span class="lines">@@ -84,8 +84,17 @@
</span><span class="cx">     &lt;!--
</span><span class="cx">     &lt;key&gt;DBType&lt;/key&gt;
</span><span class="cx">     &lt;string&gt;postgres&lt;/string&gt;
</span><del>-    &lt;key&gt;DSN&lt;/key&gt;
-    &lt;string&gt;:caldav:caldav:::&lt;/string&gt;
</del><ins>+    &lt;key&gt;DatabaseConnection&lt;/key&gt;
+    &lt;dict&gt;
+            &lt;key&gt;endpoint&lt;/key&gt;
+            &lt;string&gt;tcp:localhost&lt;/string&gt;
+            &lt;key&gt;database&lt;/key&gt;
+            &lt;string&gt;caldav&lt;/string&gt;
+            &lt;key&gt;user&lt;/key&gt;
+            &lt;string&gt;caldav&lt;/string&gt;
+            &lt;key&gt;password&lt;/key&gt;
+            &lt;string&gt;&lt;/string&gt;
+    &lt;/dict&gt;
</ins><span class="cx">      --&gt;
</span><span class="cx"> 
</span><span class="cx">     &lt;!-- Data root --&gt;
</span></span></pre></div>
<a id="CalendarServertrunktwistedcaldavstdconfigpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/twistedcaldav/stdconfig.py (14662 => 14663)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/twistedcaldav/stdconfig.py        2015-04-06 16:44:14 UTC (rev 14662)
+++ CalendarServer/trunk/twistedcaldav/stdconfig.py        2015-04-06 21:13:15 UTC (rev 14663)
</span><span class="lines">@@ -202,9 +202,12 @@
</span><span class="cx"> 
</span><span class="cx">     &quot;SpawnedDBUser&quot;: &quot;caldav&quot;, # The username to use when DBType is empty
</span><span class="cx"> 
</span><del>-    &quot;DSN&quot;: &quot;&quot;, # Data Source Name.  Used to connect to an external
-               # database if DBType is non-empty.  Format varies
-               # depending on database type.
</del><ins>+    &quot;DatabaseConnection&quot;: { # Used to connect to an external database if DBType is non-empty
+        &quot;endpoint&quot;: &quot;&quot;,     # Database connection endpoint
+        &quot;database&quot;: &quot;&quot;,     # Name of database or Oracle SID
+        &quot;user&quot;: &quot;&quot;,         # User name to connect as
+        &quot;password&quot;: &quot;&quot;,     # Password to use
+    },
</ins><span class="cx"> 
</span><span class="cx">     &quot;DBAMPFD&quot;: 0, # Internally used by database to tell slave
</span><span class="cx">                   # processes to inherit a file descriptor and use it
</span></span></pre></div>
<a id="CalendarServertrunktxdavbasedatastoredbapiclientpy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/base/datastore/dbapiclient.py (14662 => 14663)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/base/datastore/dbapiclient.py        2015-04-06 16:44:14 UTC (rev 14662)
+++ CalendarServer/trunk/txdav/base/datastore/dbapiclient.py        2015-04-06 21:13:15 UTC (rev 14663)
</span><span class="lines">@@ -14,11 +14,17 @@
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> ##
</span><span class="cx"> 
</span><ins>+
</ins><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> General utility client code for interfacing with DB-API 2.0 modules.
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> from twext.enterprise.util import mapOracleOutputType
</span><ins>+from twext.python.filepath import CachingFilePath
</ins><span class="cx"> 
</span><ins>+from txdav.common.icommondatastore import InternalDataStoreError
+
+import pg8000 as postgres
+
</ins><span class="cx"> try:
</span><span class="cx">     import os
</span><span class="cx">     # In order to encode and decode values going to and from the database,
</span><span class="lines">@@ -178,6 +184,45 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+class DBAPIParameters(object):
+    &quot;&quot;&quot;
+    Object that holds the parameters needed to configure a DBAPIConnector. Since this varies based on
+    the actual DB module in use, this class abstracts the parameters into separate properties that
+    are then used to create the actual parameters for each module.
+    &quot;&quot;&quot;
+
+    def __init__(self, endpoint=None, user=None, password=None, database=None):
+        &quot;&quot;&quot;
+        @param endpoint: endpoint string describing the connection
+        @type endpoint: L{str}
+        @param user: user name to connect as
+        @type user: L{str}
+        @param password: password to use
+        @type password: L{str}
+        @param database: database name to connect to
+        @type database: L{str}
+        &quot;&quot;&quot;
+        self.endpoint = endpoint
+        if self.endpoint.startswith(&quot;unix:&quot;):
+            self.unixsocket = self.endpoint[5:]
+            if &quot;:&quot; in self.unixsocket:
+                self.unixsocket, self.port = self.unixsocket.split(&quot;:&quot;)
+            else:
+                self.port = None
+            self.host = None
+        elif self.endpoint.startswith(&quot;tcp:&quot;):
+            self.unixsocket = None
+            self.host = self.endpoint[4:]
+            if &quot;:&quot; in self.host:
+                self.host, self.port = self.host.split(&quot;:&quot;)
+            else:
+                self.port = None
+        self.user = user
+        self.password = password
+        self.database = database
+
+
+
</ins><span class="cx"> class DBAPIConnector(object):
</span><span class="cx">     &quot;&quot;&quot;
</span><span class="cx">     A simple wrapper for DB-API connectors.
</span><span class="lines">@@ -201,7 +246,87 @@
</span><span class="cx">         return w
</span><span class="cx"> 
</span><span class="cx"> 
</span><ins>+    @staticmethod
+    def connectorFor(dbtype, **kwargs):
+        if dbtype == &quot;postgres&quot;:
+            return DBAPIConnector._connectorFor_module(postgres, **kwargs)
+        elif dbtype == &quot;oracle&quot;:
+            return DBAPIConnector._connectorFor_module(cx_Oracle, **kwargs)
+        else:
+            raise InternalDataStoreError(
+                &quot;Unknown database type: {}&quot;.format(dbtype)
+            )
</ins><span class="cx"> 
</span><ins>+
+    @staticmethod
+    def _connectorFor_module(dbmodule, **kwargs):
+        m = getattr(DBAPIConnector, &quot;_connectorFor_{}&quot;.format(dbmodule.__name__), None)
+        if m is None:
+            raise InternalDataStoreError(
+                &quot;Unknown DBAPI module: {}&quot;.format(dbmodule)
+            )
+
+        return m(dbmodule, **kwargs)
+
+
+    @staticmethod
+    def _connectorFor_pgdb(dbmodule, **kwargs):
+        &quot;&quot;&quot;
+        Turn properties into pgdb kwargs
+        &quot;&quot;&quot;
+        params = DBAPIParameters(**kwargs)
+
+        dsn = &quot;{0.host}:dbname={0.database}:{0.user}:{0.password}::&quot;.format(params)
+
+        dbkwargs = {}
+        if params.port:
+            dbkwargs[&quot;host&quot;] = &quot;{}:{}&quot;.format(params.host, params.port)
+        return DBAPIConnector(postgres, postgresPreflight, dsn, **dbkwargs)
+
+
+    @staticmethod
+    def _connectorFor_pg8000(dbmodule, **kwargs):
+        &quot;&quot;&quot;
+        Turn properties into pg8000 kwargs
+        &quot;&quot;&quot;
+        params = DBAPIParameters(**kwargs)
+        dbkwargs = {
+            &quot;user&quot;: params.user,
+            &quot;password&quot;: params.password,
+            &quot;database&quot;: params.database,
+        }
+        if params.unixsocket:
+            dbkwargs[&quot;unix_sock&quot;] = params.unixsocket
+
+            # We're using a socket file
+            socketFP = CachingFilePath(dbkwargs[&quot;unix_sock&quot;])
+
+            if socketFP.isdir():
+                # We have been given the directory, not the actual socket file
+                socketFP = socketFP.child(&quot;.s.PGSQL.{}&quot;.format(params.port if params.port else &quot;5432&quot;))
+                dbkwargs[&quot;unix_sock&quot;] = socketFP.path
+
+            if not socketFP.isSocket():
+                raise InternalDataStoreError(
+                    &quot;No such socket file: {}&quot;.format(socketFP.path)
+                )
+        else:
+            dbkwargs[&quot;host&quot;] = params.host
+            if params.port:
+                dbkwargs[&quot;port&quot;] = int(params.port)
+        return DBAPIConnector(dbmodule, postgresPreflight, **dbkwargs)
+
+
+    @staticmethod
+    def _connectorFor_cx_Oracle(self, **kwargs):
+        &quot;&quot;&quot;
+        Turn properties into DSN string
+        &quot;&quot;&quot;
+        dsn = &quot;{0.user}/{0.password}@{0.host}:{0.port}/{0.database}&quot;.format(DBAPIParameters(**kwargs))
+        return OracleConnector(dsn)
+
+
+
</ins><span class="cx"> class OracleConnectionWrapper(DiagnosticConnectionWrapper):
</span><span class="cx"> 
</span><span class="cx">     wrapper = OracleCursorWrapper
</span></span></pre></div>
<a id="CalendarServertrunktxdavbasedatastoresuboraclepy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/base/datastore/suboracle.py (14662 => 14663)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/base/datastore/suboracle.py        2015-04-06 16:44:14 UTC (rev 14662)
+++ CalendarServer/trunk/txdav/base/datastore/suboracle.py        2015-04-06 21:13:15 UTC (rev 14663)
</span><span class="lines">@@ -14,7 +14,6 @@
</span><span class="cx"> # See the License for the specific language governing permissions and
</span><span class="cx"> # limitations under the License.
</span><span class="cx"> # #
</span><del>-from twisted.internet.defer import inlineCallbacks
</del><span class="cx"> 
</span><span class="cx"> &quot;&quot;&quot;
</span><span class="cx"> Stub service for Oracle.
</span><span class="lines">@@ -22,10 +21,10 @@
</span><span class="cx"> 
</span><span class="cx"> from twext.python.log import Logger
</span><span class="cx"> 
</span><del>-from txdav.base.datastore.dbapiclient import OracleConnector
-from txdav.common.icommondatastore import InternalDataStoreError
</del><ins>+from txdav.base.datastore.dbapiclient import DBAPIConnector
</ins><span class="cx"> 
</span><span class="cx"> from twisted.application.service import MultiService
</span><ins>+from twisted.internet.defer import inlineCallbacks
</ins><span class="cx"> 
</span><span class="cx"> log = Logger()
</span><span class="cx"> 
</span><span class="lines">@@ -70,26 +69,16 @@
</span><span class="cx"> 
</span><span class="cx"> 
</span><span class="cx">     def _connectorFor(self):
</span><del>-        m = getattr(self, &quot;_connectorFor_{}&quot;.format(&quot;cx_oracle&quot;), None)
-        if m is None:
-            raise InternalDataStoreError(
-                &quot;Unknown Oracle DBM module: {}&quot;.format(&quot;cx_oracle&quot;)
-            )
</del><ins>+        kwargs = {
+            &quot;endpoint&quot;: &quot;tcp:192.168.56.101:1521&quot;,
+            &quot;database&quot;: &quot;orcl&quot;,
+            &quot;user&quot;: self.dsnUser if self.dsnUser else &quot;hr&quot;,
+            &quot;password&quot;: &quot;oracle&quot;,
+        }
</ins><span class="cx"> 
</span><del>-        return m()
</del><ins>+        return DBAPIConnector.connectorFor(&quot;oracle&quot;, **kwargs)
</ins><span class="cx"> 
</span><span class="cx"> 
</span><del>-    def _connectorFor_cx_oracle(self):
-        dsn = &quot;{}/oracle@192.168.56.101:1521/orcl&quot;.format(self.dsnUser if self.dsnUser else &quot;hr&quot;)
-
-        log.info(
-            &quot;Connecting to Oracle with dsn={dsn!r}&quot;,
-            dsn=dsn,
-        )
-
-        return OracleConnector(dsn)
-
-
</del><span class="cx">     def produceConnection(self, label=&quot;&lt;unlabeled&gt;&quot;):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Produce a DB-API 2.0 connection pointed at this database.
</span></span></pre></div>
<a id="CalendarServertrunktxdavbasedatastoresubpostgrespy"></a>
<div class="modfile"><h4>Modified: CalendarServer/trunk/txdav/base/datastore/subpostgres.py (14662 => 14663)</h4>
<pre class="diff"><span>
<span class="info">--- CalendarServer/trunk/txdav/base/datastore/subpostgres.py        2015-04-06 16:44:14 UTC (rev 14662)
+++ CalendarServer/trunk/txdav/base/datastore/subpostgres.py        2015-04-06 21:13:15 UTC (rev 14663)
</span><span class="lines">@@ -26,7 +26,6 @@
</span><span class="cx"> from hashlib import md5
</span><span class="cx"> from pipes import quote as shell_quote
</span><span class="cx"> 
</span><del>-import pg8000 as postgres
</del><span class="cx"> 
</span><span class="cx"> from twisted.python.procutils import which
</span><span class="cx"> from twisted.internet.protocol import ProcessProtocol
</span><span class="lines">@@ -38,7 +37,7 @@
</span><span class="cx"> from twisted.protocols.basic import LineReceiver
</span><span class="cx"> from twisted.internet.defer import Deferred
</span><span class="cx"> from txdav.base.datastore.dbapiclient import DBAPIConnector
</span><del>-from txdav.base.datastore.dbapiclient import postgresPreflight
</del><ins>+from txdav.base.datastore.dbapiclient import postgres
</ins><span class="cx"> from txdav.common.icommondatastore import InternalDataStoreError
</span><span class="cx"> 
</span><span class="cx"> from twisted.application.service import MultiService
</span><span class="lines">@@ -320,73 +319,24 @@
</span><span class="cx">         if databaseName is None:
</span><span class="cx">             databaseName = self.databaseName
</span><span class="cx"> 
</span><del>-        m = getattr(self, &quot;_connectorFor_{}&quot;.format(postgres.__name__), None)
-        if m is None:
-            raise InternalDataStoreError(
-                &quot;Unknown Postgres DBM module: {}&quot;.format(postgres)
-            )
</del><ins>+        kwargs = {
+            &quot;database&quot;: databaseName,
+        }
</ins><span class="cx"> 
</span><del>-        return m(databaseName)
-
-
-    def _connectorFor_pgdb(self, databaseName):
-        dsn = &quot;{}:dbname={}&quot;.format(self.host, databaseName)
-
-        if self.spawnedDBUser:
-            dsn = &quot;{}:{}&quot;.format(dsn, self.spawnedDBUser)
-        elif self.uid is not None:
-            dsn = &quot;{}:{}&quot;.format(dsn, pwd.getpwuid(self.uid).pw_name)
-
-        kwargs = {}
-        if self.port:
-            kwargs[&quot;host&quot;] = &quot;{}:{}&quot;.format(self.host, self.port)
-
-        log.info(
-            &quot;Connecting to Postgres with dsn={dsn!r} args={args}&quot;,
-            dsn=dsn, args=kwargs
-        )
-
-        return DBAPIConnector(postgres, postgresPreflight, dsn, **kwargs)
-
-
-    def _connectorFor_pg8000(self, databaseName):
-        kwargs = dict(database=databaseName)
-
</del><span class="cx">         if self.host.startswith(&quot;/&quot;):
</span><del>-            # We're using a socket file
-            socketFP = CachingFilePath(self.host)
-
-            if socketFP.isdir():
-                # We have been given the directory, not the actual socket file
-                nameFormat = self.socketName if self.socketName else &quot;.s.PGSQL.{}&quot;
-                socketFP = socketFP.child(
-                    nameFormat.format(self.port if self.port else 5432)
-                )
-
-            if not socketFP.isSocket():
-                raise InternalDataStoreError(
-                    &quot;No such socket file: {}&quot;.format(socketFP.path)
-                )
-
-            kwargs[&quot;host&quot;] = None
-            kwargs[&quot;unix_sock&quot;] = socketFP.path
</del><ins>+            kwargs[&quot;endpoint&quot;] = &quot;unix:{}&quot;.format(self.host)
</ins><span class="cx">         else:
</span><del>-            kwargs[&quot;host&quot;] = self.host
-            kwargs[&quot;unix_sock&quot;] = None
-
-        if self.port:
-            kwargs[&quot;port&quot;] = int(self.port)
-
</del><ins>+            kwargs[&quot;endpoint&quot;] = &quot;tcp:{}&quot;.format(self.host)
+            if self.port:
+                kwargs[&quot;endpoint&quot;] = &quot;{}:{}&quot;.format(kwargs[&quot;endpoint&quot;], self.port)
</ins><span class="cx">         if self.spawnedDBUser:
</span><span class="cx">             kwargs[&quot;user&quot;] = self.spawnedDBUser
</span><span class="cx">         elif self.uid is not None:
</span><span class="cx">             kwargs[&quot;user&quot;] = pwd.getpwuid(self.uid).pw_name
</span><span class="cx"> 
</span><del>-        log.info(&quot;Connecting to Postgres with args={args}&quot;, args=kwargs)
</del><ins>+        return DBAPIConnector.connectorFor(&quot;postgres&quot;, **kwargs)
</ins><span class="cx"> 
</span><del>-        return DBAPIConnector(postgres, postgresPreflight, **kwargs)
</del><span class="cx"> 
</span><del>-
</del><span class="cx">     def produceConnection(self, label=&quot;&lt;unlabeled&gt;&quot;, databaseName=None):
</span><span class="cx">         &quot;&quot;&quot;
</span><span class="cx">         Produce a DB-API 2.0 connection pointed at this database.
</span></span></pre>
</div>
</div>

</body>
</html>