types: added PickleType, its slightly trickier than trivial, so OK now its standard.
attributes: the level of pain if an AttributeError occurs inside a CallableProp, in combination with an object that implements __getattr__, is too deep for me to put the users through....so convert AttributeErrors to Assertions...
engine: im not a fan of catching universal exceptions and squashing them
if passive:
value = None
else:
- value = self.callable_()
+ try:
+ value = self.callable_()
+ except AttributeError, e:
+ # this catch/raise is because this call is frequently within an
+ # AttributeError-sensitive callstack
+ raise AssertionError("AttributeError caught in callable prop:" + str(e.args))
self.obj.__dict__[self.key] = value
p = PropHistory(self.obj, self.key, **self.kwargs)
if passive:
value = None
else:
- value = self.callable_()
+ try:
+ value = self.callable_()
+ except AttributeError, e:
+ # this catch/raise is because this call is frequently within an
+ # AttributeError-sensitive callstack
+ raise AssertionError("AttributeError caught in callable prop:" + str(e.args))
else:
value = None
p = self.manager.create_list(self.obj, self.key, value, readonly=self.live, **self.kwargs)
-
if not self.live and not passive:
# set the new history list as the new attribute, discards ourself
self.manager.attribute_history(self.obj)[self.key] = p
def __getitem__(self, key):
return self.__parent._get_col(self.__row, key)
def __getattr__(self, name):
- try:
- return self.__parent._get_col(self.__row, name)
- except:
- raise AttributeError
+ #try:
+ return self.__parent._get_col(self.__row, name)
+ #except:
+ # raise AttributeError
def items(self):
return [(key, getattr(self, key)) for key in self.keys()]
def keys(self):
list. if the instance already exists in the given identity map, its not added. in
either case, executes all the property loaders on the instance to also process extra
information in the row."""
-
# look in main identity map. if its there, we dont do anything to it,
# including modifying any of its related items lists, as its already
# been exposed to being modified by the application.
if self.extension.append_result(self, row, imap, result, instance, isnew, populate_existing=populate_existing):
if result is not None:
result.append_nohistory(instance)
-
return instance
# look in result-local identitymap for it.
# instances from the row and possibly populate this item.
if self.extension.populate_instance(self, instance, row, identitykey, imap, isnew):
self.populate_instance(instance, row, identitykey, imap, isnew, translate=False)
-
if self.extension.append_result(self, row, imap, result, instance, isnew, populate_existing=populate_existing):
if result is not None:
result.append_nohistory(instance)
-
return instance
def populate_instance(self, instance, row, identitykey, imap, isnew, translate=True):
__all__ = [ 'TypeEngine', 'TypeDecorator', 'NullTypeEngine',
'INT', 'CHAR', 'VARCHAR', 'TEXT', 'FLOAT', 'DECIMAL',
'TIMESTAMP', 'DATETIME', 'CLOB', 'BLOB', 'BOOLEAN', 'String', 'Integer', 'Smallinteger',
- 'Numeric', 'Float', 'DateTime', 'Date', 'Time', 'Binary', 'Boolean', 'Unicode', 'NULLTYPE',
+ 'Numeric', 'Float', 'DateTime', 'Date', 'Time', 'Binary', 'Boolean', 'Unicode', 'PickleType', 'NULLTYPE',
'SMALLINT', 'DATE', 'TIME'
]
import sqlalchemy.util as util
-
+try:
+ import cPickle as pickle
+except:
+ import pickle
+
class TypeEngine(object):
basetypes = []
def __init__(self, *args, **kwargs):
def get_constructor_args(self):
return {'length':self.length}
+class PickleType(Binary):
+ def __init__(self, protocol=pickle.HIGHEST_PROTOCOL):
+ """allows the pickle protocol to be specified"""
+ self.protocol = protocol
+ def convert_result_value(self, value, engine):
+ if value is None:
+ return None
+ buf = Binary.convert_result_value(self, value, engine)
+ return pickle.loads(str(buf))
+ def convert_bind_param(self, value, engine):
+ if value is None:
+ return None
+ return Binary.convert_bind_param(self, pickle.dumps(value, self.protocol), engine)
+ def get_constructor_args(self):
+ return {}
+
class Boolean(TypeEngine):
pass
def has_item(self, item):
return self.records.has_key(item)
def __setitem__(self, i, item):
- if self._setrecord(a):
+ if self._setrecord(item):
self.data[i] = item
def __delitem__(self, i):
self._delrecord(self.data[i])