summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfuzzyman <devnull@localhost>2009-10-25 17:52:41 +0000
committerfuzzyman <devnull@localhost>2009-10-25 17:52:41 +0000
commitcead96333b2a8420906fc832be1f9805770e6c14 (patch)
treefa3bc62ed8e96528a34577a3cf2bb03f1c4d8f57
parent05c1e062a9e71fe63c7fed3709dfc22699d47f22 (diff)
downloadconfigobj-git-cead96333b2a8420906fc832be1f9805770e6c14.tar.gz
Fixing bugs.
-rw-r--r--configobj.py52
-rw-r--r--configobj.wpr4
-rw-r--r--docs/configobj.txt4
-rw-r--r--docs/validate.txt5
-rw-r--r--test_configobj.py15
-rw-r--r--validate.py2
6 files changed, 37 insertions, 45 deletions
diff --git a/configobj.py b/configobj.py
index ff2755c..0b0c514 100644
--- a/configobj.py
+++ b/configobj.py
@@ -31,22 +31,7 @@ except ImportError:
pass
-try:
- from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF16_BE, BOM_UTF16_LE
-except ImportError:
- # Python 2.2 does not have these
- # UTF-8
- BOM_UTF8 = '\xef\xbb\xbf'
- # UTF-16, little endian
- BOM_UTF16_LE = '\xff\xfe'
- # UTF-16, big endian
- BOM_UTF16_BE = '\xfe\xff'
- if sys.byteorder == 'little':
- # UTF-16, native endianness
- BOM_UTF16 = BOM_UTF16_LE
- else:
- # UTF-16, native endianness
- BOM_UTF16 = BOM_UTF16_BE
+from codecs import BOM_UTF8, BOM_UTF16, BOM_UTF16_BE, BOM_UTF16_LE
# A dictionary mapping BOM to
# the encoding to decode with, and what to set the
@@ -100,16 +85,6 @@ wspace_plus = ' \r\n\v\t\'"'
tsquot = '"""%s"""'
tdquot = "'''%s'''"
-try:
- enumerate
-except NameError:
- def enumerate(obj):
- """enumerate for Python 2.2."""
- i = -1
- for item in obj:
- i += 1
- yield i, item
-
# Sentinel for use in getattr calls to replace hasattr
MISSING = object()
@@ -2129,8 +2104,18 @@ class ConfigObj(Section):
#
configspec = section.configspec
self._set_configspec(section, copy)
+
def validate_entry(entry, spec, val, missing, ret_true, ret_false):
+ section.default_values.pop(entry, None)
+
+ try:
+ section.default_values[entry] = validator.get_default_value(configspec[entry])
+ except (KeyError, AttributeError, validator.baseErrorClass):
+ # No default, bad default or validator has no 'get_default_value'
+ # (e.g. SimpleVal)
+ pass
+
try:
check = validator.check(spec,
val,
@@ -2145,21 +2130,6 @@ class ConfigObj(Section):
ret_false = False
ret_true = False
else:
- try:
- section.default_values.pop(entry, None)
- except AttributeError:
- # For Python 2.2 compatibility
- try:
- del section.default_values[entry]
- except KeyError:
- pass
-
- try:
- section.default_values[entry] = validator.get_default_value(configspec[entry])
- except (KeyError, AttributeError):
- # No default or validator has no 'get_default_value' (e.g. SimpleVal)
- pass
-
ret_false = False
out[entry] = True
if self.stringify or missing:
diff --git a/configobj.wpr b/configobj.wpr
index b0d67f4..e61d18c 100644
--- a/configobj.wpr
+++ b/configobj.wpr
@@ -5,7 +5,9 @@
##################################################################
[project attributes]
proj.directory-list = [{'dirloc': loc('.'),
- 'excludes': (),
+ 'excludes': [u'configobj.py.orig',
+ u'configobj.py.rej',
+ u'configobj_speedup.patch'],
'filter': '*',
'include_hidden': False,
'recursive': True,
diff --git a/docs/configobj.txt b/docs/configobj.txt
index 31e7243..9d6786e 100644
--- a/docs/configobj.txt
+++ b/docs/configobj.txt
@@ -2339,7 +2339,9 @@ From version 4 it lists all releases and changes.
* Minimum supported version of Python is now 2.3
* ~25% performance improvement thanks to Christian Heimes
-* Removed __revision__ and __docformat__.
+* Removed __revision__ and __docformat__
+* BUGFIX: Checks that failed validation would not populate 'default_values' and
+ 'restore_default_value' wouldn't work.
2009/04/13 - Version 4.6.0
--------------------------
diff --git a/docs/validate.txt b/docs/validate.txt
index 5f5b153..a604c3b 100644
--- a/docs/validate.txt
+++ b/docs/validate.txt
@@ -611,6 +611,11 @@ to specify arguments for 'mixed_lists'.
CHANGELOG
=========
+2009/10/25 - Version 1.0.1
+--------------------------
+
+* BUGFIX: Fixed compatibility with Python 2.3.
+
2009/04/13 - Version 1.0.0
--------------------------
diff --git a/test_configobj.py b/test_configobj.py
index 2d105a0..f73517a 100644
--- a/test_configobj.py
+++ b/test_configobj.py
@@ -1197,7 +1197,20 @@ def _test_validate():
... 'test4': 6.0
... }}}
1
-
+ >>> a = ['foo = fish']
+ >>> b = ['foo = integer(default=3)']
+ >>> c = ConfigObj(a, configspec=b)
+ >>> c
+ ConfigObj({'foo': 'fish'})
+ >>> from validate import Validator
+ >>> v = Validator()
+ >>> c.validate(v)
+ 0
+ >>> c.default_values
+ {'foo': 3}
+ >>> c.restore_default('foo')
+ 3
+
Now testing with repeated sections : BIG TEST
>>> repeated_1 = '''
diff --git a/validate.py b/validate.py
index 30bdfac..904d294 100644
--- a/validate.py
+++ b/validate.py
@@ -620,7 +620,7 @@ class Validator(object):
fun_kwargs = dict(fun_kwargs)
else:
fun_name, fun_args, fun_kwargs, default = self._parse_check(check)
- fun_kwargs = dict((str(key), value) for (key, value) in fun_kwargs.items())
+ fun_kwargs = dict([(str(key), value) for (key, value) in fun_kwargs.items()])
self._cache[check] = fun_name, list(fun_args), dict(fun_kwargs), default
return fun_name, fun_args, fun_kwargs, default