Errors in ConfigParser python 2.5.1 module

Bug #145537 reported by Joe_Bishop on 2007-09-27
2
Affects Status Importance Assigned to Milestone
python2.5 (Ubuntu)
Undecided
Unassigned

Bug Description

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.

Markon (marco-b) wrote :

I think it' s not a ConfigParser error, because I've this traceback:

Traceback (most recent call last):
  File "conf.py", line 37, in <module>
    if isMobileDevice (section):
  File "conf.py", line 14, in isMobileDevice
    return isMobileDevice (map['parent'])
  File "conf.py", line 9, 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: 'Motorola Internet Browser'

The error should be given by the file structure (i think)

Bye

The file is
http://browsers.garykeith.com/stream.asp?BrowsCapINI

2007/12/23, Markon <email address hidden>:
>
> I think it' s not a ConfigParser error, because I've this traceback:
>
> Traceback (most recent call last):
> File "conf.py", line 37, in <module>
> if isMobileDevice (section):
> File "conf.py", line 14, in isMobileDevice
> return isMobileDevice (map['parent'])
> File "conf.py", line 9, 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: 'Motorola Internet Browser'
>
> The error should be given by the file structure (i think)
>
> Bye
>
> --
> Errors in ConfigParser python 2.5.1 module
> https://bugs.launchpad.net/bugs/145537
> You received this bug notification because you are a direct subscriber
> of the bug.
>

Matthias Klose (doko) wrote :

this works for me both in hardy and intrepid.

Changed in python2.5:
status: New → Fix Released

It was my fault - there were no errors, only non-pythonic approach used in
this library, which put me off.
The thread should be closed now.

2008/9/12 Matthias Klose <email address hidden>

> this works for me both in hardy and intrepid.
>
>
> ** Changed in: python2.5 (Ubuntu)
> Status: New => Fix Released
>
> --
> Errors in ConfigParser python 2.5.1 module
> https://bugs.launchpad.net/bugs/145537
> You received this bug notification because you are a direct subscriber
> of the bug.
>

Matthias Klose (doko) on 2008-09-12
Changed in python2.5:
status: Fix Released → Invalid
To post a comment you must log in.
This report contains Public information  Edit
Everyone can see this information.

Other bug subscribers