/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/util/configobj/configobj.py

(John Arbash Meinel)  Fix bug #158333,
        make sure that Repository.fetch(self) is properly a no-op for all
        Repository implementations.

Show diffs side-by-side

added added

removed removed

Lines of Context:
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)
362
362
        #
363
363
        if isinstance(value, Section):
364
 
            if not self.has_key(key):
 
364
            if key not in self:
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):
 
370
            if key not in self:
371
371
                self.sections.append(key)
372
372
            new_depth = self.depth + 1
373
373
            dict.__setitem__(
380
380
                    indict=value,
381
381
                    name=key))
382
382
        else:
383
 
            if not self.has_key(key):
 
383
            if key not in self:
384
384
                self.scalars.append(key)
385
385
            if not self.main.stringify:
386
386
                if isinstance(value, StringTypes):
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])
1024
1025
            else:
1025
1026
                self.configspec = None
1026
1027
            return
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)
1345
1346
                #
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')
1363
1366
                continue
1364
1367
            #
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)
1393
1396
                        continue
1394
1397
                #
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)
1401
1405
                    continue
1402
1406
                # add the key
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')
1412
1417
                continue
1413
1418
            #
1414
1419
            # it neither matched as a keyword
1451
1456
        The error will have occured at ``cur_index``
1452
1457
        """
1453
1458
        line = infile[cur_index]
 
1459
        cur_index += 1
1454
1460
        message = text % cur_index
1455
1461
        error = ErrorClass(message, cur_index, line)
1456
1462
        if self.raise_errors:
1745
1751
        for entry in configspec.sections:
1746
1752
            if entry == '__many__':
1747
1753
                continue
1748
 
            if not section.has_key(entry):
 
1754
            if entry not in section:
1749
1755
                section[entry] = {}
1750
1756
            self._set_configspec_value(configspec[entry], section[entry])
1751
1757
 
1776
1782
        #
1777
1783
        section.configspec = scalars
1778
1784
        for entry in sections:
1779
 
            if not section.has_key(entry):
 
1785
            if entry not in section:
1780
1786
                section[entry] = {}
1781
1787
            self._handle_repeat(section[entry], sections[entry])
1782
1788
 
2007
2013
        >>> try:
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')
2011
2017
        ... else:
2012
2018
        ...     config = '''
2013
2019
        ...     test1=40
2852
2858
    >>> uc2 = ConfigObj(file_like)
2853
2859
    >>> uc2 == uc
2854
2860
    1
2855
 
    >>> uc2.filename == None
 
2861
    >>> uc2.filename is None
2856
2862
    1
2857
2863
    >>> uc2.newlines == '\\r'
2858
2864
    1