Public bug reported:

There are serious bugs in python 2.5.1 module ConfigParser.
file: wget -q http://browsers.garykeith.com/stream.asp?BrowsCapINI -O 
browscap.ini

Script example:
#------------------------------------------------------------------------------
#!/usr/bin/env python
#coding=utf8

import os
import ConfigParser
import sys
import string

cfg = ConfigParser.ConfigParser()

def isMobileDevice (sectionName):
        map = dict (cfg.items(sectionName))
        if 'ismobiledevice' in map:
                return map['ismobiledevice'] == 'true'
        elif 'parent' in map:
                print cfg.items (sectionName)
                return isMobileDevice (map['parent'])
        else:
                return False
        
def convertMask (mask):
        mask = string.replace (mask, '\\', '\\\\')
        mask = string.replace (mask, '.', '\\.')
        mask = string.replace (mask, '?', '.')
        mask = string.replace (mask, '*', '.*')
        for taboo in '[]{}()^$':
                mask = string.replace (mask, taboo, '\\' + taboo)
        return mask

try:
        descriptor = os.popen ('wget -q 
http://browsers.garykeith.com/stream.asp?BrowsCapINI -O -')
        cfg.readfp (descriptor)
except ConfigParser.Error:
        print 'Cannot get browscap.ini'
        sys.exit (-1)
        
mobileDeviceList = []
for section in cfg.sections():
        print section
        if isMobileDevice (section):
                mobileDeviceList.append (convertMask(section))

if len (sys.argv) > 1:
        descriptor = open (sys.argv[1], 'w')
else:
        descriptor = sys.stdout

descriptor.writelines (mobileDeviceList)
#------------------------------------------------------------------------------
And after execution got:
Traceback (most recent call last):
  File "./mobile_device_list.py", line 40, in <module>
    if isMobileDevice (section):
  File "./mobile_device_list.py", line 17, in isMobileDevice
    return isMobileDevice (map['parent'])
  File "./mobile_device_list.py", line 12, in isMobileDevice
    map = dict (cfg.items(sectionName))
  File "/usr/lib/python2.5/ConfigParser.py", line 544, in items
    raise NoSectionError(section)
ConfigParser.NoSectionError: No section: 'Seamonkey 1.1'

It was true, the ini file didn't have "Seamonkey 1.1" section. The ini file had 
a following structure:
ini file = list of named structures (sections)
each named structure (section) = list of pairs (name, value)
And some sections might have a reference to another (their parent) section by 
item ('parent', <another section name>)
But no pair has "Seamonkey 1.1" value.
Althoug, some sections has the following order of pairs:
Parent=SeaMonkey

Version=1.1
I suppose, the parser passed "\nVersion=".
Actually, there wasn't "Seamonkey" word in the whole ini file, there was only 
SeaMonkey.

** Affects: ubuntu
     Importance: Undecided
         Status: New

-- 
Errors in ConfigParser python 2.5.1 module
https://bugs.launchpad.net/bugs/145537
You received this bug notification because you are a member of Ubuntu
Bugs, which is the bug contact for Ubuntu.

-- 
ubuntu-bugs mailing list
ubuntu-bugs@lists.ubuntu.com
https://lists.ubuntu.com/mailman/listinfo/ubuntu-bugs

Reply via email to