Changeset: c57caf2e3730 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=c57caf2e3730
Added Files:
clients/python3/test/control.py
Modified Files:
clients/python3/monetdb/__init__.py
clients/python3/monetdb/control.py
clients/python3/monetdb/exceptions.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/monetdb/sql/monetize.py
clients/python3/monetdb/sql/pythonize.py
clients/python3/monetdb/sql/types.py
Branch: Feb2013
Log Message:
sync python3 with python2
diffs (truncated from 1253 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
@@ -32,4 +32,3 @@ __all__ = ["sql", "mapi"]
# for backwards compatability
monetdb_exceptions = exceptions
-
diff --git a/clients/python3/monetdb/control.py
b/clients/python3/monetdb/control.py
--- a/clients/python3/monetdb/control.py
+++ b/clients/python3/monetdb/control.py
@@ -20,6 +20,7 @@ def parse_statusline(line):
subparts = rest.split(',')
sub_iter = iter(subparts)
+
info = {}
info['name'] = sub_iter.__next__()
diff --git a/clients/python3/monetdb/exceptions.py
b/clients/python3/monetdb/exceptions.py
--- a/clients/python3/monetdb/exceptions.py
+++ b/clients/python3/monetdb/exceptions.py
@@ -18,6 +18,7 @@
MonetDB Python API specific exceptions
"""
+
class Warning(Exception):
"""Exception raised for important warnings like data
truncations while inserting, etc. It must be a subclass of
@@ -25,6 +26,7 @@ class Warning(Exception):
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
@@ -41,17 +43,20 @@ class InterfaceError(Error):
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
@@ -61,12 +66,14 @@ class OperationalError(DatabaseError):
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
@@ -74,6 +81,7 @@ class InternalError(DatabaseError):
DatabaseError."""
pass
+
class ProgrammingError(DatabaseError):
"""Exception raised for programming errors, e.g. table not
found or already exists, syntax error in the SQL
@@ -81,11 +89,10 @@ class ProgrammingError(DatabaseError):
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/mapi.py b/clients/python3/monetdb/mapi.py
--- a/clients/python3/monetdb/mapi.py
+++ b/clients/python3/monetdb/mapi.py
@@ -24,14 +24,15 @@ import logging
import struct
import hashlib
from io import BytesIO
-import time
-from monetdb.exceptions import OperationalError, DatabaseError,
ProgrammingError, NotSupportedError
+
+from monetdb.exceptions import OperationalError, DatabaseError,\
+ ProgrammingError, NotSupportedError
logger = logging.getLogger("monetdb")
logger.addHandler(logging.NullHandler())
-MAX_PACKAGE_LENGTH = (1024*8)-2
+MAX_PACKAGE_LENGTH = (1024 * 8) - 2
MSG_PROMPT = ""
MSG_MORE = "\1\2\n"
@@ -53,6 +54,7 @@ STATE_INIT = 0
STATE_READY = 1
+# noinspection PyExceptionInherit
class Connection(object):
"""
MAPI (low level MonetDB API) connection
@@ -85,15 +87,9 @@ class Connection(object):
self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 0)
self.socket.setsockopt(socket.IPPROTO_TCP, socket.TCP_NODELAY, 1)
- try:
- self.socket.connect((hostname, port))
- except socket.error as error:
- (error_code, error_str) = error
- raise OperationalError(error_str + " (%s:%s)" % (self.hostname,
self.port))
-
+ self.socket.connect((hostname, port))
self.__login()
-
def __login(self, iteration=0):
""" Reads challenge from line, generate response and check if
everything is okay """
@@ -103,13 +99,13 @@ class Connection(object):
self.__putblock(response)
prompt = self.__getblock().strip()
- if len(prompt) == 0 :
+ if len(prompt) == 0:
# Empty response, server is happy
pass
elif prompt == MSG_OK:
pass
elif prompt.startswith(MSG_INFO):
- logger.info("II %s" % prompt[1:])
+ logger.info("%s" % prompt[1:])
elif prompt.startswith(MSG_ERROR):
logger.error(prompt[1:])
@@ -120,23 +116,22 @@ class Connection(object):
# the first
redirect = prompt.split()[0][1:].split(':')
if redirect[1] == "merovingian":
- logger.debug("II: merovingian proxy, restarting " +
- "authenticatiton")
+ logger.debug("restarting authentication")
if iteration <= 10:
- self.__login(iteration=iteration+1)
+ self.__login(iteration=iteration + 1)
else:
- raise OperationalError("maximal number of redirects " +
- "reached (10)")
+ raise OperationalError("maximal number of redirects "
+ "reached (10)")
elif redirect[1] == "monetdb":
self.hostname = redirect[2][2:]
self.port, self.database = redirect[3].split('/')
self.port = int(self.port)
- logger.info("II: merovingian redirect to monetdb://%s:%s/%s" %
- (self.hostname, self.port, self.database))
+ logger.info("redirect to monetdb://%s:%s/%s" %
+ (self.hostname, self.port, self.database))
self.socket.close()
self.connect(self.hostname, self.port, self.username,
- self.password, self.database, self.language)
+ self.password, self.database, self.language)
else:
raise ProgrammingError("unknown redirect: %s" % prompt)
@@ -147,16 +142,14 @@ class Connection(object):
self.state = STATE_READY
return True
-
def disconnect(self):
""" disconnect from the monetdb server """
self.state = STATE_INIT
self.socket.close()
-
def cmd(self, operation):
""" put a mapi command on the line"""
- logger.debug("II: executing command %s" % operation)
+ logger.debug("executing command %s" % operation)
if self.state != STATE_READY:
raise ProgrammingError
@@ -177,7 +170,6 @@ class Connection(object):
else:
raise ProgrammingError("unknown state: %s" % response)
-
def __challenge_response(self, challenge):
""" generate a response to a mapi login challenge """
challenges = challenge.split(':')
@@ -207,11 +199,11 @@ class Connection(object):
m.update(salt.encode())
pwhash = "{MD5}" + m.hexdigest()
else:
- raise NotSupportedError("Unsupported hash algorithms required for
login: %s" % (hashes));
+ raise NotSupportedError("Unsupported hash algorithms required"
+ " for login: %s" % hashes)
return ":".join(["BIG", self.username, pwhash, self.language,
- self.database]) + ":"
-
+ self.database]) + ":"
def __getblock(self):
""" read one mapi encoded block """
@@ -219,17 +211,13 @@ class Connection(object):
last = 0
while not last:
flag = self.__getbytes(2)
- unpacked = struct.unpack('<H', flag)[0] # unpack little endian
short
+ unpacked = struct.unpack('<H', flag)[0] # little endian short
length = unpacked >> 1
last = unpacked & 1
- #logger.debug("II: reading %i bytes, last: %s" % (length,
bool(last)))
result.write(self.__getbytes(length))
result_str = result.getvalue()
- #logger.debug("RX: length: %i payload: %s" % (len(result_str),
result_str))
return result_str.decode()
-
-
def __getbytes(self, bytes):
"""Read an amount of bytes from the socket"""
result = BytesIO()
@@ -238,33 +226,27 @@ class Connection(object):
recv = self.socket.recv(count)
if len(recv) == 0:
raise OperationalError("Server closed connection")
- #logger.debug("II: package size: %i payload: %s" % (len(recv),
recv))
count -= len(recv)
result.write(recv)
return result.getvalue()
-
def __putblock(self, block):
""" wrap the line in mapi format and put it into the socket """
pos = 0
last = 0
while not last:
- data = block[pos:pos+MAX_PACKAGE_LENGTH].encode()
+ data = block[pos:pos + MAX_PACKAGE_LENGTH].encode()
length = len(data)
if length < MAX_PACKAGE_LENGTH:
last = 1
- flag = struct.pack( '<H', ( length << 1 ) + last )
- #logger.debug("II: sending %i bytes, last: %s" % (length,
bool(last)))
- #logger.debug("TX: %s" % data)
+ flag = struct.pack('<H', (length << 1) + last)
self.socket.send(flag)
self.socket.send(data)
pos += length
-
def __del__(self):
if self.socket:
self.socket.close()
#backwards compatiblity
Server = Connection
-
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
@@ -19,22 +19,24 @@ from monetdb.sql.connections import Conn
from monetdb.sql.pythonize import *
from monetdb.exceptions import *
-apilevel="2.0"
-threadsafety=0
-paramstyle="pyformat"
+apilevel = "2.0"
+threadsafety = 0
+paramstyle = "pyformat"
+
_______________________________________________
checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list