353
353
if not isinstance(key, StringTypes):
354
354
raise ValueError, 'The key "%s" is not a string.' % key
355
355
# add the comment
356
if key not in self.comments:
356
if not self.comments.has_key(key):
357
357
self.comments[key] = []
358
358
self.inline_comments[key] = ''
359
359
# remove the entry from defaults
361
361
self.defaults.remove(key)
363
363
if isinstance(value, Section):
364
if not self.has_key(key):
365
365
self.sections.append(key)
366
366
dict.__setitem__(self, key, value)
367
367
elif isinstance(value, dict):
368
368
# First create the new depth level,
369
369
# then create the section
370
if not self.has_key(key):
371
371
self.sections.append(key)
372
372
new_depth = self.depth + 1
373
373
dict.__setitem__(
678
678
>>> def testuni(val):
679
679
... for entry in val:
680
680
... if not isinstance(entry, unicode):
681
... sys.stderr.write(type(entry))
682
... sys.stderr.write('\n')
681
... print >> sys.stderr, type(entry)
683
682
... raise AssertionError, 'decode failed.'
684
683
... if isinstance(val[entry], dict):
685
684
... testuni(val[entry])
1026
1025
self.configspec = None
1028
elif getattr(infile, 'read', None) is not None:
1027
elif hasattr(infile, 'read'):
1029
1028
# This supports file like objects
1030
1029
infile = infile.read() or []
1031
1030
# needs splitting into lines - but needs doing *after* decoding
1309
1308
reset_comment = True
1310
1309
# first we check if it's a section marker
1311
1310
mat = self._sectionmarker.match(line)
1312
## sys.stderr.write('%s %s\n' % (sline, mat))
1311
## print >> sys.stderr, sline, mat
1313
1312
if mat is not None:
1314
1313
# is a section line
1315
1314
(indent, sect_open, sect_name, sect_close, comment) = (
1345
1344
NestingError, infile, cur_index)
1347
1346
sect_name = self._unquote(sect_name)
1348
if sect_name in parent:
1349
## sys.stderr.write(sect_name)
1350
## sys.stderr.write('\n')
1347
if parent.has_key(sect_name):
1348
## print >> sys.stderr, sect_name
1351
1349
self._handle_error(
1352
1350
'Duplicate section name at line %s.',
1353
1351
DuplicateError, infile, cur_index)
1361
1359
parent[sect_name] = this_section
1362
1360
parent.inline_comments[sect_name] = comment
1363
1361
parent.comments[sect_name] = comment_list
1364
## sys.stderr.write(parent[sect_name] is this_section)
1365
## sys.stderr.write('\n')
1362
## print >> sys.stderr, parent[sect_name] is this_section
1368
1365
# it's not a section marker,
1369
1366
# so it should be a valid ``key = value`` line
1370
1367
mat = self._keyword.match(line)
1371
## sys.stderr.write('%s %s\n' % (sline, mat))
1368
## print >> sys.stderr, sline, mat
1372
1369
if mat is not None:
1373
1370
# is a keyword value
1374
1371
# value will include any inline comment
1395
1392
ParseError, infile, cur_index)
1398
## sys.stderr.write(sline)
1399
## sys.stderr.write('\n')
1395
## print >> sys.stderr, sline
1400
1396
key = self._unquote(key)
1401
if key in this_section:
1397
if this_section.has_key(key):
1402
1398
self._handle_error(
1403
1399
'Duplicate keyword name at line %s.',
1404
1400
DuplicateError, infile, cur_index)
1407
## sys.stderr.write(this_section.name + '\n')
1403
## print >> sys.stderr, this_section.name
1408
1404
this_section[key] = value
1409
1405
this_section.inline_comments[key] = comment
1410
1406
this_section.comments[key] = comment_list
1411
## sys.stderr.write('%s %s\n' % (key, this_section[key]))
1407
## print >> sys.stderr, key, this_section[key]
1412
1408
## if this_section.name is not None:
1413
## sys.stderr.write(this_section + '\n')
1414
## sys.stderr.write(this_section.parent + '\n')
1415
## sys.stderr.write(this_section.parent[this_section.name])
1416
## sys.stderr.write('\n')
1409
## print >> sys.stderr, this_section
1410
## print >> sys.stderr, this_section.parent
1411
## print >> sys.stderr, this_section.parent[this_section.name]
1419
1414
# it neither matched as a keyword
2014
2008
... from validate import Validator
2015
2009
... except ImportError:
2016
... sys.stderr.write('Cannot import the Validator object, skipping the related tests\n')
2010
... print >> sys.stderr, 'Cannot import the Validator object, skipping the related tests'
2018
2012
... config = '''