~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: wang
  • Date: 2006-10-29 13:41:32 UTC
  • mto: (2104.4.1 wang_65714)
  • mto: This revision was merged to the branch mainline in revision 2109.
  • Revision ID: wang@ubuntu-20061029134132-3d7f4216f20c4aef
Replace python's difflib by patiencediff because the worst case 
performance is cubic for difflib and people commiting large data 
files are often hurt by this. The worst case performance of patience is 
quadratic. Fix bug 65714.

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):
1024
1024
            else:
1025
1025
                self.configspec = None
1026
1026
            return
1027
 
        elif hasattr(infile, 'read'):
 
1027
        elif getattr(infile, 'read', None) is not None:
1028
1028
            # This supports file like objects
1029
1029
            infile = infile.read() or []
1030
1030
            # needs splitting into lines - but needs doing *after* decoding
1344
1344
                        NestingError, infile, cur_index)
1345
1345
                #
1346
1346
                sect_name = self._unquote(sect_name)
1347
 
                if parent.has_key(sect_name):
 
1347
                if sect_name in parent:
1348
1348
##                    print >> sys.stderr, sect_name
1349
1349
                    self._handle_error(
1350
1350
                        'Duplicate section name at line %s.',
1394
1394
                #
1395
1395
##                print >> sys.stderr, sline
1396
1396
                key = self._unquote(key)
1397
 
                if this_section.has_key(key):
 
1397
                if key in this_section:
1398
1398
                    self._handle_error(
1399
1399
                        'Duplicate keyword name at line %s.',
1400
1400
                        DuplicateError, infile, cur_index)
1745
1745
        for entry in configspec.sections:
1746
1746
            if entry == '__many__':
1747
1747
                continue
1748
 
            if not section.has_key(entry):
 
1748
            if entry not in section:
1749
1749
                section[entry] = {}
1750
1750
            self._set_configspec_value(configspec[entry], section[entry])
1751
1751
 
1776
1776
        #
1777
1777
        section.configspec = scalars
1778
1778
        for entry in sections:
1779
 
            if not section.has_key(entry):
 
1779
            if entry not in section:
1780
1780
                section[entry] = {}
1781
1781
            self._handle_repeat(section[entry], sections[entry])
1782
1782
 
2852
2852
    >>> uc2 = ConfigObj(file_like)
2853
2853
    >>> uc2 == uc
2854
2854
    1
2855
 
    >>> uc2.filename == None
 
2855
    >>> uc2.filename is None
2856
2856
    1
2857
2857
    >>> uc2.newlines == '\\r'
2858
2858
    1