Patch for ConfigParser.py in 1.5.2

Lars Damerow lars at pixar.com
Thu May 6 13:55:49 EDT 1999


Got it.  How about this:

202c202
<         option = self.optionxform (option)
---
>         option = string.lower(option)
239,241d238
<     def optionxform (self, optionstr):
<         return string.lower (optionstr)
< 
252c249
<         r'(?P<option>[-.\w\t /]+)'            # - . _ \t " " / alphanum
---
>         r'(?P<option>[-.\w]+)'                # - . _ alphanum
313c310
<                         optname = self.optionxform(optname)
---
>                         optname = string.lower(optname)


I've still made the change to the regular expression, though that could be
factored out and changed in a subclass as well.  Now I can do this:

#-----------------------------------
import ConfigParser

class MyCP (ConfigParser):
   def optionxform (self, optionstr):
      return string.strip(optionstr)
#-----------------------------------

That's a bit safer for existing code, I think.  The name 'optionxform' is a 
bit clunky though.
Do changes like this have a chance of becoming part of the standard
distribution?

-lars

On Wed, 5 May 1999, Fredrik Lundh wrote:

> Lars Damerow <lars at pixar.com> wrote:
> > I made a slight change to ConfigParser.py from the 1.5.2 distribution.  I 
> > needed the option lines to allow spaces, slashes and whitespace as the option
> > name, as well as to leave the case of the option name intact.
> > Can anybody think of a bad reason to do this?
> 
> that it breaks existing applications?  (for which the docs say
> "option names are not case sensitive")
> 
> preferred solution: factor out the "option name" handling
> into submethods, and create a subclass that implement
> your favourite behaviour.
> 
> </F>
> 
> 
> 

___________________________________________________________
Lars Damerow
animation support guy
lars at pixar.com

"Prepare for a dose of my harmful rays!"





More information about the Python-list mailing list