Discussion:
[FE-discuss] Schemas with dotted variables
Mike Orr
2009-01-22 20:24:57 UTC
Permalink
FormEncode schemas seem like a good way to validate other kinds of
data besides form input, in particular a Pylons configuration from an
INI file. However, the schema format does not allow variables with
dots in their names, which is common in this situation.

I wonder if a small enhancement would alleviate this, such as treating
a double underscore in the middle of a name as a dot.

class ConfigValidator(Schema):
beaker__cache_time = Integer() # => {'beaker.cache_time': 3600}

Or the schema class could have a dict attribute of validators to merge in:

class ConfigValidator(Schema):
other_validators = {
"beaker.cache_time": Integer(),
}
--
Mike Orr <***@gmail.com>
Ian Bicking
2009-01-22 20:36:57 UTC
Permalink
Post by Mike Orr
FormEncode schemas seem like a good way to validate other kinds of
data besides form input, in particular a Pylons configuration from an
INI file. However, the schema format does not allow variables with
dots in their names, which is common in this situation.
I wonder if a small enhancement would alleviate this, such as treating
a double underscore in the middle of a name as a dot.
beaker__cache_time = Integer() # => {'beaker.cache_time': 3600}
other_validators = {
"beaker.cache_time": Integer(),
}
I'm pretty sure this works:

class ConfigValidator(Schema):
fields = {'beaker.cache_time': Integer()}
--
Ian Bicking | http://blog.ianbicking.org
Loading...