Re: [Rest2web-develop] sections and configspec
Brought to you by:
mjfoord
|
From: Nicola L. <ni...@te...> - 2005-08-11 13:55:12
|
>> Or better, how do I specify that, when reading the config file, all
>> subsections of the "cats" section have to be validated against the "cat"
>> configspec, and that all subsections of the "dogs" section have to be
>> validated against the "dog" configspec?
> You want named types of configspec sections and to be able to apply
> those types in your config file.
Not necessarily "named". :-)
> In this particular example you are saying that all 'dogs' (sub-sections
> in the dogs section) should use the [[dog]] configspec and 'cats'
> (sub-sections in the cats section) should use the 'cat' configspec.
Yes.
> Two possible implementations spring to mind - named sections, or
> repeated sections. Repeated sections would meet your specific example
> here - but aren't a generic solution.
I don't care. I don't know if YAGNI, but surely INNIN (I'm Not Needing It
Now), where "it" is "named sections". Repeated sections are enough.
> I'll suggest an alternative implementation of named sections, that is
> less complicated than yesterdays.
But probably still too complicated. ;-)
> Named Sections
> ==============
>
> The trouble is that with a hierarchical structure (rather than a flat
> one) there is no unique identifier per section (sections have non unique
> names).
>
> The alternatives are either to allow sections to be named - a magic
> value (either '__name__' or '__type__') or to use something like a
> dotted syntax to reference sections 'section.sub-section.sub-sub-section'.
Dotted syntax would yield unique ids, so magic values are not needed, and
best avoided, since they're ugly. But even it is not needed anyway. :-)
> I think my previous explanation was overly complex. I favour this
> solution - using a '__type__' magic value in sections.
I don't, it's ugly.
> [ cats ]
> [[ felix ]]
> __type__ = cat
> color = black
> whiskers = 5
> [[ miao ]]
> __type__ = cat
> color = white
> whiskers = 7
> [ dogs ]
> [[ fido ]]
> __type__ = dog
> color = brown
> trained = yes
> [[ lassie ]]
> __type__ = dog
> color = grey
> trained = no
> [[ rintintin ]]
> __type__ = dog
> color = pink
> trained = no
Magic values in the config file even, not just in the configspec? Oh, the
horrors. :-)
> When parsing a configspec any __type__ values are not treated as checks,
> but a *separate* dictionary of types is kept.
>
> If the validate method encounters a section with a __type__ value it
> looks for the configspec for this section in the type dictionary.
>
> There are a couple of implementation questions if you like this
> solution.....
I don't. :-) We don't really need to give users the ability to define
custom types. That way lies madness, and XML, and ZConfig. ;-)
> Repeated sections could solve this particular example without the use of
> a magic value in the config file.
>
> You could do something like
>
> [ cats ]
> [[ __repeated__ ]]
> color = string
> whiskers = int
> [ dogs ]
> [[ __repeated__ ]]
> __type__ = dog
> color = string
> trained = boolean
>
> Effectively saying that any subsection of 'cats' or 'dogs' has to meet
> the __repeated__ specification. This isn't useful if you want to be able
> to have a 'dog' somewhere else of course.....
I don't want to. :-)
> Using the dotted syntax allows you to avoid magic values in your
> configspec (which is less useful).
But it is enough, and less ugly.
> You could do :
>
> [ dogs ]
> [[ fido ]]
> __type__ = dogs.dog
> color = brown
> trained = yes
> [[ lassie ]]
> __type__ = dogs.dog
> color = grey
> trained = no
> [[ rintintin ]]
> __type__ = dogs.dog
> color = pink
> trained = no
>
> I don't like this personally.....
Me neither. I don't want to pollute the config file this way. Types are not
the users' problem.
BTW, __repeated__ is a bit long, what about __many__?
I also need nested repeated sections:
[ cats ]
[[ __many__ ]]
color = string
whiskers = int
[[[ kittens ]]]
[[[[ __many__ ]]]]
age = string
[ dogs ]
[[ __many__ ]]
color = string
trained = boolean
[[[ puppies ]]]
[[[[ __many__ ]]]]
age = string
allowing one to write:
[ cats ]
[[ felix ]]
color = black
whiskers = 5
[[[ kittens ]]]
[[[[ mia ]]]]
age = 1
[[[[ amy ]]]]
age = 3
[ dogs ]
[[ fido ]]
color = brown
trained = yes
[[[ puppies ]]]
[[[[ fuffy ]]]]
age = 2
[[ lassie ]]
color = grey
trained = no
Yes, I like this. All those brackets are a little obtrusive, though. What
if we only keep the closing ones?
[ cats ]
[ felix ]]
color = black
whiskers = 5
[ kittens ]]]
[ mia ]]]]
age = 1
[ amy ]]]]
age = 3
[ dogs ]
[ fido ]]
color = brown
trained = yes
[ puppies ]]]
[ fuffy ]]]]
age = 2
[ lassie ]]
color = grey
trained = no
Nicer. They're not balanced anymore, but who cares? They just form tokens
here. Look, it's almost as if an invisible rope pulls and stretches them
rightward. :-)
--
Nicola Larosa - ni...@te...
When I thought life had some purpose - Then I thought I had some choice
(I was running blind)
And I made some value judgments - In a self-important voice
(I was outa line)
But then absurdity came over me - And I longed to lose control
(into no mind)
Oh all I ever wanted - Was just to come in from the cold
-- Joni Mitchell, Come in from the cold, Night Ride Home, 1991
|