Averroes / iniparse

Other
0 stars 0 forks source link

Problems in removing sections #1

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
From: Jeremy Evans
Date: Sat, 23 Oct 2004 12:22:32 -0700
Subject: Problem with cfgparse.remove_section

Paramjit,

I've been using cfgparse for a project I'm working on, and I'm getting
an error in remove_section.  Here's the traceback:

  File "C:\Python23\Lib\site-packages\cfgparse\compat.py", line 175, in
remove_section
    del self.data[section]
  File "C:\Python23\Lib\site-packages\cfgparse\iniparser.py", line 377,
in __delitem__
    self._data.contents.remove(self._sections[key]._lineobj)
ValueError: list.remove(x): x not in list

The section name exists in the config.  If you try to remove a section
name that doesn't exist in the config, it is silently ignored instead of
raising a NoSectionError.

Just thought I'd let you know, so you could incorporate the fixes into a
future version.  Thanks for your work on cfgparse. I was planning to
write something similar for my project, so it's saved me quite a bit of
time.

Jeremy Evans

Original issue reported on code.google.com by psobe...@gmail.com on 15 Jul 2007 at 11:15

GoogleCodeExporter commented 9 years ago
From: David Ortega
Date: Wed, 18 Oct 2006 12:22:17 +0200
Subject: Bug

Hello, trying your library I've found a little bug. I proceed to explain
you. When I try to delete a section I receive this message:

>>> from compat import ConfigParser
>>> cfg = ConfigParser()
>>> cfg.add_section("500")
>>> cfg.sections()
['500']
>>> cfg.remove_section("500")
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "compat.py", line 175, in remove_section
del self.data[section]
File "iniparser.py", line 377, in _delitem_
self._data.contents.remove(self._sections[key]._lineobj)
ValueError: list.remove(x): x not in list

This error comes from the line 377 of iniparser.py. In this line you try
 to delete an item from a list, but the object that you try to pass is
incorrect. The line says:

self._data.contents.remove(self._sections[key]._lineobj)

self._sections[key] returns a section object, this object don't have the
attribute _lineobj, but have _lines. In this way we could put _lines[0]
for obtain lineobj. The line looks now like this:

self._data.contents.remove(self._sections[key]._lines[0])

and all runs correctly.

Greetings.

Original comment by psobe...@gmail.com on 15 Jul 2007 at 11:27

GoogleCodeExporter commented 9 years ago
From: "Gregory, Matthew"
Date: Mon, 12 Feb 2007 16:17:55 -0800
Subject: newbie question about cfgparse

Hi Paramjit,

Apologies for such a trivial question; I am new to Python, but have
found your cfgparse to be very useful in preserving comments and order
in an ini file.

However, I cannot figure out how best to remove sections from an
ini_namespace once loaded.  I see from your examples that it is trivial
to remove sections from a basic_namespace instance, but when I convert
that over into a ini_namespace instance and try "del", it raises the
error "ValueError: list.remove(x): x not in list".

Here is what I've done:

from cfgparse.iniparser import ini_namespace
from cfgparse.config import basic_namespace

n = basic_namespace()
n.playlist.expand_playlist = True
n.ui.display_clock = True
n.ui.display_qlength = True
n.ui.width = 150

 = ini_namespace()
i.import_namespace(n)
del i.playlist

The last line raises the error.  Any guidance you could give would be
much appreciated.

thanks, matt

Original comment by psobe...@gmail.com on 15 Jul 2007 at 11:31

GoogleCodeExporter commented 9 years ago
Logic for deleting sections was broken.  Fixed in svn #44.

Regarding the first comment - calling remove_section() on a non-existent 
section should not raise a 
NoSectionError.  It should return false.

Original comment by psobe...@gmail.com on 16 Jul 2007 at 12:36