~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/config.py

  • Committer: Vincent Ladeuil
  • Date: 2011-09-02 14:30:23 UTC
  • mto: (6123.1.7 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6124.
  • Revision ID: v.ladeuil+lp@free.fr-20110902143023-61h8n8cm3r96lov9
Disable list_values for config.Store, using a dedicated configobj object to trigger the string -> list conversion on-demand (via the option registration) only.

Show diffs side-by-side

added added

removed removed

Lines of Context:
2422
2422
 
2423
2423
 
2424
2424
def list_from_store(unicode_str):
 
2425
    if not isinstance(unicode_str, basestring):
 
2426
        raise TypeError
 
2427
    # Use a an empty dict to initialize an empty configobj avoiding all
 
2428
    # parsing and encoding checks
 
2429
    c = ConfigObj({}, encoding='utf-8')
 
2430
    # Now inject our string directly as unicode All callers got their value
 
2431
    # from configobj, so values that need to be quoted are already properly
 
2432
    # quoted.
 
2433
    c._parse([u"list=%s" % (unicode_str,)])
 
2434
    co_list_or_not = c['list']
2425
2435
    # ConfigObj return '' instead of u''. Use 'str' below to catch all cases.
2426
 
    if isinstance(unicode_str, (str, unicode)):
2427
 
        if unicode_str:
 
2436
    if isinstance(co_list_or_not, basestring):
 
2437
        if co_list_or_not:
2428
2438
            # A single value, most probably the user forgot (or didn't care to
2429
2439
            # add) the final ','
2430
 
            l = [unicode_str]
 
2440
            l = [co_list_or_not]
2431
2441
        else:
2432
2442
            # The empty string, convert to empty list
2433
2443
            l = []
2434
2444
    else:
2435
2445
        # We rely on ConfigObj providing us with a list already
2436
 
        l = unicode_str
 
2446
        l = co_list_or_not
2437
2447
    return l
2438
2448
 
2439
2449
 
2705
2715
        co_input = StringIO(bytes)
2706
2716
        try:
2707
2717
            # The config files are always stored utf8-encoded
2708
 
            self._config_obj = ConfigObj(co_input, encoding='utf-8')
 
2718
            self._config_obj = ConfigObj(co_input, encoding='utf-8',
 
2719
                                         list_values=False)
2709
2720
        except configobj.ConfigObjError, e:
2710
2721
            self._config_obj = None
2711
2722
            raise errors.ParseConfigError(e.errors, self.external_url())