Re: [Rest2web-develop] Last Commit
Brought to you by:
mjfoord
From: Michael F. <mi...@pc...> - 2005-08-07 23:03:21
|
Hello Nicola, -----Original Message----- >From: "Nicola Larosa"<ni...@te...> >Sent: 07/08/05 22:29:33 >To: "res...@li..."<res...@li...> >Subject: Re: [Rest2web-develop] Last Commit >>> The first one: there is no default value. There should be a way to check >>> a param's value, when it is set in the config file, or else to fill in a >>> default value when it is not. As it is, one may leave the configspec >>> empty, meaning that the value may not be present: alas, by doing so one >>> loses any check on the value, and there's no default value anyway. > >> Easy - allow all the functions to take a keyword argument 'default'. >> Amend ConfigObj so that instead of automatically failing missing values >> it calls the tests with a 'missing=True' keyword. >> >> The test function can then decide if being missing is an automatic fail. >> If a default is available - then it's not. > >It sounds easy enough, I'll try it. > Cool - you can implement the whole thing. In ConfigObj.validate it currently *automatically* fails missing keys. Parsing the configspec will automatically create missing sections already (but they'llmbe empty). Instead it should now merely pass a ``missing=True`` keyword to validate.check and ``None`` as the value. In Validator.check - if missing = True and no default keyword is supplied in the configspec - then an Exception should be raised (check fails). Otherwise the default should be passed to the check function instead. Create a new section attribute ``_defaults``. If a test passes where a value was missing (so the default was used) ConfigObj.validate should add the key to ``_defaults``. Section.__setitem__ should remove a key from ``_defaults`` if the key is altered other than by the validate method. ``write`` should then not write out keys in the ``_defaults`` list. Easy hey :-) You still end up writing section markers for empty sections though. [snip..] >>>> Hmmm... Well I want to get validate working as a Section attribute >>>> rather than an attribute just on ConfigObj... > >> In the version you now have, the configspec is a Section attribute - a >> dictionary of tests for that section. > >So I can already reuse the same configspec to instantiate a Section, and >attach it to a ConfigObj? Cool. > Hmm.. Not quite I don't think. You can do : c = ConfigObj(filename) # # suppose configspec is a dictionary of checks c['section'] = {} c['section'].configspec = configspec c['section2'] = {} c['section2'].configspec = configspec Which is nearly what you said ? Best Regards, Fuzzyman http://www.voidspace.org.uk/python >------------------------------------------------------- >SF.Net email is Sponsored by the Better Software Conference & EXPO >September 19-22, 2005 * San Francisco, CA * Development Lifecycle Practices >Agile & Plan-Driven Development * Managing Projects & Teams * Testing & QA >Security * Process Improvement & Measurement * http://www.sqe.com/bsce5sf >_______________________________________________ >Rest2web-develop mailing list >Res...@li... >https://lists.sourceforge.net/lists/listinfo/rest2web-develop > > > |