[Rest2web-develop] Repeated Section
Brought to you by:
mjfoord
From: Michael F. <mi...@pc...> - 2005-08-12 09:44:11
|
Hello All, I've just committed changes to ConfigObj that implement repeated sections using the '__many__' section name in the configspec. The actual code is about twenty lines - plus nearly 70 lines of tests. If a section of a configspec (including the root section) has a sub-section called '__many__' - then *this* is the configspec that will be applied to *all* sub-sections in that section. The '__many__' sub-section can itself have nested sections, including nested '__many__' sections. E.g. [cats] [[__many__]] age = float(0, default=5) height = float(default=0.25) mood = option(grumpy, aloof, vain, default=aloof) [[[description]]] coat = option(brown, grey, black, "tortoise shell", default=brown) [[[fleas]]] [[[[__many__]]]] bloodsucker = boolean(default=True) children = integer(0, default=1000) The above configspec creates a section called 'cats'. Any subsection in 'cats' must match the '__many__' configspec. So each cat has several attributes (including a subsection called 'description'). Each cat can also optionally have many fleas.... Because all the checks have defaults - if you create any empty cats and then call validate, the default values will be filled in. Nicola - you will need to properly format the doctests - as well as check that I haven't broken anything and that it works as advertised. (By the way floats become numbers like 3.000000001 when converted backwards and forward. Decimal would be better - but is a Python 2.4 module. This might not matter.) Best Regards, Fuzzyman http://www.voidspace.org.uk/python |