for bw compat, use schema_type instead of __schema_type__

This commit is contained in:
Chris McDonough
2012-10-09 13:15:55 -04:00
parent bbb0edade9
commit 50373defdf
3 changed files with 23 additions and 23 deletions

View File

@@ -19,11 +19,11 @@ Features
``bindings`` attribute of the value ``{'a':1, 'b':2}``.
- It is no longer necessary to pass a ``typ`` argument to a SchemaNode
constructor if the node class has a ``__schema_type__`` callable as a class
constructor if the node class has a ``schema_type`` callable as a class
attribute which, when called with no arguments, returns a schema type.
This callable will be called to obtain the schema type if a ``typ`` is not
supplied to the constructor. The default ``SchemaNode`` object's
``__schema_type__`` callable raises a ``NotImplementedError`` when it is
``schema_type`` callable raises a ``NotImplementedError`` when it is
called.
- SchemaNode now has a ``raise_invalid`` method which accepts a message and

View File

@@ -1650,7 +1650,7 @@ class _SchemaNode(object):
self.typ = arg[0]
_add_node_children(self, arg[1:])
else:
self.typ = self.__schema_type__()
self.typ = self.schema_type()
# bw compat forces us to manufacture a title if one is not supplied
title = kw.get('title', _marker)
@@ -1663,10 +1663,10 @@ class _SchemaNode(object):
self.__dict__.update(kw)
@staticmethod
def __schema_type__():
def schema_type():
raise NotImplementedError(
'Schema node construction without a typ argument or '
'a __schema_node__ callable present on the node class '
'a schema_type() callable present on the node class '
)
@property
@@ -1944,15 +1944,15 @@ SchemaNode = _SchemaMeta(
)
class Schema(SchemaNode):
__schema_type__ = Mapping
schema_type = Mapping
MappingSchema = Schema
class TupleSchema(SchemaNode):
__schema_type__ = Tuple
schema_type = Tuple
class SequenceSchema(SchemaNode):
__schema_type__ = Sequence
schema_type = Sequence
def __init__(self, *args, **kw):
SchemaNode.__init__(self, *args, **kw)

View File

@@ -2383,7 +2383,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
def test_subclass_uses_validator_method(self):
import colander
class MyNode(colander.SchemaNode):
__schema_type__ = colander.Int
schema_type = colander.Int
name = 'my'
def validator(self, node, cstruct):
if cstruct > 10:
@@ -2394,7 +2394,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
def test_subclass_uses_missing(self):
import colander
class MyNode(colander.SchemaNode):
__schema_type__ = colander.Int
schema_type = colander.Int
name = 'my'
missing = 10
node = MyNode()
@@ -2404,7 +2404,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
def test_subclass_value_overridden_by_constructor(self):
import colander
class MyNode(colander.SchemaNode):
__schema_type__ = colander.Int
schema_type = colander.Int
name = 'my'
missing = 10
node = MyNode(missing=5)
@@ -2414,7 +2414,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
def test_method_values_can_rely_on_binding(self):
import colander
class MyNode(colander.SchemaNode):
__schema_type__ = colander.Int
schema_type = colander.Int
def amethod(self):
return self.bindings['request']
@@ -2425,7 +2425,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
def test_nonmethod_values_can_rely_on_after_bind(self):
import colander
class MyNode(colander.SchemaNode):
__schema_type__ = colander.Int
schema_type = colander.Int
def after_bind(self, node, kw):
self.missing = kw['missing']
@@ -2436,7 +2436,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
def test_deferred_methods_dont_quite_work_yet(self):
import colander
class MyNode(colander.SchemaNode):
__schema_type__ = colander.Int
schema_type = colander.Int
@colander.deferred
def avalidator(self, node, kw): # pragma: no cover
def _avalidator(node, cstruct):
@@ -2451,7 +2451,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
def _missing(node, kw):
return 10
class MyNode(colander.SchemaNode):
__schema_type__ = colander.Int
schema_type = colander.Int
missing = colander.deferred(_missing)
node = MyNode()
@@ -2461,7 +2461,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
def test_functions_can_be_deferred(self):
import colander
class MyNode(colander.SchemaNode):
__schema_type__ = colander.Int
schema_type = colander.Int
@colander.deferred
def missing(node, kw):
return 10
@@ -2473,7 +2473,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
def test_schema_child_names_conflict_with_value_names_notused(self):
import colander
class MyNode(colander.SchemaNode):
__schema_type__ = colander.Mapping
schema_type = colander.Mapping
title = colander.SchemaNode(
colander.String(),
)
@@ -2487,7 +2487,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
name='name',
)
class MyNode(colander.SchemaNode):
__schema_type__ = colander.Mapping
schema_type = colander.Mapping
name = 'fred'
wontmatter = doesntmatter
node = MyNode()
@@ -2504,7 +2504,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
colander.String(),
)
class MyNode(colander.SchemaNode):
__schema_type__ = colander.Mapping
schema_type = colander.Mapping
name = 'fred'
wontmatter = doesntmatter
class AnotherNode(MyNode):
@@ -2521,7 +2521,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
id='name',
)
class AnotherNode(MyNode):
__schema_type__ = colander.Mapping
schema_type = colander.Mapping
name = 'fred'
doesntmatter = colander.SchemaNode(
colander.String(),
@@ -3172,10 +3172,10 @@ class TestUltraDeclarative(unittest.TestCase, TestFunctional):
import colander
class IntSchema(colander.SchemaNode):
__schema_type__ = colander.Int
schema_type = colander.Int
class StringSchema(colander.SchemaNode):
__schema_type__ = colander.String
schema_type = colander.String
class TupleSchema(colander.TupleSchema):
tupint = IntSchema()
@@ -3195,7 +3195,7 @@ class TestUltraDeclarative(unittest.TestCase, TestFunctional):
validator = colander.Range(0, 10)
class GlobalObjectSchema(colander.SchemaNode):
def __schema_type__(self):
def schema_type(self):
return colander.GlobalObject(package=colander)
class MainSchema(colander.MappingSchema):