Rev 6092: Tweaks suggested by jam during review. in file:///home/vila/src/bzr/experimental/expand-in-stack/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Fri Sep 2 06:21:33 UTC 2011
At file:///home/vila/src/bzr/experimental/expand-in-stack/
------------------------------------------------------------
revno: 6092
revision-id: v.ladeuil+lp at free.fr-20110902062132-dq9y0slcwe28op73
parent: v.ladeuil+lp at free.fr-20110829141650-mydqd8d3mloo7dwq
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: expand-in-stack
timestamp: Fri 2011-09-02 08:21:32 +0200
message:
Tweaks suggested by jam during review.
-------------- next part --------------
=== modified file 'bzrlib/config.py'
--- a/bzrlib/config.py 2011-08-29 14:16:50 +0000
+++ b/bzrlib/config.py 2011-09-02 06:21:32 +0000
@@ -75,7 +75,6 @@
import os
import string
import sys
-import re
from bzrlib.decorators import needs_write_lock
@@ -107,6 +106,7 @@
from bzrlib import (
commands,
hooks,
+ lazy_regex,
registry,
)
from bzrlib.symbol_versioning import (
@@ -2968,6 +2968,15 @@
class Stack(object):
"""A stack of configurations where an option can be defined"""
+ _option_ref_re = lazy_regex.lazy_compile('({[^{}]+})')
+ """Describes an exandable option reference.
+
+ We want to match the most embedded reference first.
+
+ I.e. for '{{foo}}' we will get '{foo}',
+ for '{bar{baz}}' we will get '{baz}'
+ """
+
def __init__(self, sections_def, store=None, mutable_section_name=None):
"""Creates a stack of sections with an optional store for changes.
@@ -2985,9 +2994,6 @@
self.sections_def = sections_def
self.store = store
self.mutable_section_name = mutable_section_name
- # Used to describe an expandable option reference (see
- # _expand_options_in_string)
- self._option_ref_re = None
def get(self, name, expand=None):
"""Return the *first* option value found in the sections.
@@ -3039,7 +3045,7 @@
if opt is not None and value is not None:
value = opt.convert_from_unicode(value)
if value is None:
- # The conversion failed fallback to the default value
+ # The conversion failed, fallback to the default value
value = opt.get_default()
if expand:
value = self._expand_option_value(value)
@@ -3114,16 +3120,11 @@
if _refs is None:
# What references are currently resolved (to detect loops)
_refs = []
- if self._option_ref_re is None:
- # We want to match the most embedded reference first (i.e. for
- # '{{foo}}' we will get '{foo}',
- # for '{bar{baz}}' we will get '{baz}'
- self._option_ref_re = re.compile('({[^{}]+})')
result = string
# We need to iterate until no more refs appear ({{foo}} will need two
# iterations for example).
while True:
- raw_chunks = self._option_ref_re.split(result)
+ raw_chunks = Stack._option_ref_re.split(result)
if len(raw_chunks) == 1:
# Shorcut the trivial case: no refs
return result
=== modified file 'bzrlib/tests/test_config.py'
--- a/bzrlib/tests/test_config.py 2011-08-29 12:59:56 +0000
+++ b/bzrlib/tests/test_config.py 2011-09-02 06:21:32 +0000
@@ -2435,6 +2435,7 @@
opt = self.get_option()
self.assertConverted(16, opt, u'16')
+
class TestOptionWithListConverter(tests.TestCase, TestOptionConverterMixin):
def get_option(self):
More information about the bazaar-commits
mailing list