for bw compat, use schema_type instead of __schema_type__
This commit is contained in:
@@ -19,11 +19,11 @@ Features
|
|||||||
``bindings`` attribute of the value ``{'a':1, 'b':2}``.
|
``bindings`` attribute of the value ``{'a':1, 'b':2}``.
|
||||||
|
|
||||||
- It is no longer necessary to pass a ``typ`` argument to a SchemaNode
|
- 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.
|
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
|
This callable will be called to obtain the schema type if a ``typ`` is not
|
||||||
supplied to the constructor. The default ``SchemaNode`` object's
|
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.
|
called.
|
||||||
|
|
||||||
- SchemaNode now has a ``raise_invalid`` method which accepts a message and
|
- SchemaNode now has a ``raise_invalid`` method which accepts a message and
|
||||||
|
|||||||
@@ -1650,7 +1650,7 @@ class _SchemaNode(object):
|
|||||||
self.typ = arg[0]
|
self.typ = arg[0]
|
||||||
_add_node_children(self, arg[1:])
|
_add_node_children(self, arg[1:])
|
||||||
else:
|
else:
|
||||||
self.typ = self.__schema_type__()
|
self.typ = self.schema_type()
|
||||||
|
|
||||||
# bw compat forces us to manufacture a title if one is not supplied
|
# bw compat forces us to manufacture a title if one is not supplied
|
||||||
title = kw.get('title', _marker)
|
title = kw.get('title', _marker)
|
||||||
@@ -1663,10 +1663,10 @@ class _SchemaNode(object):
|
|||||||
self.__dict__.update(kw)
|
self.__dict__.update(kw)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __schema_type__():
|
def schema_type():
|
||||||
raise NotImplementedError(
|
raise NotImplementedError(
|
||||||
'Schema node construction without a typ argument or '
|
'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
|
@property
|
||||||
@@ -1944,15 +1944,15 @@ SchemaNode = _SchemaMeta(
|
|||||||
)
|
)
|
||||||
|
|
||||||
class Schema(SchemaNode):
|
class Schema(SchemaNode):
|
||||||
__schema_type__ = Mapping
|
schema_type = Mapping
|
||||||
|
|
||||||
MappingSchema = Schema
|
MappingSchema = Schema
|
||||||
|
|
||||||
class TupleSchema(SchemaNode):
|
class TupleSchema(SchemaNode):
|
||||||
__schema_type__ = Tuple
|
schema_type = Tuple
|
||||||
|
|
||||||
class SequenceSchema(SchemaNode):
|
class SequenceSchema(SchemaNode):
|
||||||
__schema_type__ = Sequence
|
schema_type = Sequence
|
||||||
|
|
||||||
def __init__(self, *args, **kw):
|
def __init__(self, *args, **kw):
|
||||||
SchemaNode.__init__(self, *args, **kw)
|
SchemaNode.__init__(self, *args, **kw)
|
||||||
|
|||||||
@@ -2383,7 +2383,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
|
|||||||
def test_subclass_uses_validator_method(self):
|
def test_subclass_uses_validator_method(self):
|
||||||
import colander
|
import colander
|
||||||
class MyNode(colander.SchemaNode):
|
class MyNode(colander.SchemaNode):
|
||||||
__schema_type__ = colander.Int
|
schema_type = colander.Int
|
||||||
name = 'my'
|
name = 'my'
|
||||||
def validator(self, node, cstruct):
|
def validator(self, node, cstruct):
|
||||||
if cstruct > 10:
|
if cstruct > 10:
|
||||||
@@ -2394,7 +2394,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
|
|||||||
def test_subclass_uses_missing(self):
|
def test_subclass_uses_missing(self):
|
||||||
import colander
|
import colander
|
||||||
class MyNode(colander.SchemaNode):
|
class MyNode(colander.SchemaNode):
|
||||||
__schema_type__ = colander.Int
|
schema_type = colander.Int
|
||||||
name = 'my'
|
name = 'my'
|
||||||
missing = 10
|
missing = 10
|
||||||
node = MyNode()
|
node = MyNode()
|
||||||
@@ -2404,7 +2404,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
|
|||||||
def test_subclass_value_overridden_by_constructor(self):
|
def test_subclass_value_overridden_by_constructor(self):
|
||||||
import colander
|
import colander
|
||||||
class MyNode(colander.SchemaNode):
|
class MyNode(colander.SchemaNode):
|
||||||
__schema_type__ = colander.Int
|
schema_type = colander.Int
|
||||||
name = 'my'
|
name = 'my'
|
||||||
missing = 10
|
missing = 10
|
||||||
node = MyNode(missing=5)
|
node = MyNode(missing=5)
|
||||||
@@ -2414,7 +2414,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
|
|||||||
def test_method_values_can_rely_on_binding(self):
|
def test_method_values_can_rely_on_binding(self):
|
||||||
import colander
|
import colander
|
||||||
class MyNode(colander.SchemaNode):
|
class MyNode(colander.SchemaNode):
|
||||||
__schema_type__ = colander.Int
|
schema_type = colander.Int
|
||||||
def amethod(self):
|
def amethod(self):
|
||||||
return self.bindings['request']
|
return self.bindings['request']
|
||||||
|
|
||||||
@@ -2425,7 +2425,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
|
|||||||
def test_nonmethod_values_can_rely_on_after_bind(self):
|
def test_nonmethod_values_can_rely_on_after_bind(self):
|
||||||
import colander
|
import colander
|
||||||
class MyNode(colander.SchemaNode):
|
class MyNode(colander.SchemaNode):
|
||||||
__schema_type__ = colander.Int
|
schema_type = colander.Int
|
||||||
def after_bind(self, node, kw):
|
def after_bind(self, node, kw):
|
||||||
self.missing = kw['missing']
|
self.missing = kw['missing']
|
||||||
|
|
||||||
@@ -2436,7 +2436,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
|
|||||||
def test_deferred_methods_dont_quite_work_yet(self):
|
def test_deferred_methods_dont_quite_work_yet(self):
|
||||||
import colander
|
import colander
|
||||||
class MyNode(colander.SchemaNode):
|
class MyNode(colander.SchemaNode):
|
||||||
__schema_type__ = colander.Int
|
schema_type = colander.Int
|
||||||
@colander.deferred
|
@colander.deferred
|
||||||
def avalidator(self, node, kw): # pragma: no cover
|
def avalidator(self, node, kw): # pragma: no cover
|
||||||
def _avalidator(node, cstruct):
|
def _avalidator(node, cstruct):
|
||||||
@@ -2451,7 +2451,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
|
|||||||
def _missing(node, kw):
|
def _missing(node, kw):
|
||||||
return 10
|
return 10
|
||||||
class MyNode(colander.SchemaNode):
|
class MyNode(colander.SchemaNode):
|
||||||
__schema_type__ = colander.Int
|
schema_type = colander.Int
|
||||||
missing = colander.deferred(_missing)
|
missing = colander.deferred(_missing)
|
||||||
|
|
||||||
node = MyNode()
|
node = MyNode()
|
||||||
@@ -2461,7 +2461,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
|
|||||||
def test_functions_can_be_deferred(self):
|
def test_functions_can_be_deferred(self):
|
||||||
import colander
|
import colander
|
||||||
class MyNode(colander.SchemaNode):
|
class MyNode(colander.SchemaNode):
|
||||||
__schema_type__ = colander.Int
|
schema_type = colander.Int
|
||||||
@colander.deferred
|
@colander.deferred
|
||||||
def missing(node, kw):
|
def missing(node, kw):
|
||||||
return 10
|
return 10
|
||||||
@@ -2473,7 +2473,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
|
|||||||
def test_schema_child_names_conflict_with_value_names_notused(self):
|
def test_schema_child_names_conflict_with_value_names_notused(self):
|
||||||
import colander
|
import colander
|
||||||
class MyNode(colander.SchemaNode):
|
class MyNode(colander.SchemaNode):
|
||||||
__schema_type__ = colander.Mapping
|
schema_type = colander.Mapping
|
||||||
title = colander.SchemaNode(
|
title = colander.SchemaNode(
|
||||||
colander.String(),
|
colander.String(),
|
||||||
)
|
)
|
||||||
@@ -2487,7 +2487,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
|
|||||||
name='name',
|
name='name',
|
||||||
)
|
)
|
||||||
class MyNode(colander.SchemaNode):
|
class MyNode(colander.SchemaNode):
|
||||||
__schema_type__ = colander.Mapping
|
schema_type = colander.Mapping
|
||||||
name = 'fred'
|
name = 'fred'
|
||||||
wontmatter = doesntmatter
|
wontmatter = doesntmatter
|
||||||
node = MyNode()
|
node = MyNode()
|
||||||
@@ -2504,7 +2504,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
|
|||||||
colander.String(),
|
colander.String(),
|
||||||
)
|
)
|
||||||
class MyNode(colander.SchemaNode):
|
class MyNode(colander.SchemaNode):
|
||||||
__schema_type__ = colander.Mapping
|
schema_type = colander.Mapping
|
||||||
name = 'fred'
|
name = 'fred'
|
||||||
wontmatter = doesntmatter
|
wontmatter = doesntmatter
|
||||||
class AnotherNode(MyNode):
|
class AnotherNode(MyNode):
|
||||||
@@ -2521,7 +2521,7 @@ class TestSchemaNodeSubclassing(unittest.TestCase):
|
|||||||
id='name',
|
id='name',
|
||||||
)
|
)
|
||||||
class AnotherNode(MyNode):
|
class AnotherNode(MyNode):
|
||||||
__schema_type__ = colander.Mapping
|
schema_type = colander.Mapping
|
||||||
name = 'fred'
|
name = 'fred'
|
||||||
doesntmatter = colander.SchemaNode(
|
doesntmatter = colander.SchemaNode(
|
||||||
colander.String(),
|
colander.String(),
|
||||||
@@ -3172,10 +3172,10 @@ class TestUltraDeclarative(unittest.TestCase, TestFunctional):
|
|||||||
import colander
|
import colander
|
||||||
|
|
||||||
class IntSchema(colander.SchemaNode):
|
class IntSchema(colander.SchemaNode):
|
||||||
__schema_type__ = colander.Int
|
schema_type = colander.Int
|
||||||
|
|
||||||
class StringSchema(colander.SchemaNode):
|
class StringSchema(colander.SchemaNode):
|
||||||
__schema_type__ = colander.String
|
schema_type = colander.String
|
||||||
|
|
||||||
class TupleSchema(colander.TupleSchema):
|
class TupleSchema(colander.TupleSchema):
|
||||||
tupint = IntSchema()
|
tupint = IntSchema()
|
||||||
@@ -3195,7 +3195,7 @@ class TestUltraDeclarative(unittest.TestCase, TestFunctional):
|
|||||||
validator = colander.Range(0, 10)
|
validator = colander.Range(0, 10)
|
||||||
|
|
||||||
class GlobalObjectSchema(colander.SchemaNode):
|
class GlobalObjectSchema(colander.SchemaNode):
|
||||||
def __schema_type__(self):
|
def schema_type(self):
|
||||||
return colander.GlobalObject(package=colander)
|
return colander.GlobalObject(package=colander)
|
||||||
|
|
||||||
class MainSchema(colander.MappingSchema):
|
class MainSchema(colander.MappingSchema):
|
||||||
|
|||||||
Reference in New Issue
Block a user