Changeset: 2c68f6403a16 for MonetDB URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=2c68f6403a16 Modified Files: clients/python2/monetdb/__init__.py clients/python2/monetdb/control.py clients/python2/monetdb/exceptions.py clients/python2/monetdb/mapi.py clients/python2/monetdb/sql/__init__.py clients/python2/monetdb/sql/connections.py clients/python2/monetdb/sql/converters.py clients/python2/monetdb/sql/cursors.py clients/python2/monetdb/sql/monetize.py clients/python2/monetdb/sql/pythonize.py clients/python2/monetdb/sql/types.py Branch: Feb2013 Log Message:
fix all pep8 warnings, less debug logging diffs (truncated from 1099 to 300 lines): diff --git a/clients/python2/monetdb/__init__.py b/clients/python2/monetdb/__init__.py --- a/clients/python2/monetdb/__init__.py +++ b/clients/python2/monetdb/__init__.py @@ -32,4 +32,3 @@ __all__ = ["sql", "mapi"] # for backwards compatability monetdb_exceptions = exceptions - diff --git a/clients/python2/monetdb/control.py b/clients/python2/monetdb/control.py --- a/clients/python2/monetdb/control.py +++ b/clients/python2/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/python2/monetdb/exceptions.py b/clients/python2/monetdb/exceptions.py --- a/clients/python2/monetdb/exceptions.py +++ b/clients/python2/monetdb/exceptions.py @@ -18,6 +18,7 @@ MonetDB Python API specific exceptions """ + class Warning(StandardError): """Exception raised for important warnings like data truncations while inserting, etc. It must be a subclass of @@ -25,6 +26,7 @@ class Warning(StandardError): exceptions).""" pass + class Error(StandardError): """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/python2/monetdb/mapi.py b/clients/python2/monetdb/mapi.py --- a/clients/python2/monetdb/mapi.py +++ b/clients/python2/monetdb/mapi.py @@ -24,13 +24,14 @@ import logging import struct import hashlib from cStringIO import StringIO -import time -from monetdb.exceptions import OperationalError, DatabaseError, ProgrammingError, NotSupportedError + +from monetdb.exceptions import OperationalError, DatabaseError,\ + ProgrammingError, NotSupportedError logger = logging.getLogger("monetdb") -MAX_PACKAGE_LENGTH = (1024*8)-2 +MAX_PACKAGE_LENGTH = (1024 * 8) - 2 MSG_PROMPT = "" MSG_MORE = "\1\2\n" @@ -52,6 +53,7 @@ STATE_INIT = 0 STATE_READY = 1 +# noinspection PyExceptionInherit class Connection(object): """ MAPI (low level MonetDB API) connection @@ -87,7 +89,6 @@ class Connection(object): self.socket.connect((hostname, port)) self.__login() - def __login(self, iteration=0): """ Reads challenge from line, generate response and check if everything is okay """ @@ -97,13 +98,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:]) @@ -114,23 +115,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) @@ -141,16 +141,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, "Not connected") @@ -171,7 +169,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(':') @@ -201,11 +198,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 """ @@ -213,50 +210,41 @@ 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)) - #logger.debug("RX: %s" % result.getvalue()) return result.getvalue() - - def __getbytes(self, bytes): + def __getbytes(self, bytes_): """Read an amount of bytes from the socket""" result = StringIO() - count = bytes + count = bytes_ while count > 0: 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] + data = block[pos:pos + MAX_PACKAGE_LENGTH] 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/python2/monetdb/sql/__init__.py b/clients/python2/monetdb/sql/__init__.py --- a/clients/python2/monetdb/sql/__init__.py +++ b/clients/python2/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" + 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', - 'FIELD_TYPE', 'IntegrityError', 'InterfaceError', 'InternalError', _______________________________________________ checkin-list mailing list checkin-list@monetdb.org http://mail.monetdb.org/mailman/listinfo/checkin-list