Changeset: 669ad11ea799 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=669ad11ea799
Added Files:
        clients/python3/monetdb/sql/monetize.py
        clients/python3/monetdb/sql/pythonize.py
Removed Files:
        clients/python3/monetdb/monetdb_exceptions.py
Modified Files:
        clients/python3/monetdb/__init__.py
        clients/python3/monetdb/mapi.py
        clients/python3/monetdb/sql/__init__.py
        clients/python3/monetdb/sql/connections.py
        clients/python3/monetdb/sql/converters.py
        clients/python3/monetdb/sql/cursors.py
        clients/python3/test/capabilities.py
Branch: default
Log Message:

restructuring code layout


diffs (truncated from 948 to 300 lines):

diff --git a/clients/python3/monetdb/__init__.py 
b/clients/python3/monetdb/__init__.py
--- a/clients/python3/monetdb/__init__.py
+++ b/clients/python3/monetdb/__init__.py
@@ -14,3 +14,20 @@
 # Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
 # Copyright August 2008-2012 MonetDB B.V.
 # All Rights Reserved.
+
+"""
+This is the MonetDB Python API.
+
+The MAPI (MonetDB API) related code is in monetdb.mapi.
+
+The SQL related code is in monetdb.sql.
+
+To set up a connection use monetdb.sql.connect()
+
+"""
+from monetdb import sql
+from monetdb import mapi
+
+__all__ = ["sql", "mapi"]
+
+connect = sql.connect
\ No newline at end of file
diff --git a/clients/python3/monetdb/mapi.py b/clients/python3/monetdb/mapi.py
--- a/clients/python3/monetdb/mapi.py
+++ b/clients/python3/monetdb/mapi.py
@@ -26,7 +26,7 @@ import hashlib
 import platform
 from io import BytesIO
 
-from monetdb.monetdb_exceptions import *
+from monetdb.exceptions import *
 
 logger = logging.getLogger("monetdb")
 
diff --git a/clients/python3/monetdb/monetdb_exceptions.py 
b/clients/python3/monetdb/monetdb_exceptions.py
deleted file mode 100644
--- a/clients/python3/monetdb/monetdb_exceptions.py
+++ /dev/null
@@ -1,91 +0,0 @@
-# The contents of this file are subject to the MonetDB Public License
-# Version 1.1 (the "License"); you may not use this file except in
-# compliance with the License. You may obtain a copy of the License at
-# http://www.monetdb.org/Legal/MonetDBLicense
-#
-# Software distributed under the License is distributed on an "AS IS"
-# basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See the
-# License for the specific language governing rights and limitations
-# under the License.
-#
-# The Original Code is the MonetDB Database System.
-#
-# The Initial Developer of the Original Code is CWI.
-# Portions created by CWI are Copyright (C) 1997-July 2008 CWI.
-# Copyright August 2008-2012 MonetDB B.V.
-# All Rights Reserved.
-
-# DBAPI states that we should subclass StandardError.
-# StandardError is depricated in python 3.0, so we use Exception
-
-class Warning(Exception):
-    """Exception raised for important warnings like data
-    truncations while inserting, etc. It must be a subclass of
-    the Python StandardError (defined in the module
-    exceptions)."""
-    pass
-
-class Error(Exception):
-    """Exception that is the base class of all other error
-    exceptions. You can use this to catch all errors with one
-    single 'except' statement. Warnings are not considered
-    errors and thus should not use this class as base. It must
-    be a subclass of the Python StandardError (defined in the
-    module exceptions)."""
-    pass
-
-
-class InterfaceError(Error):
-    """Exception raised for errors that are related to the
-    database interface rather than the database itself.  It
-    must be a subclass of Error."""
-    pass
-
-class DatabaseError(Error):
-    """Exception raised for errors that are related to the
-    database.  It must be a subclass of Error."""
-    pass
-
-class DataError(DatabaseError):
-    """Exception raised for errors that are due to problems with
-    the processed data like division by zero, numeric value
-    out of range, etc. It must be a subclass of DatabaseError."""
-    pass
-
-class OperationalError(DatabaseError):
-    """Exception raised for errors that are related to the
-    database's operation and not necessarily under the control
-    of the programmer, e.g. an unexpected disconnect occurs,
-    the data source name is not found, a transaction could not
-    be processed, a memory allocation error occurred during
-    processing, etc.  It must be a subclass of DatabaseError."""
-    pass
-
-class IntegrityError(DatabaseError):
-    """Exception raised when the relational integrity of the
-    database is affected, e.g. a foreign key check fails.  It
-    must be a subclass of DatabaseError."""
-    pass
-
-class InternalError(DatabaseError):
-    """Exception raised when the database encounters an internal
-    error, e.g. the cursor is not valid anymore, the
-    transaction is out of sync, etc.  It must be a subclass of
-    DatabaseError."""
-    pass
-
-class ProgrammingError(DatabaseError):
-    """Exception raised for programming errors, e.g. table not
-    found or already exists, syntax error in the SQL
-    statement, wrong number of parameters specified, etc.  It
-    must be a subclass of DatabaseError."""
-    pass
-
-class NotSupportedError(DatabaseError):
-    """Exception raised in case a method or database API was used which is not
-    supported by the database, e.g. requesting a .rollback() on a connection
-    that does not support transaction or has transactions turned off.  It must
-    be a subclass of DatabaseError."""
-    pass
-
-
diff --git a/clients/python3/monetdb/sql/__init__.py 
b/clients/python3/monetdb/sql/__init__.py
--- a/clients/python3/monetdb/sql/__init__.py
+++ b/clients/python3/monetdb/sql/__init__.py
@@ -15,9 +15,9 @@
 # Copyright August 2008-2012 MonetDB B.V.
 # All Rights Reserved.
 
-from monetdb.monetdb_exceptions import *
 from monetdb.sql.connections import Connection
-from monetdb.sql.converters import *
+from monetdb.sql.pythonize import *
+from monetdb.exceptions import *
 
 apilevel="2.0"
 threadsafety=0
@@ -26,6 +26,8 @@ paramstyle="pyformat"
 def connect(*args, **kwargs):
     return Connection(*args, **kwargs)
 
+connect.__doc__ = Connection.__init__.__doc__
+
 __all__ = [ 'BINARY', 'Binary', 'connect', 'Connection', 'DATE',
     'Date', 'Time', 'Timestamp', 'DateFromTicks', 'TimeFromTicks',
     'TimestampFromTicks', 'DataError', 'DatabaseError', 'Error',
diff --git a/clients/python3/monetdb/sql/connections.py 
b/clients/python3/monetdb/sql/connections.py
--- a/clients/python3/monetdb/sql/connections.py
+++ b/clients/python3/monetdb/sql/connections.py
@@ -19,36 +19,27 @@ import sys
 import logging
 
 from monetdb.sql import cursors
-from monetdb.monetdb_exceptions import *
+from monetdb.exceptions import *
 from monetdb import mapi
 
 logger = logging.getLogger("monetdb")
 
 class Connection:
-    """This represents a MonetDB SQL database connection"""
+    """A MonetDB SQL database connection"""
     default_cursor = cursors.Cursor
 
-
     def __init__(self, username="monetdb", password="monetdb",
         hostname="localhost", port=50000, database="demo", autocommit=False,
-        use_unicode=False, user=None, host=None):
+        user=None, host=None):
         """ Set up a connection to a MonetDB SQL database.
 
-        user/username -- username for connection (default: monetdb)
-        password -- password for connection (default: monetdb)
-        host/hostname -- hostname to connect to (default: localhost)
-        port -- port to connect to (default: 50000)
-        database -- name of the database (default: demo)
-        autocommit -- enable/disable auto commit (default: False,
-                      required by DBAPI)
-        use_unicode -- use unicode for strings or not (default: False,
-                       only has effect on python2 since python3 is
-                       always unicode)
-
-        If user and username are provided, user overrides the value of 
username.
-        If host and hostname are provided, host overrides the value of 
hostname.
+        username   -- username for connection (default: monetdb)
+        password   -- password for connection (default: monetdb)
+        hostname   -- hostname to connect to (default: localhost)
+        port       -- port to connect to (default: 50000)
+        database   -- name of the database (default: demo)
+        autocommit -- enable/disable auto commit (default: False)
         """
-
         if user is not None:
             username = user
         if host is not None:
@@ -58,18 +49,14 @@ class Connection:
             password=password, database=database, language="sql")
         self.set_autocommit(autocommit)
         self.set_sizeheader(True)
-        self.use_unicode=use_unicode
-
 
     def close(self):
-        """ Close the connection now (rather than whenever __del__ is
-        called).  The connection will be unusable from this point
-        forward; an Error (or subclass) exception will be raised
-        if any operation is attempted with the connection. The
-        same applies to all cursor objects trying to use the
-        connection.  Note that closing a connection without
-        committing the changes first will cause an implicit
-        rollback to be performed.
+        """ Close the connection. The connection will be unusable from this
+        point forward; an Error  exception will be raised if any operation
+        is attempted with the connection. The same applies to all cursor
+        objects trying to use the connection.  Note that closing a connection
+        without committing the changes first will cause an implicit rollback
+        to be performed.
         """
 
         if self.mapi:
@@ -80,7 +67,6 @@ class Connection:
         else:
             raise Error("already closed")
 
-
     def set_autocommit(self, autocommit):
         """
         Set auto commit on or off. 'autocommit' must be a boolean
@@ -88,7 +74,6 @@ class Connection:
         self.command("Xauto_commit %s" % int(autocommit))
         self.autocommit = autocommit
 
-
     def set_sizeheader(self, sizeheader):
         """
         Set sizeheader on or off. When enabled monetdb will return
@@ -97,7 +82,6 @@ class Connection:
         self.command("Xsizeheader %s" % int(sizeheader))
         self.sizeheader = sizeheader
 
-
     def commit(self):
         """
         Commit any pending transaction to the database. Note that
@@ -108,12 +92,8 @@ class Connection:
         Database modules that do not support transactions should
         implement this method with void functionality.
         """
-
         self.__mapi_check()
         return self.cursor().execute('COMMIT')
-        #return self.execute('COMMIT')
-
-
 
     def rollback(self):
         """
@@ -126,12 +106,8 @@ class Connection:
         committing the changes first will cause an implicit
         rollback to be performed.
         """
-
         self.__mapi_check()
         return self.cursor().execute('ROLLBACK')
-        #return self.execute('ROLLBACK')
-
-
 
     def cursor(self):
         """
@@ -142,18 +118,15 @@ class Connection:
         """
         return cursors.Cursor(self)
 
-
     def execute(self, query):
         """ use this for executing SQL queries """
         return self.command('s' + query + ';')
 
-
     def command(self, command):
         """ use this function to send low level mapi commands """
         self.__mapi_check()
         return self.mapi.cmd(command)
 
-
     def __mapi_check(self):
         """ check if there is a connection with a server """
         if not self.mapi:
_______________________________________________
Checkin-list mailing list
Checkin-list@monetdb.org
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to