|
From: Rob D. <rd...@gm...> - 2015-01-22 13:19:48
|
Getting the same results implies that we're using the same version of Python/configobj, which is nice.
The real reason I wrote that example up was to give you a string formatted configspec example that I believed should work, and one that appeared to be formatted the same way your example was (But with a different error message than what you had posted before).
Is there a way to either link to your code repo, or at least paste the real config file and validation code to a gist?
On Thu, Jan 22, 2015 at 12:37 AM, Darren Spruell <pha...@gm...>
wrote:
> Same results running the Gist:
> $ python config_fest.py
> expected to fail: formatted: [(['bar'], 'category', VdtValueError('the
> value "unknown" is unacceptable.',))]
> expected to pass: formatted: []
> expected to fail: unformatted: [(['bar'], 'category',
> VdtUnknownCheckError('the check "allowed_category_options" is
> unknown.',))]
> expected to pass: unformatted: [(['bar'], 'category',
> VdtUnknownCheckError('the check "allowed_category_options" is
> unknown.',))]
> I have to admit ignorance knowing quite how to interpret that though.
> - Darren
> (My turn to be sorry for a late reply).
> On Wed, Jan 14, 2015 at 8:31 AM, Rob Dennis <rd...@gm...> wrote:
>> (sorry for the late reply; work situation came up when I started to reply
>> earlier, but I had already checked off that I had responded)
>>
>> I've taken your brief example and made a gist that you can execute:
>> https://gist.github.com/robdennis/bf13312a078fe8557101
>> Unfortunately, I don't expect your example to work as written, since it'd
>> need the constructed "option" string to be formatted into the configspec.
>>
>> You have a different error message though, so I'm assuming there's some
>> other issue that's not obvious from what you included.
>>
>> the output I show for the test:
>> ```
>> expected to fail: formatted: [(['bar'], 'category', VdtValueError('the value
>> "unknown" is unacceptable.',))]
>> expected to pass: formatted: []
>> expected to fail: unformatted: [(['bar'], 'category',
>> VdtUnknownCheckError('the check "allowed_category_options" is unknown.',))]
>> expected to pass: unformatted: [(['bar'], 'category',
>> VdtUnknownCheckError('the check "allowed_category_options" is unknown.',))]
>> ```
>>
>> Maybe give it a shot and see if that gets your closer?
>>
>> On Sat, Jan 10, 2015 at 6:12 PM, Darren Spruell <pha...@gm...>
>> wrote:
>>>
>>> Thanks. I think it's on the right track (repr() didn't occur to me
>>> before), but although testing with Validator.check() works, I still
>>> get validation failures when using the resulting code within a
>>> configspec.
>>>
>>> BTW this is CPython 2.6.6.
>>>
>>>
>>> # DEFAULTS['CATEGORIES'] is the list() of categories
>>> allowed_category_options = "option({0})".format(
>>> ', '.join([repr(cat) for cat in DEFAULTS['CATEGORIES']])
>>> )
>>>
>>> CONFIGSPEC = '''\
>>> logfile = string
>>> [foo]
>>> user = string
>>> pass = string
>>> [bar]
>>> [[__many__]]
>>> category = allowed_category_options
>>> '''
>>>
>>> config = ConfigObj(conf_file, configspec=CONFIGSPEC.splitlines())
>>> validator = Validator()
>>> results = config.validate(validator)
>>>
>>>
>>> Results in:
>>> The 'category' key in section 'bar, 2019761' failed validation
>>>
>>> Should this type of usage in a configspec (the way it's being parsed
>>> in my case) work correctly?
>>>
>>> DS
>>>
>>>
>>> On Sat, Jan 10, 2015 at 6:26 AM, Rob Dennis <rd...@gm...> wrote:
>>> > Hello Darren,
>>> >
>>> > I'm one of the current maintainers along with Eli, I'm modifying a
>>> > slightly
>>> > tweaked example from here:
>>> >
>>> > https://configobj.readthedocs.org/en/latest/validate.html#the-standard-functions
>>> >
>>> > I'm seeing the behavior I expect for handcrafting the options validator:
>>> >>>> from validate import Validator
>>> >>>> vtor = Validator()
>>> >>>> checked_val = vtor.check("option('option 1', 'option 2', 'option
>>> >>>> 3')",
>>> >>>> 'option 1')
>>> >>>> checked_val
>>> > 'option 1'
>>> >>>> checked_val = vtor.check("option('option 1', 'option 2', 'option
>>> >>>> 3')",
>>> >>>> 'option 4')
>>> > Traceback (most recent call last):
>>> > File "<stdin>", line 1, in <module>
>>> > File "validate.py", line 625, in check
>>> > return self._check_value(value, fun_name, fun_args, fun_kwargs)
>>> > File "validate.py", line 657, in _check_value
>>> > return fun(value, *fun_args, **fun_kwargs)
>>> > File "validate.py", line 1332, in is_option
>>> > raise VdtValueError(value)
>>> > validate.VdtValueError: the value "option 4" is unacceptable.
>>> >
>>> >
>>> > which if we tweak a bit more shows:
>>> >>>> my_categories = 'option 1', 'option 2', 'option 3'
>>> >>>> checked_val = vtor.check("option({})".format(', '.join(repr(cat) for
>>> >>>> cat
>>> >>>> in my_categories)), 'option 1')
>>> >>>> checked_val
>>> > 'option 1'
>>> >
>>> > note the example still does use join, but is also joining the repr of
>>> > each
>>> > element (to get the quotes around strings, mostly)
>>> >>>> "option({})".format(', '.join(repr(cat) for cat in my_categories))
>>> > "option('option 1', 'option 2', 'option 3')"
>>> >
>>> >
>>> > Is this on the right track for what you need?
>>> > I'm out of contact for the next ~6 hours, but could try and respond
>>> > after
>>> >
>>> > On Sat, Jan 10, 2015 at 12:57 AM, Darren Spruell <pha...@gm...>
>>> > wrote:
>>> >>
>>> >> I have a case in a script where I have a data structure defined in an
>>> >> external module, which is also a library we use in the script. I'd
>>> >> like to use that data in a DRY fashion in this script (which uses
>>> >> ConfigObj) by passing the structure (a list) as the argument to the
>>> >> option() validator. The reason for this is that the data in the target
>>> >> configuration field will ultimately be passed to the external module
>>> >> and will be validated against it, so the external module is
>>> >> essentially "authoritative" for the application.
>>> >>
>>> >> In the external module (mylib.py):
>>> >>
>>> >> CATEGORIES = ['WHITE', 'GREEN', 'AMBER', 'RED']
>>> >>
>>> >>
>>> >> In the script:
>>> >>
>>> >> from mylib import CATEGORIES as allowed_categories
>>> >>
>>> >> CONFIGSPEC = '''\
>>> >> logfile = string
>>> >> [foo]
>>> >> user = string
>>> >> pass = string
>>> >> [bar]
>>> >> [[__many__]]
>>> >> category = string
>>> >> '''
>>> >>
>>> >>
>>> >> As shown I currently validate the 'category' option with string(), but
>>> >> I'd really like to use option() instead with the set of choices taken
>>> >> from the list imported from mylib; something like the following:
>>> >>
>>> >> category = option(allowed_categories)
>>> >>
>>> >> That syntax doesn't work and various attempts to coerce the list into
>>> >> a string that resembles a list of allowed values with join() hasn't
>>> >> done the trick. Is there currently a way to get this to function as I
>>> >> want? Any way to allow option() to accept a tuple or list as the
>>> >> arguments to ease working with structured data for that validator?
>>> >>
>>> >> --
>>> >> Darren Spruell
>>> >> pha...@gm...
>>> >>
>>> >>
>>> >>
>>> >> ------------------------------------------------------------------------------
>>> >> Dive into the World of Parallel Programming! The Go Parallel Website,
>>> >> sponsored by Intel and developed in partnership with Slashdot Media, is
>>> >> your
>>> >> hub for all things parallel software development, from weekly thought
>>> >> leadership blogs to news, videos, case studies, tutorials and more.
>>> >> Take a
>>> >> look and join the conversation now. http://goparallel.sourceforge.net
>>> >> _______________________________________________
>>> >> Configobj-develop mailing list
>>> >> Con...@li...
>>> >> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>>> >
>>> >
>>> >
>>> >
>>> > ------------------------------------------------------------------------------
>>> > Dive into the World of Parallel Programming! The Go Parallel Website,
>>> > sponsored by Intel and developed in partnership with Slashdot Media, is
>>> > your
>>> > hub for all things parallel software development, from weekly thought
>>> > leadership blogs to news, videos, case studies, tutorials and more. Take
>>> > a
>>> > look and join the conversation now. http://goparallel.sourceforge.net
>>> > _______________________________________________
>>> > Configobj-develop mailing list
>>> > Con...@li...
>>> > https://lists.sourceforge.net/lists/listinfo/configobj-develop
>>> >
>>>
>>>
>>>
>>> --
>>> Darren Spruell
>>> pha...@gm...
>>>
>>>
>>> ------------------------------------------------------------------------------
>>> Dive into the World of Parallel Programming! The Go Parallel Website,
>>> sponsored by Intel and developed in partnership with Slashdot Media, is
>>> your
>>> hub for all things parallel software development, from weekly thought
>>> leadership blogs to news, videos, case studies, tutorials and more. Take a
>>> look and join the conversation now. http://goparallel.sourceforge.net
>>> _______________________________________________
>>> Configobj-develop mailing list
>>> Con...@li...
>>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>>
>>
>>
>> ------------------------------------------------------------------------------
>> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
>> GigeNET is offering a free month of service with a new server in Ashburn.
>> Choose from 2 high performing configs, both with 100TB of bandwidth.
>> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
>> http://p.sf.net/sfu/gigenet
>> _______________________________________________
>> Configobj-develop mailing list
>> Con...@li...
>> https://lists.sourceforge.net/lists/listinfo/configobj-develop
>>
> --
> Darren Spruell
> pha...@gm...
> ------------------------------------------------------------------------------
> New Year. New Location. New Benefits. New Data Center in Ashburn, VA.
> GigeNET is offering a free month of service with a new server in Ashburn.
> Choose from 2 high performing configs, both with 100TB of bandwidth.
> Higher redundancy.Lower latency.Increased capacity.Completely compliant.
> http://p.sf.net/sfu/gigenet
> _______________________________________________
> Configobj-develop mailing list
> Con...@li...
> https://lists.sourceforge.net/lists/listinfo/configobj-develop |