|
From: Michael F. <fuz...@gm...> - 2006-03-17 13:20:51
|
On 17/03/06, Kevin Dangoor <da...@gm...> wrote: > > Hi Michael, > > I ended up discovering that the path of least resistance for > TurboGears 0.9a2 configuration was to use CherryPy''s config module. I > still see a decent possibility, though, that I'm going to need to > migrate to ConfigObj for TurboGears 1.1 (First Class). > > In order to either maintain backward compatibility with existing > config files *or* to make the transition in an automated manner, I'd > need ConfigObj to support CherryPy's "unrepr" format. It's actually a > handy format in some ways, anyhow, because it gets you a bit of type > conversion without a configspec. (A configspec will never fly with > TurboGears, because the configuration options are determined by > individual applications are parts that TurboGears brings together...) > > I have *no idea* if there's a mechanism in ConfigObj that would allow > me to do the unrepr, or if a change is required in ConfigObj itself to > do so. Here's what the config looks like: > > foo=3D"bar" > baz=3DTrue > blork=3D8 It's not currently possible. You can use the ``as_bool`` and ``as_int`` method to fetch values as integers etc. Is it just ints and booleans that are automatically converted ? What about floats ? I can't just make this change because it's not backward compatible. I can add an 'unrepr' mode as an optional keyword (default False) that implements it. Currently ConfigObj doesn't keep a record of whether a value was quoted or not, so it would take a bit of work to add this into the parsing code (and the writing code). Not too difficult though. The code from CherryPy will probably be helpful to see how it detects 'convertible values'. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > So, foo is a string, baz is a boolean and blork is an int. Quite > simple, I think. The only drawback is that the user doing the config > needs to use "" around strings. > > The unrepr that CherryPy uses is found here: > http://svn.cherrypy.org/trunk/cherrypy/lib/cptools.py > > Thoughts? > > Kevin > > -- > Kevin Dangoor > Author of the Zesty News RSS newsreader > > email: ki...@bl... > company: http://www.BlazingThings.com > blog: http://www.BlueSkyOnMars.com > -- http://www.Voidspace.org.uk The Place where headspace meets cyberspace. Online resource site - covering science, technology, computing, cyberpunk, psychology, spirituality, fictio= n and more. --- http://www.Voidspace.org.uk/python/index.shtml Python utilities, modules and apps. Including Nanagram, Dirwatcher and more. --- http://www.fuchsiashockz.co.uk http://groups.yahoo.com/group/void-shockz --- Everyone has talent. What is rare is the courage to follow talent to the dark place where it leads. -Erica Jong Ambition is a poor excuse for not having sense enough to be lazy. -Milan Kundera |
|
From: Kevin D. <da...@gm...> - 2006-03-17 13:31:04
|
On 3/17/06, Michael Foord <fuz...@gm...> wrote: > I can't just make this change because it's not backward compatible. > > I can add an 'unrepr' mode as an optional keyword (default False) that > implements it. Yes, this is what I was thinking. > Currently ConfigObj doesn't keep a record of whether a value was quoted o= r > not, so it would take a bit of work to add this into the parsing code (an= d > the writing code). Not too difficult though. If the unrepr mode is being used, the writing code should be able to just use repr(). Parsing would be different, though... > The code from CherryPy will probably be helpful to see how it detects > 'convertible values'. Yep. And that code is freely usable, as well. Kevin |
|
From: Kevin D. <da...@gm...> - 2006-03-17 16:20:42
|
On 3/17/06, Michael Foord <fuz...@gm...> wrote: > > foo=3D"bar" > > baz=3DTrue > > blork=3D8 > [snip] > > I can add an 'unrepr' mode as an optional keyword (default False) that > implements it. You know what might be interesting: the ability to provide a callback to set each value. That would allow plugging in of different sorts of unrepr-style behavior. Of course, there would have to be a companion function for handling the writing side of things as well. Kevin |
|
From: Fuzzyman <fuz...@vo...> - 2006-03-17 16:40:42
|
Kevin Dangoor wrote: > On 3/17/06, Michael Foord <fuz...@gm...> wrote: > >>> foo="bar" >>> baz=True >>> blork=8 >>> > > [snip] > >> I can add an 'unrepr' mode as an optional keyword (default False) that >> implements it. >> > > You know what might be interesting: the ability to provide a callback > to set each value. That would allow plugging in of different sorts of > unrepr-style behavior. > Hmm... sounds a little bit heavyweight for a config file reader/writer. You can actually already do this by reading the config file in with ``list_values`` set to ``False``. (This stops the parsing of values - except to remove any comment and handle multi line values I think). You then use the ``walk`` method and pass in a callable which is called on every value and each value is substituted with the return. Properly handling lists would be a pain this way - you would want to leverage the code already in ConfigObj to do this. This however this isn't symmetric with ``write`` which *currently* won't quote a value if it doesn't need it - so a string value of '1' will be written without quotes. > Of course, there would have to be a companion function for handling > the writing side of things as well. > Do you envisage needing programmatic writing from Turbogears ? If not, ConfigObj can possibly already do what you want. I'm happy to implement ``unrepr`` mode *anyway*. All the best, Fuzzyman http://www.voidspace.org.uk/python/index.shtml > Kevin > > > ------------------------------------------------------- > This SF.Net email is sponsored by xPML, a groundbreaking scripting language > that extends applications into web and mobile media. Attend the live webcast > and join the prime developer group breaking into this new coding territory! > http://sel.as-us.falkag.net/sel?cmd=k&kid0944&bid$1720&dat1642 > _______________________________________________ > Configobj-develop mailing list > Con...@li... > https://lists.sourceforge.net/lists/listinfo/configobj-develop > > |