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 not self.comments.has_key(key):
356
if key not in self.comments:
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
... print >> sys.stderr, type(entry)
681
... sys.stderr.write(type(entry))
682
... sys.stderr.write('\n')
682
683
... raise AssertionError, 'decode failed.'
683
684
... if isinstance(val[entry], dict):
684
685
... testuni(val[entry])
1025
1026
self.configspec = None
1027
elif hasattr(infile, 'read'):
1028
elif getattr(infile, 'read', None) is not None:
1028
1029
# This supports file like objects
1029
1030
infile = infile.read() or []
1030
1031
# needs splitting into lines - but needs doing *after* decoding
1308
1309
reset_comment = True
1309
1310
# first we check if it's a section marker
1310
1311
mat = self._sectionmarker.match(line)
1311
## print >> sys.stderr, sline, mat
1312
## sys.stderr.write('%s %s\n' % (sline, mat))
1312
1313
if mat is not None:
1313
1314
# is a section line
1314
1315
(indent, sect_open, sect_name, sect_close, comment) = (
1344
1345
NestingError, infile, cur_index)
1346
1347
sect_name = self._unquote(sect_name)
1347
if parent.has_key(sect_name):
1348
## print >> sys.stderr, sect_name
1348
if sect_name in parent:
1349
## sys.stderr.write(sect_name)
1350
## sys.stderr.write('\n')
1349
1351
self._handle_error(
1350
1352
'Duplicate section name at line %s.',
1351
1353
DuplicateError, infile, cur_index)
1359
1361
parent[sect_name] = this_section
1360
1362
parent.inline_comments[sect_name] = comment
1361
1363
parent.comments[sect_name] = comment_list
1362
## print >> sys.stderr, parent[sect_name] is this_section
1364
## sys.stderr.write(parent[sect_name] is this_section)
1365
## sys.stderr.write('\n')
1365
1368
# it's not a section marker,
1366
1369
# so it should be a valid ``key = value`` line
1367
1370
mat = self._keyword.match(line)
1368
## print >> sys.stderr, sline, mat
1371
## sys.stderr.write('%s %s\n' % (sline, mat))
1369
1372
if mat is not None:
1370
1373
# is a keyword value
1371
1374
# value will include any inline comment
1392
1395
ParseError, infile, cur_index)
1395
## print >> sys.stderr, sline
1398
## sys.stderr.write(sline)
1399
## sys.stderr.write('\n')
1396
1400
key = self._unquote(key)
1397
if this_section.has_key(key):
1401
if key in this_section:
1398
1402
self._handle_error(
1399
1403
'Duplicate keyword name at line %s.',
1400
1404
DuplicateError, infile, cur_index)
1403
## print >> sys.stderr, this_section.name
1407
## sys.stderr.write(this_section.name + '\n')
1404
1408
this_section[key] = value
1405
1409
this_section.inline_comments[key] = comment
1406
1410
this_section.comments[key] = comment_list
1407
## print >> sys.stderr, key, this_section[key]
1411
## sys.stderr.write('%s %s\n' % (key, this_section[key]))
1408
1412
## if this_section.name is not None:
1409
## print >> sys.stderr, this_section
1410
## print >> sys.stderr, this_section.parent
1411
## print >> sys.stderr, this_section.parent[this_section.name]
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')
1414
1419
# it neither matched as a keyword
2008
2014
... from validate import Validator
2009
2015
... except ImportError:
2010
... print >> sys.stderr, 'Cannot import the Validator object, skipping the related tests'
2016
... sys.stderr.write('Cannot import the Validator object, skipping the related tests\n')
2012
2018
... config = '''