dal almost runs with python 3.3 but fails a test on 2.5

This commit is contained in:
mdipierro
2012-10-23 11:30:02 -05:00
parent 093e8b356e
commit 5f67edbf87
4 changed files with 28 additions and 18 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.2.1 (2012-10-23 11:13:22) stable Version 2.2.1 (2012-10-23 11:29:56) stable
+18 -11
View File
@@ -170,16 +170,20 @@ import glob
import traceback import traceback
import platform import platform
python_version = sys.version_info[0] PYTHON_VERSION = sys.version_info[0]
if python_version == 2: if PYTHON_VERSION == 2:
import cPickle as pickle import cPickle as pickle
import cStringIO as StringIO import cStringIO as StringIO
import copy_reg as copyreg import copy_reg as copyreg
hashlib_md5 = hashlib.md5
bytes, unicode = str, unicode
else: else:
import pickle import pickle
from io import StringIO as StringIO from io import StringIO as StringIO
import copyreg import copyreg
long = int long = int
hashlib_md5 = lambda s: hashlib.md5(bytes(s,'utf8'))
bytes, unicode = bytes, str
CALLABLETYPES = (types.LambdaType, types.FunctionType, CALLABLETYPES = (types.LambdaType, types.FunctionType,
types.BuiltinFunctionType, types.BuiltinFunctionType,
@@ -1592,7 +1596,7 @@ class BaseAdapter(ConnectionPool):
else: else:
(cache_model, time_expire) = cache (cache_model, time_expire) = cache
key = self.uri + '/' + sql + '/rows' key = self.uri + '/' + sql + '/rows'
if len(key)>200: key = hashlib.md5(key).hexdigest() if len(key)>200: key = hashlib_md5(key).hexdigest()
def _select_aux2(): def _select_aux2():
self.execute(sql) self.execute(sql)
return self._fetchall() return self._fetchall()
@@ -1615,7 +1619,7 @@ class BaseAdapter(ConnectionPool):
del attributes['cache'] del attributes['cache']
(cache_model, time_expire) = cache (cache_model, time_expire) = cache
key = self.uri + '/' + sql key = self.uri + '/' + sql
if len(key)>200: key = hashlib.md5(key).hexdigest() if len(key)>200: key = hashlib_md5(key).hexdigest()
args = (sql,fields,attributes) args = (sql,fields,attributes)
return cache_model( return cache_model(
key, key,
@@ -1769,8 +1773,8 @@ class BaseAdapter(ConnectionPool):
obj = obj.isoformat()[:10] obj = obj.isoformat()[:10]
else: else:
obj = str(obj) obj = str(obj)
if not isinstance(obj,str): if not isinstance(obj,bytes):
obj = str(obj) obj = bytes(obj)
try: try:
obj.decode(self.db_codec) obj.decode(self.db_codec)
except: except:
@@ -2097,8 +2101,11 @@ class SQLiteAdapter(BaseAdapter):
else: else:
dbpath = uri.split('://',1)[1] dbpath = uri.split('://',1)[1]
if dbpath[0] != '/': if dbpath[0] != '/':
dbpath = pjoin( if PYTHON_VERSION == 2:
self.folder.decode(path_encoding).encode('utf8'), dbpath) dbpath = pjoin(
self.folder.decode(path_encoding).encode('utf8'), dbpath)
else:
dbpath = pjoin(self.folder, dbpath)
if not 'check_same_thread' in driver_args: if not 'check_same_thread' in driver_args:
driver_args['check_same_thread'] = False driver_args['check_same_thread'] = False
if not 'detect_types' in driver_args: if not 'detect_types' in driver_args:
@@ -6633,7 +6640,7 @@ class DAL(object):
db = super(DAL, cls).__new__(cls) db = super(DAL, cls).__new__(cls)
THREAD_LOCAL.db_instances_zombie[db_uid] = db THREAD_LOCAL.db_instances_zombie[db_uid] = db
else: else:
db_uid = kwargs.get('db_uid',hashlib.md5(repr(uri)).hexdigest()) db_uid = kwargs.get('db_uid',hashlib_md5(repr(uri)).hexdigest())
if db_uid in THREAD_LOCAL.db_instances_zombie: if db_uid in THREAD_LOCAL.db_instances_zombie:
db = THREAD_LOCAL.db_instances_zombie[db_uid] db = THREAD_LOCAL.db_instances_zombie[db_uid]
del THREAD_LOCAL.db_instances_zombie[db_uid] del THREAD_LOCAL.db_instances_zombie[db_uid]
@@ -6798,7 +6805,7 @@ class DAL(object):
db_codec=db_codec) db_codec=db_codec)
migrate = fake_migrate = False migrate = fake_migrate = False
adapter = self._adapter adapter = self._adapter
self._uri_hash = hashlib.md5(adapter.uri).hexdigest() self._uri_hash = hashlib_md5(adapter.uri).hexdigest()
self._tables = SQLCallableList() self._tables = SQLCallableList()
self.check_reserved = check_reserved self.check_reserved = check_reserved
if self.check_reserved: if self.check_reserved:
@@ -8792,7 +8799,7 @@ class Set(object):
cache_model, time_expire = cache cache_model, time_expire = cache
sql = self._count(distinct=distinct) sql = self._count(distinct=distinct)
key = db._uri + '/' + sql key = db._uri + '/' + sql
if len(key)>200: key = hashlib.md5(key).hexdigest() if len(key)>200: key = hashlib_md5(key).hexdigest()
return cache_model( return cache_model(
key, key,
(lambda self=self,distinct=distinct: \ (lambda self=self,distinct=distinct: \
+8 -5
View File
@@ -13,7 +13,10 @@ else:
import unittest import unittest
import datetime import datetime
import cStringIO try:
import cStringIO as StringIO
except:
from io import StringIO
from dal import DAL, Field, Table, SQLALL from dal import DAL, Field, Table, SQLALL
ALLOWED_DATATYPES = [ ALLOWED_DATATYPES = [
@@ -555,11 +558,11 @@ class TestImportExportFields(unittest.TestCase):
id = db.person.insert(name=str(k)) id = db.person.insert(name=str(k))
db.pet.insert(friend=id,name=str(k)) db.pet.insert(friend=id,name=str(k))
db.commit() db.commit()
stream = cStringIO.StringIO() stream = StringIO.StringIO()
db.export_to_csv_file(stream) db.export_to_csv_file(stream)
db(db.pet).delete() db(db.pet).delete()
db(db.person).delete() db(db.person).delete()
stream = cStringIO.StringIO(stream.getvalue()) stream = StringIO.StringIO(stream.getvalue())
db.import_from_csv_file(stream) db.import_from_csv_file(stream)
assert db(db.person.id==db.pet.friend)(db.person.name==db.pet.name).count()==10 assert db(db.person.id==db.pet.friend)(db.person.name==db.pet.name).count()==10
db.pet.drop() db.pet.drop()
@@ -579,9 +582,9 @@ class TestImportExportUuidFields(unittest.TestCase):
id = db.person.insert(name=str(k),uuid=str(k)) id = db.person.insert(name=str(k),uuid=str(k))
db.pet.insert(friend=id,name=str(k)) db.pet.insert(friend=id,name=str(k))
db.commit() db.commit()
stream = cStringIO.StringIO() stream = StringIO.StringIO()
db.export_to_csv_file(stream) db.export_to_csv_file(stream)
stream = cStringIO.StringIO(stream.getvalue()) stream = StringIO.StringIO(stream.getvalue())
db.import_from_csv_file(stream) db.import_from_csv_file(stream)
assert db(db.person).count()==10 assert db(db.person).count()==10
assert db(db.person.id==db.pet.friend)(db.person.name==db.pet.name).count()==20 assert db(db.person.id==db.pet.friend)(db.person.name==db.pet.name).count()==20
+1 -1
View File
@@ -38,7 +38,7 @@ try:
except ImportError: except ImportError:
try: try:
from .aes import AES from .aes import AES
except ImportError: except (ImportError, ValueError):
from contrib.aes import AES from contrib.aes import AES
try: try: