On Thu, Sep 5, 2013 at 1:22 PM, Mike Orr <[email protected]> wrote:
> Is it possible to define a Colander schema with fieldnames that aren't
> valid Python identifiers? I want to validate the settings in my INI
> file at application startup, .... But INI
> files have keys like "sqlalchemy.url" which can't be declared in
> class-attribute syntax.
Yes, using what the Colander manual calls "Defining a Schema Imperatively".
import colander
schema = colander.SchemaNode(colander.Mapping())
schema.add(colander.SchemaNode(Int), name="sqlalchemy.pool_size"))
orig = {"sqlalchemy.pool_size": "5"}
sqlalchemy.deserialize(orig)
{"sqlalchemy.pool_size": 5}
That's more verbose than putting a dict specfication in a class
attribute, but I can write a wrapper function to make a schema from a
dict.
> Also, does Colander have flags equivalent to FormEncode's
> 'allow_other_keys' and 'filter_other_keys'? Because the settings may
> have keys not mentioned in the schema, which should be preserved.
Haven't determined this yet.
--
Mike Orr <[email protected]>
--
You received this message because you are subscribed to the Google Groups
"pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/pylons-discuss.
For more options, visit https://groups.google.com/groups/opt_out.