コード例 #1
0
    def _connection_factory(self):
        """Create a MySQLdb DBI connection based on the DSN"""

        conn_info = parseDSN(self.dsn)

        # patch to  present ALL connection parameters
        conn_all = {}
        conn_all['db'] = conn_info['dbname']
        conn_all['host'] = conn_info['host']
        conn_all['user'] = conn_info['username']
        conn_all['passwd'] = conn_info['password']
        conn_all['port'] = int(conn_info['port'] or '3306')
        for k in conn_info['parameters'].keys():
            conn_all[str(k)] = str(conn_info['parameters'][k])
        connection = MySQLdb.Connect(**conn_all)

        #connection = MySQLdb.Connect(db=conn_info['dbname'],
        #                    host=conn_info['host'],
        #                    user=conn_info['username'],
        #                    passwd=conn_info['password'],
        #                    port=int(conn_info['port'] or '3306'))

        if self.__stringConverter.encoding != self.getEncoding():
            #avoid resetting this everytime, otherwise the adapter
            #gets modified on each connection and that causes ZODB conflicts
            self.__stringConverter = MySQLStringConverter(self.getEncoding())
        return connection
コード例 #2
0
    def _connection_factory(self):
        """Create a Gadfly DBI connection based on the DSN.

        Only local (filesystem-based) Gadfly connections are supported
        at this moment."""

        conn_info = parseDSN(self.dsn)
        if conn_info['host'] != '' or conn_info['username'] != '' or \
           conn_info['port'] != '' or conn_info['password'] != '':
            raise DatabaseAdapterError(
                "DSN for GadflyDA must be of the form "
                "dbi://dbname or dbi://dbname;dir=directory."
                )

        connection = conn_info['dbname']
        dir = os.path.join(getGadflyRoot(),
                           conn_info['parameters'].get('dir', connection))

        if not os.path.isdir(dir):
            raise DatabaseAdapterError('Not a directory ' + dir)

        if not os.path.exists(os.path.join(dir, connection + ".gfd")):
            db = gadfly.gadfly()
            db.startup(connection, dir)
        else:
            db = gadfly.gadfly(connection, dir)

        return db
コード例 #3
0
 def testAllOptionsAndParams(self):
     dsn = 'dbi://*****:*****@bohr:5432/test;param1=value1;param2=value2'
     result = {'parameters': {'param1': 'value1', 'param2': 'value2'},
               'dbname': 'test', 'username': '******', 'password': '******',
               'host': 'bohr', 'port': '5432'}
     self.assertEqual(result, parseDSN(dsn))
コード例 #4
0
 def testAllOptions(self):
     dsn = 'dbi://*****:*****@bohr:5432/test'
     result = {'parameters': {}, 'dbname': 'test', 'username': '******',
               'password': '******', 'host': 'bohr', 'port': '5432'}
     self.assertEqual(result, parseDSN(dsn))
コード例 #5
0
 def testUserPasswordAndHostWithoutPort(self):
     dsn = 'dbi://*****:*****@bohr/test'
     result = {'parameters': {}, 'dbname': 'test', 'username': '******',
               'password': '******', 'host': 'bohr', 'port': ''}
     self.assertEqual(result, parseDSN(dsn))
コード例 #6
0
 def testParamsWithSpecialCharacters(self):
     dsn = 'dbi://test;param%40=value%21;param%23=value%24'
     result = {'parameters': {'param@': 'value!', 'param#': 'value$'},
               'dbname': 'test', 'username': '', 'password': '',
               'host': '', 'port': ''}
     self.assertEqual(result, parseDSN(dsn))
コード例 #7
0
 def testUserPasswordAndParams(self):
     dsn = 'dbi://mike:muster/test;param1=value1;param2=value2'
     result = {'parameters': {'param1': 'value1', 'param2': 'value2'},
               'dbname': 'test', 'username': '******', 'password': '******',
               'host': '', 'port': ''}
     self.assertEqual(result, parseDSN(dsn))
コード例 #8
0
 def testPasswordWithColon(self):
     dsn = 'dbi://mike:before:after/test'
     result = {'parameters': {}, 'dbname': 'test', 'username': '******',
               'password': '******', 'host': '', 'port': ''}
     self.assertEqual(result, parseDSN(dsn))
コード例 #9
0
 def testUserPasswordWithSpecialCharacters(self):
     dsn = 'dbi://m+i+k+e:m%7Bu%7Dster/test'
     result = {'parameters': {}, 'dbname': 'test', 'username': '******',
               'password': '******', 'host': '', 'port': ''}
     self.assertEqual(result, parseDSN(dsn))
コード例 #10
0
 def testUser(self):
     dsn = 'dbi://mike/test'
     result = {'parameters': {}, 'dbname': 'test', 'username': '******',
               'password': '', 'host': '', 'port': ''}
     self.assertEqual(result, parseDSN(dsn))
コード例 #11
0
 def testDBNameWithSpecialCharacters(self):
     dsn = 'dbi://test%2Fmore+'
     result = {'parameters': {}, 'dbname': 'test/more ', 'username': '',
               'password': '', 'host': '', 'port': ''}
     self.assertEqual(result, parseDSN(dsn))