Author: phd
Date: 2005-01-05 12:08:42 +0000 (Wed, 05 Jan 2005)
New Revision: 510
Modified:
trunk/SQLObject/sqlobject/col.py
Log:
Applied the law of Demeter: a class should not name (instantiate)
another class directly - the other class must be a parameter. Now
UnicodeCol and BoolClo instantiate their validators using self.validatorClass;
to allow even better flexibility the validator is created in the
createValidator() method.
Modified: trunk/SQLObject/sqlobject/col.py
===================================================================
--- trunk/SQLObject/sqlobject/col.py 2005-01-05 11:43:06 UTC (rev 509)
+++ trunk/SQLObject/sqlobject/col.py 2005-01-05 12:08:42 UTC (rev 510)
@@ -354,13 +354,18 @@
return unicode(value, self.db_encoding)
class SOUnicodeCol(SOStringCol):
+ validatorClass = UnicodeStringValidator # can be overriden in descendants
def __init__(self, **kw):
self.dbEncoding = popKey(kw, 'dbEncoding', 'UTF-8')
SOStringCol.__init__(self, **kw)
self.validator = validators.All.join(
- UnicodeStringValidator(self.dbEncoding), self.validator)
+ self.createValidator(), self.validator)
+ def createValidator(self):
+ """Create a validator for the column. Can be overriden in descendants."""
+ return self.validatorClass(self.dbEncoding)
+
class UnicodeCol(Col):
baseClass = SOUnicodeCol
@@ -392,14 +397,19 @@
return sqlbuilder.TRUE
class SOBoolCol(SOCol):
+ validatorClass = BoolValidator # can be overriden in descendants
def __init__(self, **kw):
SOCol.__init__(self, **kw)
- self.validator = validators.All.join(BoolValidator(), self.validator)
+ self.validator = validators.All.join(self.createValidator(), self.validator)
def autoConstraints(self):
return [consts.isBool]
+ def createValidator(self):
+ """Create a validator for the column. Can be overriden in descendants."""
+ return self.validatorClass()
+
def _postgresType(self):
return 'BOOL'
|