|
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 |