On 03/05/2011 18:12, Gustavo Fonseca wrote:
There are lots of situations where the same data structure should be
used, and I think your suggestion would make them less reusable.
Agreed, so how about this class decorator as an alternative:
class instantiate:
def __init__(self,*args,**kw):
self.args,self.kw = args,kw
def __call__(self,class_):
return class_(*self.args,**self.kw)
Which I could use as:
class Person(colander.MappingSchema):
name = colander.SchemaNode(colander.String())
age = colander.SchemaNode(colander.Int(),
validator=colander.Range(0, 200))
@instantiate()
class friends(colander.SequenceSchema):
@instantiate()
class friend(colander.TupleSchema):
rank = colander.SchemaNode(
colander.Int(),
validator=colander.Range(0, 9999)
)
name = colander.SchemaNode(colander.String())
What do other people think about this approach?
cheers,
Chris
--
Simplistix - Content Management, Batch Processing & Python Consulting
- http://www.simplistix.co.uk
--
You received this message because you are subscribed to the Google Groups
"pylons-devel" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/pylons-devel?hl=en.