Hello community,
here is the log from the commit of package python-iniparse for openSUSE:Factory
checked in at Sat Sep 18 01:46:56 CEST 2010.
--------
--- python-iniparse/python-iniparse.changes 2009-08-05 18:14:07.000000000 +0200
+++ python-iniparse/python-iniparse.changes 2010-09-16 10:42:56.000000000 +0200
@@ -1,0 +2,13 @@
+Thu Sep 16 08:42:13 UTC 2010 - coolo@novell.com
+
+- update to 0.4
+ * Fixed pickling and multiprocessing bugs
+ * Enabled auto-addition of config attributes via square bracket
+ syntax
+ * Utility function to tidy INI files
+ * Ability to change comment syntax for parsing Mercurial config
+ files
+ * Added ConfigParser exceptions and constants to the top-level
+ iniparse module
+
+-------------------------------------------------------------------
calling whatdependson for head-i586
Old:
----
iniparse-0.3.1.tar.gz
New:
----
iniparse-0.4.tar.gz
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Other differences:
------------------
++++++ python-iniparse.spec ++++++
--- /var/tmp/diff_new_pack.UQe1tj/_old 2010-09-18 01:45:41.000000000 +0200
+++ /var/tmp/diff_new_pack.UQe1tj/_new 2010-09-18 01:45:41.000000000 +0200
@@ -1,7 +1,7 @@
#
-# spec file for package python-iniparse (Version 0.3.1)
+# spec file for package python-iniparse (Version 0.4)
#
-# Copyright (c) 2009 SUSE LINUX Products GmbH, Nuernberg, Germany.
+# Copyright (c) 2010 SUSE LINUX Products GmbH, Nuernberg, Germany.
#
# All modifications and additions to the file contributed by third parties
# remain the property of their copyright owners, unless otherwise agreed
@@ -20,7 +20,7 @@
Name: python-iniparse
BuildRequires: python-setuptools
-Version: 0.3.1
+Version: 0.4
Release: 1
Summary: Python Module for Accessing and Modifying Configuration Data in INI files
Group: Development/Libraries/Python
@@ -28,6 +28,10 @@
Url: http://code.google.com/p/iniparse/
Source0: http://iniparse.googlecode.com/files/iniparse-%{version}.tar.gz
BuildRoot: %{_tmppath}/%{name}-%{version}-build
+%if %suse_version > 1120
+BuildArch: noarch
+%endif
+%py_requires
%description
iniparse is an INI parser for Python which is API compatible with the
@@ -35,13 +39,6 @@
(order of sections & options, indentation, comments, and blank lines
are preserved when data is updated), and is more convenient to use.
-
-
-Authors:
---------
- Paramjit Oberoi
- Tim Lauridsen
-
%prep
%setup -q -n iniparse-%{version}
++++++ iniparse-0.3.1.tar.gz -> iniparse-0.4.tar.gz ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/Changelog new/iniparse-0.4/Changelog
--- old/iniparse-0.3.1/Changelog 2009-03-02 16:10:56.000000000 +0100
+++ new/iniparse-0.4/Changelog 2010-06-12 18:15:17.000000000 +0200
@@ -1,3 +1,30 @@
+2010-06-12
+* released 0.4
+
+2010-05-08
+* reorganize code to remove circular imports
+* auto-create config settings when they are accessed via square bracket
+ syntax (for example, cfg[x][y]). Previously this raised KeyError.
+
+2010-05-07
+* Ensure that __special__ method lookups don't cause config attributes
+ to be added.
+
+2010-05-06
+* Fix problems with pickling INIConfig objects. This also fixes
+ multiprocessing problems.
+
+2010-04-17
+* released 0.3.2
+
+2010-02-26
+* added tidy() and change_comment_syntax() based on patch
+ by Paul Lambert.
+* added ConfigParser exceptions and constants to the iniparse module
+
+2009-03-23
+* Added debian package support contributed by Gavin Kinsey
+
2009-03-02
* released 0.3.1
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/Makefile new/iniparse-0.4/Makefile
--- old/iniparse-0.3.1/Makefile 2007-08-08 07:07:54.000000000 +0200
+++ new/iniparse-0.4/Makefile 2010-04-17 20:24:28.000000000 +0200
@@ -12,7 +12,7 @@
python setup.py sdist -d .
@echo "The archive is in ${PKGNAME}-$(SETUPVERSION).tar.gz"
-buildrpm: archive
+rpmbuild: archive
rpmbuild -ta ${PKGNAME}-$(SPECVERSION).tar.gz
pychecker:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/PKG-INFO new/iniparse-0.4/PKG-INFO
--- old/iniparse-0.3.1/PKG-INFO 2009-03-02 16:13:59.000000000 +0100
+++ new/iniparse-0.4/PKG-INFO 2010-06-12 18:47:42.000000000 +0200
@@ -1,6 +1,6 @@
Metadata-Version: 1.0
Name: iniparse
-Version: 0.3.1
+Version: 0.4
Summary: Accessing and Modifying INI files
Home-page: http://code.google.com/p/iniparse/
Author: Paramjit Oberoi
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/iniparse/__init__.py new/iniparse-0.4/iniparse/__init__.py
--- old/iniparse-0.3.1/iniparse/__init__.py 2008-12-06 23:04:23.000000000 +0100
+++ new/iniparse-0.4/iniparse/__init__.py 2010-05-08 21:36:42.000000000 +0200
@@ -3,11 +3,23 @@
# Copyright (c) 2007 Tim Lauridsen
# All Rights Reserved. See LICENSE-PSF & LICENSE for details.
-from ini import INIConfig
+from ini import INIConfig, change_comment_syntax
from config import BasicConfig, ConfigNamespace
from compat import RawConfigParser, ConfigParser, SafeConfigParser
+from utils import tidy
+
+from ConfigParser import DuplicateSectionError, \
+ NoSectionError, NoOptionError, \
+ InterpolationMissingOptionError, \
+ InterpolationDepthError, \
+ InterpolationSyntaxError, \
+ DEFAULTSECT, MAX_INTERPOLATION_DEPTH
__all__ = [
- 'INIConfig', 'BasicConfig', 'ConfigNamespace',
+ 'BasicConfig', 'ConfigNamespace',
+ 'INIConfig', 'tidy', 'change_comment_syntax',
'RawConfigParser', 'ConfigParser', 'SafeConfigParser',
+ 'DuplicateSectionError', 'NoSectionError', 'NoOptionError',
+ 'InterpolationMissingOptionError', 'InterpolationDepthError',
+ 'InterpolationSyntaxError', 'DEFAULTSECT', 'MAX_INTERPOLATION_DEPTH',
]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/iniparse/compat.py new/iniparse-0.4/iniparse/compat.py
--- old/iniparse-0.3.1/iniparse/compat.py 2009-02-22 22:18:07.000000000 +0100
+++ new/iniparse-0.4/iniparse/compat.py 2010-05-08 02:51:42.000000000 +0200
@@ -68,17 +68,13 @@
The DEFAULT section is not acknowledged.
"""
- try:
- self.data[section]
- return True
- except KeyError:
- return False
+ return (section in self.data)
def options(self, section):
"""Return a list of option names for the given section name."""
- try:
+ if section in self.data:
return list(self.data[section])
- except KeyError:
+ else:
raise NoSectionError(section)
def read(self, filenames):
@@ -119,19 +115,20 @@
raise NoSectionError(section)
if vars is not None and option in vars:
value = vars[option]
- try:
- sec = self.data[section]
+
+ sec = self.data[section]
+ if option in sec:
return sec._compat_get(option)
- except KeyError:
+ else:
raise NoOptionError(option, section)
def items(self, section):
- try:
+ if section in self.data:
ans = []
for opt in self.data[section]:
ans.append((opt, self.get(section, opt)))
return ans
- except KeyError:
+ else:
raise NoSectionError(section)
def getint(self, section, option):
@@ -151,21 +148,17 @@
def has_option(self, section, option):
"""Check for the existence of a given option in a given section."""
- try:
+ if section in self.data:
sec = self.data[section]
- except KeyError:
+ else:
raise NoSectionError(section)
- try:
- sec[option]
- return True
- except KeyError:
- return False
+ return (option in sec)
def set(self, section, option, value):
"""Set an option."""
- try:
+ if section in self.data:
self.data[section][option] = value
- except KeyError:
+ else:
raise NoSectionError(section)
def write(self, fp):
@@ -174,15 +167,14 @@
def remove_option(self, section, option):
"""Remove an option."""
- try:
+ if section in self.data:
sec = self.data[section]
- except KeyError:
+ else:
raise NoSectionError(section)
- try:
- sec[option]
+ if option in sec:
del sec[option]
return 1
- except KeyError:
+ else:
return 0
def remove_section(self, section):
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/iniparse/config.py new/iniparse-0.4/iniparse/config.py
--- old/iniparse-0.3.1/iniparse/config.py 2009-02-23 01:09:20.000000000 +0100
+++ new/iniparse-0.4/iniparse/config.py 2010-05-08 21:55:43.000000000 +0200
@@ -17,7 +17,7 @@
# Methods that must be implemented by subclasses
- def __getitem__(self, key):
+ def _getitem(self, key):
return NotImplementedError(key)
def __setitem__(self, key, value):
@@ -32,7 +32,15 @@
def _new_namespace(self, name):
raise NotImplementedError(name)
- # Machinery for converting dotted access into contained access
+ def __contains__(self, key):
+ try:
+ self._getitem(key)
+ except KeyError:
+ return False
+ return True
+
+ # Machinery for converting dotted access into container access,
+ # and automatically creating new sections/namespaces.
#
# To distinguish between accesses of class members and namespace
# keys, we first call object.__getattribute__(). If that succeeds,
@@ -43,10 +51,18 @@
# not just in the __init__() function. See BasicNamespace for
# an example.
+ def __getitem__(self, key):
+ try:
+ return self._getitem(key)
+ except KeyError:
+ return Undefined(key, self)
+
def __getattr__(self, name):
try:
- return self.__getitem__(name)
+ return self._getitem(name)
except KeyError:
+ if name.startswith('__') and name.endswith('__'):
+ raise AttributeError
return Undefined(name, self)
def __setattr__(self, name, value):
@@ -63,9 +79,10 @@
except AttributeError:
self.__delitem__(name)
- def __getstate__(self):
- return self.__dict__
-
+ # During unpickling, Python checks if the class has a __setstate__
+ # method. But, the data dicts have not been initialised yet, which
+ # leads to _getitem and hence __getattr__ raising an exception. So
+ # we explicitly impement default __setstate__ behavior.
def __setstate__(self, state):
self.__dict__.update(state)
@@ -85,6 +102,10 @@
obj = self.namespace._new_namespace(self.name)
obj[name] = value
+ def __setitem__(self, name, value):
+ obj = self.namespace._new_namespace(self.name)
+ obj[name] = value
+
# ---- Basic implementation of a ConfigNamespace
@@ -164,7 +185,7 @@
def __init__(self):
self._data = {}
- def __getitem__(self, key):
+ def _getitem(self, key):
return self._data[key]
def __setitem__(self, key, value):
@@ -215,11 +236,11 @@
name_components = name.split('.')
ns = self
for n in name_components[:-1]:
- try:
+ if n in ns:
ns = ns[n]
if not isinstance(ns, ConfigNamespace):
raise TypeError('value-namespace conflict', n)
- except KeyError:
+ else:
ns = ns._new_namespace(n)
ns[name_components[-1]] = value
@@ -259,11 +280,11 @@
for name in source:
value = source[name]
if isinstance(value, ConfigNamespace):
- try:
+ if name in target:
myns = target[name]
if not isinstance(myns, ConfigNamespace):
raise TypeError('value-namespace conflict')
- except KeyError:
+ else:
myns = target._new_namespace(name)
update_config(myns, value)
else:
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/iniparse/ini.py new/iniparse-0.4/iniparse/ini.py
--- old/iniparse-0.3.1/iniparse/ini.py 2009-03-01 23:30:31.000000000 +0100
+++ new/iniparse-0.4/iniparse/ini.py 2010-05-08 21:36:42.000000000 +0200
@@ -21,6 +21,7 @@
>>> print cfg['foo-ext'].special
1
>>> cfg.foo.newopt = 'hi!'
+ >>> cfg.baz.enabled = 0
>>> print cfg
# configure foo-application
@@ -30,6 +31,9 @@
newopt = hi!
[foo-ext]
special = 1
+ <BLANKLINE>
+ [baz]
+ enabled = 0
"""
@@ -158,6 +162,14 @@
parse = classmethod(parse)
+def change_comment_syntax(comment_chars='%;#', allow_rem=False):
+ comment_chars = re.sub(r'([\]\-\^])', r'\\\1', comment_chars)
+ regex = r'^(?P<csep>[%s]' % comment_chars
+ if allow_rem:
+ regex += '|[rR][eE][mM]'
+ regex += r')(?P<comment>.*)$'
+ CommentLine.regex = re.compile(regex)
+
class CommentLine(LineType):
regex = re.compile(r'^(?P<csep>[;#]|[rR][eE][mM])'
r'(?P<comment>.*)$')
@@ -339,7 +351,7 @@
value = re.sub('\n+', '\n', value)
return value
- def __getitem__(self, key):
+ def _getitem(self, key):
if key == '__name__':
return self._lines[-1].name
if self._optionxform: key = self._optionxform(key)
@@ -461,7 +473,7 @@
_optionxform = _make_xform_property('_optionxform', 'optionxform')
_sectionxform = _make_xform_property('_sectionxform', 'optionxform')
- def __getitem__(self, key):
+ def _getitem(self, key):
if key == DEFAULTSECT:
return self._defaults
if self._sectionxform: key = self._sectionxform(key)
@@ -628,3 +640,4 @@
if exc:
raise exc
+
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/iniparse/utils.py new/iniparse-0.4/iniparse/utils.py
--- old/iniparse-0.3.1/iniparse/utils.py 1970-01-01 01:00:00.000000000 +0100
+++ new/iniparse-0.4/iniparse/utils.py 2010-05-08 21:36:42.000000000 +0200
@@ -0,0 +1,47 @@
+import compat
+from ini import LineContainer, EmptyLine
+
+def tidy(cfg):
+ """Clean up blank lines.
+
+ This functions makes the configuration look clean and
+ handwritten - consecutive empty lines and empty lines at
+ the start of the file are removed, and one is guaranteed
+ to be at the end of the file.
+ """
+
+ if isinstance(cfg, compat.RawConfigParser):
+ cfg = cfg.data
+ cont = cfg._data.contents
+ i = 1
+ while i < len(cont):
+ if isinstance(cont[i], LineContainer):
+ tidy_section(cont[i])
+ i += 1
+ elif (isinstance(cont[i-1], EmptyLine) and
+ isinstance(cont[i], EmptyLine)):
+ del cont[i]
+ else:
+ i += 1
+
+ # Remove empty first line
+ if cont and isinstance(cont[0], EmptyLine):
+ del cont[0]
+
+ # Ensure a last line
+ if cont and not isinstance(cont[-1], EmptyLine):
+ cont.append(EmptyLine())
+
+def tidy_section(lc):
+ cont = lc.contents
+ i = 1
+ while i < len(cont):
+ if (isinstance(cont[i-1], EmptyLine) and
+ isinstance(cont[i], EmptyLine)):
+ del cont[i]
+ else:
+ i += 1
+
+ # Remove empty first line
+ if len(cont) > 1 and isinstance(cont[1], EmptyLine):
+ del cont[1]
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/python-iniparse.spec new/iniparse-0.4/python-iniparse.spec
--- old/iniparse-0.3.1/python-iniparse.spec 2009-03-02 16:12:15.000000000 +0100
+++ new/iniparse-0.4/python-iniparse.spec 2010-06-12 18:16:53.000000000 +0200
@@ -1,7 +1,7 @@
%{!?python_sitelib: %define python_sitelib %(%{__python} -c "from distutils.sysconfig import get_python_lib; print get_python_lib()")}
Name: python-iniparse
-Version: 0.3.1
+Version: 0.4
Release: 1%{?dist}
Summary: Python Module for Accessing and Modifying Configuration Data in INI files
Group: Development/Libraries
@@ -48,6 +48,10 @@
%changelog
+* Sat Jun 12 2010 Paramjit Oberoi - 0.4-1
+- Release 0.4
+* Sat Apr 17 2010 Paramjit Oberoi - 0.3.2-1
+- Release 0.3.2
* Mon Mar 2 2009 Paramjit Oberoi - 0.3.1-1
- Release 0.3.1
* Fri Feb 27 2009 Paramjit Oberoi - 0.3.0-1
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/setup.py new/iniparse-0.4/setup.py
--- old/iniparse-0.3.1/setup.py 2009-03-02 16:11:22.000000000 +0100
+++ new/iniparse-0.4/setup.py 2010-06-12 18:15:40.000000000 +0200
@@ -2,7 +2,7 @@
from distutils.core import setup
-VERSION = '0.3.1'
+VERSION = '0.4'
setup(name ='iniparse',
version = VERSION,
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/tests/__init__.py new/iniparse-0.4/tests/__init__.py
--- old/iniparse-0.3.1/tests/__init__.py 2009-03-01 17:20:28.000000000 +0100
+++ new/iniparse-0.4/tests/__init__.py 2010-05-05 23:00:22.000000000 +0200
@@ -5,6 +5,8 @@
import test_fuzz
import test_compat
import test_unicode
+import test_tidy
+import test_multiprocessing
from iniparse import config
from iniparse import ini
@@ -18,4 +20,6 @@
test_fuzz.suite(),
test_compat.suite(),
test_unicode.suite(),
+ test_tidy.suite(),
+ test_multiprocessing.suite(),
])
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/tests/test_fuzz.py new/iniparse-0.4/tests/test_fuzz.py
--- old/iniparse-0.3.1/tests/test_fuzz.py 2009-03-01 23:25:18.000000000 +0100
+++ new/iniparse-0.4/tests/test_fuzz.py 2010-05-08 21:36:42.000000000 +0200
@@ -1,10 +1,10 @@
import re
+import os
import random
import unittest
import ConfigParser
-from textwrap import dedent
from StringIO import StringIO
-from iniparse import compat, ini
+from iniparse import compat, ini, tidy
# TODO:
# tabs
@@ -69,35 +69,58 @@
class test_fuzz(unittest.TestCase):
def test_fuzz(self):
random.seed(42)
- for i in range(100):
- # parse random file with errors disabled
- s = random_ini_file()
- c = ini.INIConfig(parse_exc=False)
- c._readfp(StringIO(s))
- # check that file is preserved, except for
- # commenting out erroneous lines
- l1 = s.split('\n')
- l2 = str(c).split('\n')
- self.assertEqual(len(l1), len(l2))
- good_lines = []
- for i in range(len(l1)):
- try:
- self.assertEqual(l1[i], l2[i])
- good_lines.append(l1[i])
- except AssertionError:
- self.assertEqual('#'+l1[i], l2[i])
- # parse the good subset of the file
- # using ConfigParser
- s = '\n'.join(good_lines)
- cc = compat.RawConfigParser()
- cc.readfp(StringIO(s))
- cc_py = ConfigParser.RawConfigParser()
- cc_py.readfp(StringIO(s))
- # compare the two configparsers
- self.assertEqualSorted(cc_py.sections(), cc.sections())
- self.assertEqualSorted(cc_py.defaults().items(), cc.defaults().items())
- for sec in cc_py.sections():
- self.assertEqualSorted(cc_py.items(sec), cc.items(sec))
+ try:
+ num_iter = int(os.environ['INIPARSE_FUZZ_ITERATIONS'])
+ except (KeyError, ValueError):
+ num_iter = 100
+ for fuzz_iter in range(num_iter):
+ try:
+ # parse random file with errors disabled
+ s = random_ini_file()
+ c = ini.INIConfig(parse_exc=False)
+ c._readfp(StringIO(s))
+ # check that file is preserved, except for
+ # commenting out erroneous lines
+ l1 = s.split('\n')
+ l2 = str(c).split('\n')
+ self.assertEqual(len(l1), len(l2))
+ good_lines = []
+ for i in range(len(l1)):
+ try:
+ self.assertEqual(l1[i], l2[i])
+ good_lines.append(l1[i])
+ except AssertionError:
+ self.assertEqual('#'+l1[i], l2[i])
+ # parse the good subset of the file
+ # using ConfigParser
+ s = '\n'.join(good_lines)
+ cc = compat.RawConfigParser()
+ cc.readfp(StringIO(s))
+ cc_py = ConfigParser.RawConfigParser()
+ cc_py.readfp(StringIO(s))
+ # compare the two configparsers
+ self.assertEqualConfig(cc_py, cc)
+ # check that tidy does not change semantics
+ tidy(cc)
+ cc_tidy = ConfigParser.RawConfigParser()
+ cc_tidy.readfp(StringIO(str(cc.data)))
+ self.assertEqualConfig(cc_py, cc_tidy)
+ except AssertionError:
+ fname = 'fuzz-test-iter-%d.ini' % fuzz_iter
+ print 'Fuzz test failed at iteration', fuzz_iter
+ print 'Writing out failing INI file as', fname
+ f = open(fname, 'w')
+ f.write(s)
+ f.close()
+ raise
+
+ def assertEqualConfig(self, c1, c2):
+ self.assertEqualSorted(c1.sections(), c2.sections())
+ self.assertEqualSorted(c1.defaults().items(), c2.defaults().items())
+ for sec in c1.sections():
+ self.assertEqualSorted(c1.options(sec), c2.options(sec))
+ for opt in c1.options(sec):
+ self.assertEqual(c1.get(sec, opt), c2.get(sec, opt))
def assertEqualSorted(self, l1, l2):
l1.sort()
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/tests/test_ini.py new/iniparse-0.4/tests/test_ini.py
--- old/iniparse-0.3.1/tests/test_ini.py 2009-03-01 17:17:10.000000000 +0100
+++ new/iniparse-0.4/tests/test_ini.py 2010-05-08 21:36:03.000000000 +0200
@@ -218,6 +218,20 @@
self.assertEqual(p.section1.just.__class__, config.Undefined)
self.assertEqual(p.section2.help.__class__, config.Undefined)
+ def test_newsection(self):
+ sio = StringIO(self.s1)
+ p = ini.INIConfig(sio)
+ p.new1.created = 1
+ setattr(getattr(p, 'new2'), 'created', 1)
+ p.new3['created'] = 1
+ p['new4'].created = 1
+ p['new5']['created'] = 1
+ self.assertEqual(p.new1.created, 1)
+ self.assertEqual(p.new2.created, 1)
+ self.assertEqual(p.new3.created, 1)
+ self.assertEqual(p.new4.created, 1)
+ self.assertEqual(p.new5.created, 1)
+
def test_order(self):
sio = StringIO(self.s1)
p = ini.INIConfig(sio)
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/tests/test_misc.py new/iniparse-0.4/tests/test_misc.py
--- old/iniparse-0.3.1/tests/test_misc.py 2009-02-28 22:59:08.000000000 +0100
+++ new/iniparse-0.4/tests/test_misc.py 2010-05-05 07:15:39.000000000 +0200
@@ -1,3 +1,4 @@
+import re
import unittest
import pickle
import ConfigParser
@@ -384,19 +385,66 @@
c = cfg_class()
c.readfp(StringIO(self.s))
self.do_compat_checks(c)
- p = pickle.dumps(c)
- c = None
- c2 = pickle.loads(p)
- self.do_compat_checks(c2)
+ for i in range(0, pickle.HIGHEST_PROTOCOL+1):
+ p = pickle.dumps(c, protocol=i)
+ c2 = pickle.loads(p)
+ self.do_compat_checks(c2)
def test_ini(self):
c = ini.INIConfig()
c._readfp(StringIO(self.s))
self.do_ini_checks(c)
- p = pickle.dumps(c)
- c = None
- c2 = pickle.loads(p)
- self.do_ini_checks(c2)
+ for i in range(0, pickle.HIGHEST_PROTOCOL+1):
+ p = pickle.dumps(c, protocol=i)
+ c2 = pickle.loads(p)
+ self.do_ini_checks(c2)
+
+class test_comment_syntax(unittest.TestCase):
+ """Test changing comment syntax with change_comment_syntax"""
+
+ def test_regex(self):
+ # original regular expression
+ org_regex = re.compile(r'^(?P<csep>[;#]|[rR][eE][mM])(?P<comment>.*)$')
+ ini.change_comment_syntax(';#', True)
+ self.assertEqual(ini.CommentLine.regex, org_regex)
+
+ # mercurial-safe comment line regex, as given by Steve Borho & Paul Lambert
+ # bitbucket.org/tortoisehg/stable/src/tip/tortoisehg/hgtk/thgconfig.py#cl-1084
+ # http://groups.google.com/group/iniparse-discuss/msg/b41a54aa185a9b7c
+ hg_regex = re.compile(r'^(?P<csep>[%;#])(?P<comment>.*)$')
+ ini.change_comment_syntax('%;#', False)
+ self.assertEqual(ini.CommentLine.regex, hg_regex)
+
+ # change_comment_syntax() defaults to hg regex
+ ini.change_comment_syntax()
+ self.assertEqual(ini.CommentLine.regex, hg_regex)
+
+ # test escaping of special chars in pattern
+ regex = re.compile(r'^(?P<csep>[;#\-\^[\]])(?P<comment>.*)$')
+ ini.change_comment_syntax(';#-^[]')
+ self.assertEqual(ini.CommentLine.regex, regex)
+
+ def test_ignore_includes(self):
+ ini.change_comment_syntax()
+ cfg = ini.INIConfig(StringIO(dedent("""
+ # This is a mercurial-style config
+ % include foobar
+
+ [ui]
+ username = Firstname Lastname
+ """)))
+ self.assertEqual(cfg.ui.username, 'Firstname Lastname ')
+ self.assertEqual(str(cfg), dedent("""
+ # This is a mercurial-style config
+ % include foobar
+
+ [ui]
+ username = Firstname Lastname
+ """))
+
+ def tearDown(self):
+ ini.change_comment_syntax(';#', True)
+
class suite(unittest.TestSuite):
def __init__(self):
@@ -408,4 +456,5 @@
unittest.makeSuite(test_custom_dict, 'test'),
unittest.makeSuite(test_compat, 'test'),
unittest.makeSuite(test_pickle, 'test'),
- ])
\ No newline at end of file
+ unittest.makeSuite(test_comment_syntax, 'test'),
+ ])
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/tests/test_multiprocessing.py new/iniparse-0.4/tests/test_multiprocessing.py
--- old/iniparse-0.3.1/tests/test_multiprocessing.py 1970-01-01 01:00:00.000000000 +0100
+++ new/iniparse-0.4/tests/test_multiprocessing.py 2010-05-07 07:45:01.000000000 +0200
@@ -0,0 +1,33 @@
+import unittest
+try:
+ from multiprocessing import Process, Queue, Pipe
+ disabled = False
+except ImportError:
+ disabled = True
+
+from iniparse import compat, ini
+
+class test_ini(unittest.TestCase):
+ """Test sending INIConfig objects."""
+
+ def test_queue(self):
+ def getxy(q, w):
+ cfg = q.get_nowait()
+ w.put(cfg.x.y)
+ cfg = ini.INIConfig()
+ cfg.x.y = '42'
+ q = Queue()
+ w = Queue()
+ q.put(cfg)
+ p = Process(target=getxy, args=(q, w))
+ p.start()
+ self.assertEqual(w.get(timeout=1), '42')
+
+class suite(unittest.TestSuite):
+ def __init__(self):
+ if disabled:
+ unittest.TestSuite.__init__(self, [])
+ else:
+ unittest.TestSuite.__init__(self, [
+ unittest.makeSuite(test_ini, 'test'),
+ ])
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/iniparse-0.3.1/tests/test_tidy.py new/iniparse-0.4/tests/test_tidy.py
--- old/iniparse-0.3.1/tests/test_tidy.py 1970-01-01 01:00:00.000000000 +0100
+++ new/iniparse-0.4/tests/test_tidy.py 2010-05-08 21:36:42.000000000 +0200
@@ -0,0 +1,136 @@
+import unittest
+from textwrap import dedent
+from StringIO import StringIO
+
+from iniparse import tidy,INIConfig
+from iniparse.ini import EmptyLine
+from iniparse.compat import ConfigParser
+
+class test_tidy(unittest.TestCase):
+ def setUp(self):
+ self.cfg = INIConfig()
+
+ def test_empty_file(self):
+ self.assertEqual(str(self.cfg), '')
+ tidy(self.cfg)
+ self.assertEqual(str(self.cfg), '')
+
+ def test_last_line(self):
+ self.cfg.newsection.newproperty = "Ok"
+ self.assertEqual(str(self.cfg), dedent("""\
+ [newsection]
+ newproperty = Ok"""))
+ tidy(self.cfg)
+ self.assertEqual(str(self.cfg), dedent("""\
+ [newsection]
+ newproperty = Ok
+ """))
+
+ def test_first_line(self):
+ s = dedent("""\
+
+ [newsection]
+ newproperty = Ok
+ """)
+ self.cfg._readfp(StringIO(s))
+ tidy(self.cfg)
+ self.assertEqual(str(self.cfg), dedent("""\
+ [newsection]
+ newproperty = Ok
+ """))
+
+ def test_remove_newlines(self):
+ s = dedent("""\
+
+
+ [newsection]
+ newproperty = Ok
+
+
+
+
+ [newsection2]
+
+ newproperty2 = Ok
+
+
+ newproperty3 = yup
+
+
+ [newsection4]
+
+
+ # remove blank lines, but leave continuation lines unharmed
+
+ a = 1
+
+ b = l1
+ l2
+
+
+ # asdf
+ l5
+
+ c = 2
+
+
+ """)
+ self.cfg._readfp(StringIO(s))
+ tidy(self.cfg)
+ self.assertEqual(str(self.cfg), dedent("""\
+ [newsection]
+ newproperty = Ok
+
+ [newsection2]
+ newproperty2 = Ok
+
+ newproperty3 = yup
+
+ [newsection4]
+ # remove blank lines, but leave continuation lines unharmed
+
+ a = 1
+
+ b = l1
+ l2
+
+
+ # asdf
+ l5
+
+ c = 2
+ """))
+
+ def test_compat(self):
+ s = dedent("""
+ [sec1]
+ a=1
+
+
+ [sec2]
+
+ b=2
+
+ c=3
+
+
+ """)
+ cfg = ConfigParser()
+ cfg.readfp(StringIO(s))
+ tidy(cfg)
+ self.assertEqual(str(cfg.data), dedent("""\
+ [sec1]
+ a=1
+
+ [sec2]
+ b=2
+
+ c=3
+ """))
+
+
+class suite(unittest.TestSuite):
+ def __init__(self):
+ unittest.TestSuite.__init__(self, [
+ unittest.makeSuite(test_tidy, 'test'),
+ ])
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Remember to have fun...
--
To unsubscribe, e-mail: opensuse-commit+unsubscribe@opensuse.org
For additional commands, e-mail: opensuse-commit+help@opensuse.org