Changeset: 6adbf2ef5e51 for MonetDB
URL: http://dev.monetdb.org/hg/MonetDB?cmd=changeset;node=6adbf2ef5e51
Removed Files:
        clients/python3/monetdb/mclient.py
        clients/python3/monetdb/sql/type_codes.py
Modified Files:
        clients/python3/monetdb/sql/__init__.py
        clients/python3/monetdb/sql/converters.py
        clients/python3/monetdb/sql/monetize.py
        clients/python3/monetdb/sql/pythonize.py
        clients/python3/test/capabilities.py
        clients/python3/test/dbapi20.py
Branch: default
Log Message:

more cleanup, made string escape much faster


diffs (truncated from 525 to 300 lines):

diff --git a/clients/python3/monetdb/mclient.py 
b/clients/python3/monetdb/mclient.py
deleted file mode 100755
--- a/clients/python3/monetdb/mclient.py
+++ /dev/null
@@ -1,94 +0,0 @@
-#!/usr/bin/env python
-
-# 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.
-
-#
-
-import sys
-import getopt
-
-from monetdb import mapi
-
-
-def main(argv) :
-    hostname = 'localhost'
-    port = '50000'
-    username = 'monetdb'
-    password = 'monetdb'
-    language = 'sql'
-    database = ''
-    encoding = None
-
-    opts, args = getopt.getopt(argv[1:], '',
-                               ['host=', 'port=', 'user=', 'passwd=',
-                                'language=', 'database=', 'encoding='])
-    for o, a in opts:
-        if o == '--host':
-            hostname = a
-        elif o == '--port':
-            port = a
-        elif o == '--user':
-            username = a
-        elif o == '--passwd':
-            password = a
-        elif o == '--language':
-            language = a
-        elif o == '--database':
-            database = a
-        elif o == '--encoding':
-            encoding = a
-
-    if encoding is None:
-        import locale
-        encoding = locale.getlocale()[1]
-        if encoding is None:
-            encoding = locale.getdefaultlocale()[1]
-
-    s = mapi.Server()
-
-    s.connect(hostname = hostname,
-              port = int(port),
-              username = username,
-              password = password,
-              language = language,
-              database = database)
-    print "#mclient (python) connected to %s:%d as %s" % (hostname, int(port), 
username)
-
-    fi = sys.stdin
-
-    prompt = '%s>' % language
-
-    sys.stdout.write(prompt.encode('utf-8'))
-    line = fi.readline()
-    if encoding != 'utf-8':
-        prompt = unicode(prompt, 'utf-8').encode(encoding, 'replace')
-    while line and line != "\q\n":
-        if encoding != 'utf-8':
-            line = unicode(line, encoding).encode('utf-8')
-        res = s.cmd('s' + line)
-        if encoding != 'utf-8':
-            res = unicode(res, 'utf-8').encode(encoding, 'replace')
-        print res
-        sys.stdout.write(prompt)
-        line = fi.readline()
-
-    s.disconnect()
-
-if __name__ == "__main__":
-    main(sys.argv)
-
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
@@ -29,12 +29,12 @@ def connect(*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',
-    'MySQLError', 'NULL', 'NUMBER', 'NotSupportedError', 'DBAPISet',
-    'OperationalError', 'ProgrammingError', 'ROWID', 'STRING', 'TIME',
-    'TIMESTAMP', 'Set', 'Warning', 'apilevel', 'connect', 'connections',
-    'constants', 'cursors', 'debug', 'escape', 'escape_dict',
-    'escape_sequence', 'escape_string', 'get_client_info',
-    'paramstyle', 'string_literal', 'threadsafety', 'version_info']
+            'Date', 'Time', 'Timestamp', 'DateFromTicks', 'TimeFromTicks',
+            'TimestampFromTicks', 'DataError', 'DatabaseError', 'Error',
+            'FIELD_TYPE', 'IntegrityError', 'InterfaceError', 'InternalError',
+            'MySQLError', 'NULL', 'NUMBER', 'NotSupportedError', 'DBAPISet',
+            'OperationalError', 'ProgrammingError', 'ROWID', 'STRING', 'TIME',
+            'TIMESTAMP', 'Set', 'Warning', 'apilevel', 'connect', 
'connections',
+            'constants', 'cursors', 'debug', 'escape', 'escape_dict',
+            'escape_sequence', 'escape_string', 'get_client_info',
+            'paramstyle', 'string_literal', 'threadsafety', 'version_info']
diff --git a/clients/python3/monetdb/sql/converters.py 
b/clients/python3/monetdb/sql/converters.py
--- a/clients/python3/monetdb/sql/converters.py
+++ b/clients/python3/monetdb/sql/converters.py
@@ -15,6 +15,10 @@
 # Copyright August 2008-2012 MonetDB B.V.
 # All Rights Reserved.
 
+"""
+Backwards compatible converterts
+"""
+
 from monetdb.sql import monetize
 from monetdb.sql import pythonize
 
diff --git a/clients/python3/monetdb/sql/monetize.py 
b/clients/python3/monetdb/sql/monetize.py
--- a/clients/python3/monetdb/sql/monetize.py
+++ b/clients/python3/monetdb/sql/monetize.py
@@ -15,6 +15,10 @@
 # Copyright August 2008-2012 MonetDB B.V.
 # All Rights Reserved.
 
+"""
+functions for converting python objects to monetdb SQL format
+"""
+
 import datetime
 import logging
 import decimal
diff --git a/clients/python3/monetdb/sql/pythonize.py 
b/clients/python3/monetdb/sql/pythonize.py
--- a/clients/python3/monetdb/sql/pythonize.py
+++ b/clients/python3/monetdb/sql/pythonize.py
@@ -15,49 +15,25 @@
 # Copyright August 2008-2012 MonetDB B.V.
 # All Rights Reserved.
 
+"""
+functions for converting monetdb SQL fields to Python objects
+"""
+
 import logging
 import time
 import datetime
 from decimal import Decimal
-from monetdb.sql import type_codes
+from monetdb.sql import types
+import monetdb.exceptions
+import re
 
 logger = logging.getLogger("monetdb")
 
 def strip(data):
     """ returns a python string, chops off quotes,
-    replaces escape characters.
-    inverse of escape"""
+    replaces escape characters"""
+    return bytes(data[1:-1], "utf-8").decode("unicode_escape")
 
-    c_escapes = {'n':'\n', 't':'\t', 'r':'\r', '"':'\"'}
-    a = []
-    n = 0
-    for c in data:
-        if c == '\\':
-            n = n + 1
-        else:
-            if n > 0:
-                if n % 2 == 0:
-                    # even number of slashes: '\' '\' 'n' --> '\' 'n'
-                    a.extend(['\\'] * int(n/2))
-                    a.append(c)
-                    n = 0
-                else:
-                    # odd number of slashes: '\' '\' '\' 'n' --> '\' '\n'
-                    a.extend(['\\'] * int((n - 1)/2))
-                    if c in c_escapes.keys():
-                        a.append(c_escapes[c])
-                    else:
-                        logging.warning('unsupported escape character: \\%s' % 
c)
-                    n = 0
-            else:
-                a.append(c)
-                n = 0
-    if n > 0:
-        a.extend(['\\'] * (n/2))
-        a.append(c)
-    data = ''.join(a)
-
-    return data[1:-1]
 
 def py_bool(data):
     """ return python boolean """
@@ -104,31 +80,31 @@ def py_blob(x):
     return ''.join(map(lambda x: chr(int(x, 16)), x.split(" ")))
 
 mapping = {
-    type_codes.CHAR: strip,
-    type_codes.VARCHAR: strip,
-    type_codes.CLOB: strip,
-    type_codes.BLOB: str,
-    type_codes.DECIMAL: Decimal,
-    type_codes.SMALLINT: int,
-    type_codes.INT: int,
-    type_codes.WRD: int,
-    type_codes.BIGINT: int,
-    type_codes.SERIAL: int,
-    type_codes.REAL: float,
-    type_codes.DOUBLE: float,
-    type_codes.BOOLEAN: py_bool,
-    type_codes.DATE: py_date,
-    type_codes.TIME: py_time,
-    type_codes.TIMESTAMP: py_timestamp,
-    type_codes.TIMESTAMPTZ: py_timestamptz,
-    type_codes.INTERVAL: strip,
-    type_codes.MONTH_INTERVAL: strip,
-    type_codes.SEC_INTERVAL: strip,
-    type_codes.TINYINT: int,
-    type_codes.SHORTINT: int,
-    type_codes.MEDIUMINT: int,
-    type_codes.LONGINT: int,
-    type_codes.FLOAT: float,
+    types.CHAR: strip,
+    types.VARCHAR: strip,
+    types.CLOB: strip,
+    types.BLOB: str,
+    types.DECIMAL: Decimal,
+    types.SMALLINT: int,
+    types.INT: int,
+    types.WRD: int,
+    types.BIGINT: int,
+    types.SERIAL: int,
+    types.REAL: float,
+    types.DOUBLE: float,
+    types.BOOLEAN: py_bool,
+    types.DATE: py_date,
+    types.TIME: py_time,
+    types.TIMESTAMP: py_timestamp,
+    types.TIMESTAMPTZ: py_timestamptz,
+    types.INTERVAL: strip,
+    types.MONTH_INTERVAL: strip,
+    types.SEC_INTERVAL: strip,
+    types.TINYINT: int,
+    types.SHORTINT: int,
+    types.MEDIUMINT: int,
+    types.LONGINT: int,
+    types.FLOAT: float,
 }
 
 def convert(data, type_code):
@@ -177,12 +153,12 @@ class DBAPISet(frozenset):
         else:
             return other in self
 
-STRING    = DBAPISet([type_codes.VARCHAR])
-BINARY    = DBAPISet([type_codes.BLOB])
-NUMBER    = DBAPISet([type_codes.DECIMAL, type_codes.DOUBLE, type_codes.REAL,
-                      type_codes.BIGINT, type_codes.SMALLINT])
-DATE      = DBAPISet([type_codes.DATE])
-TIME      = DBAPISet([type_codes.TIME])
-TIMESTAMP = DBAPISet([type_codes.TIMESTAMP])
+STRING    = DBAPISet([types.VARCHAR])
+BINARY    = DBAPISet([types.BLOB])
+NUMBER    = DBAPISet([types.DECIMAL, types.DOUBLE, types.REAL,
+                      types.BIGINT, types.SMALLINT])
+DATE      = DBAPISet([types.DATE])
+TIME      = DBAPISet([types.TIME])
+TIMESTAMP = DBAPISet([types.TIMESTAMP])
 DATETIME  = TIMESTAMP
 ROWID     = DBAPISet()
diff --git a/clients/python3/monetdb/sql/type_codes.py 
b/clients/python3/monetdb/sql/type_codes.py
deleted file mode 100644
--- a/clients/python3/monetdb/sql/type_codes.py
+++ /dev/null
@@ -1,58 +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
_______________________________________________
Checkin-list mailing list
[email protected]
http://mail.monetdb.org/mailman/listinfo/checkin-list

Reply via email to